476 |
} |
} |
477 |
|
|
478 |
|
|
479 |
|
/* |
480 |
|
chroma optimize filter, invented by mf |
481 |
|
a chroma pixel is average from the surrounding pixels, when the |
482 |
|
correpsonding luma pixels are pure black or white. |
483 |
|
*/ |
484 |
|
|
485 |
|
void |
486 |
|
image_chroma_optimize(IMAGE * img, int width, int height, int edged_width) |
487 |
|
{ |
488 |
|
int x,y; |
489 |
|
int pixels = 0; |
490 |
|
|
491 |
|
for (y = 1; y < height/2 - 1; y++) |
492 |
|
for (x = 1; x < width/2 - 1; x++) |
493 |
|
{ |
494 |
|
#define IS_PURE(a) ((a)<=16||(a)>=235) |
495 |
|
#define IMG_Y(Y,X) img->y[(Y)*edged_width + (X)] |
496 |
|
#define IMG_U(Y,X) img->u[(Y)*edged_width/2 + (X)] |
497 |
|
#define IMG_V(Y,X) img->v[(Y)*edged_width/2 + (X)] |
498 |
|
|
499 |
|
if (IS_PURE(IMG_Y(y*2 ,x*2 )) && |
500 |
|
IS_PURE(IMG_Y(y*2 ,x*2+1)) && |
501 |
|
IS_PURE(IMG_Y(y*2+1,x*2 )) && |
502 |
|
IS_PURE(IMG_Y(y*2+1,x*2+1))) |
503 |
|
{ |
504 |
|
IMG_U(y,x) = (IMG_U(y,x-1) + IMG_U(y-1, x) + IMG_U(y, x+1) + IMG_U(y+1, x)) / 4; |
505 |
|
IMG_V(y,x) = (IMG_V(y,x-1) + IMG_V(y-1, x) + IMG_V(y, x+1) + IMG_V(y+1, x)) / 4; |
506 |
|
pixels++; |
507 |
|
} |
508 |
|
|
509 |
|
#undef IS_PURE |
510 |
|
#undef IMG_Y |
511 |
|
#undef IMG_U |
512 |
|
#undef IMG_V |
513 |
|
} |
514 |
|
|
515 |
|
DPRINTF(DPRINTF_DEBUG,"chroma_optimized_pixels = %i/%i", pixels, width*height/4); |
516 |
|
} |
517 |
|
|
518 |
|
|
519 |
|
|
520 |
|
|
521 |
|
|
522 |
/* |
/* |
523 |
perform safe packed colorspace conversion, by splitting |
perform safe packed colorspace conversion, by splitting |