Changeset 235
- Timestamp:
- Nov 29, 2003, 8:35:07 PM (17 years ago)
- Location:
- libcaca/trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/examples/demo.c
r226 r235 101 101 case 'd': 102 102 case 'D': 103 dithering = (dithering + 1) % 3; 104 caca_set_dithering(dithering == 0 ? CACA_DITHER_NONE : 105 dithering == 1 ? CACA_DITHER_ORDERED : 106 CACA_DITHER_RANDOM); 103 dithering = (dithering + 1) % 4; 104 caca_set_dithering(dithering); 107 105 display_menu(); 108 106 break; … … 204 202 caca_printf(4, 18, "'b': drawing boundaries: %s", 205 203 bounds == 0 ? "screen" : "infinite"); 206 caca_printf(4, 19, "'d': %s dithering",207 dithering == 0 ? "no" : dithering == 1 ? "ordered" : "random");204 caca_printf(4, 19, "'d': dithering (%s)", 205 caca_get_dithering_name(dithering)); 208 206 209 207 caca_putstr(4, yo - 2, "'q': quit"); -
libcaca/trunk/examples/view.c
r233 r235 38 38 int x, y, w, h; 39 39 40 int dithering = 1; 41 const enum caca_dithering dithering_list[] = 42 { CACA_DITHER_NONE, CACA_DITHER_ORDERED, CACA_DITHER_RANDOM }; 40 int dithering = CACA_DITHERING_ORDERED4; 43 41 44 42 static void load_image(const char *); … … 105 103 case CACA_EVENT_KEY_PRESS | 'd': 106 104 case CACA_EVENT_KEY_PRESS | 'D': 107 dithering = (dithering + 1) % 3;105 dithering = (dithering + 1) % 4; 108 106 update = 1; 109 107 break; … … 179 177 { 180 178 caca_clear(); 181 caca_set_dithering(dithering _list[dithering]);179 caca_set_dithering(dithering); 182 180 caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLUE); 183 181 … … 227 225 "d:Dithering ?:Help"); 228 226 caca_printf(3, wh - 1, "cacaview %s", VERSION); 227 caca_printf(ww / 2 - 5, wh - 1, "(dithering: %s)", 228 caca_get_dithering_name(dithering)); 229 229 caca_printf(ww - 14, wh - 1, 230 230 "(zoom: %s%i)", zoom > 0 ? "+" : "", zoom); -
libcaca/trunk/src/bitmap.c
r230 r235 54 54 static void increment_no_dither(void); 55 55 56 static void init_ordered_dither(int); 57 static int get_ordered_dither(void); 58 static void increment_ordered_dither(void); 56 static void init_ordered4_dither(int); 57 static int get_ordered4_dither(void); 58 static void increment_ordered4_dither(void); 59 60 static void init_ordered8_dither(int); 61 static int get_ordered8_dither(void); 62 static void increment_ordered8_dither(void); 59 63 60 64 static void init_random_dither(int); … … 63 67 64 68 /* Current dithering method */ 65 static enum caca_dithering _caca_dithering = CACA_DITHER _NONE;69 static enum caca_dithering _caca_dithering = CACA_DITHERING_NONE; 66 70 67 71 static void (*_init_dither) (int) = init_no_dither; … … 73 77 switch(dither) 74 78 { 75 case CACA_DITHER _NONE:79 case CACA_DITHERING_NONE: 76 80 _init_dither = init_no_dither; 77 81 _get_dither = get_no_dither; … … 79 83 break; 80 84 81 case CACA_DITHER _ORDERED:82 _init_dither = init_ordered _dither;83 _get_dither = get_ordered _dither;84 _increment_dither = increment_ordered _dither;85 case CACA_DITHERING_ORDERED4: 86 _init_dither = init_ordered4_dither; 87 _get_dither = get_ordered4_dither; 88 _increment_dither = increment_ordered4_dither; 85 89 break; 86 90 87 case CACA_DITHER_RANDOM: 91 case CACA_DITHERING_ORDERED8: 92 _init_dither = init_ordered8_dither; 93 _get_dither = get_ordered8_dither; 94 _increment_dither = increment_ordered8_dither; 95 break; 96 97 case CACA_DITHERING_RANDOM: 88 98 _init_dither = init_random_dither; 89 99 _get_dither = get_random_dither; … … 311 321 312 322 static char foo[] = 313 { 314 ' ', ' ', ' ', ' ', 315 ',', '`', '.', '\'', 316 'i', '-', ':', '^', 317 '|', '/', ';', '\\', 318 '=', '+', 'o', 'x', 319 '<', 'x', '%', '>', 320 '&', 'z', '$', 'w', 321 'W', 'X', 'K', 'M', 322 '#', '8', '#', '#', 323 '8', '@', '8', '#', 324 '@', '8', '@', '8', 325 }; 323 " " 324 " ,' " 325 ",`.'" 326 "i-:^" 327 "|/;\\" 328 "=+ox" 329 "<x%>" 330 "&z$w" 331 "WXKM" 332 "#8##" 333 "8@8#" 334 "@8@8"; 326 335 327 336 int x, y, w, h, pitch; … … 378 387 rgb2hsv_default(R, G, B, &hue, &sat, &val); 379 388 380 if(sat < 0x 6000 + _get_dither() * 0x800)389 if(sat < 0x2000 + _get_dither() * 0x80) 381 390 caca_set_color(white_colors[val * 3 / 0x10000], CACA_COLOR_BLACK); 382 else if(val > (_get_dither() + 40) * 0x400)383 caca_set_color(light_colors[(hue + 0x8000 + _get_dither() * 0x1000) / 0x10000], CACA_COLOR_BLACK);391 else if(val > 0x8000 + _get_dither() * 0x40) 392 caca_set_color(light_colors[(hue + _get_dither() * 0x100) / 0x10000], CACA_COLOR_BLACK); 384 393 else 385 caca_set_color(dark_colors[(hue + 0x8000 + _get_dither() * 0x1000) / 0x10000], CACA_COLOR_BLACK);394 caca_set_color(dark_colors[(hue + _get_dither() * 0x100) / 0x10000], CACA_COLOR_BLACK); 386 395 387 396 /* FIXME: choose better characters! */ 388 ch = (val + 0x20 0 * _get_dither()) * 10 / 0x10000;389 ch = 4 * ch + (_get_dither() + 8) / 4;397 ch = (val + 0x20 * _get_dither() - 0x1000 /*???*/) * 10 / 0x10000; 398 ch = 4 * ch + (_get_dither() + 8) / 0x40; 390 399 caca_putchar(x, y, foo[ch]); 391 400 … … 409 418 static int get_no_dither(void) 410 419 { 411 return 0 ;420 return 0x80; 412 421 } 413 422 … … 418 427 419 428 /* 420 * Ordered dithering 421 */ 422 static int dither4x4[] = {-8, 0, -6, 2, 423 4, -4, 6, -2, 424 -5, 3, -7, 1, 425 7, -1, 5, -3}; 426 static int *dither_table; 427 static int dither_index; 428 429 static void init_ordered_dither(int line) 430 { 431 dither_table = dither4x4 + (line % 4) * 4; 432 dither_index = 0; 433 } 434 435 static int get_ordered_dither(void) 436 { 437 return dither_table[dither_index]; 438 } 439 440 static void increment_ordered_dither(void) 441 { 442 dither_index = (dither_index + 1) % 4; 429 * Ordered 4 dithering 430 */ 431 /*static int dither4x4[] = { 5, 0, 1, 6, 432 -1, -6, -5, 2, 433 -2, -7, -8, 3, 434 4, -3, -4, -7};*/ 435 static int *ordered4_table; 436 static int ordered4_index; 437 438 static void init_ordered4_dither(int line) 439 { 440 static int dither4x4[] = 441 { 442 0x00, 0x80, 0x20, 0xa0, 443 0xc0, 0x40, 0xe0, 0x60, 444 0x30, 0xb0, 0x10, 0x90, 445 0xf0, 0x70, 0xd0, 0x50 446 }; 447 448 ordered4_table = dither4x4 + (line % 4) * 4; 449 ordered4_index = 0; 450 } 451 452 static int get_ordered4_dither(void) 453 { 454 return ordered4_table[ordered4_index]; 455 } 456 457 static void increment_ordered4_dither(void) 458 { 459 ordered4_index = (ordered4_index + 1) % 4; 460 } 461 462 /* 463 * Ordered 8 dithering 464 */ 465 static int *ordered8_table; 466 static int ordered8_index; 467 468 static void init_ordered8_dither(int line) 469 { 470 static int dither8x8[] = 471 { 472 0x00, 0x80, 0x20, 0xa0, 0x08, 0x88, 0x28, 0xa8, 473 0xc0, 0x40, 0xe0, 0x60, 0xc8, 0x48, 0xe8, 0x68, 474 0x30, 0xb0, 0x10, 0x90, 0x38, 0xb8, 0x18, 0x98, 475 0xf0, 0x70, 0xd0, 0x50, 0xf8, 0x78, 0xd8, 0x58, 476 0x0c, 0x8c, 0x2c, 0xac, 0x04, 0x84, 0x24, 0xa4, 477 0xcc, 0x4c, 0xec, 0x6c, 0xc4, 0x44, 0xe4, 0x64, 478 0x3c, 0xbc, 0x1c, 0x9c, 0x34, 0xb4, 0x14, 0x94, 479 0xfc, 0x7c, 0xdc, 0x5c, 0xf4, 0x74, 0xd4, 0x54, 480 }; 481 482 ordered8_table = dither8x8 + (line % 8) * 8; 483 ordered8_index = 0; 484 } 485 486 static int get_ordered8_dither(void) 487 { 488 return ordered8_table[ordered8_index]; 489 } 490 491 static void increment_ordered8_dither(void) 492 { 493 ordered8_index = (ordered8_index + 1) % 8; 443 494 } 444 495 … … 453 504 static int get_random_dither(void) 454 505 { 455 return caca_rand( -8, 7);506 return caca_rand(0x00, 0xff); 456 507 } 457 508 -
libcaca/trunk/src/caca.c
r234 r235 153 153 } 154 154 155 const char *caca_get_color_name( unsigned intcolor)156 { 157 static const char *color_names[ 16] =155 const char *caca_get_color_name(enum caca_color color) 156 { 157 static const char *color_names[] = 158 158 { 159 159 "black", … … 176 176 177 177 if(color < 0 || color > 15) 178 return "unknown color";178 return "unknown"; 179 179 180 180 return color_names[color]; 181 } 182 183 const char *caca_get_dithering_name(enum caca_dithering dithering) 184 { 185 static const char *dithering_names[] = 186 { 187 "none", 188 "ordered 4x4", 189 "ordered 8x8", 190 "random" 191 }; 192 193 if(dithering < 0 || dithering > 3) 194 return "unknown"; 195 196 return dithering_names[dithering]; 181 197 } 182 198 -
libcaca/trunk/src/caca.h
r226 r235 82 82 }; 83 83 84 const char *caca_get_color_name(enum caca_color); 85 84 86 /** 85 87 * The dithering modes to be used with caca_set_dithering(). … … 87 89 enum caca_dithering 88 90 { 89 CACA_DITHER_NONE, 90 CACA_DITHER_ORDERED, 91 CACA_DITHER_RANDOM 92 }; 91 CACA_DITHERING_NONE = 0, 92 CACA_DITHERING_ORDERED4 = 1, 93 CACA_DITHERING_ORDERED8 = 2, 94 CACA_DITHERING_RANDOM = 3 95 }; 96 97 const char *caca_get_dithering_name(enum caca_dithering); 98 99 /* Backwards compatibility */ 100 #define CACA_DITHER_NONE CACA_DITHERING_NONE 101 #define CACA_DITHER_ORDERED CACA_DITHERING_ORDERED8 102 #define CACA_DITHER_RANDOM CACA_DITHERING_RANDOM 93 103 94 104 /** … … 139 149 unsigned int caca_get_width(void); 140 150 unsigned int caca_get_height(void); 141 const char *caca_get_color_name(unsigned int);142 151 void caca_refresh(void); 143 152 void caca_end(void);
Note: See TracChangeset
for help on using the changeset viewer.