-}
-
-#define SCALE_BITS 10
-
-#define C_Y (76309 >> (16 - SCALE_BITS))
-#define C_RV (117504 >> (16 - SCALE_BITS))
-#define C_BU (138453 >> (16 - SCALE_BITS))
-#define C_GU (13954 >> (16 - SCALE_BITS))
-#define C_GV (34903 >> (16 - SCALE_BITS))
-
-#define YUV_TO_RGB2(r, g, b, y1)\
-{\
- y = (y1 - 16) * C_Y;\
- r = cm[(y + r_add) >> SCALE_BITS];\
- g = cm[(y + g_add) >> SCALE_BITS];\
- b = cm[(y + b_add) >> SCALE_BITS];\
-}
-
-/* XXX: no chroma interpolating is done */
-#define RGB_FUNCTIONS(rgb_name) \
- \
-static void yuv420p_to_ ## rgb_name (AVPicture *dst, AVPicture *src, \
- int width, int height) \
-{ \
- uint8_t *y1_ptr, *y2_ptr, *cb_ptr, *cr_ptr, *d, *d1, *d2; \
- int w, y, cb, cr, r_add, g_add, b_add, width2; \
- uint8_t *cm = cropTbl + MAX_NEG_CROP; \
- unsigned int r, g, b; \
- \
- d = dst->data[0]; \
- y1_ptr = src->data[0]; \
- cb_ptr = src->data[1]; \
- cr_ptr = src->data[2]; \
- width2 = (width + 1) >> 1; \
- for(;height >= 2; height -= 2) { \
- d1 = d; \
- d2 = d + dst->linesize[0]; \
- y2_ptr = y1_ptr + src->linesize[0]; \
- for(w = width; w >= 2; w -= 2) { \
- cb = cb_ptr[0] - 128; \
- cr = cr_ptr[0] - 128; \
- r_add = C_RV * cr + (1 << (SCALE_BITS - 1)); \
- g_add = - C_GU * cb - C_GV * cr + (1 << (SCALE_BITS - 1)); \
- b_add = C_BU * cb + (1 << (SCALE_BITS - 1)); \
- \
- /* output 4 pixels */ \
- YUV_TO_RGB2(r, g, b, y1_ptr[0]); \
- RGB_OUT(d1, r, g, b); \
- \
- YUV_TO_RGB2(r, g, b, y1_ptr[1]); \
- RGB_OUT(d1 + BPP, r, g, b); \
- \
- YUV_TO_RGB2(r, g, b, y2_ptr[0]); \
- RGB_OUT(d2, r, g, b); \
- \
- YUV_TO_RGB2(r, g, b, y2_ptr[1]); \
- RGB_OUT(d2 + BPP, r, g, b); \
- \
- d1 += 2 * BPP; \
- d2 += 2 * BPP; \
- \
- y1_ptr += 2; \
- y2_ptr += 2; \
- cb_ptr++; \
- cr_ptr++; \
- } \
- /* handle odd width */ \
- if (w) { \
- cb = cb_ptr[0] - 128; \
- cr = cr_ptr[0] - 128; \
- r_add = C_RV * cr + (1 << (SCALE_BITS - 1)); \
- g_add = - C_GU * cb - C_GV * cr + (1 << (SCALE_BITS - 1)); \
- b_add = C_BU * cb + (1 << (SCALE_BITS - 1)); \
- \
- YUV_TO_RGB2(r, g, b, y1_ptr[0]); \
- RGB_OUT(d1, r, g, b); \
- \
- YUV_TO_RGB2(r, g, b, y2_ptr[0]); \
- RGB_OUT(d2, r, g, b); \
- d1 += BPP; \
- d2 += BPP; \
- y1_ptr++; \
- y2_ptr++; \
- cb_ptr++; \
- cr_ptr++; \
- } \
- d += 2 * dst->linesize[0]; \
- y1_ptr += 2 * src->linesize[0] - width; \
- cb_ptr += src->linesize[1] - width2; \
- cr_ptr += src->linesize[2] - width2; \
- } \
- /* handle odd height */ \
- if (height) { \
- d1 = d; \
- for(w = width; w >= 2; w -= 2) { \
- cb = cb_ptr[0] - 128; \
- cr = cr_ptr[0] - 128; \
- r_add = C_RV * cr + (1 << (SCALE_BITS - 1)); \
- g_add = - C_GU * cb - C_GV * cr + (1 << (SCALE_BITS - 1)); \
- b_add = C_BU * cb + (1 << (SCALE_BITS - 1)); \
- \
- /* output 2 pixels */ \
- YUV_TO_RGB2(r, g, b, y1_ptr[0]); \
- RGB_OUT(d1, r, g, b); \
- \
- YUV_TO_RGB2(r, g, b, y1_ptr[1]); \
- RGB_OUT(d1 + BPP, r, g, b); \
- \
- d1 += 2 * BPP; \
- \
- y1_ptr += 2; \
- cb_ptr++; \
- cr_ptr++; \
- } \
- /* handle width */ \
- if (w) { \
- cb = cb_ptr[0] - 128; \
- cr = cr_ptr[0] - 128; \
- r_add = C_RV * cr + (1 << (SCALE_BITS - 1)); \
- g_add = - C_GU * cb - C_GV * cr + (1 << (SCALE_BITS - 1)); \
- b_add = C_BU * cb + (1 << (SCALE_BITS - 1)); \
- \
- /* output 2 pixels */ \
- YUV_TO_RGB2(r, g, b, y1_ptr[0]); \
- RGB_OUT(d1, r, g, b); \
- d1 += BPP; \
- \
- y1_ptr++; \
- cb_ptr++; \
- cr_ptr++; \
- } \
- } \
-} \
- \
-/* XXX: no chroma interpolating is done */ \
-static void yuv422p_to_ ## rgb_name (AVPicture *dst, AVPicture *src, \
- int width, int height) \
-{ \
- uint8_t *y1_ptr, *cb_ptr, *cr_ptr, *d, *d1; \
- int w, y, cb, cr, r_add, g_add, b_add, width2; \
- uint8_t *cm = cropTbl + MAX_NEG_CROP; \
- unsigned int r, g, b; \
- \
- d = dst->data[0]; \
- y1_ptr = src->data[0]; \
- cb_ptr = src->data[1]; \
- cr_ptr = src->data[2]; \
- width2 = (width + 1) >> 1; \
- for(;height > 0; height --) { \
- d1 = d; \
- for(w = width; w >= 2; w -= 2) { \
- cb = cb_ptr[0] - 128; \
- cr = cr_ptr[0] - 128; \
- r_add = C_RV * cr + (1 << (SCALE_BITS - 1)); \
- g_add = - C_GU * cb - C_GV * cr + (1 << (SCALE_BITS - 1)); \
- b_add = C_BU * cb + (1 << (SCALE_BITS - 1)); \
- \
- /* output 2 pixels */ \
- YUV_TO_RGB2(r, g, b, y1_ptr[0]); \
- RGB_OUT(d1, r, g, b); \
- \
- YUV_TO_RGB2(r, g, b, y1_ptr[1]); \
- RGB_OUT(d1 + BPP, r, g, b); \
- \
- d1 += 2 * BPP; \
- \
- y1_ptr += 2; \
- cb_ptr++; \
- cr_ptr++; \
- } \
- /* handle width */ \
- if (w) { \
- cb = cb_ptr[0] - 128; \
- cr = cr_ptr[0] - 128; \
- r_add = C_RV * cr + (1 << (SCALE_BITS - 1)); \
- g_add = - C_GU * cb - C_GV * cr + (1 << (SCALE_BITS - 1)); \
- b_add = C_BU * cb + (1 << (SCALE_BITS - 1)); \
- \
- /* output 2 pixels */ \
- YUV_TO_RGB2(r, g, b, y1_ptr[0]); \
- RGB_OUT(d1, r, g, b); \
- d1 += BPP; \
- \
- y1_ptr++; \
- cb_ptr++; \
- cr_ptr++; \
- } \
- d += dst->linesize[0]; \
- y1_ptr += src->linesize[0] - width; \
- cb_ptr += src->linesize[1] - width2; \
- cr_ptr += src->linesize[2] - width2; \
- } \
-} \
- \
-static void rgb_name ## _to_yuv420p(AVPicture *dst, AVPicture *src, \
- int width, int height) \
-{ \
- int wrap, wrap3, x, y; \
- int r, g, b, r1, g1, b1; \
- uint8_t *lum, *cb, *cr; \
- const uint8_t *p; \
- \
- lum = dst->data[0]; \
- cb = dst->data[1]; \
- cr = dst->data[2]; \
- \
- wrap = dst->linesize[0]; \
- wrap3 = src->linesize[0]; \
- p = src->data[0]; \
- for(y=0;y<height;y+=2) { \
- for(x=0;x<width;x+=2) { \
- RGB_IN(r, g, b, p); \
- r1 = r; \
- g1 = g; \
- b1 = b; \
- lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g + \
- FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; \
- RGB_IN(r, g, b, p + BPP); \
- r1 += r; \
- g1 += g; \
- b1 += b; \
- lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g + \
- FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; \
- p += wrap3; \
- lum += wrap; \
- \
- RGB_IN(r, g, b, p); \
- r1 += r; \
- g1 += g; \
- b1 += b; \
- lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g + \
- FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; \
- \
- RGB_IN(r, g, b, p + BPP); \
- r1 += r; \
- g1 += g; \
- b1 += b; \
- lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g + \
- FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; \
- \
- cb[0] = ((- FIX(0.16874) * r1 - FIX(0.33126) * g1 + \
- FIX(0.50000) * b1 + 4 * ONE_HALF - 1) >> \
- (SCALEBITS + 2)) + 128; \
- cr[0] = ((FIX(0.50000) * r1 - FIX(0.41869) * g1 - \
- FIX(0.08131) * b1 + 4 * ONE_HALF - 1) >> \
- (SCALEBITS + 2)) + 128; \
- \
- cb++; \
- cr++; \
- p += -wrap3 + 2 * BPP; \
- lum += -wrap + 2; \
- } \
- p += wrap3 + (wrap3 - width * BPP); \
- lum += wrap + (wrap - width); \
- cb += dst->linesize[1] - width / 2; \
- cr += dst->linesize[2] - width / 2; \
- } \
-} \
- \
-static void rgb_name ## _to_gray(AVPicture *dst, AVPicture *src, \
- int width, int height) \
-{ \
- const unsigned char *p; \
- unsigned char *q; \
- int r, g, b, dst_wrap, src_wrap; \
- int x, y; \
- \
- p = src->data[0]; \
- src_wrap = src->linesize[0] - BPP * width; \
- \
- q = dst->data[0]; \
- dst_wrap = dst->linesize[0] - width; \
- \
- for(y=0;y<height;y++) { \
- for(x=0;x<width;x++) { \
- RGB_IN(r, g, b, p); \
- q[0] = (FIX(0.29900) * r + FIX(0.58700) * g + \
- FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; \
- q++; \
- p += BPP; \
- } \
- p += src_wrap; \
- q += dst_wrap; \
- } \
-} \
- \
-static void gray_to_ ## rgb_name(AVPicture *dst, AVPicture *src, \
- int width, int height) \
-{ \
- const unsigned char *p; \
- unsigned char *q; \
- int r, dst_wrap, src_wrap; \
- int x, y; \
- \
- p = src->data[0]; \
- src_wrap = src->linesize[0] - width; \
- \
- q = dst->data[0]; \
- dst_wrap = dst->linesize[0] - BPP * width; \
- \
- for(y=0;y<height;y++) { \
- for(x=0;x<width;x++) { \
- r = p[0]; \
- RGB_OUT(q, r, r, r); \
- q += BPP; \
- p ++; \
- } \
- p += src_wrap; \
- q += dst_wrap; \
- } \
-} \
- \
-static void pal8_to_ ## rgb_name(AVPicture *dst, AVPicture *src, \
- int width, int height) \
-{ \
- const unsigned char *p; \
- unsigned char *q; \
- int r, g, b, dst_wrap, src_wrap; \
- int x, y; \
- uint32_t v;\
- const uint32_t *palette;\
-\
- p = src->data[0]; \
- src_wrap = src->linesize[0] - width; \
- palette = (uint32_t *)src->data[1];\
- \
- q = dst->data[0]; \
- dst_wrap = dst->linesize[0] - BPP * width; \
- \
- for(y=0;y<height;y++) { \
- for(x=0;x<width;x++) { \
- v = palette[p[0]];\
- r = (v >> 16) & 0xff;\
- g = (v >> 8) & 0xff;\
- b = (v) & 0xff;\
- RGB_OUT(q, r, g, b); \
- q += BPP; \
- p ++; \
- } \
- p += src_wrap; \
- q += dst_wrap; \
- } \