yuv2rgb.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <assert.h>
#include "config.h"
#include "rgb2rgb.h"
#include "swscale.h"
#include "swscale_internal.h"

Go to the source code of this file.

Defines

#define DITHER1XBPP
#define RGB(i)
#define DST1(i)
#define DST2(i)
#define DST1RGB(i)
#define DST2RGB(i)
#define DST1BGR(i)
#define DST2BGR(i)
#define PROLOG(func_name, dst_type)
#define EPILOG1(dst_delta)
#define EPILOG2()
#define EPILOG(dst_delta)
#define DST1bpp8(i, o)
#define DST2bpp8(i, o)
#define DST1_4(i)
#define DST2_4(i)
#define DST1bpp4(i, o)
#define DST2bpp4(i, o)
#define DST1bpp4b(i, o)
#define DST2bpp4b(i, o)
#define DST1bpp1(i, o)
#define DST2bpp1(i, o)

Functions

const uint8_t __attribute__ ((aligned(8)))
 RGB (0)
 DST1 (0)
 DST2 (0)
 RGB (1)
 DST2 (1)
 DST1 (1)
 RGB (2)
 DST1 (2)
 DST2 (2)
 RGB (3)
 DST2 (3)
 DST1 (3)
 DST1RGB (0)
 DST2RGB (0)
 DST2RGB (1)
 DST1RGB (1)
 DST1RGB (2)
 DST2RGB (2)
 DST2RGB (3)
 DST1RGB (3)
 DST1BGR (0)
 DST2BGR (0)
 DST2BGR (1)
 DST1BGR (1)
 DST1BGR (2)
 DST2BGR (2)
 DST2BGR (3)
 DST1BGR (3)
 DST1bpp8 (0, 0)
 DST2bpp8 (0, 0)
 DST2bpp8 (1, 2)
 DST1bpp8 (1, 2)
 DST1bpp8 (2, 4)
 DST2bpp8 (2, 4)
 DST2bpp8 (3, 6)
 DST1bpp8 (3, 6)
 DST1_4 (0)
 DST2_4 (0)
 DST2_4 (1)
 DST1_4 (1)
 DST1_4 (2)
 DST2_4 (2)
 DST2_4 (3)
 DST1_4 (3)
 DST1bpp4 (0, 0)
 DST2bpp4 (0, 0)
 DST2bpp4 (1, 2)
 DST1bpp4 (1, 2)
 DST1bpp4 (2, 4)
 DST2bpp4 (2, 4)
 DST2bpp4 (3, 6)
 DST1bpp4 (3, 6)
 DST1bpp4b (0, 0)
 DST2bpp4b (0, 0)
 DST2bpp4b (1, 2)
 DST1bpp4b (1, 2)
 DST1bpp4b (2, 4)
 DST2bpp4b (2, 4)
 DST2bpp4b (3, 6)
 DST1bpp4b (3, 6)
 DST1bpp1 (0, 0)
 DST2bpp1 (0, 0)
 DST2bpp1 (1, 2)
 DST1bpp1 (1, 2)
 DST1bpp1 (2, 4)
 DST2bpp1 (2, 4)
 DST2bpp1 (3, 6)
 DST1bpp1 (3, 6)
SwsFunc yuv2rgb_get_func_ptr (SwsContext *c)
static int div_round (int dividend, int divisor)
int yuv2rgb_c_init_tables (SwsContext *c, const int inv_table[4], int fullRange, int brightness, int contrast, int saturation)

Variables

const int32_t Inverse_Table_6_9 [8][4]
const uint8_t * d32 = dither_8x8_32[y&7]
const uint8_t * d64 = dither_8x8_73[y&7]
int acc
const uint8_t * d64 = dither_8x8_73[y&7]
const uint8_t * d128 = dither_8x8_220[y&7]
int acc
const uint8_t * d64 = dither_8x8_73[y&7]
const uint8_t * d128 = dither_8x8_220[y&7]
const uint8_t * d128 = dither_8x8_220[y&7]
char out_1 = 0
char out_2 = 0
 g = c->table_gU[128] + c->table_gV[128]
 dst_1 [0] = out_1
 dst_2 [0] = out_2


Define Documentation

#define DITHER1XBPP

Definition at line 42 of file yuv2rgb.c.

#define DST1 (  ) 

Value:

Y = py_1[2*i];                      \
    dst_1[2*i] = r[Y] + g[Y] + b[Y];    \
    Y = py_1[2*i+1];                    \
    dst_1[2*i+1] = r[Y] + g[Y] + b[Y];

Definition at line 203 of file yuv2rgb.c.

#define DST1_4 (  ) 

Value:

Y = py_1[2*i];                  \
    acc = r[Y] + g[Y] + b[Y];       \
    Y = py_1[2*i+1];                \
    acc |= (r[Y] + g[Y] + b[Y])<<4; \
    dst_1[i] = acc;

Definition at line 441 of file yuv2rgb.c.

#define DST1BGR (  ) 

Value:

Y = py_1[2*i];                                                \
    dst_1[6*i] = b[Y]; dst_1[6*i+1] = g[Y]; dst_1[6*i+2] = r[Y];  \
    Y = py_1[2*i+1];                                              \
    dst_1[6*i+3] = b[Y]; dst_1[6*i+4] = g[Y]; dst_1[6*i+5] = r[Y];

Definition at line 227 of file yuv2rgb.c.

#define DST1bpp1 ( i,
 ) 

Value:

Y = py_1[2*i];                  \
    out_1+= out_1 + g[Y+d128[0+o]]; \
    Y = py_1[2*i+1];                \
    out_1+= out_1 + g[Y+d128[1+o]];

Definition at line 568 of file yuv2rgb.c.

#define DST1bpp4 ( i,
 ) 

Value:

Y = py_1[2*i];                                                \
    acc = r[Y+d128[0+o]] + g[Y+d64[0+o]] + b[Y+d128[0+o]];        \
    Y = py_1[2*i+1];                                              \
    acc |= (r[Y+d128[1+o]] + g[Y+d64[1+o]] + b[Y+d128[1+o]])<<4;  \
    dst_1[i]= acc;

Definition at line 477 of file yuv2rgb.c.

#define DST1bpp4b ( i,
 ) 

Value:

Y = py_1[2*i];                                                    \
    dst_1[2*i]   = r[Y+d128[0+o]] + g[Y+d64[0+o]] + b[Y+d128[0+o]];   \
    Y = py_1[2*i+1];                                                  \
    dst_1[2*i+1] = r[Y+d128[1+o]] + g[Y+d64[1+o]] + b[Y+d128[1+o]];

Definition at line 533 of file yuv2rgb.c.

#define DST1bpp8 ( i,
 ) 

Value:

Y = py_1[2*i];                                                  \
    dst_1[2*i]   = r[Y+d32[0+o]] + g[Y+d32[0+o]] + b[Y+d64[0+o]];   \
    Y = py_1[2*i+1];                                                \
    dst_1[2*i+1] = r[Y+d32[1+o]] + g[Y+d32[1+o]] + b[Y+d64[1+o]];

Definition at line 406 of file yuv2rgb.c.

#define DST1RGB (  ) 

Value:

Y = py_1[2*i];                                                \
    dst_1[6*i] = r[Y]; dst_1[6*i+1] = g[Y]; dst_1[6*i+2] = b[Y];  \
    Y = py_1[2*i+1];                                              \
    dst_1[6*i+3] = r[Y]; dst_1[6*i+4] = g[Y]; dst_1[6*i+5] = b[Y];

Definition at line 215 of file yuv2rgb.c.

#define DST2 (  ) 

Value:

Y = py_2[2*i];                      \
    dst_2[2*i] = r[Y] + g[Y] + b[Y];    \
    Y = py_2[2*i+1];                    \
    dst_2[2*i+1] = r[Y] + g[Y] + b[Y];

Definition at line 209 of file yuv2rgb.c.

#define DST2_4 (  ) 

Value:

Y = py_2[2*i];                  \
    acc = r[Y] + g[Y] + b[Y];       \
    Y = py_2[2*i+1];                \
    acc |= (r[Y] + g[Y] + b[Y])<<4; \
    dst_2[i] = acc;

Definition at line 448 of file yuv2rgb.c.

#define DST2BGR (  ) 

Value:

Y = py_2[2*i];                                                \
    dst_2[6*i] = b[Y]; dst_2[6*i+1] = g[Y]; dst_2[6*i+2] = r[Y];  \
    Y = py_2[2*i+1];                                              \
    dst_2[6*i+3] = b[Y]; dst_2[6*i+4] = g[Y]; dst_2[6*i+5] = r[Y];

Definition at line 233 of file yuv2rgb.c.

#define DST2bpp1 ( i,
 ) 

Value:

Y = py_2[2*i];                  \
    out_2+= out_2 + g[Y+d128[8+o]]; \
    Y = py_2[2*i+1];                \
    out_2+= out_2 + g[Y+d128[9+o]];

Definition at line 574 of file yuv2rgb.c.

#define DST2bpp4 ( i,
 ) 

Value:

Y = py_2[2*i];                                                \
    acc =  r[Y+d128[8+o]] + g[Y+d64[8+o]] + b[Y+d128[8+o]];       \
    Y = py_2[2*i+1];                                              \
    acc |=  (r[Y+d128[9+o]] + g[Y+d64[9+o]] + b[Y+d128[9+o]])<<4; \
    dst_2[i]= acc;

Definition at line 484 of file yuv2rgb.c.

#define DST2bpp4b ( i,
 ) 

Value:

Y = py_2[2*i];                                                    \
    dst_2[2*i]   =  r[Y+d128[8+o]] + g[Y+d64[8+o]] + b[Y+d128[8+o]];  \
    Y = py_2[2*i+1];                                                  \
    dst_2[2*i+1] =  r[Y+d128[9+o]] + g[Y+d64[9+o]] + b[Y+d128[9+o]];

Definition at line 539 of file yuv2rgb.c.

#define DST2bpp8 ( i,
 ) 

Value:

Y = py_2[2*i];                                                  \
    dst_2[2*i]   =  r[Y+d32[8+o]] + g[Y+d32[8+o]] + b[Y+d64[8+o]];  \
    Y = py_2[2*i+1];                                                \
    dst_2[2*i+1] =  r[Y+d32[9+o]] + g[Y+d32[9+o]] + b[Y+d64[9+o]];

Definition at line 412 of file yuv2rgb.c.

#define DST2RGB (  ) 

Value:

Y = py_2[2*i];                                                \
    dst_2[6*i] = r[Y]; dst_2[6*i+1] = g[Y]; dst_2[6*i+2] = b[Y];  \
    Y = py_2[2*i+1];                                              \
    dst_2[6*i+3] = r[Y]; dst_2[6*i+4] = g[Y]; dst_2[6*i+5] = b[Y];

Definition at line 221 of file yuv2rgb.c.

#define EPILOG ( dst_delta   ) 

Value:

EPILOG1(dst_delta)\
    EPILOG2()

Definition at line 279 of file yuv2rgb.c.

#define EPILOG1 ( dst_delta   ) 

Value:

pu += 4;\
            pv += 4;\
            py_1 += 8;\
            py_2 += 8;\
            dst_1 += dst_delta;\
            dst_2 += dst_delta;\
        }\
        if (c->dstW & 4) {\
            int av_unused Y, U, V;\

Definition at line 262 of file yuv2rgb.c.

 
#define EPILOG2 (  ) 

Value:

}\
    }\
    return srcSliceH;\
}

Definition at line 273 of file yuv2rgb.c.

#define PROLOG ( func_name,
dst_type   ) 

Value:

static int func_name(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, \
                     int srcSliceH, uint8_t* dst[], int dstStride[]){\
    int y;\
\
    if (c->srcFormat == PIX_FMT_YUV422P){\
        srcStride[1] *= 2;\
        srcStride[2] *= 2;\
    }\
    for (y=0; y<srcSliceH; y+=2){\
        dst_type *dst_1= (dst_type*)(dst[0] + (y+srcSliceY  )*dstStride[0]);\
        dst_type *dst_2= (dst_type*)(dst[0] + (y+srcSliceY+1)*dstStride[0]);\
        dst_type av_unused *r, *b;\
        dst_type *g;\
        uint8_t *py_1= src[0] + y*srcStride[0];\
        uint8_t *py_2= py_1 + srcStride[0];\
        uint8_t *pu= src[1] + (y>>1)*srcStride[1];\
        uint8_t *pv= src[2] + (y>>1)*srcStride[2];\
        unsigned int h_size= c->dstW>>3;\
        while (h_size--) {\
            int av_unused U, V;\
            int Y;\

Definition at line 239 of file yuv2rgb.c.

#define RGB (  ) 

Value:

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];

Definition at line 196 of file yuv2rgb.c.


Function Documentation

const uint8_t __attribute__ ( (aligned(8))   ) 

Definition at line 44 of file yuv2rgb.c.

00044                                                               {
00045 {  1,   3,   1,   3,   1,   3,   1,   3, },
00046 {  2,   0,   2,   0,   2,   0,   2,   0, },
00047 };

static int div_round ( int  dividend,
int  divisor 
) [static]

Definition at line 668 of file yuv2rgb.c.

Referenced by yuv2rgb_c_init_tables().

00669 {
00670     if (dividend > 0)
00671         return (dividend + (divisor>>1)) / divisor;
00672     else
00673         return -((-dividend + (divisor>>1)) / divisor);
00674 }

DST1 (  ) 

DST1 (  ) 

DST1 (  ) 

DST1 (  ) 

DST1_4 (  ) 

DST1_4 (  ) 

DST1_4 (  ) 

DST1_4 (  ) 

DST1BGR (  ) 

DST1BGR (  ) 

DST1BGR (  ) 

DST1BGR (  ) 

DST1bpp1 ( ,
 
)

DST1bpp1 ( ,
 
)

DST1bpp1 ( ,
 
)

DST1bpp1 ( ,
 
)

DST1bpp4 ( ,
 
)

DST1bpp4 ( ,
 
)

DST1bpp4 ( ,
 
)

DST1bpp4 ( ,
 
)

DST1bpp4b ( ,
 
)

DST1bpp4b ( ,
 
)

DST1bpp4b ( ,
 
)

DST1bpp4b ( ,
 
)

DST1bpp8 ( ,
 
)

DST1bpp8 ( ,
 
)

DST1bpp8 ( ,
 
)

DST1bpp8 ( ,
 
)

DST1RGB (  ) 

DST1RGB (  ) 

DST1RGB (  ) 

DST1RGB (  ) 

DST2 (  ) 

DST2 (  ) 

DST2 (  ) 

DST2 (  ) 

DST2_4 (  ) 

DST2_4 (  ) 

DST2_4 (  ) 

DST2_4 (  ) 

DST2BGR (  ) 

DST2BGR (  ) 

DST2BGR (  ) 

DST2BGR (  ) 

DST2bpp1 ( ,
 
)

DST2bpp1 ( ,
 
)

DST2bpp1 ( ,
 
)

DST2bpp1 ( ,
 
)

DST2bpp4 ( ,
 
)

DST2bpp4 ( ,
 
)

DST2bpp4 ( ,
 
)

DST2bpp4 ( ,
 
)

DST2bpp4b ( ,
 
)

DST2bpp4b ( ,
 
)

DST2bpp4b ( ,
 
)

DST2bpp4b ( ,
 
)

DST2bpp8 ( ,
 
)

DST2bpp8 ( ,
 
)

DST2bpp8 ( ,
 
)

DST2bpp8 ( ,
 
)

DST2RGB (  ) 

DST2RGB (  ) 

DST2RGB (  ) 

DST2RGB (  ) 

RGB (  ) 

RGB (  ) 

RGB (  ) 

RGB (  ) 

int yuv2rgb_c_init_tables ( SwsContext c,
const int  inv_table[4],
int  fullRange,
int  brightness,
int  contrast,
int  saturation 
)

Definition at line 676 of file yuv2rgb.c.

References av_free(), av_log(), AV_LOG_ERROR, av_malloc(), c, div_round(), fmt_depth(), isBGR, and NULL.

00677 {
00678     const int isRgb = isBGR(c->dstFormat);
00679     const int bpp = fmt_depth(c->dstFormat);
00680     int i;
00681     uint8_t table_Y[1024];
00682     uint32_t *table_32 = 0;
00683     uint16_t *table_16 = 0;
00684     uint8_t *table_8 = 0;
00685     uint8_t *table_332 = 0;
00686     uint8_t *table_121 = 0;
00687     uint8_t *table_1 = 0;
00688     int entry_size = 0;
00689     void *table_r = 0, *table_g = 0, *table_b = 0;
00690     void *table_start;
00691 
00692     int64_t crv =  inv_table[0];
00693     int64_t cbu =  inv_table[1];
00694     int64_t cgu = -inv_table[2];
00695     int64_t cgv = -inv_table[3];
00696     int64_t cy  = 1<<16;
00697     int64_t oy  = 0;
00698 
00699 //printf("%lld %lld %lld %lld %lld\n", cy, crv, cbu, cgu, cgv);
00700     if (!fullRange){
00701         cy= (cy*255) / 219;
00702         oy= 16<<16;
00703     }else{
00704         crv= (crv*224) / 255;
00705         cbu= (cbu*224) / 255;
00706         cgu= (cgu*224) / 255;
00707         cgv= (cgv*224) / 255;
00708     }
00709 
00710     cy = (cy *contrast             )>>16;
00711     crv= (crv*contrast * saturation)>>32;
00712     cbu= (cbu*contrast * saturation)>>32;
00713     cgu= (cgu*contrast * saturation)>>32;
00714     cgv= (cgv*contrast * saturation)>>32;
00715 //printf("%lld %lld %lld %lld %lld\n", cy, crv, cbu, cgu, cgv);
00716     oy -= 256*brightness;
00717 
00718     for (i = 0; i < 1024; i++) {
00719         int j;
00720 
00721         j= (cy*(((i - 384)<<16) - oy) + (1<<31))>>32;
00722         j = (j < 0) ? 0 : ((j > 255) ? 255 : j);
00723         table_Y[i] = j;
00724     }
00725 
00726     switch (bpp) {
00727     case 32:
00728         table_start= table_32 = av_malloc ((197 + 2*682 + 256 + 132) * sizeof (uint32_t));
00729 
00730         entry_size = sizeof (uint32_t);
00731         table_r = table_32 + 197;
00732         table_b = table_32 + 197 + 685;
00733         table_g = table_32 + 197 + 2*682;
00734 
00735         for (i = -197; i < 256+197; i++)
00736             ((uint32_t *)table_r)[i] = table_Y[i+384] << (isRgb ? 16 : 0);
00737         for (i = -132; i < 256+132; i++)
00738             ((uint32_t *)table_g)[i] = table_Y[i+384] << 8;
00739         for (i = -232; i < 256+232; i++)
00740             ((uint32_t *)table_b)[i] = table_Y[i+384] << (isRgb ? 0 : 16);
00741         break;
00742 
00743     case 24:
00744         table_start= table_8 = av_malloc ((256 + 2*232) * sizeof (uint8_t));
00745 
00746         entry_size = sizeof (uint8_t);
00747         table_r = table_g = table_b = table_8 + 232;
00748 
00749         for (i = -232; i < 256+232; i++)
00750             ((uint8_t * )table_b)[i] = table_Y[i+384];
00751         break;
00752 
00753     case 15:
00754     case 16:
00755         table_start= table_16 = av_malloc ((197 + 2*682 + 256 + 132) * sizeof (uint16_t));
00756 
00757         entry_size = sizeof (uint16_t);
00758         table_r = table_16 + 197;
00759         table_b = table_16 + 197 + 685;
00760         table_g = table_16 + 197 + 2*682;
00761 
00762         for (i = -197; i < 256+197; i++) {
00763             int j = table_Y[i+384] >> 3;
00764 
00765             if (isRgb)
00766                 j <<= ((bpp==16) ? 11 : 10);
00767 
00768             ((uint16_t *)table_r)[i] = j;
00769         }
00770         for (i = -132; i < 256+132; i++) {
00771             int j = table_Y[i+384] >> ((bpp==16) ? 2 : 3);
00772 
00773             ((uint16_t *)table_g)[i] = j << 5;
00774         }
00775         for (i = -232; i < 256+232; i++) {
00776             int j = table_Y[i+384] >> 3;
00777 
00778             if (!isRgb)
00779                 j <<= ((bpp==16) ? 11 : 10);
00780 
00781             ((uint16_t *)table_b)[i] = j;
00782         }
00783         break;
00784 
00785     case 8:
00786         table_start= table_332 = av_malloc ((197 + 2*682 + 256 + 132) * sizeof (uint8_t));
00787 
00788         entry_size = sizeof (uint8_t);
00789         table_r = table_332 + 197;
00790         table_b = table_332 + 197 + 685;
00791         table_g = table_332 + 197 + 2*682;
00792 
00793         for (i = -197; i < 256+197; i++) {
00794             int j = (table_Y[i+384 - 16] + 18)/36;
00795 
00796             if (isRgb)
00797                 j <<= 5;
00798 
00799             ((uint8_t *)table_r)[i] = j;
00800         }
00801         for (i = -132; i < 256+132; i++) {
00802             int j = (table_Y[i+384 - 16] + 18)/36;
00803 
00804             if (!isRgb)
00805                 j <<= 1;
00806 
00807             ((uint8_t *)table_g)[i] = j << 2;
00808         }
00809         for (i = -232; i < 256+232; i++) {
00810             int j = (table_Y[i+384 - 37] + 43)/85;
00811 
00812             if (!isRgb)
00813                 j <<= 6;
00814 
00815             ((uint8_t *)table_b)[i] = j;
00816         }
00817         break;
00818     case 4:
00819     case 4|128:
00820         table_start= table_121 = av_malloc ((197 + 2*682 + 256 + 132) * sizeof (uint8_t));
00821 
00822         entry_size = sizeof (uint8_t);
00823         table_r = table_121 + 197;
00824         table_b = table_121 + 197 + 685;
00825         table_g = table_121 + 197 + 2*682;
00826 
00827         for (i = -197; i < 256+197; i++) {
00828             int j = table_Y[i+384 - 110] >> 7;
00829 
00830             if (isRgb)
00831                 j <<= 3;
00832 
00833             ((uint8_t *)table_r)[i] = j;
00834         }
00835         for (i = -132; i < 256+132; i++) {
00836             int j = (table_Y[i+384 - 37]+ 43)/85;
00837 
00838             ((uint8_t *)table_g)[i] = j << 1;
00839         }
00840         for (i = -232; i < 256+232; i++) {
00841             int j =table_Y[i+384 - 110] >> 7;
00842 
00843             if (!isRgb)
00844                 j <<= 3;
00845 
00846             ((uint8_t *)table_b)[i] = j;
00847         }
00848         break;
00849 
00850     case 1:
00851         table_start= table_1 = av_malloc (256*2 * sizeof (uint8_t));
00852 
00853         entry_size = sizeof (uint8_t);
00854         table_g = table_1;
00855         table_r = table_b = NULL;
00856 
00857         for (i = 0; i < 256+256; i++) {
00858             int j = table_Y[i + 384 - 110]>>7;
00859 
00860             ((uint8_t *)table_g)[i] = j;
00861         }
00862         break;
00863 
00864     default:
00865         table_start= NULL;
00866         av_log(c, AV_LOG_ERROR, "%ibpp not supported by yuv2rgb\n", bpp);
00867         //free mem?
00868         return -1;
00869     }
00870 
00871     for (i = 0; i < 256; i++) {
00872         c->table_rV[i] = (uint8_t *)table_r + entry_size * div_round (crv * (i-128), 76309);
00873         c->table_gU[i] = (uint8_t *)table_g + entry_size * div_round (cgu * (i-128), 76309);
00874         c->table_gV[i] = entry_size * div_round (cgv * (i-128), 76309);
00875         c->table_bU[i] = (uint8_t *)table_b + entry_size * div_round (cbu * (i-128), 76309);
00876     }
00877 
00878     av_free(c->yuvTable);
00879     c->yuvTable= table_start;
00880     return 0;
00881 }

SwsFunc yuv2rgb_get_func_ptr ( SwsContext c  ) 

Definition at line 596 of file yuv2rgb.c.

References