00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef SWSCALE_SWSCALE_INTERNAL_H
00022 #define SWSCALE_SWSCALE_INTERNAL_H
00023
00024 #include "config.h"
00025
00026 #if HAVE_ALTIVEC_H
00027 #include <altivec.h>
00028 #endif
00029
00030 #include "libavutil/avutil.h"
00031
00032 #define STR(s) AV_TOSTRING(s) //AV_STRINGIFY is too long
00033
00034 #define MAX_FILTER_SIZE 256
00035
00036 #define VOFW 2048
00037 #define VOF (VOFW*2)
00038
00039 #ifdef WORDS_BIGENDIAN
00040 #define ALT32_CORR (-1)
00041 #else
00042 #define ALT32_CORR 1
00043 #endif
00044
00045 #if ARCH_X86_64
00046 # define APCK_PTR2 8
00047 # define APCK_COEF 16
00048 # define APCK_SIZE 24
00049 #else
00050 # define APCK_PTR2 4
00051 # define APCK_COEF 8
00052 # define APCK_SIZE 16
00053 #endif
00054
00055 struct SwsContext;
00056
00057 typedef int (*SwsFunc)(struct SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY,
00058 int srcSliceH, uint8_t* dst[], int dstStride[]);
00059
00060
00061 typedef struct SwsContext{
00065 const AVClass *av_class;
00066
00071 SwsFunc swScale;
00072 int srcW, srcH, dstH;
00073 int chrSrcW, chrSrcH, chrDstW, chrDstH;
00074 int lumXInc, chrXInc;
00075 int lumYInc, chrYInc;
00076 enum PixelFormat dstFormat, srcFormat;
00077 int origDstFormat, origSrcFormat;
00078 int chrSrcHSubSample, chrSrcVSubSample;
00079 int chrIntHSubSample, chrIntVSubSample;
00080 int chrDstHSubSample, chrDstVSubSample;
00081 int vChrDrop;
00082 int sliceDir;
00083 double param[2];
00084
00085 uint32_t pal_yuv[256];
00086 uint32_t pal_rgb[256];
00087
00088 int16_t **lumPixBuf;
00089 int16_t **chrPixBuf;
00090 int16_t *hLumFilter;
00091 int16_t *hLumFilterPos;
00092 int16_t *hChrFilter;
00093 int16_t *hChrFilterPos;
00094 int16_t *vLumFilter;
00095 int16_t *vLumFilterPos;
00096 int16_t *vChrFilter;
00097 int16_t *vChrFilterPos;
00098
00099 uint8_t formatConvBuffer[VOF];
00100
00101 int hLumFilterSize;
00102 int hChrFilterSize;
00103 int vLumFilterSize;
00104 int vChrFilterSize;
00105 int vLumBufSize;
00106 int vChrBufSize;
00107
00108 uint8_t *funnyYCode;
00109 uint8_t *funnyUVCode;
00110 int32_t *lumMmx2FilterPos;
00111 int32_t *chrMmx2FilterPos;
00112 int16_t *lumMmx2Filter;
00113 int16_t *chrMmx2Filter;
00114
00115 int canMMX2BeUsed;
00116
00117 int lastInLumBuf;
00118 int lastInChrBuf;
00119 int lumBufIndex;
00120 int chrBufIndex;
00121 int dstY;
00122 int flags;
00123 void * yuvTable;
00124 uint8_t * table_rV[256];
00125 uint8_t * table_gU[256];
00126 int table_gV[256];
00127 uint8_t * table_bU[256];
00128
00129
00130 int contrast, brightness, saturation;
00131 int srcColorspaceTable[4];
00132 int dstColorspaceTable[4];
00133 int srcRange, dstRange;
00134 int yuv2rgb_y_offset;
00135 int yuv2rgb_y_coeff;
00136 int yuv2rgb_v2r_coeff;
00137 int yuv2rgb_v2g_coeff;
00138 int yuv2rgb_u2g_coeff;
00139 int yuv2rgb_u2b_coeff;
00140
00141 #define RED_DITHER "0*8"
00142 #define GREEN_DITHER "1*8"
00143 #define BLUE_DITHER "2*8"
00144 #define Y_COEFF "3*8"
00145 #define VR_COEFF "4*8"
00146 #define UB_COEFF "5*8"
00147 #define VG_COEFF "6*8"
00148 #define UG_COEFF "7*8"
00149 #define Y_OFFSET "8*8"
00150 #define U_OFFSET "9*8"
00151 #define V_OFFSET "10*8"
00152 #define LUM_MMX_FILTER_OFFSET "11*8"
00153 #define CHR_MMX_FILTER_OFFSET "11*8+4*4*256"
00154 #define DSTW_OFFSET "11*8+4*4*256*2" //do not change, it is hardcoded in the ASM
00155 #define ESP_OFFSET "11*8+4*4*256*2+8"
00156 #define VROUNDER_OFFSET "11*8+4*4*256*2+16"
00157 #define U_TEMP "11*8+4*4*256*2+24"
00158 #define V_TEMP "11*8+4*4*256*2+32"
00159
00160 uint64_t redDither __attribute__((aligned(8)));
00161 uint64_t greenDither __attribute__((aligned(8)));
00162 uint64_t blueDither __attribute__((aligned(8)));
00163
00164 uint64_t yCoeff __attribute__((aligned(8)));
00165 uint64_t vrCoeff __attribute__((aligned(8)));
00166 uint64_t ubCoeff __attribute__((aligned(8)));
00167 uint64_t vgCoeff __attribute__((aligned(8)));
00168 uint64_t ugCoeff __attribute__((aligned(8)));
00169 uint64_t yOffset __attribute__((aligned(8)));
00170 uint64_t uOffset __attribute__((aligned(8)));
00171 uint64_t vOffset __attribute__((aligned(8)));
00172 int32_t lumMmxFilter[4*MAX_FILTER_SIZE];
00173 int32_t chrMmxFilter[4*MAX_FILTER_SIZE];
00174 int dstW;
00175 uint64_t esp __attribute__((aligned(8)));
00176 uint64_t vRounder __attribute__((aligned(8)));
00177 uint64_t u_temp __attribute__((aligned(8)));
00178 uint64_t v_temp __attribute__((aligned(8)));
00179
00180 #if HAVE_ALTIVEC
00181
00182 vector signed short CY;
00183 vector signed short CRV;
00184 vector signed short CBU;
00185 vector signed short CGU;
00186 vector signed short CGV;
00187 vector signed short OY;
00188 vector unsigned short CSHIFT;
00189 vector signed short *vYCoeffsBank, *vCCoeffsBank;
00190
00191 #endif
00192
00193
00194 #if ARCH_BFIN
00195 uint32_t oy __attribute__((aligned(4)));
00196 uint32_t oc __attribute__((aligned(4)));
00197 uint32_t zero __attribute__((aligned(4)));
00198 uint32_t cy __attribute__((aligned(4)));
00199 uint32_t crv __attribute__((aligned(4)));
00200 uint32_t rmask __attribute__((aligned(4)));
00201 uint32_t cbu __attribute__((aligned(4)));
00202 uint32_t bmask __attribute__((aligned(4)));
00203 uint32_t cgu __attribute__((aligned(4)));
00204 uint32_t cgv __attribute__((aligned(4)));
00205 uint32_t gmask __attribute__((aligned(4)));
00206 #endif
00207
00208 #if HAVE_VIS
00209 uint64_t sparc_coeffs[10] __attribute__((aligned(8)));
00210 #endif
00211
00212 } SwsContext;
00213
00214
00215 SwsFunc sws_yuv2rgb_get_func_ptr (SwsContext *c);
00216 int sws_yuv2rgb_c_init_tables (SwsContext *c, const int inv_table[4], int fullRange, int brightness, int contrast, int saturation);
00217
00218 void sws_yuv2rgb_altivec_init_tables (SwsContext *c, const int inv_table[4],int brightness,int contrast, int saturation);
00219 SwsFunc sws_yuv2rgb_init_altivec (SwsContext *c);
00220 void altivec_yuv2packedX (SwsContext *c,
00221 int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize,
00222 int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize,
00223 uint8_t *dest, int dstW, int dstY);
00224
00225 const char *sws_format_name(int format);
00226
00227
00228 #define isPlanarYUV(x) ( \
00229 (x)==PIX_FMT_YUV410P \
00230 || (x)==PIX_FMT_YUV420P \
00231 || (x)==PIX_FMT_YUV411P \
00232 || (x)==PIX_FMT_YUV422P \
00233 || (x)==PIX_FMT_YUV444P \
00234 || (x)==PIX_FMT_YUV440P \
00235 || (x)==PIX_FMT_NV12 \
00236 || (x)==PIX_FMT_NV21 \
00237 )
00238 #define isYUV(x) ( \
00239 (x)==PIX_FMT_UYVY422 \
00240 || (x)==PIX_FMT_YUYV422 \
00241 || isPlanarYUV(x) \
00242 )
00243 #define isGray(x) ( \
00244 (x)==PIX_FMT_GRAY8 \
00245 || (x)==PIX_FMT_GRAY16BE \
00246 || (x)==PIX_FMT_GRAY16LE \
00247 )
00248 #define isGray16(x) ( \
00249 (x)==PIX_FMT_GRAY16BE \
00250 || (x)==PIX_FMT_GRAY16LE \
00251 )
00252 #define isRGB(x) ( \
00253 (x)==PIX_FMT_RGB32 \
00254 || (x)==PIX_FMT_RGB32_1 \
00255 || (x)==PIX_FMT_RGB24 \
00256 || (x)==PIX_FMT_RGB565 \
00257 || (x)==PIX_FMT_RGB555 \
00258 || (x)==PIX_FMT_RGB8 \
00259 || (x)==PIX_FMT_RGB4 \
00260 || (x)==PIX_FMT_RGB4_BYTE \
00261 || (x)==PIX_FMT_MONOBLACK \
00262 || (x)==PIX_FMT_MONOWHITE \
00263 )
00264 #define isBGR(x) ( \
00265 (x)==PIX_FMT_BGR32 \
00266 || (x)==PIX_FMT_BGR32_1 \
00267 || (x)==PIX_FMT_BGR24 \
00268 || (x)==PIX_FMT_BGR565 \
00269 || (x)==PIX_FMT_BGR555 \
00270 || (x)==PIX_FMT_BGR8 \
00271 || (x)==PIX_FMT_BGR4 \
00272 || (x)==PIX_FMT_BGR4_BYTE \
00273 || (x)==PIX_FMT_MONOBLACK \
00274 || (x)==PIX_FMT_MONOWHITE \
00275 )
00276 #define isALPHA(x) ( \
00277 (x)==PIX_FMT_BGR32 \
00278 || (x)==PIX_FMT_BGR32_1 \
00279 || (x)==PIX_FMT_RGB32 \
00280 || (x)==PIX_FMT_RGB32_1 \
00281 || (x)==PIX_FMT_YUVA420P \
00282 )
00283
00284 static inline int fmt_depth(int fmt)
00285 {
00286 switch(fmt) {
00287 case PIX_FMT_BGRA:
00288 case PIX_FMT_ABGR:
00289 case PIX_FMT_RGBA:
00290 case PIX_FMT_ARGB:
00291 return 32;
00292 case PIX_FMT_BGR24:
00293 case PIX_FMT_RGB24:
00294 return 24;
00295 case PIX_FMT_BGR565:
00296 case PIX_FMT_RGB565:
00297 case PIX_FMT_GRAY16BE:
00298 case PIX_FMT_GRAY16LE:
00299 return 16;
00300 case PIX_FMT_BGR555:
00301 case PIX_FMT_RGB555:
00302 return 15;
00303 case PIX_FMT_BGR8:
00304 case PIX_FMT_RGB8:
00305 return 8;
00306 case PIX_FMT_BGR4:
00307 case PIX_FMT_RGB4:
00308 case PIX_FMT_BGR4_BYTE:
00309 case PIX_FMT_RGB4_BYTE:
00310 return 4;
00311 case PIX_FMT_MONOBLACK:
00312 case PIX_FMT_MONOWHITE:
00313 return 1;
00314 default:
00315 return 0;
00316 }
00317 }
00318
00319 extern const uint64_t ff_dither4[2];
00320 extern const uint64_t ff_dither8[2];
00321
00322 extern const AVClass sws_context_class;
00323
00324 #endif