Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. #include "common.h"
  20. #if !defined(__KERNEL__)
  21. # include <stdio.h>
  22. # include <stdlib.h>
  23. # include <string.h>
  24. #endif
  25. #include "cucul.h"
  26. #include "cucul_internals.h"
  27. /*
  28. * Functions from canvas.c
  29. */
  30. int cucul_putchar(cucul_canvas_t *cv, int x, int y, unsigned long int ch)
  31. {
  32. return cucul_put_char(cv, x, y, ch);
  33. }
  34. unsigned long int cucul_getchar(cucul_canvas_t *cv, int x, int y)
  35. {
  36. return cucul_get_char(cv, x, y);
  37. }
  38. int cucul_putstr(cucul_canvas_t *cv, int x, int y, char const *s)
  39. {
  40. return cucul_put_str(cv, x, y, s);
  41. }
  42. /*
  43. * Functions from color.c
  44. */
  45. int cucul_set_color(cucul_canvas_t *cv, unsigned char fg, unsigned char bg)
  46. {
  47. return cucul_set_color_ansi(cv, fg, bg);
  48. }
  49. int cucul_set_truecolor(cucul_canvas_t *cv, unsigned int fg, unsigned int bg)
  50. {
  51. return cucul_set_color_argb(cv, fg, bg);
  52. }
  53. /*
  54. * Functions from dither.c
  55. */
  56. int cucul_set_dither_invert(cucul_dither_t *d, int value)
  57. {
  58. float gamma = cucul_get_dither_gamma(d);
  59. if(gamma * (value ? -1 : 1) < 0)
  60. cucul_set_dither_gamma(d, -gamma);
  61. return 0;
  62. }
  63. int cucul_set_dither_mode(cucul_dither_t *d, char const *s)
  64. {
  65. return cucul_set_dither_algorithm(d, s);
  66. }
  67. char const * const * cucul_get_dither_mode_list(cucul_dither_t const *d)
  68. {
  69. return cucul_get_dither_algorithm_list(d);
  70. }
  71. /*
  72. * Functions from import.c
  73. */
  74. cucul_canvas_t * cucul_import_canvas(cucul_buffer_t *buf, char const *format)
  75. {
  76. cucul_canvas_t *cv = cucul_create_canvas(0, 0);
  77. int ret = cucul_import_memory(cv, (unsigned char const *)buf->data,
  78. buf->size, format);
  79. if(ret < 0)
  80. {
  81. cucul_free_canvas(cv);
  82. return NULL;
  83. }
  84. return cv;
  85. }
  86. /*
  87. * Functions from export.c
  88. */
  89. cucul_buffer_t * cucul_export_canvas(cucul_canvas_t *cv, char const *format)
  90. {
  91. cucul_buffer_t *ex;
  92. ex = malloc(sizeof(cucul_buffer_t));
  93. if(!ex)
  94. {
  95. seterrno(ENOMEM);
  96. return NULL;
  97. }
  98. ex->data = cucul_export_memory(cv, format, &ex->size);
  99. if(!ex->data)
  100. {
  101. free(ex);
  102. return NULL;
  103. }
  104. ex->user_data = 0;
  105. return ex;
  106. }
  107. /*
  108. * Functions from frame.c
  109. */
  110. unsigned int cucul_get_canvas_frame_count(cucul_canvas_t *cv)
  111. {
  112. return cucul_get_frame_count(cv);
  113. }
  114. int cucul_set_canvas_frame(cucul_canvas_t *cv, unsigned int id)
  115. {
  116. return cucul_set_frame(cv, id);
  117. }
  118. int cucul_create_canvas_frame(cucul_canvas_t *cv, unsigned int id)
  119. {
  120. return cucul_create_frame(cv, id);
  121. }
  122. int cucul_free_canvas_frame(cucul_canvas_t *cv, unsigned int id)
  123. {
  124. return cucul_free_frame(cv, id);
  125. }
  126. /*
  127. * Functions from buffer.c
  128. */
  129. cucul_buffer_t *cucul_load_memory(void *data, unsigned long int size)
  130. {
  131. cucul_buffer_t *buf;
  132. buf = malloc(sizeof(cucul_buffer_t));
  133. if(!buf)
  134. return NULL;
  135. buf->data = data;
  136. buf->size = size;
  137. buf->user_data = 1;
  138. return buf;
  139. }
  140. #if !defined(__KERNEL__)
  141. cucul_buffer_t *cucul_load_file(char const *file)
  142. {
  143. cucul_buffer_t *buf;
  144. FILE *fp;
  145. long int size;
  146. fp = fopen(file, "rb");
  147. if(!fp)
  148. return NULL;
  149. buf = malloc(sizeof(cucul_buffer_t));
  150. if(!buf)
  151. {
  152. fclose(fp);
  153. return NULL;
  154. }
  155. fseek(fp, 0, SEEK_END);
  156. size = ftell(fp);
  157. buf->data = malloc(size);
  158. if(!buf->data)
  159. {
  160. free(buf);
  161. fclose(fp);
  162. return NULL;
  163. }
  164. buf->size = size;
  165. buf->user_data = 0;
  166. fseek(fp, 0, SEEK_SET);
  167. fread(buf->data, buf->size, 1, fp);
  168. fclose(fp);
  169. return buf;
  170. }
  171. #endif
  172. unsigned long int cucul_get_buffer_size(cucul_buffer_t *buf)
  173. {
  174. return buf->size;
  175. }
  176. void * cucul_get_buffer_data(cucul_buffer_t *buf)
  177. {
  178. return buf->data;
  179. }
  180. int cucul_free_buffer(cucul_buffer_t *buf)
  181. {
  182. if(!buf->user_data)
  183. free(buf->data);
  184. free(buf);
  185. return 0;
  186. }
  187. /*
  188. * Functions from transform.c
  189. */
  190. int cucul_rotate(cucul_canvas_t *cv)
  191. {
  192. return cucul_rotate_180(cv);
  193. }