Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

187 lignes
3.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; you can redistribute it and/or
  9. * modify it under the terms of the Do What The Fuck You Want To
  10. * Public License, Version 2, as published by Sam Hocevar. See
  11. * http://sam.zoy.org/wtfpl/COPYING for more details.
  12. */
  13. /*
  14. * This file contains legacy functions that we keep around until all
  15. * applications are ported.
  16. */
  17. #include "config.h"
  18. #include "common.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 import.c
  54. */
  55. cucul_canvas_t * cucul_import_canvas(cucul_buffer_t *buf, char const *format)
  56. {
  57. cucul_canvas_t *cv = cucul_create_canvas(0, 0);
  58. int ret = cucul_import_memory(cv, (unsigned char const *)buf->data,
  59. buf->size, format);
  60. if(ret < 0)
  61. {
  62. cucul_free_canvas(cv);
  63. return NULL;
  64. }
  65. return cv;
  66. }
  67. /*
  68. * Functions from export.c
  69. */
  70. cucul_buffer_t * cucul_export_canvas(cucul_canvas_t *cv, char const *format)
  71. {
  72. cucul_buffer_t *ex;
  73. ex = malloc(sizeof(cucul_buffer_t));
  74. if(!ex)
  75. {
  76. seterrno(ENOMEM);
  77. return NULL;
  78. }
  79. ex->data = cucul_export_memory(cv, format, &ex->size);
  80. if(!ex->data)
  81. {
  82. free(ex);
  83. return NULL;
  84. }
  85. ex->user_data = 0;
  86. return ex;
  87. }
  88. /*
  89. * Functions from buffer.c
  90. */
  91. cucul_buffer_t *cucul_load_memory(void *data, unsigned long int size)
  92. {
  93. cucul_buffer_t *buf;
  94. buf = malloc(sizeof(cucul_buffer_t));
  95. if(!buf)
  96. return NULL;
  97. buf->data = data;
  98. buf->size = size;
  99. buf->user_data = 1;
  100. return buf;
  101. }
  102. #if !defined(__KERNEL__)
  103. cucul_buffer_t *cucul_load_file(char const *file)
  104. {
  105. cucul_buffer_t *buf;
  106. FILE *fp;
  107. long int size;
  108. fp = fopen(file, "rb");
  109. if(!fp)
  110. return NULL;
  111. buf = malloc(sizeof(cucul_buffer_t));
  112. if(!buf)
  113. {
  114. fclose(fp);
  115. return NULL;
  116. }
  117. fseek(fp, 0, SEEK_END);
  118. size = ftell(fp);
  119. buf->data = malloc(size);
  120. if(!buf->data)
  121. {
  122. free(buf);
  123. fclose(fp);
  124. return NULL;
  125. }
  126. buf->size = size;
  127. buf->user_data = 0;
  128. fseek(fp, 0, SEEK_SET);
  129. fread(buf->data, buf->size, 1, fp);
  130. fclose(fp);
  131. return buf;
  132. }
  133. #endif
  134. unsigned long int cucul_get_buffer_size(cucul_buffer_t *buf)
  135. {
  136. return buf->size;
  137. }
  138. void * cucul_get_buffer_data(cucul_buffer_t *buf)
  139. {
  140. return buf->data;
  141. }
  142. int cucul_free_buffer(cucul_buffer_t *buf)
  143. {
  144. if(!buf->user_data)
  145. free(buf->data);
  146. free(buf);
  147. return 0;
  148. }