Changeset 249
- Timestamp:
- Dec 12, 2003, 3:49:41 PM (17 years ago)
- Location:
- libcaca/trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/examples/aafire.c
r246 r249 134 134 caca_set_bitmap_palette(caca_bitmap, r, g, b, a); 135 135 bitmap = malloc(XSIZ * YSIZ * sizeof(char)); 136 caca_set_dithering(CACA_DITHERING_ORDERED8);137 136 #else 138 137 aa_hidecursor (context); -
libcaca/trunk/examples/demo.c
r246 r249 132 132 if(sprite) 133 133 demo = demo_sprites; 134 break; 134 135 case 'r': 135 136 case 'R': … … 502 503 int buffer[256*256]; 503 504 int *dest; 504 int x, y, z, t,xo, yo;505 int x, y, z, xo, yo; 505 506 static int i = 0; 506 507 … … 511 512 for(y = 0; y < 256; y++) 512 513 { 513 *dest++ = 0 ;514 *dest++ = 0xff000000; 514 515 } 515 516 … … 517 518 xo = 128 + 48 * sin(0.02 * i); 518 519 yo = 128 + 48 * cos(0.03 * i); 519 t = 256 * (2.0 + sin(4 + 0.017 * i)) / 3;520 520 for(z = 0; z < 240; z++) 521 draw_circle(buffer, xo, yo, z, 0x00ff0000, 522 ((255 - z) * t / 256) << 16); 521 draw_circle(buffer, xo, yo, z, 0x00ff0000, 200 << 16); 523 522 524 523 /* green */ 525 524 xo = 128 + 48 * sin(2 + 0.06 * i); 526 525 yo = 128 + 48 * cos(2 + 0.05 * i); 527 t = 256 * (2.0 + sin(8 + 0.021 * i)) / 3;528 526 for(z = 0; z < 240; z++) 529 draw_circle(buffer, xo, yo, z, 0x0000ff00, 530 ((255 - z) * t / 256) << 8); 527 draw_circle(buffer, xo, yo, z, 0x0000ff00, 200 << 8); 531 528 532 529 /* blue */ 533 530 xo = 128 + 48 * sin(1 + 0.04 * i); 534 531 yo = 128 + 48 * cos(1 + 0.03 * i); 535 t = 256 * (2.0 + sin(3 + 0.033 * i)) / 3;536 532 for(z = 0; z < 240; z++) 537 draw_circle(buffer, xo, yo, z, 0x000000ff, (255 - z) * t / 256);533 draw_circle(buffer, xo, yo, z, 0x000000ff, 200); 538 534 539 535 bitmap = caca_create_bitmap(32, 256, 256, 4 * 256, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000); … … 548 544 549 545 #define POINT(X,Y) \ 550 buffer[(X) + 256 * (Y)] = (buffer[(X) + 256 * (Y)] & ~mask) | val;546 buffer[(X) + 256 * (Y)] = 0xff000000 | (buffer[(X) + 256 * (Y)] & ~mask) | val; 551 547 552 548 for(t = 0, dx = 0, dy = r; dx <= dy; dx++) -
libcaca/trunk/examples/view.c
r246 r249 47 47 { 48 48 int quit = 0, update = 1, help = 0, reload = 0, fullscreen = 0, zoom = 0; 49 int dithering = CACA_DITHERING_ORDERED4;50 49 51 50 char **list = NULL; … … 109 108 update = 1; 110 109 break; 110 case CACA_EVENT_KEY_PRESS | 'b': 111 i = 1 + caca_get_feature(CACA_BACKGROUND); 112 if(i > CACA_BACKGROUND_MAX) i = CACA_BACKGROUND_MIN; 113 caca_set_feature(i); 114 update = 1; 115 break; 116 case CACA_EVENT_KEY_PRESS | 'B': 117 i = -1 + caca_get_feature(CACA_BACKGROUND); 118 if(i < CACA_BACKGROUND_MIN) i = CACA_BACKGROUND_MAX; 119 caca_set_feature(i); 120 update = 1; 121 break; 122 case CACA_EVENT_KEY_PRESS | 'a': 123 i = 1 + caca_get_feature(CACA_ANTIALIASING); 124 if(i > CACA_ANTIALIASING_MAX) i = CACA_ANTIALIASING_MIN; 125 caca_set_feature(i); 126 update = 1; 127 break; 128 case CACA_EVENT_KEY_PRESS | 'A': 129 i = -1 + caca_get_feature(CACA_ANTIALIASING); 130 if(i < CACA_ANTIALIASING_MIN) i = CACA_ANTIALIASING_MAX; 131 caca_set_feature(i); 132 update = 1; 133 break; 111 134 case CACA_EVENT_KEY_PRESS | 'd': 112 dithering = (dithering + 1) % 5; 135 i = 1 + caca_get_feature(CACA_DITHERING); 136 if(i > CACA_DITHERING_MAX) i = CACA_DITHERING_MIN; 137 caca_set_feature(i); 113 138 update = 1; 114 139 break; 115 140 case CACA_EVENT_KEY_PRESS | 'D': 116 dithering = (dithering + 4) % 5; 141 i = -1 + caca_get_feature(CACA_DITHERING); 142 if(i < CACA_DITHERING_MIN) i = CACA_DITHERING_MAX; 143 caca_set_feature(i); 117 144 update = 1; 118 145 break; … … 192 219 193 220 caca_clear(); 194 caca_set_dithering(dithering);195 221 caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLUE); 196 222 … … 250 276 caca_draw_line(0, 0, ww - 1, 0, ' '); 251 277 caca_draw_line(0, wh - 1, ww - 1, wh - 1, '-'); 252 caca_putstr(0, 0, "q:Quit n /p:Next/Prev +/-/x:Zoom "253 "h /j/k/l: Move d:Dithering");278 caca_putstr(0, 0, "q:Quit np:Next/Prev +-x:Zoom " 279 "hjkl:Move d:Dithering a:Antialias"); 254 280 caca_putstr(ww - strlen("?:Help"), 0, "?:Help"); 255 caca_printf(3, wh - 1, "cacaview %s ", VERSION);256 caca_printf(ww / 2 - 5, wh - 1, "(%s dithering)",257 caca_get_dithering_name(dithering));281 caca_printf(3, wh - 1, "cacaview %s (%s, %s)", VERSION, 282 caca_get_feature_name(caca_get_feature(CACA_DITHERING)), 283 caca_get_feature_name(caca_get_feature(CACA_ANTIALIASING))); 258 284 caca_printf(ww - 14, wh - 1, 259 285 "(zoom: %s%i)", zoom > 0 ? "+" : "", zoom); … … 262 288 if(help) 263 289 { 264 caca_putstr(ww - 22, 2, " +: zoom in "); 265 caca_putstr(ww - 22, 3, " -: zoom out "); 266 caca_putstr(ww - 22, 4, " x: reset zoom "); 267 caca_putstr(ww - 22, 5, " ------------------- "); 268 caca_putstr(ww - 22, 6, " hjkl: move view "); 269 caca_putstr(ww - 22, 7, " arrows: move view "); 270 caca_putstr(ww - 22, 8, " ------------------- "); 271 caca_putstr(ww - 22, 9, " d: dithering method "); 272 caca_putstr(ww - 22, 10, " ------------------- "); 273 caca_putstr(ww - 22, 11, " ?: help "); 274 caca_putstr(ww - 22, 12, " q: quit "); 290 caca_putstr(ww - 22, 2, " +: zoom in "); 291 caca_putstr(ww - 22, 3, " -: zoom out "); 292 caca_putstr(ww - 22, 4, " x: reset zoom "); 293 caca_putstr(ww - 22, 5, " ---------------------- "); 294 caca_putstr(ww - 22, 6, " hjkl: move view "); 295 caca_putstr(ww - 22, 7, " arrows: move view "); 296 caca_putstr(ww - 22, 8, " ---------------------- "); 297 caca_putstr(ww - 22, 9, " a: antialiasing method "); 298 caca_putstr(ww - 22, 9, " d: dithering method "); 299 caca_putstr(ww - 22, 10, " ---------------------- "); 300 caca_putstr(ww - 22, 11, " ?: help "); 301 caca_putstr(ww - 22, 12, " q: quit "); 275 302 276 303 help = 0; -
libcaca/trunk/src/bitmap.c
r247 r249 47 47 #include "caca_internals.h" 48 48 49 #define NEW_RENDERER 1 50 49 /* 50 * Global variables 51 */ 52 enum caca_feature _caca_background; 53 enum caca_feature _caca_dithering; 54 enum caca_feature _caca_antialiasing; 55 56 /* 57 * Local prototypes 58 */ 51 59 static void mask2shift(unsigned int, int *, int *); 52 60 … … 76 84 static unsigned int get_random_dither(void); 77 85 static void increment_random_dither(void); 78 79 /* Current dithering method */80 static enum caca_dithering _caca_dithering = CACA_DITHERING_NONE;81 82 static void (*_init_dither) (int) = init_no_dither;83 static unsigned int (*_get_dither) (void) = get_no_dither;84 static void (*_increment_dither) (void) = increment_no_dither;85 86 void caca_set_dithering(enum caca_dithering dither)87 {88 switch(dither)89 {90 case CACA_DITHERING_NONE:91 _init_dither = init_no_dither;92 _get_dither = get_no_dither;93 _increment_dither = increment_no_dither;94 break;95 96 case CACA_DITHERING_ORDERED2:97 _init_dither = init_ordered2_dither;98 _get_dither = get_ordered2_dither;99 _increment_dither = increment_ordered2_dither;100 break;101 102 case CACA_DITHERING_ORDERED4:103 _init_dither = init_ordered4_dither;104 _get_dither = get_ordered4_dither;105 _increment_dither = increment_ordered4_dither;106 break;107 108 case CACA_DITHERING_ORDERED8:109 _init_dither = init_ordered8_dither;110 _get_dither = get_ordered8_dither;111 _increment_dither = increment_ordered8_dither;112 break;113 114 case CACA_DITHERING_RANDOM:115 _init_dither = init_random_dither;116 _get_dither = get_random_dither;117 _increment_dither = increment_random_dither;118 break;119 120 default:121 return;122 }123 124 _caca_dithering = dither;125 }126 86 127 87 struct caca_bitmap … … 288 248 if(bitmap->palette) 289 249 { 290 *r = bitmap->red[bits];291 *g = bitmap->green[bits];292 *b = bitmap->blue[bits];293 *a = bitmap->alpha[bits];250 *r += bitmap->red[bits]; 251 *g += bitmap->green[bits]; 252 *b += bitmap->blue[bits]; 253 *a += bitmap->alpha[bits]; 294 254 } 295 255 else 296 256 { 297 *r = ((bits & bitmap->rmask) >> bitmap->rright) << bitmap->rleft;298 *g = ((bits & bitmap->gmask) >> bitmap->gright) << bitmap->gleft;299 *b = ((bits & bitmap->bmask) >> bitmap->bright) << bitmap->bleft;300 *a = ((bits & bitmap->amask) >> bitmap->aright) << bitmap->aleft;257 *r += ((bits & bitmap->rmask) >> bitmap->rright) << bitmap->rleft; 258 *g += ((bits & bitmap->gmask) >> bitmap->gright) << bitmap->gleft; 259 *b += ((bits & bitmap->bmask) >> bitmap->bright) << bitmap->bleft; 260 *a += ((bits & bitmap->amask) >> bitmap->aright) << bitmap->aleft; 301 261 } 302 262 } … … 335 295 const struct caca_bitmap *bitmap, void *pixels) 336 296 { 337 #if !NEW_RENDERER 297 /* Current dithering method */ 298 void (*_init_dither) (int); 299 unsigned int (*_get_dither) (void); 300 void (*_increment_dither) (void); 301 302 /* Only used when background is black */ 338 303 static const int white_colors[] = 339 304 { … … 343 308 CACA_COLOR_WHITE 344 309 }; 345 #endif346 310 347 311 static const int light_colors[] = … … 404 368 } 405 369 370 switch(_caca_dithering) 371 { 372 case CACA_DITHERING_NONE: 373 _init_dither = init_no_dither; 374 _get_dither = get_no_dither; 375 _increment_dither = increment_no_dither; 376 break; 377 378 case CACA_DITHERING_ORDERED2: 379 _init_dither = init_ordered2_dither; 380 _get_dither = get_ordered2_dither; 381 _increment_dither = increment_ordered2_dither; 382 break; 383 384 case CACA_DITHERING_ORDERED4: 385 _init_dither = init_ordered4_dither; 386 _get_dither = get_ordered4_dither; 387 _increment_dither = increment_ordered4_dither; 388 break; 389 390 case CACA_DITHERING_ORDERED8: 391 _init_dither = init_ordered8_dither; 392 _get_dither = get_ordered8_dither; 393 _increment_dither = increment_ordered8_dither; 394 break; 395 396 case CACA_DITHERING_RANDOM: 397 _init_dither = init_random_dither; 398 _get_dither = get_random_dither; 399 _increment_dither = increment_random_dither; 400 break; 401 402 default: 403 /* Something wicked happened! */ 404 return; 405 } 406 406 407 for(y = y1 > 0 ? y1 : 0; y <= y2 && y <= (int)_caca_height; y++) 407 408 for(x = x1 > 0 ? x1 : 0, _init_dither(y); … … 410 411 { 411 412 int ch; 412 unsigned int r, g, b, a , R, G, B;413 unsigned int r, g, b, a; 413 414 int hue, sat, val; 414 int fromx = w * (x - x1) / (x2 - x1 + 1); 415 int fromy = h * (y - y1) / (y2 - y1 + 1); 415 int fromx, fromy, tox, toy, myx, myy, dots; 416 416 enum caca_color outfg, outbg; 417 417 char outch; 418 #if NEW_RENDERER 418 419 /* Only used by coloured background */ 419 420 int distbg, distfg, dist, hue1, hue2; 420 #endif 421 422 /* Clip values (yuck) */ 423 if(fromx == 0) fromx = 1; 424 if(fromy == 0) fromy = 1; 421 422 r = g = b = a = 0; 425 423 426 424 /* First get RGB */ 427 R = 0, G = 0, B = 0; 428 get_rgba_default(bitmap, pixels, fromx, fromy, &r, &g, &b, &a); 429 if(a == 0) 430 continue; 431 #if 1 432 R += r; G += g; B += b; 433 #else 434 R += r; G += g; B += b; 435 get_rgba_default(bitmap, pixels, fromx - 1, fromy, &r, &g, &b, &a); 436 R += r; G += g; B += b; 437 get_rgba_default(bitmap, pixels, fromx, fromy - 1, &r, &g, &b, &a); 438 R += r; G += g; B += b; 439 get_rgba_default(bitmap, pixels, fromx + 1, fromy, &r, &g, &b, &a); 440 R += r; G += g; B += b; 441 get_rgba_default(bitmap, pixels, fromx, fromy + 1, &r, &g, &b, &a); 442 R += r; G += g; B += b; 443 R /= 5; G /= 5; B /= 5; 444 #endif 445 446 /* Now get HSV from RGB */ 447 rgb2hsv_default(R, G, B, &hue, &sat, &val); 448 449 /* The hard work: calculate foreground and background colours, 450 * as well as the most appropriate character to output. */ 451 #if NEW_RENDERER 452 # define XRATIO 5*5 453 # define YRATIO 3*3 454 # define HRATIO 2*2 455 # define FUZZINESS XRATIO * 0x800 456 457 /* distance to black */ 458 distbg = XRATIO * val * val; 459 distbg += FUZZINESS * _get_dither() - 0x80 * FUZZINESS; 460 distbg = distbg * 2 / 4; 461 outbg = CACA_COLOR_BLACK; 462 463 /* distance to 30% */ 464 dist = XRATIO * (val - 0x600) * (val - 0x600) 465 + YRATIO * sat * sat; 466 dist += FUZZINESS * _get_dither() - 0x80 * FUZZINESS; 467 dist = dist * 3 / 2; 468 if(dist <= distbg) 425 if(_caca_antialiasing == CACA_ANTIALIASING_PREFILTER) 469 426 { 470 outfg = outbg; 471 distfg = distbg; 472 outbg = CACA_COLOR_DARKGRAY; 473 distbg = dist; 427 fromx = ((x - x1) * (w - 1)) / (x2 - x1 + 1); 428 fromy = ((y - y1) * (h - 1)) / (y2 - y1 + 1); 429 tox = ((x - x1 + 1) * (w - 1)) / (x2 - x1 + 1); 430 toy = ((y - y1 + 1) * (h - 1)) / (y2 - y1 + 1); 431 dots = 0; 432 433 for(myx = fromx; myx <= tox; myx++) 434 for(myy = fromy; myy <= toy; myy++) 435 { 436 dots++; 437 get_rgba_default(bitmap, pixels, myx, myy, &r, &g, &b, &a); 438 } 439 440 /* Normalize */ 441 r /= dots; 442 g /= dots; 443 b /= dots; 444 a /= dots; 474 445 } 475 446 else 476 447 { 477 outfg = CACA_COLOR_DARKGRAY; 478 distfg = dist; 448 fromx = ((x - x1) * (w - 1)) / (x2 - x1 + 1); 449 fromy = ((y - y1) * (h - 1)) / (y2 - y1 + 1); 450 tox = ((x - x1 + 1) * (w - 1)) / (x2 - x1 + 1); 451 toy = ((y - y1 + 1) * (h - 1)) / (y2 - y1 + 1); 452 453 myx = (fromx + tox) / 2; 454 myy = (fromy + toy) / 2; 455 456 get_rgba_default(bitmap, pixels, myx, myy, &r, &g, &b, &a); 479 457 } 480 458 481 /* check dist to 70% */ 482 dist = XRATIO * (val - 0xa00) * (val - 0xa00) 483 + YRATIO * sat * sat; 484 dist += FUZZINESS * _get_dither() - 0x80 * FUZZINESS; 485 dist = dist * 3 / 2; 486 if(dist <= distbg) 459 if(a < 0x100) 460 continue; 461 462 /* Now get HSV from RGB */ 463 rgb2hsv_default(r, g, b, &hue, &sat, &val); 464 465 /* The hard work: calculate foreground and background colours, 466 * as well as the most appropriate character to output. */ 467 if(_caca_background == CACA_BACKGROUND_SOLID) 487 468 { 488 outfg = outbg; 489 distfg = distbg; 490 outbg = CACA_COLOR_LIGHTGRAY; 491 distbg = dist; 469 # define XRATIO 5*5 470 # define YRATIO 3*3 471 # define HRATIO 2*2 472 # define FUZZINESS XRATIO * 0x800 473 474 /* distance to black */ 475 distbg = XRATIO * val * val; 476 distbg += FUZZINESS * _get_dither() - 0x80 * FUZZINESS; 477 distbg = distbg * 2 / 4; 478 outbg = CACA_COLOR_BLACK; 479 480 /* distance to 30% */ 481 dist = XRATIO * (val - 0x600) * (val - 0x600) 482 + YRATIO * sat * sat; 483 dist += FUZZINESS * _get_dither() - 0x80 * FUZZINESS; 484 dist = dist * 3 / 2; 485 if(dist <= distbg) 486 { 487 outfg = outbg; 488 distfg = distbg; 489 outbg = CACA_COLOR_DARKGRAY; 490 distbg = dist; 491 } 492 else 493 { 494 outfg = CACA_COLOR_DARKGRAY; 495 distfg = dist; 496 } 497 498 /* check dist to 70% */ 499 dist = XRATIO * (val - 0xa00) * (val - 0xa00) 500 + YRATIO * sat * sat; 501 dist += FUZZINESS * _get_dither() - 0x80 * FUZZINESS; 502 dist = dist * 3 / 2; 503 if(dist <= distbg) 504 { 505 outfg = outbg; 506 distfg = distbg; 507 outbg = CACA_COLOR_LIGHTGRAY; 508 distbg = dist; 509 } 510 else if(dist <= distfg) 511 { 512 outfg = CACA_COLOR_LIGHTGRAY; 513 distfg = dist; 514 } 515 516 /* check dist to white */ 517 dist = XRATIO * (val - 0x1000) * (val - 0x1000) 518 + YRATIO * sat * sat; 519 dist += FUZZINESS * _get_dither() - 0x80 * FUZZINESS; 520 if(dist <= distbg) 521 { 522 outfg = outbg; 523 distfg = distbg; 524 outbg = CACA_COLOR_WHITE; 525 distbg = dist; 526 } 527 else if(dist <= distfg) 528 { 529 outfg = CACA_COLOR_WHITE; 530 distfg = dist; 531 } 532 533 hue1 = (hue + 0x800) & ~0xfff; 534 if(hue > hue1) 535 hue2 = (hue + 0x1800) & ~0xfff; 536 else 537 hue2 = (hue - 0x800) & ~0xfff; 538 539 /* check dist to 2nd closest dark color */ 540 dist = XRATIO * (val - 0x600) * (val - 0x600) 541 + YRATIO * (sat - 0x1000) * (sat - 0x1000) 542 + HRATIO * (hue - hue2) * (hue - hue2); 543 dist += FUZZINESS * _get_dither() - 0x80 * FUZZINESS; 544 //dist = dist * 3 / 4; 545 if(dist <= distbg) 546 { 547 outfg = outbg; 548 distfg = distbg; 549 outbg = dark_colors[hue2 / 0x1000]; 550 distbg = dist; 551 } 552 else if(dist <= distfg) 553 { 554 outfg = dark_colors[hue2 / 0x1000]; 555 distfg = dist; 556 } 557 558 /* check dist to 2nd closest light color */ 559 dist = XRATIO * (val - 0x1000) * (val - 0x1000) 560 + YRATIO * (sat - 0x1000) * (sat - 0x1000) 561 + HRATIO * (hue - hue2) * (hue - hue2); 562 dist += FUZZINESS * _get_dither() - 0x80 * FUZZINESS; 563 //dist = dist * 3 / 4; 564 //dist = dist / 2; 565 if(dist <= distbg) 566 { 567 outfg = outbg; 568 distfg = distbg; 569 outbg = light_colors[hue2 / 0x1000]; 570 distbg = dist; 571 } 572 else if(dist <= distfg) 573 { 574 outfg = light_colors[hue2 / 0x1000]; 575 distfg = dist; 576 } 577 578 /* check dist to closest dark color */ 579 dist = XRATIO * (val - 0x600) * (val - 0x600) 580 + YRATIO * (sat - 0x1000) * (sat - 0x1000) 581 + HRATIO * (hue - hue1) * (hue - hue1); 582 dist += FUZZINESS * _get_dither() - 0x80 * FUZZINESS; 583 dist = dist * 3 / 4; 584 if(dist <= distbg) 585 { 586 outfg = outbg; 587 distfg = distbg; 588 outbg = dark_colors[hue1 / 0x1000]; 589 distbg = dist; 590 } 591 else if(dist <= distfg) 592 { 593 outfg = dark_colors[hue1 / 0x1000]; 594 distfg = dist; 595 } 596 597 /* check dist to closest light color */ 598 dist = XRATIO * (val - 0x1000) * (val - 0x1000) 599 + YRATIO * (sat - 0x1000) * (sat - 0x1000) 600 + HRATIO * (hue - hue1) * (hue - hue1); 601 dist += FUZZINESS * _get_dither() - 0x80 * FUZZINESS; 602 dist = dist / 2; 603 if(dist <= distbg) 604 { 605 outfg = outbg; 606 distfg = distbg; 607 outbg = light_colors[hue1 / 0x1000]; 608 distbg = dist; 609 } 610 else if(dist <= distfg) 611 { 612 outfg = light_colors[hue1 / 0x1000]; 613 distfg = dist; 614 } 615 616 if(distbg <= 0) distbg = 1; 617 if(distfg <= 0) distfg = 1; 618 619 /* distbg can be > distfg because of dithering fuzziness */ 620 ch = distbg * 2 * (DENSITY_CHARS - 1) / (distbg + distfg); 621 ch = 4 * ch + _get_dither() / 0x40; 622 outch = density_chars[ch]; 492 623 } 493 else if(dist <= distfg)624 else 494 625 { 495 outfg = CACA_COLOR_LIGHTGRAY; 496 distfg = dist; 626 outbg = CACA_COLOR_BLACK; 627 if((unsigned int)sat < 0x200 + _get_dither() * 0x8) 628 outfg = white_colors[1 + (val * 2 + _get_dither() * 0x10) 629 / 0x1000]; 630 else if((unsigned int)val > 0x800 + _get_dither() * 0x4) 631 outfg = light_colors[(hue + _get_dither() * 0x10) / 0x1000]; 632 else 633 outfg = dark_colors[(hue + _get_dither() * 0x10) / 0x1000]; 634 635 ch = (val + 0x2 * _get_dither()) * 10 / 0x1000; 636 ch = 4 * ch + _get_dither() / 0x40; 637 outch = density_chars[ch]; 497 638 } 498 499 /* check dist to white */500 dist = XRATIO * (val - 0x1000) * (val - 0x1000)501 + YRATIO * sat * sat;502 dist += FUZZINESS * _get_dither() - 0x80 * FUZZINESS;503 if(dist <= distbg)504 {505 outfg = outbg;506 distfg = distbg;507 outbg = CACA_COLOR_WHITE;508 distbg = dist;509 }510 else if(dist <= distfg)511 {512 outfg = CACA_COLOR_WHITE;513 distfg = dist;514 }515 516 hue1 = (hue + 0x800) & ~0xfff;517 if(hue > hue1)518 hue2 = (hue + 0x1800) & ~0xfff;519 else520 hue2 = (hue - 0x800) & ~0xfff;521 522 /* check dist to 2nd closest dark color */523 dist = XRATIO * (val - 0x600) * (val - 0x600)524 + YRATIO * (sat - 0x1000) * (sat - 0x1000)525 + HRATIO * (hue - hue2) * (hue - hue2);526 dist += FUZZINESS * _get_dither() - 0x80 * FUZZINESS;527 // dist = dist * 3 / 4;528 if(dist <= distbg)529 {530 outfg = outbg;531 distfg = distbg;532 outbg = dark_colors[hue2 / 0x1000];533 distbg = dist;534 }535 else if(dist <= distfg)536 {537 outfg = dark_colors[hue2 / 0x1000];538 distfg = dist;539 }540 541 /* check dist to 2nd closest light color */542 dist = XRATIO * (val - 0x1000) * (val - 0x1000)543 + YRATIO * (sat - 0x1000) * (sat - 0x1000)544 + HRATIO * (hue - hue2) * (hue - hue2);545 dist += FUZZINESS * _get_dither() - 0x80 * FUZZINESS;546 //dist = dist * 3 / 4;547 //dist = dist / 2;548 if(dist <= distbg)549 {550 outfg = outbg;551 distfg = distbg;552 outbg = light_colors[hue2 / 0x1000];553 distbg = dist;554 }555 else if(dist <= distfg)556 {557 outfg = light_colors[hue2 / 0x1000];558 distfg = dist;559 }560 561 /* check dist to closest dark color */562 dist = XRATIO * (val - 0x600) * (val - 0x600)563 + YRATIO * (sat - 0x1000) * (sat - 0x1000)564 + HRATIO * (hue - hue1) * (hue - hue1);565 dist += FUZZINESS * _get_dither() - 0x80 * FUZZINESS;566 dist = dist * 3 / 4;567 if(dist <= distbg)568 {569 outfg = outbg;570 distfg = distbg;571 outbg = dark_colors[hue1 / 0x1000];572 distbg = dist;573 }574 else if(dist <= distfg)575 {576 outfg = dark_colors[hue1 / 0x1000];577 distfg = dist;578 }579 580 /* check dist to closest light color */581 dist = XRATIO * (val - 0x1000) * (val - 0x1000)582 + YRATIO * (sat - 0x1000) * (sat - 0x1000)583 + HRATIO * (hue - hue1) * (hue - hue1);584 dist += FUZZINESS * _get_dither() - 0x80 * FUZZINESS;585 dist = dist / 2;586 if(dist <= distbg)587 {588 outfg = outbg;589 distfg = distbg;590 outbg = light_colors[hue1 / 0x1000];591 distbg = dist;592 }593 else if(dist <= distfg)594 {595 outfg = light_colors[hue1 / 0x1000];596 distfg = dist;597 }598 599 if(distbg <= 0) distbg = 1;600 if(distfg <= 0) distfg = 1;601 602 /* distbg can be > distfg because of dithering fuzziness */603 ch = distbg * 2 * (DENSITY_CHARS - 1) / (distbg + distfg);604 ch = 4 * ch + _get_dither() / 0x40;605 outch = density_chars[ch];606 607 #else608 outbg = CACA_COLOR_BLACK;609 if((unsigned int)sat < 0x200 + _get_dither() * 0x8)610 outfg = white_colors[1 + (val * 2 + _get_dither() * 0x10) / 0x1000];611 else if((unsigned int)val > 0x800 + _get_dither() * 0x4)612 outfg = light_colors[(hue + _get_dither() * 0x10) / 0x1000];613 else614 outfg = dark_colors[(hue + _get_dither() * 0x10) / 0x1000];615 616 ch = (val + 0x2 * _get_dither()) * 10 / 0x1000;617 ch = 4 * ch + _get_dither() / 0x40;618 outch = density_chars[ch];619 620 #endif621 639 622 640 /* Now output the character */ -
libcaca/trunk/src/caca.c
r247 r249 49 49 #include "caca_internals.h" 50 50 51 static void caca_init_features(void); 51 52 static void caca_init_terminal(void); 52 53 … … 61 62 #endif 62 63 64 caca_init_features(); 63 65 caca_init_terminal(); 64 66 … … 157 159 } 158 160 159 const char *caca_get_dithering_name(enum caca_dithering dithering) 160 { 161 static const char *dithering_names[] = 162 { 163 "no", 164 "2x2 ordered", 165 "4x4 ordered", 166 "8x8 ordered", 167 "random" 168 }; 169 170 if(dithering < 0 || dithering > 4) 171 return "unknown"; 172 173 return dithering_names[dithering]; 161 enum caca_feature caca_get_feature(enum caca_feature feature) 162 { 163 switch(feature) 164 { 165 case CACA_BACKGROUND: 166 return _caca_background; 167 case CACA_ANTIALIASING: 168 return _caca_antialiasing; 169 case CACA_DITHERING: 170 return _caca_dithering; 171 172 default: 173 return CACA_UNKNOWN_FEATURE; 174 } 175 } 176 177 void caca_set_feature(enum caca_feature feature) 178 { 179 switch(feature) 180 { 181 case CACA_BACKGROUND: 182 feature = CACA_BACKGROUND_SOLID; 183 case CACA_BACKGROUND_BLACK: 184 case CACA_BACKGROUND_SOLID: 185 _caca_background = feature; 186 break; 187 188 case CACA_ANTIALIASING: 189 feature = CACA_ANTIALIASING_PREFILTER; 190 case CACA_ANTIALIASING_NONE: 191 case CACA_ANTIALIASING_PREFILTER: 192 _caca_antialiasing = feature; 193 break; 194 195 case CACA_DITHERING: 196 feature = CACA_DITHERING_ORDERED4; 197 case CACA_DITHERING_NONE: 198 case CACA_DITHERING_ORDERED2: 199 case CACA_DITHERING_ORDERED4: 200 case CACA_DITHERING_ORDERED8: 201 case CACA_DITHERING_RANDOM: 202 _caca_dithering = feature; 203 break; 204 205 case CACA_UNKNOWN_FEATURE: 206 break; 207 } 208 } 209 210 const char *caca_get_feature_name(enum caca_feature feature) 211 { 212 switch(feature) 213 { 214 case CACA_BACKGROUND_BLACK: return "black background"; 215 case CACA_BACKGROUND_SOLID: return "solid background"; 216 217 case CACA_ANTIALIASING_NONE: return "no antialiasing"; 218 case CACA_ANTIALIASING_PREFILTER: return "prefilter antialiasing"; 219 220 case CACA_DITHERING_NONE: return "no dithering"; 221 case CACA_DITHERING_ORDERED2: return "2x2 ordered dithering"; 222 case CACA_DITHERING_ORDERED4: return "4x4 ordered dithering"; 223 case CACA_DITHERING_ORDERED8: return "8x8 ordered dithering"; 224 case CACA_DITHERING_RANDOM: return "random dithering"; 225 226 default: return "unknown"; 227 } 174 228 } 175 229 … … 195 249 } 196 250 251 static void caca_init_features(void) 252 { 253 caca_set_feature(CACA_BACKGROUND); 254 caca_set_feature(CACA_ANTIALIASING); 255 caca_set_feature(CACA_DITHERING); 256 } 257 197 258 static void caca_init_terminal(void) 198 259 { -
libcaca/trunk/src/caca.h
r247 r249 85 85 86 86 /** 87 * The dithering modes to be used with caca_set_dithering(). 88 */ 89 enum caca_dithering 90 { 91 CACA_DITHERING_NONE = 0, 92 CACA_DITHERING_ORDERED2 = 1, 93 CACA_DITHERING_ORDERED4 = 2, 94 CACA_DITHERING_ORDERED8 = 3, 95 CACA_DITHERING_RANDOM = 4 96 }; 97 98 const char *caca_get_dithering_name(enum caca_dithering); 87 * The internal libcaca features. 88 */ 89 enum caca_feature 90 { 91 /* Properties of background characters */ 92 CACA_BACKGROUND = 0x10, 93 CACA_BACKGROUND_BLACK = 0x11, 94 CACA_BACKGROUND_SOLID = 0x12, 95 #define CACA_BACKGROUND_MIN 0x11 96 #define CACA_BACKGROUND_MAX 0x12 97 98 /* Antialiasing features */ 99 CACA_ANTIALIASING = 0x20, 100 CACA_ANTIALIASING_NONE = 0x21, 101 CACA_ANTIALIASING_PREFILTER = 0x22, 102 #define CACA_ANTIALIASING_MIN 0x21 103 #define CACA_ANTIALIASING_MAX 0x22 104 105 /* Dithering methods */ 106 CACA_DITHERING = 0x30, 107 CACA_DITHERING_NONE = 0x31, 108 CACA_DITHERING_ORDERED2 = 0x32, 109 CACA_DITHERING_ORDERED4 = 0x33, 110 CACA_DITHERING_ORDERED8 = 0x34, 111 CACA_DITHERING_RANDOM = 0x35, 112 #define CACA_DITHERING_MIN 0x31 113 #define CACA_DITHERING_MAX 0x35 114 115 /* Unknown feature */ 116 CACA_UNKNOWN_FEATURE = 0xffff 117 }; 118 119 const char *caca_get_feature_name(enum caca_feature); 99 120 100 121 /* Backwards compatibility */ 122 #define caca_dithering caca_feature 123 #define caca_set_dithering caca_set_feature 124 #define caca_get_dithering_name caca_get_feature_name 101 125 #define CACA_DITHER_NONE CACA_DITHERING_NONE 102 126 #define CACA_DITHER_ORDERED CACA_DITHERING_ORDERED8 … … 146 170 int caca_init(void); 147 171 void caca_set_delay(unsigned int); 148 void caca_set_dithering(enum caca_dithering); 172 enum caca_feature caca_get_feature(enum caca_feature); 173 void caca_set_feature(enum caca_feature); 149 174 unsigned int caca_get_rendertime(void); 150 175 unsigned int caca_get_width(void); -
libcaca/trunk/src/caca_internals.h
r247 r249 33 33 extern int _caca_init_graphics(void); 34 34 35 /* Cached screen size */ 35 36 extern unsigned int _caca_width; 36 37 extern unsigned int _caca_height; 37 38 39 /* Internal libcaca features */ 40 extern enum caca_feature _caca_background; 41 extern enum caca_feature _caca_dithering; 42 extern enum caca_feature _caca_antialiasing; 43 38 44 #endif /* __CACA_INTERNALS_H__ */
Note: See TracChangeset
for help on using the changeset viewer.