Changeset 913 for libcaca/trunk/cucul/import.c
- Timestamp:
- Apr 26, 2006, 4:36:11 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/cucul/import.c
r904 r913 201 201 } 202 202 203 static void manage_modifiers(int, uint8_t *, uint8_t *, uint8_t *, 204 uint8_t *, uint8_t *, uint8_t *); 203 /* Graphic Rendition Combination Mode */ 204 struct grcm 205 { 206 uint8_t fg, bg; 207 uint8_t bold, negative, concealed; 208 }; 209 210 static void manage_modifiers(struct grcm *, int); 205 211 206 212 static cucul_canvas_t *import_ansi(void const *data, unsigned int size) 207 213 { 214 struct grcm grcm; 215 unsigned char const *buffer = (unsigned char const*)data; 208 216 cucul_canvas_t *cv; 209 unsigned char const *buffer = (unsigned char const*)data; 210 unsigned int i, j; 211 int x = 0, y = 0; 217 unsigned int i, j, skip; 212 218 unsigned int width = 80, height = 25; 213 int save_x = 0, save_y = 0; 214 unsigned int skip; 215 uint8_t fg, bg, save_fg, save_bg, bold, reverse; 216 217 fg = save_fg = CUCUL_COLOR_LIGHTGRAY; 218 bg = save_bg = CUCUL_COLOR_BLACK; 219 bold = reverse = 0; 219 int x = 0, y = 0, save_x = 0, save_y = 0; 220 221 manage_modifiers(&grcm, 0); 220 222 221 223 cv = cucul_create_canvas(width, height); 222 cucul_set_color(cv, fg, bg);224 cucul_set_color(cv, CUCUL_COLOR_DEFAULT, CUCUL_COLOR_DEFAULT); 223 225 224 226 for(i = 0; i < size; i += skip) … … 250 252 * to the final byte. Only the final byte is mandatory, there 251 253 * can be zero of the others. 252 * 254 * 0 param=2 inter final final+1 253 255 * +-----+------------------+---------------------+-----------------+ 254 256 * | CSI | parameter bytes | intermediate bytes | final byte | … … 283 285 continue; /* Suspiciously long sequence, skip it */ 284 286 285 /* ECMA-48 5.4.2: Parameter string format */ 287 /* Parse parameter bytes as per ECMA-48 5.4.2: Parameter string 288 * format */ 286 289 if(param < inter) 287 290 { … … 342 345 case 'm': /* SGR - Select Graphic Rendition */ 343 346 for(j = 0; j < argc; j++) 344 manage_modifiers(argv[j], &fg, &bg, 345 &save_fg, &save_bg, &bold, &reverse); 346 if(bold && fg < 8) 347 fg += 8; 348 if(reverse) 349 cucul_set_color(cv, bg, fg); 347 manage_modifiers(&grcm, argv[j]); 348 if(grcm.concealed) 349 cucul_set_color(cv, CUCUL_COLOR_TRANSPARENT, 350 CUCUL_COLOR_TRANSPARENT); 351 else if(grcm.negative) 352 cucul_set_color(cv, (grcm.bold && grcm.bg < 8) ? 353 grcm.bg + 8 : grcm.bg, grcm.fg); 350 354 else 351 cucul_set_color(cv, fg, bg); 355 cucul_set_color(cv, (grcm.bold && grcm.fg < 8) ? 356 grcm.fg + 8 : grcm.fg, grcm.bg); 352 357 break; 353 358 default: … … 382 387 /* XXX : ANSI loader helper */ 383 388 384 static void manage_modifiers(int i, uint8_t *fg, uint8_t *bg, uint8_t *save_fg, 385 uint8_t *save_bg, uint8_t *bold, uint8_t *reverse) 389 static void manage_modifiers(struct grcm *g, int i) 386 390 { 387 391 static uint8_t const ansi2cucul[] = 388 392 { 389 CUCUL_COLOR_BLACK, 390 CUCUL_COLOR_RED, 391 CUCUL_COLOR_GREEN, 392 CUCUL_COLOR_BROWN, 393 CUCUL_COLOR_BLUE, 394 CUCUL_COLOR_MAGENTA, 395 CUCUL_COLOR_CYAN, 396 CUCUL_COLOR_LIGHTGRAY 393 CUCUL_COLOR_BLACK, CUCUL_COLOR_RED, 394 CUCUL_COLOR_GREEN, CUCUL_COLOR_BROWN, 395 CUCUL_COLOR_BLUE, CUCUL_COLOR_MAGENTA, 396 CUCUL_COLOR_CYAN, CUCUL_COLOR_LIGHTGRAY 397 397 }; 398 398 399 /* Defined in ECMA-48 8.3.117: SGR - SELECT GRAPHIC RENDITION */ 399 400 if(i >= 30 && i <= 37) 400 *fg = ansi2cucul[i - 30];401 g->fg = ansi2cucul[i - 30]; 401 402 else if(i >= 40 && i <= 47) 402 *bg = ansi2cucul[i - 40];403 g->bg = ansi2cucul[i - 40]; 403 404 else if(i >= 90 && i <= 97) 404 *fg = ansi2cucul[i - 90] + 8;405 g->fg = ansi2cucul[i - 90] + 8; 405 406 else if(i >= 100 && i <= 107) 406 *bg = ansi2cucul[i - 100] + 8;407 g->bg = ansi2cucul[i - 100] + 8; 407 408 else switch(i) 408 409 { 409 case 0: 410 *fg = CUCUL_COLOR_DEFAULT; 411 *bg = CUCUL_COLOR_DEFAULT; 412 *bold = 0; 413 *reverse = 0; 414 break; 415 case 1: /* BOLD */ 416 *bold = 1; 417 break; 418 case 4: // Underline 419 break; 420 case 5: // blink 421 break; 422 case 7: // reverse 423 *reverse = 1; 424 break; 425 case 8: // invisible 426 *save_fg = *fg; 427 *save_bg = *bg; 428 *fg = CUCUL_COLOR_TRANSPARENT; 429 *bg = CUCUL_COLOR_TRANSPARENT; 430 break; 431 case 28: // not invisible 432 *fg = *save_fg; 433 *bg = *save_bg; 434 break; 435 case 39: 436 *fg = CUCUL_COLOR_DEFAULT; 437 break; 438 case 49: 439 *bg = CUCUL_COLOR_DEFAULT; 410 case 0: /* default rendition */ 411 g->fg = CUCUL_COLOR_DEFAULT; 412 g->bg = CUCUL_COLOR_DEFAULT; 413 g->bold = g->negative = g->concealed = 0; 414 break; 415 case 1: /* bold or increased intensity */ 416 g->bold = 1; 417 break; 418 case 4: /* singly underlined */ 419 break; 420 case 5: /* slowly blinking (less then 150 per minute) */ 421 break; 422 case 7: /* negative image */ 423 g->negative = 1; 424 break; 425 case 8: /* concealed characters */ 426 g->concealed = 1; 427 break; 428 case 22: /* normal colour or normal intensity (neither bold nor faint) */ 429 g->bold = 0; 430 break; 431 case 28: /* revealed characters */ 432 g->concealed = 0; 433 break; 434 case 39: /* default display colour (implementation-defined) */ 435 g->fg = CUCUL_COLOR_DEFAULT; 436 break; 437 case 49: /* default background colour (implementation-defined) */ 438 g->bg = CUCUL_COLOR_DEFAULT; 440 439 break; 441 440 default: 441 //fprintf(stderr, "unknown sgr %i\n", i); 442 442 break; 443 443 }
Note: See TracChangeset
for help on using the changeset viewer.