diff --git a/cinepak.c b/cinepak.c index 895f86e2fa..b66b30b630 100644 --- a/cinepak.c +++ b/cinepak.c @@ -43,6 +43,12 @@ typedef struct { /* ------------------------------------------------------------------------ */ static unsigned char *in_buffer, uiclip[1024], *uiclp = NULL; +#define SCALEBITS 16 +#define ONE_HALF ((long) 1 << (SCALEBITS-1)) +#define FIX(x) ((long) ((x) * (1L<y0 = get_byte(); /* luma */ - c->y1 = get_byte(); - c->y2 = get_byte(); - c->y3 = get_byte(); - c->u = 128+get_byte(); /* chroma */ - c->v = 128+get_byte(); + y0 = get_byte(); /* luma */ + y1 = get_byte(); + y2 = get_byte(); + y3 = get_byte(); + u = 128+get_byte(); /* chroma */ + v = 128+get_byte(); + + /* YUV * inv(CinYUV) + * | Y | | 1 -0.0655 0.0110 | | CY | + * | Cb | = | 0 1.1656 -0.0062 | | CU | + * | Cr | | 0 0.0467 1.4187 | | CV | + */ + y_uv = (int)((CU_Y_tab[u] + CV_Y_tab[v]) >> SCALEBITS); + c->y0 = uiclp[y0 + y_uv]; + c->y1 = uiclp[y1 + y_uv]; + c->y2 = uiclp[y2 + y_uv]; + c->y3 = uiclp[y3 + y_uv]; + c->u = uiclp[(int)((CU_Cb_tab[u] + CV_Cb_tab[v]) >> SCALEBITS)]; + c->v = uiclp[(int)((CU_Cr_tab[u] + CV_Cr_tab[v]) >> SCALEBITS)]; } } @@ -324,7 +345,7 @@ int row_inc = stride-4*3; void *decode_cinepak_init(void) { cinepak_info *cvinfo; -int i; +int i, x; if((cvinfo = calloc(sizeof(cinepak_info), 1)) == NULL) return NULL; cvinfo->strip_num = 0; @@ -336,6 +357,16 @@ int i; uiclp[i] = (i < 0 ? 0 : (i > 255 ? 255 : i)); } + for(i = 0, x = -128; i < 256; i++, x++) + { + CU_Y_tab[i] = (-FIX(0.0655)) * x; + CV_Y_tab[i] = (FIX(0.0110)) * x + ONE_HALF; + CU_Cb_tab[i] = (FIX(1.1656)) * x; + CV_Cb_tab[i] = (-FIX(0.0062)) * x + ONE_HALF + FIX(128); + CU_Cr_tab[i] = (FIX(0.0467)) * x; + CV_Cr_tab[i] = (FIX(1.4187)) * x + ONE_HALF + FIX(128); + } + return (void *)cvinfo; }