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