[FFmpeg-devel] [PATCH 2/5] Put internal scale context fields initialization from sws_setColorspaceDetails() to ff_yuv2rgb_c_init_tables().

Stefano Sabatini stefano.sabatini-lala
Sun May 23 18:50:05 CEST 2010


Allow to factorize some code which was duplicated.
---
 utils.c   |   50 --------------------------------------------------
 yuv2rgb.c |   24 ++++++++++++++++++++++++
 2 files changed, 24 insertions(+), 50 deletions(-)

diff --git a/utils.c b/utils.c
index 804536c..26e0f75 100644
--- a/utils.c
+++ b/utils.c
@@ -671,23 +671,8 @@ static void getSubSampleFactors(int *h, int *v, enum PixelFormat format)
     *v = av_pix_fmt_descriptors[format].log2_chroma_h;
 }
 
-static uint16_t roundToInt16(int64_t f)
-{
-    int r= (f + (1<<15))>>16;
-         if (r<-0x7FFF) return 0x8000;
-    else if (r> 0x7FFF) return 0x7FFF;
-    else                return r;
-}
-
 int sws_setColorspaceDetails(SwsContext *c, const int yuvToRgbTable[4], int srcRange, const int rgbToYuvTable[4], int dstRange, int brightness, int contrast, int saturation)
 {
-    int64_t crv =  yuvToRgbTable[0];
-    int64_t cbu =  yuvToRgbTable[1];
-    int64_t cgu = -yuvToRgbTable[2];
-    int64_t cgv = -yuvToRgbTable[3];
-    int64_t cy  = 1<<16;
-    int64_t oy  = 0;
-
     memcpy(c->srcColorspaceTable, yuvToRgbTable, sizeof(int)*4);
     memcpy(c->dstColorspaceTable, rgbToYuvTable, sizeof(int)*4);
 
@@ -698,41 +683,6 @@ int sws_setColorspaceDetails(SwsContext *c, const int yuvToRgbTable[4], int srcR
     c->dstRange  = dstRange;
     if (isYUV(c->dstFormat) || isGray(c->dstFormat)) return -1;
 
-    c->uOffset=   0x0400040004000400LL;
-    c->vOffset=   0x0400040004000400LL;
-
-    if (!srcRange) {
-        cy= (cy*255) / 219;
-        oy= 16<<16;
-    } else {
-        crv= (crv*224) / 255;
-        cbu= (cbu*224) / 255;
-        cgu= (cgu*224) / 255;
-        cgv= (cgv*224) / 255;
-    }
-
-    cy = (cy *contrast             )>>16;
-    crv= (crv*contrast * saturation)>>32;
-    cbu= (cbu*contrast * saturation)>>32;
-    cgu= (cgu*contrast * saturation)>>32;
-    cgv= (cgv*contrast * saturation)>>32;
-
-    oy -= 256*brightness;
-
-    c->yCoeff=    roundToInt16(cy *8192) * 0x0001000100010001ULL;
-    c->vrCoeff=   roundToInt16(crv*8192) * 0x0001000100010001ULL;
-    c->ubCoeff=   roundToInt16(cbu*8192) * 0x0001000100010001ULL;
-    c->vgCoeff=   roundToInt16(cgv*8192) * 0x0001000100010001ULL;
-    c->ugCoeff=   roundToInt16(cgu*8192) * 0x0001000100010001ULL;
-    c->yOffset=   roundToInt16(oy *   8) * 0x0001000100010001ULL;
-
-    c->yuv2rgb_y_coeff  = (int16_t)roundToInt16(cy <<13);
-    c->yuv2rgb_y_offset = (int16_t)roundToInt16(oy << 9);
-    c->yuv2rgb_v2r_coeff= (int16_t)roundToInt16(crv<<13);
-    c->yuv2rgb_v2g_coeff= (int16_t)roundToInt16(cgv<<13);
-    c->yuv2rgb_u2g_coeff= (int16_t)roundToInt16(cgu<<13);
-    c->yuv2rgb_u2b_coeff= (int16_t)roundToInt16(cbu<<13);
-
     ff_yuv2rgb_c_init_tables(c, yuvToRgbTable, srcRange, brightness, contrast, saturation);
     //FIXME factorize
 
diff --git a/yuv2rgb.c b/yuv2rgb.c
index f47b15d..70841a8 100644
--- a/yuv2rgb.c
+++ b/yuv2rgb.c
@@ -620,6 +620,14 @@ static void fill_gv_table(int table[256], const int elemsize, const int inc)
     }
 }
 
+static uint16_t roundToInt16(int64_t f)
+{
+    int r= (f + (1<<15))>>16;
+         if (r<-0x7FFF) return 0x8000;
+    else if (r> 0x7FFF) return 0x7FFF;
+    else                return r;
+}
+
 av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4], int fullRange,
                                      int brightness, int contrast, int saturation)
 {
@@ -675,6 +683,22 @@ av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4], int
     cgv = (cgv*contrast * saturation) >> 32;
     oy -= 256*brightness;
 
+    c->uOffset=   0x0400040004000400LL;
+    c->vOffset=   0x0400040004000400LL;
+    c->yCoeff=    roundToInt16(cy *8192) * 0x0001000100010001ULL;
+    c->vrCoeff=   roundToInt16(crv*8192) * 0x0001000100010001ULL;
+    c->ubCoeff=   roundToInt16(cbu*8192) * 0x0001000100010001ULL;
+    c->vgCoeff=   roundToInt16(cgv*8192) * 0x0001000100010001ULL;
+    c->ugCoeff=   roundToInt16(cgu*8192) * 0x0001000100010001ULL;
+    c->yOffset=   roundToInt16(oy *   8) * 0x0001000100010001ULL;
+
+    c->yuv2rgb_y_coeff  = (int16_t)roundToInt16(cy <<13);
+    c->yuv2rgb_y_offset = (int16_t)roundToInt16(oy << 9);
+    c->yuv2rgb_v2r_coeff= (int16_t)roundToInt16(crv<<13);
+    c->yuv2rgb_v2g_coeff= (int16_t)roundToInt16(cgv<<13);
+    c->yuv2rgb_u2g_coeff= (int16_t)roundToInt16(cgu<<13);
+    c->yuv2rgb_u2b_coeff= (int16_t)roundToInt16(cbu<<13);
+
     //scale coefficients by cy
     crv = ((crv << 16) + 0x8000) / cy;
     cbu = ((cbu << 16) + 0x8000) / cy;
-- 
1.7.1




More information about the ffmpeg-devel mailing list