diff --git a/pipi/filter/yuv.c b/pipi/filter/yuv.c index 273e84d..4b3abfb 100644 --- a/pipi/filter/yuv.c +++ b/pipi/filter/yuv.c @@ -31,7 +31,7 @@ pipi_image_t *pipi_rgb2yuv(pipi_image_t *src) pipi_image_t *dst; pipi_pixels_t *srcp, *dstp; float *srcdata, *dstdata; - int x, y, w, h, gray; + int x, y, w, h; w = src->w; h = src->h; @@ -56,16 +56,19 @@ pipi_image_t *pipi_rgb2yuv(pipi_image_t *src) a = srcdata[d + 3]; yp = 0.299 * r + 0.587 * g + 0.114 * b; + yp = (yp * 220.0 + 16.0) / 255.0; + u = 0.5 - 0.14713 * r - 0.28886 * g + 0.436 * b; if (u < 0.0) u = 0.0; if (u > 1.0) u = 1.0; + v = 0.5 + 0.615 * r - 0.51499 * g - 0.10001 * b; if (v < 0.0) v = 0.0; if (v > 1.0) v = 1.0; - dstdata[d] = v; - dstdata[d + 1] = yp; - dstdata[d + 2] = u; + dstdata[d] = yp; + dstdata[d + 1] = u; + dstdata[d + 2] = v; dstdata[d + 3] = a; } } @@ -78,7 +81,7 @@ pipi_image_t *pipi_yuv2rgb(pipi_image_t *src) pipi_image_t *dst; pipi_pixels_t *srcp, *dstp; float *srcdata, *dstdata; - int x, y, w, h, gray; + int x, y, w, h; w = src->w; h = src->h; @@ -97,9 +100,9 @@ pipi_image_t *pipi_yuv2rgb(pipi_image_t *src) double r, g, b, a, yp, u, v; int d = 4 * (y * w + x); - v = srcdata[d] - 0.5; - yp = srcdata[d + 1]; - u = srcdata[d + 2] - 0.5; + yp = (srcdata[d] * 255.0 - 16.0) / 220.0; + u = srcdata[d + 1] - 0.5; + v = srcdata[d + 2] - 0.5; a = srcdata[d + 3]; r = yp + 1.13983 * v;