Changeset 463
- Timestamp:
- Jan 13, 2005, 11:19:01 PM (18 years ago)
- Location:
- libcaca/trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/src/caca.h
r375 r463 279 279 void caca_putstr(int, int, char const *); 280 280 void caca_printf(int, int, char const *, ...); 281 void caca_get_screen(char *); 281 282 void caca_clear(void); 282 283 /* @} */ -
libcaca/trunk/src/graphics.c
r369 r463 97 97 * Local variables 98 98 */ 99 #if !defined(_DOXYGEN_SKIP_ME) 100 static uint8_t *cache_char, *cache_attr; 101 #endif 102 99 103 #if defined(USE_NCURSES) 100 104 static int ncurses_attr[16*16]; … … 175 179 int x11_font_width, x11_font_height; 176 180 unsigned int x11_new_width, x11_new_height; 177 static uint8_t *x11_char, *x11_attr;178 181 static int x11_colors[16]; 179 182 static Font x11_font; … … 186 189 187 190 #if defined(USE_WIN32) 188 static uint8_t *win32_char, *win32_attr;189 191 HANDLE win32_hin, win32_hout; 190 192 static HANDLE win32_front, win32_back; … … 377 379 return; 378 380 381 cache_char[x + y * _caca_width] = c; 382 cache_attr[x + y * _caca_width] = (_caca_bgcolor << 4) | _caca_fgcolor; 383 379 384 switch(_caca_driver) 380 385 { … … 405 410 #if defined(USE_X11) 406 411 case CACA_DRIVER_X11: 407 x11_char[x + y * _caca_width] = c;408 x11_attr[x + y * _caca_width] = (_caca_bgcolor << 4) | _caca_fgcolor;409 412 break; 410 413 #endif 411 414 #if defined(USE_WIN32) 412 415 case CACA_DRIVER_WIN32: 413 win32_char[x + y * _caca_width] = c;414 win32_attr[x + y * _caca_width] = (_caca_bgcolor << 4) | _caca_fgcolor;415 416 break; 416 417 #endif … … 439 440 char *attrbuf; 440 441 #endif 442 char const *t; 441 443 unsigned int len; 442 444 … … 461 463 _caca_scratch_line[len] = '\0'; 462 464 s = _caca_scratch_line; 465 } 466 467 charbuf = cache_char + x + y * _caca_width; 468 attrbuf = cache_attr + x + y * _caca_width; 469 t = s; 470 while(*t) 471 { 472 *charbuf++ = *t++; 473 *attrbuf++ = (_caca_bgcolor << 4) | _caca_fgcolor; 463 474 } 464 475 … … 498 509 #if defined(USE_X11) 499 510 case CACA_DRIVER_X11: 500 charbuf = x11_char + x + y * _caca_width;501 attrbuf = x11_attr + x + y * _caca_width;502 while(*s)503 {504 *charbuf++ = *s++;505 *attrbuf++ = (_caca_bgcolor << 4) | _caca_fgcolor;506 }507 511 break; 508 512 #endif 509 513 #if defined(USE_WIN32) 510 514 case CACA_DRIVER_WIN32: 511 charbuf = win32_char + x + y * _caca_width;512 attrbuf = win32_attr + x + y * _caca_width;513 while(*s)514 {515 *charbuf++ = *s++;516 *attrbuf++ = (_caca_bgcolor << 4) | _caca_fgcolor;517 }518 515 break; 519 516 #endif … … 561 558 if(buf != tmp) 562 559 free(buf); 560 } 561 562 /** \brief Get the screen. 563 * 564 * This function fills a byte array with the character values. 565 */ 566 void caca_get_screen(char *buffer) 567 { 568 unsigned int x, y; 569 570 for(y = 0; y < _caca_height; y++) 571 { 572 for(x = 0; x < _caca_width; x++) 573 { 574 *buffer++ = cache_attr[x + y * _caca_width]; 575 *buffer++ = cache_char[x + y * _caca_width]; 576 } 577 } 563 578 } 564 579 … … 727 742 _caca_height = 32; 728 743 729 x11_char = malloc(_caca_width * _caca_height * sizeof(int));730 if(x11_char == NULL)731 return -1;732 733 x11_attr = malloc(_caca_width * _caca_height * sizeof(int));734 if(x11_attr == NULL)735 {736 free(x11_char);737 return -1;738 }739 740 memset(x11_char, 0, _caca_width * _caca_height * sizeof(int));741 memset(x11_attr, 0, _caca_width * _caca_height * sizeof(int));742 743 744 x11_dpy = XOpenDisplay(NULL); 744 745 if(x11_dpy == NULL) 745 {746 free(x11_char);747 free(x11_attr);748 746 return -1; 749 }750 747 751 748 if(getenv("CACA_FONT") && *(getenv("CACA_FONT"))) … … 759 756 { 760 757 XCloseDisplay(x11_dpy); 761 free(x11_char);762 free(x11_attr);763 758 return -1; 764 759 } … … 769 764 XUnloadFont(x11_dpy, x11_font); 770 765 XCloseDisplay(x11_dpy); 771 free(x11_char);772 free(x11_attr);773 766 return -1; 774 767 } … … 886 879 SetConsoleActiveScreenBuffer(win32_front); 887 880 888 win32_char = malloc(_caca_width * _caca_height * sizeof(int));889 if(win32_char == NULL)890 return -1;891 892 win32_attr = malloc(_caca_width * _caca_height * sizeof(int));893 if(win32_attr == NULL)894 {895 free(win32_char);896 return -1;897 }898 899 881 win32_buffer = malloc(_caca_width * _caca_height * sizeof(CHAR_INFO)); 900 882 if(win32_buffer == NULL) 901 {902 free(win32_attr);903 free(win32_char);904 883 return -1; 905 }906 907 memset(win32_char, 0, _caca_width * _caca_height * sizeof(int));908 memset(win32_attr, 0, _caca_width * _caca_height * sizeof(int));909 884 } 910 885 else … … 913 888 /* Dummy */ 914 889 } 890 891 cache_char = malloc(_caca_width * _caca_height * sizeof(uint8_t)); 892 if(cache_char == NULL) 893 return -1; 894 895 cache_attr = malloc(_caca_width * _caca_height * sizeof(uint8_t)); 896 if(cache_attr == NULL) 897 { 898 free(cache_char); 899 return -1; 900 } 901 902 memset(cache_char, 0, _caca_width * _caca_height * sizeof(uint8_t)); 903 memset(cache_attr, 0, _caca_width * _caca_height * sizeof(uint8_t)); 915 904 916 905 _caca_empty_line = malloc(_caca_width + 1); … … 928 917 int _caca_end_graphics(void) 929 918 { 919 free(cache_char); 920 free(cache_attr); 921 930 922 #if defined(USE_SLANG) 931 923 /* Nothing to do */ … … 955 947 XDestroyWindow(x11_dpy, x11_window); 956 948 XCloseDisplay(x11_dpy); 957 free(x11_char);958 free(x11_attr);959 949 } 960 950 else … … 966 956 CloseHandle(win32_back); 967 957 CloseHandle(win32_front); 968 free(win32_char);969 free(win32_attr);970 958 } 971 959 else … … 1167 1155 for(x = 0; x < _caca_width; x += len) 1168 1156 { 1169 u nsigned char *attr = x11_attr + x + y * _caca_width;1157 uint8_t *attr = cache_attr + x + y * _caca_width; 1170 1158 1171 1159 len = 1; … … 1186 1174 for(x = 0; x < _caca_width; x += len) 1187 1175 { 1188 u nsigned char *attr = x11_attr + x + y * _caca_width;1176 uint8_t *attr = cache_attr + x + y * _caca_width; 1189 1177 1190 1178 len = 1; 1191 1179 1192 1180 /* Skip spaces */ 1193 if( x11_char[x + y * _caca_width] == ' ')1181 if(cache_char[x + y * _caca_width] == ' ') 1194 1182 continue; 1195 1183 … … 1201 1189 XDrawString(x11_dpy, x11_pixmap, x11_gc, x * x11_font_width, 1202 1190 (y + 1) * x11_font_height - x11_font_offset, 1203 x11_char + x + y * _caca_width, len);1191 cache_char + x + y * _caca_width, len); 1204 1192 } 1205 1193 } … … 1222 1210 for(i = 0; i < _caca_width * _caca_height; i++) 1223 1211 { 1224 win32_buffer[i].Char.AsciiChar = win32_char[i];1225 win32_buffer[i].Attributes = win32_fg_palette[ win32_attr[i] & 0xf]1226 | win32_bg_palette[ win32_attr[i] >> 4];1212 win32_buffer[i].Char.AsciiChar = cache_char[i]; 1213 win32_buffer[i].Attributes = win32_fg_palette[cache_attr[i] & 0xf] 1214 | win32_bg_palette[cache_attr[i] >> 4]; 1227 1215 } 1228 1216 … … 1319 1307 _caca_width = x11_new_width; 1320 1308 _caca_height = x11_new_height; 1321 1322 free(x11_char);1323 free(x11_attr);1324 1309 1325 1310 new_pixmap = XCreatePixmap(x11_dpy, x11_window, … … 1333 1318 XFreePixmap(x11_dpy, x11_pixmap); 1334 1319 x11_pixmap = new_pixmap; 1335 1336 x11_char = malloc(_caca_width * _caca_height * sizeof(int));1337 memset(x11_char, 0, _caca_width * _caca_height * sizeof(int));1338 x11_attr = malloc(_caca_width * _caca_height * sizeof(int));1339 memset(x11_attr, 0, _caca_width * _caca_height * sizeof(int));1340 1320 } 1341 1321 else … … 1349 1329 { 1350 1330 /* Dummy */ 1331 } 1332 1333 if(_caca_width != old_width || _caca_height != old_height) 1334 { 1335 free(cache_char); 1336 free(cache_attr); 1337 1338 cache_char = malloc(_caca_width * _caca_height * sizeof(uint8_t)); 1339 memset(cache_char, 0, _caca_width * _caca_height * sizeof(uint8_t)); 1340 cache_attr = malloc(_caca_width * _caca_height * sizeof(uint8_t)); 1341 memset(cache_attr, 0, _caca_width * _caca_height * sizeof(uint8_t)); 1351 1342 } 1352 1343
Note: See TracChangeset
for help on using the changeset viewer.