You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

243 line
4.4 KiB

  1. /*
  2. * libcucul Canvas for ultrafast compositing of Unicode letters
  3. * Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  7. *
  8. * This library is free software. It comes without any warranty, to
  9. * the extent permitted by applicable law. You can redistribute it
  10. * and/or modify it under the terms of the Do What The Fuck You Want
  11. * To Public License, Version 2, as published by Sam Hocevar. See
  12. * http://sam.zoy.org/wtfpl/COPYING for more details.
  13. */
  14. /*
  15. * This file contains legacy functions that we keep around until all
  16. * applications are ported.
  17. */
  18. #include "config.h"
  19. #if !defined(__KERNEL__)
  20. # include <stdio.h>
  21. # include <stdlib.h>
  22. # include <string.h>
  23. #endif
  24. #include "cucul.h"
  25. #include "cucul_internals.h"
  26. /*
  27. * Functions from canvas.c
  28. */
  29. int cucul_putchar(cucul_canvas_t *cv, int x, int y, unsigned long int ch)
  30. {
  31. return cucul_put_char(cv, x, y, ch);
  32. }
  33. unsigned long int cucul_getchar(cucul_canvas_t *cv, int x, int y)
  34. {
  35. return cucul_get_char(cv, x, y);
  36. }
  37. int cucul_putstr(cucul_canvas_t *cv, int x, int y, char const *s)
  38. {
  39. return cucul_put_str(cv, x, y, s);
  40. }
  41. /*
  42. * Functions from color.c
  43. */
  44. int cucul_set_color(cucul_canvas_t *cv, unsigned char fg, unsigned char bg)
  45. {
  46. return cucul_set_color_ansi(cv, fg, bg);
  47. }
  48. int cucul_set_truecolor(cucul_canvas_t *cv, unsigned int fg, unsigned int bg)
  49. {
  50. return cucul_set_color_argb(cv, fg, bg);
  51. }
  52. /*
  53. * Functions from dither.c
  54. */
  55. int cucul_set_dither_invert(cucul_dither_t *d, int value)
  56. {
  57. float gamma = cucul_get_dither_gamma(d);
  58. if(gamma * (value ? -1 : 1) < 0)
  59. cucul_set_dither_gamma(d, -gamma);
  60. return 0;
  61. }
  62. int cucul_set_dither_mode(cucul_dither_t *d, char const *s)
  63. {
  64. return cucul_set_dither_algorithm(d, s);
  65. }
  66. char const * const * cucul_get_dither_mode_list(cucul_dither_t const *d)
  67. {
  68. return cucul_get_dither_algorithm_list(d);
  69. }
  70. /*
  71. * Functions from import.c
  72. */
  73. cucul_canvas_t * cucul_import_canvas(cucul_buffer_t *buf, char const *format)
  74. {
  75. cucul_canvas_t *cv = cucul_create_canvas(0, 0);
  76. int ret = cucul_import_memory(cv, (unsigned char const *)buf->data,
  77. buf->size, format);
  78. if(ret < 0)
  79. {
  80. cucul_free_canvas(cv);
  81. return NULL;
  82. }
  83. return cv;
  84. }
  85. /*
  86. * Functions from export.c
  87. */
  88. cucul_buffer_t * cucul_export_canvas(cucul_canvas_t *cv, char const *format)
  89. {
  90. cucul_buffer_t *ex;
  91. ex = malloc(sizeof(cucul_buffer_t));
  92. if(!ex)
  93. {
  94. seterrno(ENOMEM);
  95. return NULL;
  96. }
  97. ex->data = cucul_export_memory(cv, format, &ex->size);
  98. if(!ex->data)
  99. {
  100. free(ex);
  101. return NULL;
  102. }
  103. ex->user_data = 0;
  104. return ex;
  105. }
  106. /*
  107. * Functions from frame.c
  108. */
  109. unsigned int cucul_get_canvas_frame_count(cucul_canvas_t *cv)
  110. {
  111. return cucul_get_frame_count(cv);
  112. }
  113. int cucul_set_canvas_frame(cucul_canvas_t *cv, unsigned int id)
  114. {
  115. return cucul_set_frame(cv, id);
  116. }
  117. int cucul_create_canvas_frame(cucul_canvas_t *cv, unsigned int id)
  118. {
  119. return cucul_create_frame(cv, id);
  120. }
  121. int cucul_free_canvas_frame(cucul_canvas_t *cv, unsigned int id)
  122. {
  123. return cucul_free_frame(cv, id);
  124. }
  125. /*
  126. * Functions from buffer.c
  127. */
  128. cucul_buffer_t *cucul_load_memory(void *data, unsigned long int size)
  129. {
  130. cucul_buffer_t *buf;
  131. buf = malloc(sizeof(cucul_buffer_t));
  132. if(!buf)
  133. return NULL;
  134. buf->data = data;
  135. buf->size = size;
  136. buf->user_data = 1;
  137. return buf;
  138. }
  139. #if !defined(__KERNEL__)
  140. cucul_buffer_t *cucul_load_file(char const *file)
  141. {
  142. cucul_buffer_t *buf;
  143. FILE *fp;
  144. long int size;
  145. fp = fopen(file, "rb");
  146. if(!fp)
  147. return NULL;
  148. buf = malloc(sizeof(cucul_buffer_t));
  149. if(!buf)
  150. {
  151. fclose(fp);
  152. return NULL;
  153. }
  154. fseek(fp, 0, SEEK_END);
  155. size = ftell(fp);
  156. buf->data = malloc(size);
  157. if(!buf->data)
  158. {
  159. free(buf);
  160. fclose(fp);
  161. return NULL;
  162. }
  163. buf->size = size;
  164. buf->user_data = 0;
  165. fseek(fp, 0, SEEK_SET);
  166. fread(buf->data, buf->size, 1, fp);
  167. fclose(fp);
  168. return buf;
  169. }
  170. #endif
  171. unsigned long int cucul_get_buffer_size(cucul_buffer_t *buf)
  172. {
  173. return buf->size;
  174. }
  175. void * cucul_get_buffer_data(cucul_buffer_t *buf)
  176. {
  177. return buf->data;
  178. }
  179. int cucul_free_buffer(cucul_buffer_t *buf)
  180. {
  181. if(!buf->user_data)
  182. free(buf->data);
  183. free(buf);
  184. return 0;
  185. }
  186. /*
  187. * Functions from transform.c
  188. */
  189. int cucul_rotate(cucul_canvas_t *cv)
  190. {
  191. return cucul_rotate_180(cv);
  192. }