diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2012-01-10 20:56:15 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2012-01-11 15:04:02 +0100 |
commit | 0644cabd7ab60b7384349ddc41262d4f21a084d3 (patch) | |
tree | ec1ee42cefad75d0e38a6fb5188b7cd2b15a3e4a /libswscale/yuv2rgb.c | |
parent | 7c4b39750853c1b51652ece70b5bf8fcd72e3181 (diff) | |
download | ffmpeg-0644cabd7ab60b7384349ddc41262d4f21a084d3.tar.gz |
sws: Move yuv2rgb clipping into the tables.
This fixes some cases where the clipping was entirely missing.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Thanks (for the comments and review) -to: Reimar, beastd, Ronald
Diffstat (limited to 'libswscale/yuv2rgb.c')
-rw-r--r-- | libswscale/yuv2rgb.c | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/libswscale/yuv2rgb.c b/libswscale/yuv2rgb.c index c2c9090a36..6100fbc692 100644 --- a/libswscale/yuv2rgb.c +++ b/libswscale/yuv2rgb.c @@ -62,9 +62,9 @@ const int *sws_getCoefficients(int colorspace) #define LOADCHROMA(i) \ U = pu[i]; \ V = pv[i]; \ - r = (void *)c->table_rV[V]; \ - g = (void *)(c->table_gU[U] + c->table_gV[V]); \ - b = (void *)c->table_bU[U]; + r = (void *)c->table_rV[V+YUVRGB_TABLE_HEADROOM]; \ + g = (void *)(c->table_gU[U+YUVRGB_TABLE_HEADROOM] + c->table_gV[V+YUVRGB_TABLE_HEADROOM]); \ + b = (void *)c->table_bU[U+YUVRGB_TABLE_HEADROOM]; #define PUTRGB(dst,src,i) \ Y = src[2*i]; \ @@ -479,7 +479,7 @@ CLOSEYUV2RGBFUNC(8) YUV2RGBFUNC(yuv2rgb_c_1_ordered_dither, uint8_t, 0) const uint8_t *d128 = dither_8x8_220[y&7]; char out_1 = 0, out_2 = 0; - g= c->table_gU[128] + c->table_gV[128]; + g= c->table_gU[128 + YUVRGB_TABLE_HEADROOM] + c->table_gV[128 + YUVRGB_TABLE_HEADROOM]; #define PUTRGB1(out,src,i,o) \ Y = src[2*i]; \ @@ -555,29 +555,27 @@ SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c) return NULL; } -static void fill_table(uint8_t* table[256], const int elemsize, const int inc, void *y_tab) +static void fill_table(uint8_t* table[256 + 2*YUVRGB_TABLE_HEADROOM], const int elemsize, const int inc, void *y_tab) { int i; - int64_t cb = 0; uint8_t *y_table = y_tab; y_table -= elemsize * (inc >> 9); - for (i = 0; i < 256; i++) { + for (i = 0; i < 256 + 2*YUVRGB_TABLE_HEADROOM; i++) { + int64_t cb = av_clip(i-YUVRGB_TABLE_HEADROOM, 0, 255)*inc; table[i] = y_table + elemsize * (cb >> 16); - cb += inc; } } -static void fill_gv_table(int table[256], const int elemsize, const int inc) +static void fill_gv_table(int table[256 + 2*YUVRGB_TABLE_HEADROOM], const int elemsize, const int inc) { int i; - int64_t cb = 0; int off = -(inc >> 9); - for (i = 0; i < 256; i++) { + for (i = 0; i < 256 + 2*YUVRGB_TABLE_HEADROOM; i++) { + int64_t cb = av_clip(i-YUVRGB_TABLE_HEADROOM, 0, 255)*inc; table[i] = elemsize * (off + (cb >> 16)); - cb += inc; } } |