Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

212 wiersze
3.9 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. #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 import.c
  55. */
  56. cucul_canvas_t * cucul_import_canvas(cucul_buffer_t *buf, char const *format)
  57. {
  58. cucul_canvas_t *cv = cucul_create_canvas(0, 0);
  59. int ret = cucul_import_memory(cv, (unsigned char const *)buf->data,
  60. buf->size, format);
  61. if(ret < 0)
  62. {
  63. cucul_free_canvas(cv);
  64. return NULL;
  65. }
  66. return cv;
  67. }
  68. /*
  69. * Functions from export.c
  70. */
  71. cucul_buffer_t * cucul_export_canvas(cucul_canvas_t *cv, char const *format)
  72. {
  73. cucul_buffer_t *ex;
  74. ex = malloc(sizeof(cucul_buffer_t));
  75. if(!ex)
  76. {
  77. seterrno(ENOMEM);
  78. return NULL;
  79. }
  80. ex->data = cucul_export_memory(cv, format, &ex->size);
  81. if(!ex->data)
  82. {
  83. free(ex);
  84. return NULL;
  85. }
  86. ex->user_data = 0;
  87. return ex;
  88. }
  89. /*
  90. * Functions from frame.c
  91. */
  92. unsigned int cucul_get_canvas_frame_count(cucul_canvas_t *cv)
  93. {
  94. return cucul_get_frame_count(cv);
  95. }
  96. int cucul_set_canvas_frame(cucul_canvas_t *cv, unsigned int id)
  97. {
  98. return cucul_set_frame(cv, id);
  99. }
  100. int cucul_create_canvas_frame(cucul_canvas_t *cv, unsigned int id)
  101. {
  102. return cucul_create_frame(cv, id);
  103. }
  104. int cucul_free_canvas_frame(cucul_canvas_t *cv, unsigned int id)
  105. {
  106. return cucul_free_frame(cv, id);
  107. }
  108. /*
  109. * Functions from buffer.c
  110. */
  111. cucul_buffer_t *cucul_load_memory(void *data, unsigned long int size)
  112. {
  113. cucul_buffer_t *buf;
  114. buf = malloc(sizeof(cucul_buffer_t));
  115. if(!buf)
  116. return NULL;
  117. buf->data = data;
  118. buf->size = size;
  119. buf->user_data = 1;
  120. return buf;
  121. }
  122. #if !defined(__KERNEL__)
  123. cucul_buffer_t *cucul_load_file(char const *file)
  124. {
  125. cucul_buffer_t *buf;
  126. FILE *fp;
  127. long int size;
  128. fp = fopen(file, "rb");
  129. if(!fp)
  130. return NULL;
  131. buf = malloc(sizeof(cucul_buffer_t));
  132. if(!buf)
  133. {
  134. fclose(fp);
  135. return NULL;
  136. }
  137. fseek(fp, 0, SEEK_END);
  138. size = ftell(fp);
  139. buf->data = malloc(size);
  140. if(!buf->data)
  141. {
  142. free(buf);
  143. fclose(fp);
  144. return NULL;
  145. }
  146. buf->size = size;
  147. buf->user_data = 0;
  148. fseek(fp, 0, SEEK_SET);
  149. fread(buf->data, buf->size, 1, fp);
  150. fclose(fp);
  151. return buf;
  152. }
  153. #endif
  154. unsigned long int cucul_get_buffer_size(cucul_buffer_t *buf)
  155. {
  156. return buf->size;
  157. }
  158. void * cucul_get_buffer_data(cucul_buffer_t *buf)
  159. {
  160. return buf->data;
  161. }
  162. int cucul_free_buffer(cucul_buffer_t *buf)
  163. {
  164. if(!buf->user_data)
  165. free(buf->data);
  166. free(buf);
  167. return 0;
  168. }