Changeset 239 for libcaca/trunk/src
- Timestamp:
- Nov 30, 2003, 4:56:02 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/src/bitmap.c
r238 r239 43 43 #include "caca_internals.h" 44 44 45 #define NEW_RENDERER 1 46 45 47 static void mask2shift(unsigned int, int *, int *); 46 48 … … 309 311 struct caca_bitmap *bitmap, char *pixels) 310 312 { 311 /* FIXME: this code is shite! */ 312 static int white_colors[] =313 #if !NEW_RENDERER 314 static const int white_colors[] = 313 315 { 314 316 CACA_COLOR_BLACK, … … 317 319 CACA_COLOR_WHITE 318 320 }; 319 320 static int light_colors[] = 321 #endif 322 323 static const int light_colors[] = 321 324 { 322 325 CACA_COLOR_LIGHTMAGENTA, … … 329 332 }; 330 333 331 static int dark_colors[] =334 static const int dark_colors[] = 332 335 { 333 336 CACA_COLOR_MAGENTA, … … 342 345 /* FIXME: choose better characters! */ 343 346 # define DENSITY_CHARS 13 344 static c har density_chars[] =347 static const char density_chars[] = 345 348 " " 346 349 " " … … 389 392 enum caca_color outfg, outbg; 390 393 char outch; 391 #define NEW_DITHERER 1 392 #ifdef NEW_DITHERER 393 int distbg, distfg, dist; 394 #if NEW_RENDERER 395 int distbg, distfg, dist, hue1, hue2; 394 396 #endif 395 397 … … 401 403 R = 0, G = 0, B = 0; 402 404 get_rgb_default(bitmap, pixels, fromx, fromy, &r, &g, &b); 403 #if 0 405 #if 1 406 R += r; G += g; B += b; 407 #else 404 408 R += r; G += g; B += b; 405 409 get_rgb_default(bitmap, pixels, fromx - 1, fromy, &r, &g, &b); … … 412 416 R += r; G += g; B += b; 413 417 R /= 5; G /= 5; B /= 5; 414 #else415 R += r; G += g; B += b;416 418 #endif 417 419 … … 421 423 /* The hard work: calculate foreground and background colours, 422 424 * as well as the most appropriate character to output. */ 423 #if NEW_DITHERER 424 #define XRATIO 5*5 425 #define YRATIO 3*3 425 #if NEW_RENDERER 426 # define XRATIO 5*5 427 # define YRATIO 3*3 428 # define HRATIO 2*2 429 # define FUZZINESS XRATIO * 0x800 430 426 431 /* distance to black */ 427 432 distbg = XRATIO * val * val; 428 distbg += XRATIO * 0x1000 * _get_dither() - XRATIO * 0x8000;433 distbg += FUZZINESS * _get_dither() - 0x80 * FUZZINESS; 429 434 outbg = CACA_COLOR_BLACK; 430 435 … … 432 437 dist = XRATIO * (val - 0x600) * (val - 0x600) 433 438 + YRATIO * sat * sat; 434 dist += XRATIO * 0x1000 * _get_dither() - XRATIO * 0x8000; 439 dist += FUZZINESS * _get_dither() - 0x80 * FUZZINESS; 440 dist = dist * 3 / 2; 435 441 if(dist <= distbg) 436 442 { … … 449 455 dist = XRATIO * (val - 0xa00) * (val - 0xa00) 450 456 + YRATIO * sat * sat; 451 dist += XRATIO * 0x1000 * _get_dither() - XRATIO * 0x8000; 457 dist += FUZZINESS * _get_dither() - 0x80 * FUZZINESS; 458 dist = dist * 3 / 2; 452 459 if(dist <= distbg) 453 460 { … … 466 473 dist = XRATIO * (val - 0x1000) * (val - 0x1000) 467 474 + YRATIO * sat * sat; 468 dist += XRATIO * 0x1000 * _get_dither() - XRATIO * 0x8000;475 dist += FUZZINESS * _get_dither() - 0x80 * FUZZINESS; 469 476 if(dist <= distbg) 470 477 { … … 480 487 } 481 488 482 /* check dist to dark */ 489 hue1 = (hue + 0x800) & ~0xfff; 490 if(hue > hue1) 491 hue2 = (hue + 0x1800) & ~0xfff; 492 else 493 hue2 = (hue - 0x800) & ~0xfff; 494 495 /* check dist to 2nd closest dark color */ 483 496 dist = XRATIO * (val - 0x600) * (val - 0x600) 484 + YRATIO * (sat - 0x1000) * (sat - 0x1000); 485 dist += XRATIO * 0x1000 * _get_dither() - XRATIO * 0x8000; 497 + YRATIO * (sat - 0x1000) * (sat - 0x1000) 498 + HRATIO * (hue - hue2) * (hue - hue2); 499 dist += FUZZINESS * _get_dither() - 0x80 * FUZZINESS; 486 500 dist = dist * 3 / 4; 487 501 if(dist <= distbg) … … 489 503 outfg = outbg; 490 504 distfg = distbg; 491 outbg = dark_colors[ (hue + _get_dither() * 0x10)/ 0x1000];505 outbg = dark_colors[hue2 / 0x1000]; 492 506 distbg = dist; 493 507 } 494 508 else if(dist <= distfg) 495 509 { 496 outfg = dark_colors[ (hue + _get_dither() * 0x10)/ 0x1000];510 outfg = dark_colors[hue2 / 0x1000]; 497 511 distfg = dist; 498 512 } 499 513 500 /* check dist to light*/514 /* check dist to 2nd closest light color */ 501 515 dist = XRATIO * (val - 0x1000) * (val - 0x1000) 502 + YRATIO * (sat - 0x1000) * (sat - 0x1000); 503 dist += XRATIO * 0x1000 * _get_dither() - XRATIO * 0x8000; 516 + YRATIO * (sat - 0x1000) * (sat - 0x1000) 517 + HRATIO * (hue - hue2) * (hue - hue2); 518 dist += FUZZINESS * _get_dither() - 0x80 * FUZZINESS; 504 519 dist = dist / 2; 505 520 if(dist <= distbg) … … 507 522 outfg = outbg; 508 523 distfg = distbg; 509 outbg = light_colors[ (hue + _get_dither() * 0x10)/ 0x1000];524 outbg = light_colors[hue2 / 0x1000]; 510 525 distbg = dist; 511 526 } 512 527 else if(dist <= distfg) 513 528 { 514 outfg = light_colors[(hue + _get_dither() * 0x10) / 0x1000]; 529 outfg = light_colors[hue2 / 0x1000]; 530 distfg = dist; 531 } 532 533 /* check dist to closest dark color */ 534 dist = XRATIO * (val - 0x600) * (val - 0x600) 535 + YRATIO * (sat - 0x1000) * (sat - 0x1000) 536 + HRATIO * (hue - hue1) * (hue - hue1); 537 dist += FUZZINESS * _get_dither() - 0x80 * FUZZINESS; 538 dist = dist * 3 / 4; 539 if(dist <= distbg) 540 { 541 outfg = outbg; 542 distfg = distbg; 543 outbg = dark_colors[hue1 / 0x1000]; 544 distbg = dist; 545 } 546 else if(dist <= distfg) 547 { 548 outfg = dark_colors[hue1 / 0x1000]; 549 distfg = dist; 550 } 551 552 /* check dist to closest light color */ 553 dist = XRATIO * (val - 0x1000) * (val - 0x1000) 554 + YRATIO * (sat - 0x1000) * (sat - 0x1000) 555 + HRATIO * (hue - hue1) * (hue - hue1); 556 dist += FUZZINESS * _get_dither() - 0x80 * FUZZINESS; 557 dist = dist / 2; 558 if(dist <= distbg) 559 { 560 outfg = outbg; 561 distfg = distbg; 562 outbg = light_colors[hue1 / 0x1000]; 563 distbg = dist; 564 } 565 else if(dist <= distfg) 566 { 567 outfg = light_colors[hue1 / 0x1000]; 515 568 distfg = dist; 516 569 } … … 521 574 /* distbg can be > distfg because of dithering fuzziness */ 522 575 ch = distbg * 2 * (DENSITY_CHARS - 1) / (distbg + distfg); 523 ch = 4 * ch /*+ _get_dither() / 0x40*/;576 ch = 4 * ch + _get_dither() / 0x40; 524 577 outch = density_chars[ch]; 525 578 526 579 #else 527 580 outbg = CACA_COLOR_BLACK; 528 if( sat < 0x200 + _get_dither() * 0x8)581 if((unsigned int)sat < 0x200 + _get_dither() * 0x8) 529 582 outfg = white_colors[1 + (val * 2 + _get_dither() * 0x10) / 0x1000]; 530 else if( val > 0x800 + _get_dither() * 0x4)583 else if((unsigned int)val > 0x800 + _get_dither() * 0x4) 531 584 outfg = light_colors[(hue + _get_dither() * 0x10) / 0x1000]; 532 585 else
Note: See TracChangeset
for help on using the changeset viewer.