Changeset 1302 for libcaca/trunk
- Timestamp:
- Nov 8, 2006, 1:11:07 PM (16 years ago)
- Location:
- libcaca/trunk/cucul
- Files:
-
- 5 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/cucul/Makefile.am
r977 r1302 15 15 cucul.h \ 16 16 cucul_internals.h \ 17 buffer.c \17 legacy.c \ 18 18 canvas.c \ 19 19 transform.c \ -
libcaca/trunk/cucul/colour.c
r1270 r1302 137 137 } 138 138 139 /* Legacy function for old programs */140 int cucul_set_color(cucul_canvas_t *cv, unsigned char fg, unsigned char bg)141 {142 return cucul_set_color_ansi(cv, fg, bg);143 }144 145 139 /** \brief Set the default colour pair for text (truecolor version). 146 140 * … … 186 180 187 181 return 0; 188 }189 190 /* Legacy function for old programs */191 int cucul_set_truecolor(cucul_canvas_t *cv, unsigned int fg, unsigned int bg)192 {193 return cucul_set_color_argb(cv, fg, bg);194 182 } 195 183 -
libcaca/trunk/cucul/cucul.h
r1273 r1302 36 36 /** dither structure */ 37 37 typedef struct cucul_dither cucul_dither_t; 38 /** data buffer structure */39 typedef struct cucul_buffer cucul_buffer_t;40 38 /** font structure */ 41 39 typedef struct cucul_font cucul_font_t; … … 83 81 int cucul_free_canvas(cucul_canvas_t *); 84 82 int cucul_rand(int, int); 85 /* @} */86 87 /** \defgroup buffer libcucul buffer handling88 *89 * These functions provide methods to handle libcucul buffers.90 *91 * @{ */92 cucul_buffer_t *cucul_load_memory(void *, unsigned long int);93 cucul_buffer_t *cucul_load_file(char const *);94 unsigned long int cucul_get_buffer_size(cucul_buffer_t *);95 void * cucul_get_buffer_data(cucul_buffer_t *);96 int cucul_free_buffer(cucul_buffer_t *);97 83 /* @} */ 98 84 … … 231 217 * 232 218 * @{ */ 233 cucul_buffer_t * cucul_export_canvas(cucul_canvas_t *, char const *); 219 void *cucul_export(cucul_canvas_t *, char const *, unsigned long int *); 220 long int cucul_import(cucul_canvas_t *, unsigned char const *, 221 unsigned long int, char const *); 234 222 char const * const * cucul_get_export_list(void); 235 cucul_canvas_t * cucul_import_canvas(cucul_buffer_t *, char const *);236 223 char const * const * cucul_get_import_list(void); 237 224 /* @} */ 238 225 239 226 #if !defined(_DOXYGEN_SKIP_ME) 240 /* Legacy stuff from beta versions, will probably disappear in 1.0 */ 227 /* Legacy stuff from beta versions, will probably disappear in 1.0 */ 228 typedef struct cucul_buffer cucul_buffer_t; 241 229 # ifdef __GNUC__ 242 230 # define CUCUL_DEPRECATED __attribute__ ((deprecated)) … … 244 232 # define CUCUL_DEPRECATED 245 233 # endif 246 int cucul_set_color(cucul_canvas_t *, unsigned char, 247 unsigned char) CUCUL_DEPRECATED; 248 int cucul_set_truecolor(cucul_canvas_t *, unsigned int, 249 unsigned int) CUCUL_DEPRECATED; 234 int cucul_set_color(cucul_canvas_t *, unsigned char, 235 unsigned char) CUCUL_DEPRECATED; 236 int cucul_set_truecolor(cucul_canvas_t *, unsigned int, 237 unsigned int) CUCUL_DEPRECATED; 238 cucul_buffer_t *cucul_load_memory(void *, 239 unsigned long int) CUCUL_DEPRECATED; 240 cucul_buffer_t *cucul_load_file(char const *) CUCUL_DEPRECATED; 241 unsigned long int cucul_get_buffer_size(cucul_buffer_t *) CUCUL_DEPRECATED; 242 void * cucul_get_buffer_data(cucul_buffer_t *) CUCUL_DEPRECATED; 243 int cucul_free_buffer(cucul_buffer_t *) CUCUL_DEPRECATED; 244 cucul_buffer_t * cucul_export_canvas(cucul_canvas_t *, 245 char const *) CUCUL_DEPRECATED; 246 cucul_canvas_t * cucul_import_canvas(cucul_buffer_t *, 247 char const *) CUCUL_DEPRECATED; 250 248 # define CUCUL_COLOR_BLACK CUCUL_BLACK 251 249 # define CUCUL_COLOR_BLUE CUCUL_BLUE -
libcaca/trunk/cucul/export.c
r1283 r1302 48 48 } 49 49 50 static int export_caca(cucul_canvas_t *, cucul_buffer_t *);51 static int export_ansi(cucul_canvas_t *, cucul_buffer_t *);52 static int export_utf8(cucul_canvas_t *, cucul_buffer_t *, int);53 static int export_html(cucul_canvas_t *, cucul_buffer_t *);54 static int export_html3(cucul_canvas_t *, cucul_buffer_t *);55 static int export_irc(cucul_canvas_t *, cucul_buffer_t *);56 static int export_ps(cucul_canvas_t *, cucul_buffer_t *);57 static int export_svg(cucul_canvas_t *, cucul_buffer_t *);58 static int export_tga(cucul_canvas_t *, cucul_buffer_t *);50 static void *export_caca(cucul_canvas_t *, unsigned long int *); 51 static void *export_ansi(cucul_canvas_t *, unsigned long int *); 52 static void *export_utf8(cucul_canvas_t *, unsigned long int *, int); 53 static void *export_html(cucul_canvas_t *, unsigned long int *); 54 static void *export_html3(cucul_canvas_t *, unsigned long int *); 55 static void *export_irc(cucul_canvas_t *, unsigned long int *); 56 static void *export_ps(cucul_canvas_t *, unsigned long int *); 57 static void *export_svg(cucul_canvas_t *, unsigned long int *); 58 static void *export_tga(cucul_canvas_t *, unsigned long int *); 59 59 60 60 /** \brief Export a canvas into a foreign format. 61 61 * 62 62 * This function exports a libcucul canvas into various foreign formats such 63 * as ANSI art, HTML, IRC colours, etc. One should use cucul_get_buffer_data() 64 * and cucul_get_buffer_size() to access the buffer contents. The allocated 65 * data is valid until cucul_free_buffer() is called. 63 * as ANSI art, HTML, IRC colours, etc. The returned pointer should be passed 64 * to free() to release the allocated storage when it is no longer needed. 66 65 * 67 66 * Valid values for \c format are: … … 82 81 * \param cv A libcucul canvas 83 82 * \param format A string describing the requested output format. 84 * \return A libcucul buffer, or NULL in case of error. 83 * \param bytes A pointer to an unsigned long integer where the number of 84 * allocated bytes will be written. 85 * \return A pointer to the exported memory area, or NULL in case of error. 85 86 */ 86 cucul_buffer_t * cucul_export_canvas(cucul_canvas_t *cv, char const *format) 87 { 88 cucul_buffer_t *ex; 89 int ret = -1; 90 91 ex = malloc(sizeof(cucul_buffer_t)); 92 if(!ex) 93 { 87 void *cucul_export(cucul_canvas_t *cv, char const *format, 88 unsigned long int *bytes) 89 { 90 if(!strcasecmp("caca", format)) 91 return export_caca(cv, bytes); 92 93 if(!strcasecmp("ansi", format)) 94 return export_ansi(cv, bytes); 95 96 if(!strcasecmp("utf8", format)) 97 return export_utf8(cv, bytes, 0); 98 99 if(!strcasecmp("utf8cr", format)) 100 return export_utf8(cv, bytes, 1); 101 102 if(!strcasecmp("html", format)) 103 return export_html(cv, bytes); 104 105 if(!strcasecmp("html3", format)) 106 return export_html3(cv, bytes); 107 108 if(!strcasecmp("irc", format)) 109 return export_irc(cv, bytes); 110 111 if(!strcasecmp("ps", format)) 112 return export_ps(cv, bytes); 113 114 if(!strcasecmp("svg", format)) 115 return export_svg(cv, bytes); 116 117 if(!strcasecmp("tga", format)) 118 return export_tga(cv, bytes); 119 94 120 #if defined(HAVE_ERRNO_H) 95 errno = ENOMEM;121 errno = EINVAL; 96 122 #endif 97 return NULL; 98 } 99 100 ex->size = 0; 101 ex->data = NULL; 102 ex->user_data = 0; 103 104 if(!strcasecmp("caca", format)) 105 ret = export_caca(cv, ex); 106 else if(!strcasecmp("ansi", format)) 107 ret = export_ansi(cv, ex); 108 else if(!strcasecmp("utf8", format)) 109 ret = export_utf8(cv, ex, 0); 110 else if(!strcasecmp("utf8cr", format)) 111 ret = export_utf8(cv, ex, 1); 112 else if(!strcasecmp("html", format)) 113 ret = export_html(cv, ex); 114 else if(!strcasecmp("html3", format)) 115 ret = export_html3(cv, ex); 116 else if(!strcasecmp("irc", format)) 117 ret = export_irc(cv, ex); 118 else if(!strcasecmp("ps", format)) 119 ret = export_ps(cv, ex); 120 else if(!strcasecmp("svg", format)) 121 ret = export_svg(cv, ex); 122 else if(!strcasecmp("tga", format)) 123 ret = export_tga(cv, ex); 124 125 if(ret < 0) 126 { 127 free(ex); 128 #if defined(HAVE_ERRNO_H) 129 errno = EINVAL; 130 #endif 131 return NULL; 132 } 133 134 return ex; 123 return NULL; 135 124 } 136 125 … … 171 160 172 161 /* Generate a native libcaca canvas file. */ 173 static int export_caca(cucul_canvas_t *cv, cucul_buffer_t *ex)162 static void *export_caca(cucul_canvas_t *cv, unsigned long int *bytes) 174 163 { 175 164 uint32_t *attrs = cv->attrs; 176 165 uint32_t *chars = cv->chars; 177 char * cur;166 char *data, *cur; 178 167 unsigned int n; 179 168 … … 183 172 * - 24 bytes for the frame info 184 173 * 8 bytes for each character cell */ 185 ex->size = 44 + 8 * cv->width * cv->height; 186 ex->data = malloc(ex->size); 187 188 cur = ex->data; 174 *bytes = 44 + 8 * cv->width * cv->height; 175 cur = data = malloc(*bytes); 189 176 190 177 /* magic */ … … 213 200 } 214 201 215 return 0;202 return data; 216 203 } 217 204 … … 273 260 274 261 /* Generate UTF-8 representation of current canvas. */ 275 static int export_utf8(cucul_canvas_t *cv, cucul_buffer_t *ex, int cr)262 static void *export_utf8(cucul_canvas_t *cv, unsigned long int *bytes, int cr) 276 263 { 277 264 static uint8_t const palette[] = … … 281 268 }; 282 269 283 char * cur;270 char *data, *cur; 284 271 unsigned int x, y; 285 272 … … 287 274 * 4 max bytes for a UTF-8 character). 288 275 * Add height*9 to that (zeroes color at the end and jump to next line) */ 289 ex->size = (cv->height * 9) + (cv->width * cv->height * 23); 290 ex->data = malloc(ex->size); 291 292 cur = ex->data; 276 *bytes = (cv->height * 9) + (cv->width * cv->height * 23); 277 cur = data = malloc(*bytes); 293 278 294 279 for(y = 0; y < cv->height; y++) … … 345 330 346 331 /* Crop to really used size */ 347 ex->size = (uintptr_t)(cur - ex->data);348 ex->data = realloc(ex->data, ex->size);349 350 return 0;332 *bytes = (uintptr_t)(cur - data); 333 data = realloc(data, *bytes); 334 335 return data; 351 336 } 352 337 353 338 /* Generate ANSI representation of current canvas. */ 354 static int export_ansi(cucul_canvas_t *cv, cucul_buffer_t *ex)339 static void *export_ansi(cucul_canvas_t *cv, unsigned long int *bytes) 355 340 { 356 341 static uint8_t const palette[] = … … 360 345 }; 361 346 362 char * cur;347 char *data, *cur; 363 348 unsigned int x, y; 364 349 … … 369 354 * 1 byte for a CP437 character). 370 355 * Add height*9 to that (zeroes color at the end and jump to next line) */ 371 ex->size = (cv->height * 9) + (cv->width * cv->height * 16); 372 ex->data = malloc(ex->size); 373 374 cur = ex->data; 356 *bytes = (cv->height * 9) + (cv->width * cv->height * 16); 357 cur = data = malloc(*bytes); 375 358 376 359 for(y = 0; y < cv->height; y++) … … 423 406 424 407 /* Crop to really used size */ 425 ex->size = (uintptr_t)(cur - ex->data);426 ex->data = realloc(ex->data, ex->size);427 428 return 0;408 *bytes = (uintptr_t)(cur - data); 409 data = realloc(data, *bytes); 410 411 return data; 429 412 } 430 413 431 414 /* Generate HTML representation of current canvas. */ 432 static int export_html(cucul_canvas_t *cv, cucul_buffer_t *ex)433 { 434 char * cur;415 static void *export_html(cucul_canvas_t *cv, unsigned long int *bytes) 416 { 417 char *data, *cur; 435 418 unsigned int x, y, len; 436 419 … … 441 424 * up to 9 chars for "&#xxxxxx;", far less for pure ASCII 442 425 * 7 chars for "</span>" */ 443 ex->size = 1000 + cv->height * (7 + cv->width * (47 + 83 + 9 + 7)); 444 ex->data = malloc(ex->size); 445 446 cur = ex->data; 426 *bytes = 1000 + cv->height * (7 + cv->width * (47 + 83 + 9 + 7)); 427 cur = data = malloc(*bytes); 447 428 448 429 /* HTML header */ … … 499 480 500 481 /* Crop to really used size */ 501 ex->size = strlen(ex->data) + 1;502 ex->data = realloc(ex->data, ex->size);503 504 return 0;482 *bytes = (uintptr_t)(cur - data); 483 data = realloc(data, *bytes); 484 485 return data; 505 486 } 506 487 … … 509 490 * will not work under gecko (mozilla rendering engine) unless you set a 510 491 * correct header. */ 511 static int export_html3(cucul_canvas_t *cv, cucul_buffer_t *ex)512 { 513 char * cur;492 static void *export_html3(cucul_canvas_t *cv, unsigned long int *bytes) 493 { 494 char *data, *cur; 514 495 unsigned int x, y, len; 515 496 … … 520 501 * up to 9 chars for "&#xxxxxx;", far less for pure ASCII 521 502 * 12 chars for "</font></td>" */ 522 ex->size = 1000 + cv->height * (10 + cv->width * (40 + 36 + 9 + 12)); 523 ex->data = malloc(ex->size); 524 525 cur = ex->data; 503 *bytes = 1000 + cv->height * (10 + cv->width * (40 + 36 + 9 + 12)); 504 cur = data = malloc(*bytes); 526 505 527 506 /* Table */ … … 594 573 595 574 /* Crop to really used size */ 596 ex->size = (uintptr_t)(cur - ex->data);597 ex->data = realloc(ex->data, ex->size);598 599 return 0;575 *bytes = (uintptr_t)(cur - data); 576 data = realloc(data, *bytes); 577 578 return data; 600 579 } 601 580 602 581 /* Export a text file with IRC colours */ 603 static int export_irc(cucul_canvas_t *cv, cucul_buffer_t *ex)582 static void *export_irc(cucul_canvas_t *cv, unsigned long int *bytes) 604 583 { 605 584 static uint8_t const palette[] = … … 609 588 }; 610 589 611 char * cur;590 char *data, *cur; 612 591 unsigned int x, y; 613 592 … … 622 601 */ 623 602 624 ex->size = 2 + cv->height * (3 + cv->width * 14); 625 ex->data = malloc(ex->size); 626 627 cur = ex->data; 603 *bytes = 2 + cv->height * (3 + cv->width * 14); 604 cur = data = malloc(*bytes); 628 605 629 606 for(y = 0; y < cv->height; y++) … … 702 679 703 680 /* Crop to really used size */ 704 ex->size = (uintptr_t)(cur - ex->data);705 ex->data = realloc(ex->data, ex->size);706 707 return 0;681 *bytes = (uintptr_t)(cur - data); 682 data = realloc(data, *bytes); 683 684 return data; 708 685 } 709 686 710 687 /* Export a PostScript document. */ 711 static int export_ps(cucul_canvas_t *cv, cucul_buffer_t *ex)688 static void *export_ps(cucul_canvas_t *cv, unsigned long int *bytes) 712 689 { 713 690 static char const *ps_header = … … 736 713 "6 10 scale\n"; 737 714 738 char * cur;715 char *data, *cur; 739 716 unsigned int x, y; 740 717 741 718 /* 200 is arbitrary but should be ok */ 742 ex->size = strlen(ps_header) + 100 + cv->height * (32 + cv->width * 200); 743 ex->data = malloc(ex->size); 744 745 cur = ex->data; 719 *bytes = strlen(ps_header) + 100 + cv->height * (32 + cv->width * 200); 720 cur = data = malloc(*bytes); 746 721 747 722 /* Header */ … … 811 786 812 787 /* Crop to really used size */ 813 ex->size = (uintptr_t)(cur - ex->data);814 ex->data = realloc(ex->data, ex->size);815 816 return 0;788 *bytes = (uintptr_t)(cur - data); 789 data = realloc(data, *bytes); 790 791 return data; 817 792 } 818 793 819 794 /* Export an SVG vector image */ 820 static int export_svg(cucul_canvas_t *cv, cucul_buffer_t *ex)795 static void *export_svg(cucul_canvas_t *cv, unsigned long int *bytes) 821 796 { 822 797 static char const svg_header[] = … … 827 802 " xml:space=\"preserve\" version=\"1.1\" baseProfile=\"full\">\n"; 828 803 829 char * cur;804 char *data, *cur; 830 805 unsigned int x, y; 831 806 832 807 /* 200 is arbitrary but should be ok */ 833 ex->size = strlen(svg_header) + 128 + cv->width * cv->height * 200; 834 ex->data = malloc(ex->size); 835 836 cur = ex->data; 808 *bytes = strlen(svg_header) + 128 + cv->width * cv->height * 200; 809 cur = data = malloc(*bytes); 837 810 838 811 /* Header */ … … 897 870 898 871 /* Crop to really used size */ 899 ex->size = (uintptr_t)(cur - ex->data);900 ex->data = realloc(ex->data, ex->size);901 902 return 0;872 *bytes = (uintptr_t)(cur - data); 873 data = realloc(data, *bytes); 874 875 return data; 903 876 } 904 877 905 878 /* Export a TGA image */ 906 static int export_tga(cucul_canvas_t *cv, cucul_buffer_t *ex)879 static void *export_tga(cucul_canvas_t *cv, unsigned long int *bytes) 907 880 { 908 881 char const * const *fontlist; 909 char * 882 char *data, *cur; 910 883 cucul_font_t *f; 911 884 unsigned int i, w, h; … … 913 886 fontlist = cucul_get_font_list(); 914 887 if(!fontlist[0]) 915 return -1; 888 { 889 #if defined(HAVE_ERRNO_H) 890 errno = EINVAL; 891 #endif 892 return NULL; 893 } 916 894 917 895 f = cucul_load_font(fontlist[0], 0); … … 920 898 h = cucul_get_canvas_height(cv) * cucul_get_font_height(f); 921 899 922 ex->size = w * h * 4 + 18; /* 32 bpp + 18 bytes for the header */ 923 ex->data = malloc(ex->size); 924 925 cur = ex->data; 900 *bytes = w * h * 4 + 18; /* 32 bpp + 18 bytes for the header */ 901 cur = data = malloc(*bytes); 926 902 927 903 /* ID Length */ … … 958 934 cucul_free_font(f); 959 935 960 return 0;961 } 962 936 return data; 937 } 938 -
libcaca/trunk/cucul/import.c
r1283 r1302 58 58 }; 59 59 60 static cucul_canvas_t *import_caca(void const *, unsigned int);61 static cucul_canvas_t *import_text(void const *, unsigned int);62 static cucul_canvas_t *import_ansi(void const *, unsigned int, int);60 static long int import_caca(cucul_canvas_t *, void const *, unsigned int); 61 static long int import_text(cucul_canvas_t *, void const *, unsigned int); 62 static long int import_ansi(cucul_canvas_t *, void const *, unsigned int, int); 63 63 64 64 static void ansi_parse_grcm(cucul_canvas_t *, struct ansi_grcm *, 65 65 unsigned int, unsigned int const *); 66 66 67 /** \brief Import a buffer into a canvas 68 * 69 * Import a libcucul buffer as returned by cucul_load_memory() 70 * or cucul_load_file() into an internal libcucul canvas. 67 /** \brief Import a memory buffer into a canvas 68 * 69 * Import a memory buffer into the given libcucul canvas's current 70 * frame. The current frame is resized accordingly and its contents are 71 * replaced with the imported data. 71 72 * 72 73 * Valid values for \c format are: … … 77 78 * - \c "caca": import native libcaca files. 78 79 * 79 * If an error occurs, NULLis returned and \b errno is set accordingly:80 * If an error occurs, -1 is returned and \b errno is set accordingly: 80 81 * - \c ENOMEM Not enough memory to allocate canvas. 81 82 * - \c EINVAL Invalid format requested. 82 83 * 84 * \param A libcucul canvas in which to import the file. 83 85 * \param buffer A \e libcucul buffer containing the data to be loaded 84 86 * into a canvas. 85 87 * \param format A string describing the input format. 86 * \return A libcucul canvas, or NULL in case of error.88 * \return The number of bytes read, or -1 if an error occurred. 87 89 */ 88 cucul_canvas_t * cucul_import_canvas(cucul_buffer_t *buffer, char const *format) 89 { 90 char const *buf = (char const*)buffer->data; 91 90 long int cucul_import(cucul_canvas_t *cv, unsigned char const *buf, 91 unsigned long int len, char const *format) 92 { 92 93 if(!strcasecmp("caca", format)) 93 return import_caca( buffer->data, buffer->size);94 return import_caca(cv, buf, len); 94 95 if(!strcasecmp("utf8", format)) 95 return import_ansi( buffer->data, buffer->size, 1);96 return import_ansi(cv, buf, len, 1); 96 97 if(!strcasecmp("text", format)) 97 return import_text( buffer->data, buffer->size);98 return import_text(cv, buf, len); 98 99 if(!strcasecmp("ansi", format)) 99 return import_ansi( buffer->data, buffer->size, 0);100 return import_ansi(cv, buf, len, 0); 100 101 101 102 /* Autodetection */ … … 104 105 unsigned int i; 105 106 106 /* If 4 first letters are CACA*/107 if( buffer->size >= 4 && (uint8_t)buf[0] == 0xca &&108 (uint8_t)buf[1] == 0xca && buf[2] == 'C' && buf[3] == 'V')109 return import_caca( buffer->data, buffer->size);107 /* If 4 first bytes are 0xcaca + 'CV' */ 108 if(len >= 4 && buf[0] == 0xca && 109 buf[1] == 0xca && buf[2] == 'C' && buf[3] == 'V') 110 return import_caca(cv, buf, len); 110 111 111 112 /* If we find ESC[ argv, we guess it's an ANSI file */ 112 for(i = 0; i + 1 < buffer->size; i++)113 for(i = 0; i + 1 < len; i++) 113 114 if((buf[i] == 0x1b) && (buf[i + 1] == '[')) 114 return import_ansi( buffer->data, buffer->size, 0);115 return import_ansi(cv, buf, len, 0); 115 116 116 117 /* Otherwise, import it as text */ 117 return import_text( buffer->data, buffer->size);118 return import_text(cv, buf, len); 118 119 } 119 120 … … 121 122 errno = EINVAL; 122 123 #endif 123 return NULL;124 return -1; 124 125 } 125 126 … … 153 154 */ 154 155 155 static cucul_canvas_t *import_caca(void const *data, unsigned int size)156 { 157 cucul_canvas_t *cv; 156 static long int import_caca(cucul_canvas_t *cv, 157 void const *data, unsigned int size) 158 { 158 159 uint8_t const *buf = (uint8_t const *)data; 159 160 unsigned int control_size, data_size, full_size, frames, f, n; 160 161 uint16_t version, flags; 162 163 cucul_set_canvas_size(cv, 0, 0); 161 164 162 165 if(size < 20) … … 198 201 199 202 /* FIXME: read all frames, not only the first one */ 200 cv = cucul_create_canvas(sscanu32(buf + 4 + 16), 201 sscanu32(buf + 4 + 16 + 4)); 202 203 if(!cv) 204 { 205 #if defined(HAVE_ERRNO_H) 206 errno = ENOMEM; 207 #endif 208 return NULL; 209 } 203 cucul_set_canvas_size(cv, sscanu32(buf + 4 + 16), 204 sscanu32(buf + 4 + 16 + 4)); 205 206 /* FIXME: check for return value */ 210 207 211 208 for(n = sscanu32(buf + 4 + 16) * sscanu32(buf + 4 + 16 + 4); n--; ) … … 217 214 cv->curattr = sscanu32(buf + 4 + 16 + 12); 218 215 219 return cv;216 return size; 220 217 221 218 invalid_caca: … … 223 220 errno = EINVAL; 224 221 #endif 225 return NULL;226 } 227 228 static cucul_canvas_t *import_text(void const *data, unsigned int size)229 { 230 cucul_canvas_t *cv; 222 return -1; 223 } 224 225 static long int import_text(cucul_canvas_t *cv, 226 void const *data, unsigned int size) 227 { 231 228 char const *text = (char const *)data; 232 229 unsigned int width = 0, height = 0, x = 0, y = 0, i; 233 230 234 cv = cucul_create_canvas(width, height); 235 if(!cv) 236 { 237 #if defined(HAVE_ERRNO_H) 238 errno = ENOMEM; 239 #endif 240 return NULL; 241 } 242 231 cucul_set_canvas_size(cv, width, height); 243 232 cucul_set_color_ansi(cv, CUCUL_DEFAULT, CUCUL_TRANSPARENT); 244 233 … … 275 264 cucul_set_canvas_size(cv, width, height = y); 276 265 277 return cv;278 } 279 280 static cucul_canvas_t *import_ansi(void const *data, unsigned int size,281 266 return size; 267 } 268 269 static long int import_ansi(cucul_canvas_t *cv, 270 void const *data, unsigned int size, int utf8) 282 271 { 283 272 struct ansi_grcm grcm; 284 273 unsigned char const *buffer = (unsigned char const*)data; 285 cucul_canvas_t *cv;286 274 unsigned int i, j, skip, dummy = 0; 287 275 unsigned int width = 0, height = 0, wch = 1; … … 289 277 int x = 0, y = 0, save_x = 0, save_y = 0; 290 278 291 cv = cucul_create_canvas(width, height); 292 if(!cv) 293 { 294 #if defined(HAVE_ERRNO_H) 295 errno = ENOMEM; 296 #endif 297 return NULL; 298 } 299 279 cucul_set_canvas_size(cv, width, height); 300 280 ansi_parse_grcm(cv, &grcm, 1, &dummy); 301 281 … … 495 475 } 496 476 497 return cv;477 return size; 498 478 } 499 479 -
libcaca/trunk/cucul/legacy.c
r1301 r1302 13 13 14 14 /* 15 * This file contains buffer handling functions. 15 * This file contains legacy functions that we keep around until all 16 * applications are ported. 16 17 */ 17 18 … … 20 21 21 22 #if !defined(__KERNEL__) 23 # if defined(HAVE_ERRNO_H) 24 # include <errno.h> 25 # endif 22 26 # include <stdio.h> 23 27 # include <stdlib.h> … … 28 32 #include "cucul_internals.h" 29 33 30 /** \brief Load a memory area into a buffer. 31 * 32 * Create a \e libcucul buffer that points to the given memory area. The 33 * data is not duplicated and any changes made to the original memory area 34 * will appear in the buffer. 35 * 36 * Keep in mind that buffers are not strings. When loading a C string, the 37 * terminating '\\0' must not be part of the buffer, hence \e size should 38 * be computed with strlen(). Conversely, the '\\0' is not appended to 39 * exported buffers even when they could be parsed as strings. 40 * 41 * \param data The memory area to load. 42 * \param size The size of the memory area. 43 * \return A \e libcucul buffer pointing to the memory area, or NULL 44 * if an error occurred. 34 /* 35 * Functions from color.c 45 36 */ 37 38 int cucul_set_color(cucul_canvas_t *cv, unsigned char fg, unsigned char bg) 39 { 40 return cucul_set_color_ansi(cv, fg, bg); 41 } 42 43 int cucul_set_truecolor(cucul_canvas_t *cv, unsigned int fg, unsigned int bg) 44 { 45 return cucul_set_color_argb(cv, fg, bg); 46 } 47 48 /* 49 * Functions from import.c 50 */ 51 52 cucul_canvas_t * cucul_import_canvas(cucul_buffer_t *buf, char const *format) 53 { 54 cucul_canvas_t *cv = cucul_create_canvas(0, 0); 55 int ret = cucul_import(cv, (unsigned char const *)buf->data, 56 buf->size, format); 57 if(ret < 0) 58 { 59 cucul_free_canvas(cv); 60 return NULL; 61 } 62 63 return cv; 64 } 65 66 /* 67 * Functions from export.c 68 */ 69 70 cucul_buffer_t * cucul_export_canvas(cucul_canvas_t *cv, char const *format) 71 { 72 cucul_buffer_t *ex; 73 74 ex = malloc(sizeof(cucul_buffer_t)); 75 if(!ex) 76 { 77 #if defined(HAVE_ERRNO_H) 78 errno = ENOMEM; 79 #endif 80 return NULL; 81 } 82 83 ex->data = cucul_export(cv, format, &ex->size); 84 if(!ex->data) 85 { 86 free(ex); 87 return NULL; 88 } 89 90 ex->user_data = 0; 91 92 return ex; 93 } 94 95 /* 96 * Functions from buffer.c 97 */ 98 46 99 cucul_buffer_t *cucul_load_memory(void *data, unsigned long int size) 47 100 { … … 59 112 } 60 113 61 /** \brief Load a file into a buffer.62 *63 * Load a file into memory and returns a \e libcucul buffer for use with64 * other functions.65 *66 * \param file The filename67 * \return A \e libcucul buffer containing the file's contents, or NULL68 * if an error occurred.69 */70 114 #if !defined(__KERNEL__) 71 115 cucul_buffer_t *cucul_load_file(char const *file) … … 106 150 } 107 151 #endif 108 /** \brief Get the buffer size. 109 * 110 * Return the length (in bytes) of the memory area stored in the given 111 * \e libcucul buffer. 112 * 113 * This function never fails. 114 * 115 * \param buf A \e libcucul buffer 116 * \return The buffer data length. 117 */ 152 118 153 unsigned long int cucul_get_buffer_size(cucul_buffer_t *buf) 119 154 { … … 121 156 } 122 157 123 /** \brief Get the buffer data.124 *125 * Get a pointer to the memory area stored in the given126 * \e libcucul buffer.127 *128 * This function never fails.129 *130 * \param buf A \e libcucul buffer131 * \return A pointer to the buffer memory area.132 */133 158 void * cucul_get_buffer_data(cucul_buffer_t *buf) 134 159 { … … 136 161 } 137 162 138 /** \brief Free a buffer.139 *140 * Free the structures associated with the given \e libcucul buffer.141 *142 * This function never fails.143 *144 * \param buf A \e libcucul buffer145 * \return This function always returns 0.146 */147 163 int cucul_free_buffer(cucul_buffer_t *buf) 148 164 {
Note: See TracChangeset
for help on using the changeset viewer.