[FFmpeg-cvslog] sws: Move yuv2rgb clipping into the tables.
Michael Niedermayer
git at videolan.org
Wed Jan 11 15:08:11 CET 2012
ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Tue Jan 10 20:56:15 2012 +0100| [0644cabd7ab60b7384349ddc41262d4f21a084d3] | committer: Michael Niedermayer
sws: Move yuv2rgb clipping into the tables.
This fixes some cases where the clipping was entirely missing.
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
Thanks (for the comments and review) -to: Reimar, beastd, Ronald
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=0644cabd7ab60b7384349ddc41262d4f21a084d3
---
libswscale/swscale.c | 31 +++++++++++++++----------------
libswscale/swscale_internal.h | 10 ++++++----
libswscale/yuv2rgb.c | 22 ++++++++++------------
3 files changed, 31 insertions(+), 32 deletions(-)
diff --git a/libswscale/swscale.c b/libswscale/swscale.c
index 1bf52f2..74f3c05 100644
--- a/libswscale/swscale.c
+++ b/libswscale/swscale.c
@@ -570,7 +570,7 @@ yuv2mono_X_c_template(SwsContext *c, const int16_t *lumFilter,
int y, enum PixelFormat target)
{
const uint8_t * const d128=dither_8x8_220[y&7];
- uint8_t *g = c->table_gU[128] + c->table_gV[128];
+ uint8_t *g = c->table_gU[128 + YUVRGB_TABLE_HEADROOM] + c->table_gV[128 + YUVRGB_TABLE_HEADROOM];
int i;
unsigned acc = 0;
@@ -606,7 +606,7 @@ yuv2mono_2_c_template(SwsContext *c, const int16_t *buf[2],
{
const int16_t *buf0 = buf[0], *buf1 = buf[1];
const uint8_t * const d128 = dither_8x8_220[y & 7];
- uint8_t *g = c->table_gU[128] + c->table_gV[128];
+ uint8_t *g = c->table_gU[128 + YUVRGB_TABLE_HEADROOM] + c->table_gV[128 + YUVRGB_TABLE_HEADROOM];
int yalpha1 = 4095 - yalpha;
int i;
@@ -630,7 +630,7 @@ yuv2mono_1_c_template(SwsContext *c, const int16_t *buf0,
int uvalpha, int y, enum PixelFormat target)
{
const uint8_t * const d128 = dither_8x8_220[y & 7];
- uint8_t *g = c->table_gU[128] + c->table_gV[128];
+ uint8_t *g = c->table_gU[128 + YUVRGB_TABLE_HEADROOM] + c->table_gV[128 + YUVRGB_TABLE_HEADROOM];
int i;
for (i = 0; i < dstW - 7; i += 8) {
@@ -1154,10 +1154,9 @@ yuv2rgb_X_c_template(SwsContext *c, const int16_t *lumFilter,
}
}
- /* FIXME fix tables so that clipping is not needed and then use _NOCLIP*/
- r = c->table_rV[V];
- g = (c->table_gU[U] + c->table_gV[V]);
- b = c->table_bU[U];
+ r = c->table_rV[V + YUVRGB_TABLE_HEADROOM];
+ g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]);
+ b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
r, g, b, y, target, hasAlpha);
@@ -1186,9 +1185,9 @@ yuv2rgb_2_c_template(SwsContext *c, const int16_t *buf[2],
int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
int A1, A2;
- const void *r = c->table_rV[V],
- *g = (c->table_gU[U] + c->table_gV[V]),
- *b = c->table_bU[U];
+ const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
+ *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
+ *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
if (hasAlpha) {
A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 19;
@@ -1218,9 +1217,9 @@ yuv2rgb_1_c_template(SwsContext *c, const int16_t *buf0,
int U = ubuf1[i] >> 7;
int V = vbuf1[i] >> 7;
int A1, A2;
- const void *r = c->table_rV[V],
- *g = (c->table_gU[U] + c->table_gV[V]),
- *b = c->table_bU[U];
+ const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
+ *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
+ *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
if (hasAlpha) {
A1 = abuf0[i * 2 ] >> 7;
@@ -1237,9 +1236,9 @@ yuv2rgb_1_c_template(SwsContext *c, const int16_t *buf0,
int U = (ubuf0[i] + ubuf1[i]) >> 8;
int V = (vbuf0[i] + vbuf1[i]) >> 8;
int A1, A2;
- const void *r = c->table_rV[V],
- *g = (c->table_gU[U] + c->table_gV[V]),
- *b = c->table_bU[U];
+ const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
+ *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
+ *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
if (hasAlpha) {
A1 = abuf0[i * 2 ] >> 7;
diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h
index f05925f..f4220a9 100644
--- a/libswscale/swscale_internal.h
+++ b/libswscale/swscale_internal.h
@@ -34,6 +34,8 @@
#define STR(s) AV_TOSTRING(s) // AV_STRINGIFY is too long
+#define YUVRGB_TABLE_HEADROOM 128
+
#define FAST_BGR2YV12 // use 7-bit instead of 15-bit coefficients
#define MAX_FILTER_SIZE 256
@@ -317,10 +319,10 @@ typedef struct SwsContext {
int dstY; ///< Last destination vertical line output from last slice.
int flags; ///< Flags passed by the user to select scaler algorithm, optimizations, subsampling, etc...
void *yuvTable; // pointer to the yuv->rgb table start so it can be freed()
- uint8_t *table_rV[256];
- uint8_t *table_gU[256];
- int table_gV[256];
- uint8_t *table_bU[256];
+ uint8_t *table_rV[256 + 2*YUVRGB_TABLE_HEADROOM];
+ uint8_t *table_gU[256 + 2*YUVRGB_TABLE_HEADROOM];
+ int table_gV[256 + 2*YUVRGB_TABLE_HEADROOM];
+ uint8_t *table_bU[256 + 2*YUVRGB_TABLE_HEADROOM];
//Colorspace stuff
int contrast, brightness, saturation; // for sws_getColorspaceDetails
diff --git a/libswscale/yuv2rgb.c b/libswscale/yuv2rgb.c
index c2c9090..6100fbc 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;
}
}
More information about the ffmpeg-cvslog
mailing list