return LIBSWSCALE_VERSION_INT;
}
-const char * swscale_configuration(void)
+const char *swscale_configuration(void)
{
return FFMPEG_CONFIGURATION;
}
-const char * swscale_license(void)
+const char *swscale_license(void)
{
#define LICENSE_PREFIX "libswscale license: "
return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1;
|| (x)==PIX_FMT_YUV422P16BE \
|| (x)==PIX_FMT_YUV444P16BE \
)
+
+int sws_isSupportedInput(enum PixelFormat pix_fmt)
+{
+ return isSupportedIn(pix_fmt);
+}
+
#define isSupportedOut(x) ( \
(x)==PIX_FMT_YUV420P \
|| (x)==PIX_FMT_YUVA420P \
|| (x)==PIX_FMT_YUV422P16BE \
|| (x)==PIX_FMT_YUV444P16BE \
)
+
+int sws_isSupportedOutput(enum PixelFormat pix_fmt)
+{
+ return isSupportedOut(pix_fmt);
+}
+
#define isPacked(x) ( \
(x)==PIX_FMT_PAL8 \
|| (x)==PIX_FMT_YUYV422 \
|| isRGB(x) \
|| isBGR(x) \
)
-#define usePal(x) ( \
- (x)==PIX_FMT_PAL8 \
- || (x)==PIX_FMT_BGR4_BYTE \
- || (x)==PIX_FMT_RGB4_BYTE \
- || (x)==PIX_FMT_BGR8 \
- || (x)==PIX_FMT_RGB8 \
- )
+#define usePal(x) (av_pix_fmt_descriptors[x].flags & PIX_FMT_PAL)
#define RGB2YUV_SHIFT 15
#define BY ( (int)(0.114*219/255*(1<<RGB2YUV_SHIFT)+0.5))
DECLARE_ASM_CONST(8, uint64_t, bm11111000)=0xFFFFFFFFFF000000LL;
DECLARE_ASM_CONST(8, uint64_t, bm01010101)=0x00FF00FF00FF00FFLL;
-const DECLARE_ALIGNED(8, uint64_t, ff_dither4[2]) = {
+const DECLARE_ALIGNED(8, uint64_t, ff_dither4)[2] = {
0x0103010301030103LL,
0x0200020002000200LL,};
-const DECLARE_ALIGNED(8, uint64_t, ff_dither8[2]) = {
+const DECLARE_ALIGNED(8, uint64_t, ff_dither8)[2] = {
0x0602060206020602LL,
0x0004000400040004LL,};
DECLARE_ASM_CONST(8, uint64_t, ff_rgb24toY2Coeff) = 0x0C88408700000C88ULL;
DECLARE_ASM_CONST(8, uint64_t, ff_bgr24toYOffset) = 0x0008400000084000ULL;
-DECLARE_ASM_CONST(8, uint64_t, ff_bgr24toUV[2][4]) = {
+DECLARE_ASM_CONST(8, uint64_t, ff_bgr24toUV)[2][4] = {
{0x38380000DAC83838ULL, 0xECFFDAC80000ECFFULL, 0xF6E40000D0E3F6E4ULL, 0x3838D0E300003838ULL},
{0xECFF0000DAC8ECFFULL, 0x3838DAC800003838ULL, 0x38380000D0E33838ULL, 0xF6E4D0E30000F6E4ULL},
};
#endif /* ARCH_X86 && CONFIG_GPL */
-// clipping helper table for C implementations:
-static unsigned char clip_table[768];
-
-static SwsVector *sws_getConvVec(SwsVector *a, SwsVector *b);
-
-DECLARE_ALIGNED(8, static const uint8_t, dither_2x2_4[2][8])={
+DECLARE_ALIGNED(8, static const uint8_t, dither_2x2_4)[2][8]={
{ 1, 3, 1, 3, 1, 3, 1, 3, },
{ 2, 0, 2, 0, 2, 0, 2, 0, },
};
-DECLARE_ALIGNED(8, static const uint8_t, dither_2x2_8[2][8])={
+DECLARE_ALIGNED(8, static const uint8_t, dither_2x2_8)[2][8]={
{ 6, 2, 6, 2, 6, 2, 6, 2, },
{ 0, 4, 0, 4, 0, 4, 0, 4, },
};
-DECLARE_ALIGNED(8, const uint8_t, dither_8x8_32[8][8])={
+DECLARE_ALIGNED(8, const uint8_t, dither_8x8_32)[8][8]={
{ 17, 9, 23, 15, 16, 8, 22, 14, },
{ 5, 29, 3, 27, 4, 28, 2, 26, },
{ 21, 13, 19, 11, 20, 12, 18, 10, },
{ 1, 25, 7, 31, 0, 24, 6, 30, },
};
-DECLARE_ALIGNED(8, const uint8_t, dither_8x8_73[8][8])={
+DECLARE_ALIGNED(8, const uint8_t, dither_8x8_73)[8][8]={
{ 0, 55, 14, 68, 3, 58, 17, 72, },
{ 37, 18, 50, 32, 40, 22, 54, 35, },
{ 9, 64, 5, 59, 13, 67, 8, 63, },
};
#if 1
-DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220[8][8])={
+DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220)[8][8]={
{117, 62, 158, 103, 113, 58, 155, 100, },
{ 34, 199, 21, 186, 31, 196, 17, 182, },
{144, 89, 131, 76, 141, 86, 127, 72, },
};
#elif 1
// tries to correct a gamma of 1.5
-DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220[8][8])={
+DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220)[8][8]={
{ 0, 143, 18, 200, 2, 156, 25, 215, },
{ 78, 28, 125, 64, 89, 36, 138, 74, },
{ 10, 180, 3, 161, 16, 195, 8, 175, },
};
#elif 1
// tries to correct a gamma of 2.0
-DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220[8][8])={
+DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220)[8][8]={
{ 0, 124, 8, 193, 0, 140, 12, 213, },
{ 55, 14, 104, 42, 66, 19, 119, 52, },
{ 3, 168, 1, 145, 6, 187, 3, 162, },
};
#else
// tries to correct a gamma of 2.5
-DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220[8][8])={
+DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220)[8][8]={
{ 0, 107, 3, 187, 0, 125, 6, 212, },
{ 39, 7, 86, 28, 49, 11, 102, 36, },
{ 1, 158, 0, 131, 3, 180, 1, 151, },
}\
A1>>=19;\
A2>>=19;\
- }\
+ }
#define YSCALE_YUV_2_PACKEDX_C(type,alpha) \
YSCALE_YUV_2_PACKEDX_NOCLIP_C(type,alpha)\
A >>=19;\
if (A&256)\
A = av_clip_uint8(A);\
- }\
+ }
#define YSCALE_YUV_2_RGBX_FULL_C(rnd,alpha) \
YSCALE_YUV_2_PACKEDX_FULL_C(rnd>>3,alpha)\
else if (G<0)G=0; \
if (B>=(256<<22)) B=(256<<22)-1; \
else if (B<0)B=0; \
- }\
-
+ }
#define YSCALE_YUV_2_GRAY16_C \
for (i=0; i<(dstW>>1); i++) {\
YSCALE_YUV_2_PACKEDX_C(type,alpha) /* FIXME fix tables so that clipping is not needed and then use _NOCLIP*/\
r = (type *)c->table_rV[V]; \
g = (type *)(c->table_gU[U] + c->table_gV[V]); \
- b = (type *)c->table_bU[U]; \
+ b = (type *)c->table_bU[U];
#define YSCALE_YUV_2_PACKED2_C(type,alpha) \
for (i=0; i<(dstW>>1); i++) { \
if (alpha) {\
A1= (abuf0[i2 ]*yalpha1+abuf1[i2 ]*yalpha)>>19; \
A2= (abuf0[i2+1]*yalpha1+abuf1[i2+1]*yalpha)>>19; \
- }\
+ }
#define YSCALE_YUV_2_GRAY16_2_C \
for (i=0; i<(dstW>>1); i++) { \
const int i2= 2*i; \
int Y1= (buf0[i2 ]*yalpha1+buf1[i2 ]*yalpha)>>11; \
- int Y2= (buf0[i2+1]*yalpha1+buf1[i2+1]*yalpha)>>11; \
+ int Y2= (buf0[i2+1]*yalpha1+buf1[i2+1]*yalpha)>>11;
#define YSCALE_YUV_2_RGB2_C(type,alpha) \
YSCALE_YUV_2_PACKED2_C(type,alpha)\
r = (type *)c->table_rV[V];\
g = (type *)(c->table_gU[U] + c->table_gV[V]);\
- b = (type *)c->table_bU[U];\
+ b = (type *)c->table_bU[U];
#define YSCALE_YUV_2_PACKED1_C(type,alpha) \
for (i=0; i<(dstW>>1); i++) {\
if (alpha) {\
A1= abuf0[i2 ]>>7;\
A2= abuf0[i2+1]>>7;\
- }\
+ }
#define YSCALE_YUV_2_GRAY16_1_C \
for (i=0; i<(dstW>>1); i++) {\
const int i2= 2*i;\
int Y1= buf0[i2 ]<<1;\
- int Y2= buf0[i2+1]<<1;\
+ int Y2= buf0[i2+1]<<1;
#define YSCALE_YUV_2_RGB1_C(type,alpha) \
YSCALE_YUV_2_PACKED1_C(type,alpha)\
r = (type *)c->table_rV[V];\
g = (type *)(c->table_gU[U] + c->table_gV[V]);\
- b = (type *)c->table_bU[U];\
+ b = (type *)c->table_bU[U];
#define YSCALE_YUV_2_PACKED1B_C(type,alpha) \
for (i=0; i<(dstW>>1); i++) {\
if (alpha) {\
A1= abuf0[i2 ]>>7;\
A2= abuf0[i2+1]>>7;\
- }\
+ }
#define YSCALE_YUV_2_RGB1B_C(type,alpha) \
YSCALE_YUV_2_PACKED1B_C(type,alpha)\
r = (type *)c->table_rV[V];\
g = (type *)(c->table_gU[U] + c->table_gV[V]);\
- b = (type *)c->table_bU[U];\
+ b = (type *)c->table_bU[U];
#define YSCALE_YUV_2_MONO2_C \
const uint8_t * const d128=dither_8x8_220[y&7];\
acc+= acc + g[((buf0[i+7]*yalpha1+buf1[i+7]*yalpha)>>19) + d128[7]];\
((uint8_t*)dest)[0]= c->dstFormat == PIX_FMT_MONOBLACK ? acc : ~acc;\
dest++;\
- }\
-
+ }
#define YSCALE_YUV_2_MONOX_C \
const uint8_t * const d128=dither_8x8_220[y&7];\
}\
}
-
#define YSCALE_YUV_2_ANYRGB_C(func, func2, func_g16, func_monoblack)\
switch(c->dstFormat) {\
case PIX_FMT_RGB48BE:\
((uint8_t*)dest)[2*i2+3]= Y2>>8;\
} \
break;\
- }\
-
+ }
static inline void yuv2packedXinC(SwsContext *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize,
const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize,
}
}
-static inline void rgb48ToY(uint8_t *dst, const uint8_t *src, int width)
+static inline void rgb48ToY(uint8_t *dst, const uint8_t *src, int width,
+ uint32_t *unused)
{
int i;
for (i = 0; i < width; i++) {
}
static inline void rgb48ToUV(uint8_t *dstU, uint8_t *dstV,
- uint8_t *src1, uint8_t *src2, int width)
+ const uint8_t *src1, const uint8_t *src2,
+ int width, uint32_t *unused)
{
int i;
assert(src1==src2);
}
static inline void rgb48ToUV_half(uint8_t *dstU, uint8_t *dstV,
- uint8_t *src1, uint8_t *src2, int width)
+ const uint8_t *src1, const uint8_t *src2,
+ int width, uint32_t *unused)
{
int i;
assert(src1==src2);
}
}
-
//Note: we have C, MMX, MMX2, 3DNOW versions, there is no 3DNOW+MMX2 one
//Plain C versions
#if ((!HAVE_MMX || !CONFIG_GPL) && !HAVE_ALTIVEC) || CONFIG_RUNTIME_CPUDETECT
dist-1.0);
}
-static inline int initFilter(int16_t **outFilter, int16_t **filterPos, int *outFilterSize, int xInc,
- int srcW, int dstW, int filterAlign, int one, int flags,
- SwsVector *srcFilter, SwsVector *dstFilter, double param[2])
+static int initFilter(int16_t **outFilter, int16_t **filterPos, int *outFilterSize, int xInc,
+ int srcW, int dstW, int filterAlign, int one, int flags,
+ SwsVector *srcFilter, SwsVector *dstFilter, double param[2])
{
int i;
int filterSize;
int j;
int64_t cutOff=0.0;
- /* get rid off near zero elements on the left by shifting left */
+ /* get rid of near zero elements on the left by shifting left */
for (j=0; j<filter2Size; j++) {
int k;
cutOff += FFABS(filter2[i*filter2Size]);
}
}
-
//FIXME try to align filterPos if possible
//fix borders
int xpos, i;
// create an optimized horizontal scaling routine
+ /* This scaler is made of runtime-generated MMX2 code using specially
+ * tuned pshufw instructions. For every four output pixels, if four
+ * input pixels are enough for the fast bilinear scaling, then a chunk
+ * of fragmentB is used. If five input pixels are needed, then a chunk
+ * of fragmentA is used.
+ */
//code fragment
}
#endif /* COMPILE_MMX2 */
-static void globalInit(void)
-{
- // generating tables:
- int i;
- for (i=0; i<768; i++) {
- int c= av_clip_uint8(i-256);
- clip_table[i]=c;
- }
-}
-
static SwsFunc getSwsFunc(SwsContext *c)
{
#if CONFIG_RUNTIME_CPUDETECT
#endif //!CONFIG_RUNTIME_CPUDETECT
}
-static int PlanarToNV12Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
+static int PlanarToNV12Wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY,
int srcSliceH, uint8_t* dstParam[], int dstStride[])
{
uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY;
return srcSliceH;
}
-static int PlanarToYuy2Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
+static int PlanarToYuy2Wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY,
int srcSliceH, uint8_t* dstParam[], int dstStride[])
{
uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY;
return srcSliceH;
}
-static int PlanarToUyvyWrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
+static int PlanarToUyvyWrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY,
int srcSliceH, uint8_t* dstParam[], int dstStride[])
{
uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY;
return srcSliceH;
}
-static int YUV422PToYuy2Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
+static int YUV422PToYuy2Wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY,
int srcSliceH, uint8_t* dstParam[], int dstStride[])
{
uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY;
return srcSliceH;
}
-static int YUV422PToUyvyWrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
+static int YUV422PToUyvyWrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY,
int srcSliceH, uint8_t* dstParam[], int dstStride[])
{
uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY;
return srcSliceH;
}
-static int YUYV2YUV420Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
+static int YUYV2YUV420Wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY,
int srcSliceH, uint8_t* dstParam[], int dstStride[])
{
uint8_t *ydst=dstParam[0] + dstStride[0]*srcSliceY;
return srcSliceH;
}
-static int YUYV2YUV422Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
+static int YUYV2YUV422Wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY,
int srcSliceH, uint8_t* dstParam[], int dstStride[])
{
uint8_t *ydst=dstParam[0] + dstStride[0]*srcSliceY;
return srcSliceH;
}
-static int UYVY2YUV420Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
+static int UYVY2YUV420Wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY,
int srcSliceH, uint8_t* dstParam[], int dstStride[])
{
uint8_t *ydst=dstParam[0] + dstStride[0]*srcSliceY;
return srcSliceH;
}
-static int UYVY2YUV422Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
+static int UYVY2YUV422Wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY,
int srcSliceH, uint8_t* dstParam[], int dstStride[])
{
uint8_t *ydst=dstParam[0] + dstStride[0]*srcSliceY;
return srcSliceH;
}
-static int pal2rgbWrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
+static int pal2rgbWrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY,
int srcSliceH, uint8_t* dst[], int dstStride[])
{
const enum PixelFormat srcFormat= c->srcFormat;
const uint8_t *palette)=NULL;
int i;
uint8_t *dstPtr= dst[0] + dstStride[0]*srcSliceY;
- uint8_t *srcPtr= src[0];
+ const uint8_t *srcPtr= src[0];
+
+ if (usePal(srcFormat)) {
+ switch (dstFormat) {
+ case PIX_FMT_RGB32 : conv = palette8topacked32; break;
+ case PIX_FMT_BGR32 : conv = palette8topacked32; break;
+ case PIX_FMT_BGR32_1: conv = palette8topacked32; break;
+ case PIX_FMT_RGB32_1: conv = palette8topacked32; break;
+ case PIX_FMT_RGB24 : conv = palette8topacked24; break;
+ case PIX_FMT_BGR24 : conv = palette8topacked24; break;
+ }
+ }
- if (!usePal(srcFormat))
+ if (!conv)
av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n",
sws_format_name(srcFormat), sws_format_name(dstFormat));
-
- switch(dstFormat) {
- case PIX_FMT_RGB32 : conv = palette8topacked32; break;
- case PIX_FMT_BGR32 : conv = palette8topacked32; break;
- case PIX_FMT_BGR32_1: conv = palette8topacked32; break;
- case PIX_FMT_RGB32_1: conv = palette8topacked32; break;
- case PIX_FMT_RGB24 : conv = palette8topacked24; break;
- case PIX_FMT_BGR24 : conv = palette8topacked24; break;
- default: av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n",
- sws_format_name(srcFormat), sws_format_name(dstFormat)); break;
- }
-
-
- for (i=0; i<srcSliceH; i++) {
- conv(srcPtr, dstPtr, c->srcW, (uint8_t *) c->pal_rgb);
- srcPtr+= srcStride[0];
- dstPtr+= dstStride[0];
+ else {
+ for (i=0; i<srcSliceH; i++) {
+ conv(srcPtr, dstPtr, c->srcW, (uint8_t *) c->pal_rgb);
+ srcPtr+= srcStride[0];
+ dstPtr+= dstStride[0];
+ }
}
return srcSliceH;
}
/* {RGB,BGR}{15,16,24,32,32_1} -> {RGB,BGR}{15,16,24,32} */
-static int rgb2rgbWrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
+static int rgb2rgbWrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY,
int srcSliceH, uint8_t* dst[], int dstStride[])
{
const enum PixelFormat srcFormat= c->srcFormat;
case 0x83: conv= rgb15to32; break;
case 0x84: conv= rgb16to32; break;
case 0x86: conv= rgb24to32; break;
- default: av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n",
- sws_format_name(srcFormat), sws_format_name(dstFormat)); break;
}
} else if ( (isBGR(srcFormat) && isRGB(dstFormat))
|| (isRGB(srcFormat) && isBGR(dstFormat))) {
case 0x84: conv= rgb16tobgr32; break;
case 0x86: conv= rgb24tobgr32; break;
case 0x88: conv= rgb32tobgr32; break;
- default: av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n",
- sws_format_name(srcFormat), sws_format_name(dstFormat)); break;
}
- } else {
- av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n",
- sws_format_name(srcFormat), sws_format_name(dstFormat));
}
- if(conv) {
- uint8_t *srcPtr= src[0];
+ if (!conv) {
+ av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n",
+ sws_format_name(srcFormat), sws_format_name(dstFormat));
+ } else {
+ const uint8_t *srcPtr= src[0];
if(srcFormat == PIX_FMT_RGB32_1 || srcFormat == PIX_FMT_BGR32_1)
srcPtr += ALT32_CORR;
return srcSliceH;
}
-static int bgr24toyv12Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
+static int bgr24toyv12Wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY,
int srcSliceH, uint8_t* dst[], int dstStride[])
{
-
rgb24toyv12(
src[0],
dst[0]+ srcSliceY *dstStride[0],
return srcSliceH;
}
-static int yvu9toyv12Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
+static int yvu9toyv12Wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY,
int srcSliceH, uint8_t* dst[], int dstStride[])
{
int i;
if (srcStride[0]==dstStride[0] && srcStride[0] > 0)
memcpy(dst[0]+ srcSliceY*dstStride[0], src[0], srcStride[0]*srcSliceH);
else {
- uint8_t *srcPtr= src[0];
+ const uint8_t *srcPtr= src[0];
uint8_t *dstPtr= dst[0] + dstStride[0]*srcSliceY;
for (i=0; i<srcSliceH; i++) {
}
/* unscaled copy like stuff (assumes nearly identical formats) */
-static int packedCopy(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
+static int packedCopy(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY,
int srcSliceH, uint8_t* dst[], int dstStride[])
{
if (dstStride[0]==srcStride[0] && srcStride[0] > 0)
memcpy(dst[0] + dstStride[0]*srcSliceY, src[0], srcSliceH*dstStride[0]);
else {
int i;
- uint8_t *srcPtr= src[0];
+ const uint8_t *srcPtr= src[0];
uint8_t *dstPtr= dst[0] + dstStride[0]*srcSliceY;
int length=0;
return srcSliceH;
}
-static int planarCopy(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
+static int planarCopy(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY,
int srcSliceH, uint8_t* dst[], int dstStride[])
{
int plane, i, j;
int length= (plane==0 || plane==3) ? c->srcW : -((-c->srcW )>>c->chrDstHSubSample);
int y= (plane==0 || plane==3) ? srcSliceY: -((-srcSliceY)>>c->chrDstVSubSample);
int height= (plane==0 || plane==3) ? srcSliceH: -((-srcSliceH)>>c->chrDstVSubSample);
- uint8_t *srcPtr= src[plane];
+ const uint8_t *srcPtr= src[plane];
uint8_t *dstPtr= dst[plane] + dstStride[plane]*y;
if (!dst[plane]) continue;
for (i=0; i<height; i++) {
for (j=0; j<length; j++)
- ((uint16_t*)dstPtr)[j] = bswap_16(((uint16_t*)srcPtr)[j]);
+ ((uint16_t*)dstPtr)[j] = bswap_16(((const uint16_t*)srcPtr)[j]);
srcPtr+= srcStride[plane];
dstPtr+= dstStride[plane];
}
return srcSliceH;
}
-
-static void getSubSampleFactors(int *h, int *v, int format)
+static void getSubSampleFactors(int *h, int *v, enum PixelFormat format)
{
- switch(format) {
- case PIX_FMT_UYVY422:
- case PIX_FMT_YUYV422:
- *h=1;
- *v=0;
- break;
- case PIX_FMT_YUV420P:
- case PIX_FMT_YUV420P16LE:
- case PIX_FMT_YUV420P16BE:
- case PIX_FMT_YUVA420P:
- case PIX_FMT_GRAY16BE:
- case PIX_FMT_GRAY16LE:
- case PIX_FMT_GRAY8: //FIXME remove after different subsamplings are fully implemented
- case PIX_FMT_NV12:
- case PIX_FMT_NV21:
- *h=1;
- *v=1;
- break;
- case PIX_FMT_YUV440P:
- *h=0;
- *v=1;
- break;
- case PIX_FMT_YUV410P:
- *h=2;
- *v=2;
- break;
- case PIX_FMT_YUV444P:
- case PIX_FMT_YUV444P16LE:
- case PIX_FMT_YUV444P16BE:
- *h=0;
- *v=0;
- break;
- case PIX_FMT_YUV422P:
- case PIX_FMT_YUV422P16LE:
- case PIX_FMT_YUV422P16BE:
- *h=1;
- *v=0;
- break;
- case PIX_FMT_YUV411P:
- *h=2;
- *v=0;
- break;
- default:
- *h=0;
- *v=0;
- break;
- }
+ *h = av_pix_fmt_descriptors[format].log2_chroma_w;
+ *v = av_pix_fmt_descriptors[format].log2_chroma_h;
}
static uint16_t roundToInt16(int64_t f)
}
}
-SwsContext *sws_getContext(int srcW, int srcH, enum PixelFormat srcFormat, int dstW, int dstH, enum PixelFormat dstFormat, int flags,
+SwsContext *sws_getContext(int srcW, int srcH, enum PixelFormat srcFormat,
+ int dstW, int dstH, enum PixelFormat dstFormat, int flags,
SwsFilter *srcFilter, SwsFilter *dstFilter, const double *param)
{
flags |= SWS_CPU_CAPS_BFIN;
#endif
#endif /* CONFIG_RUNTIME_CPUDETECT */
- if (clip_table[512] != 255) globalInit();
if (!rgb15to16) sws_rgb2rgb_init(flags);
unscaled = (srcW == dstW && srcH == dstH);
/* precalculate horizontal scaler filter coefficients */
{
- const int filterAlign=
- (flags & SWS_CPU_CAPS_MMX) ? 4 :
- (flags & SWS_CPU_CAPS_ALTIVEC) ? 8 :
- 1;
-
- if (initFilter(&c->hLumFilter, &c->hLumFilterPos, &c->hLumFilterSize, c->lumXInc,
- srcW , dstW, filterAlign, 1<<14,
- (flags&SWS_BICUBLIN) ? (flags|SWS_BICUBIC) : flags,
- srcFilter->lumH, dstFilter->lumH, c->param) < 0)
- goto fail;
- if (initFilter(&c->hChrFilter, &c->hChrFilterPos, &c->hChrFilterSize, c->chrXInc,
- c->chrSrcW, c->chrDstW, filterAlign, 1<<14,
- (flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags,
- srcFilter->chrH, dstFilter->chrH, c->param) < 0)
- goto fail;
-
#if defined(COMPILE_MMX2)
// can't downscale !!!
if (c->canMMX2BeUsed && (flags & SWS_FAST_BILINEAR)) {
c->chrMmx2FilterCode = av_malloc(c->chrMmx2FilterCodeSize);
#endif
- FF_ALLOCZ_OR_GOTO(c, c->lumMmx2Filter , (dstW /8+8)*sizeof(int16_t), fail);
- FF_ALLOCZ_OR_GOTO(c, c->chrMmx2Filter , (c->chrDstW /4+8)*sizeof(int16_t), fail);
- FF_ALLOCZ_OR_GOTO(c, c->lumMmx2FilterPos, (dstW /2/8+8)*sizeof(int32_t), fail);
- FF_ALLOCZ_OR_GOTO(c, c->chrMmx2FilterPos, (c->chrDstW/2/4+8)*sizeof(int32_t), fail);
+ FF_ALLOCZ_OR_GOTO(c, c->hLumFilter , (dstW /8+8)*sizeof(int16_t), fail);
+ FF_ALLOCZ_OR_GOTO(c, c->hChrFilter , (c->chrDstW /4+8)*sizeof(int16_t), fail);
+ FF_ALLOCZ_OR_GOTO(c, c->hLumFilterPos, (dstW /2/8+8)*sizeof(int32_t), fail);
+ FF_ALLOCZ_OR_GOTO(c, c->hChrFilterPos, (c->chrDstW/2/4+8)*sizeof(int32_t), fail);
- initMMX2HScaler( dstW, c->lumXInc, c->lumMmx2FilterCode, c->lumMmx2Filter, c->lumMmx2FilterPos, 8);
- initMMX2HScaler(c->chrDstW, c->chrXInc, c->chrMmx2FilterCode, c->chrMmx2Filter, c->chrMmx2FilterPos, 4);
+ initMMX2HScaler( dstW, c->lumXInc, c->lumMmx2FilterCode, c->hLumFilter, c->hLumFilterPos, 8);
+ initMMX2HScaler(c->chrDstW, c->chrXInc, c->chrMmx2FilterCode, c->hChrFilter, c->hChrFilterPos, 4);
#ifdef MAP_ANONYMOUS
mprotect(c->lumMmx2FilterCode, c->lumMmx2FilterCodeSize, PROT_EXEC | PROT_READ);
mprotect(c->chrMmx2FilterCode, c->chrMmx2FilterCodeSize, PROT_EXEC | PROT_READ);
#endif
- }
+ } else
#endif /* defined(COMPILE_MMX2) */
+ {
+ const int filterAlign=
+ (flags & SWS_CPU_CAPS_MMX) ? 4 :
+ (flags & SWS_CPU_CAPS_ALTIVEC) ? 8 :
+ 1;
+
+ if (initFilter(&c->hLumFilter, &c->hLumFilterPos, &c->hLumFilterSize, c->lumXInc,
+ srcW , dstW, filterAlign, 1<<14,
+ (flags&SWS_BICUBLIN) ? (flags|SWS_BICUBIC) : flags,
+ srcFilter->lumH, dstFilter->lumH, c->param) < 0)
+ goto fail;
+ if (initFilter(&c->hChrFilter, &c->hChrFilterPos, &c->hChrFilterSize, c->chrXInc,
+ c->chrSrcW, c->chrDstW, filterAlign, 1<<14,
+ (flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags,
+ srcFilter->chrH, dstFilter->chrH, c->param) < 0)
+ goto fail;
+ }
} // initialize horizontal stuff
-
-
/* precalculate vertical scaler filter coefficients */
{
const int filterAlign=
1;
if (initFilter(&c->vLumFilter, &c->vLumFilterPos, &c->vLumFilterSize, c->lumYInc,
- srcH , dstH, filterAlign, (1<<12),
- (flags&SWS_BICUBLIN) ? (flags|SWS_BICUBIC) : flags,
- srcFilter->lumV, dstFilter->lumV, c->param) < 0)
+ srcH , dstH, filterAlign, (1<<12),
+ (flags&SWS_BICUBLIN) ? (flags|SWS_BICUBIC) : flags,
+ srcFilter->lumV, dstFilter->lumV, c->param) < 0)
goto fail;
if (initFilter(&c->vChrFilter, &c->vChrFilterPos, &c->vChrFilterSize, c->chrYInc,
- c->chrSrcH, c->chrDstH, filterAlign, (1<<12),
- (flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags,
- srcFilter->chrV, dstFilter->chrV, c->param) < 0)
+ c->chrSrcH, c->chrDstH, filterAlign, (1<<12),
+ (flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags,
+ srcFilter->chrV, dstFilter->chrV, c->param) < 0)
goto fail;
#ifdef COMPILE_ALTIVEC
assert(c->chrDstH <= dstH);
if (flags&SWS_PRINT_INFO) {
-#ifdef DITHER1XBPP
- const char *dither= " dithered";
-#else
- const char *dither= "";
-#endif
if (flags&SWS_FAST_BILINEAR)
av_log(c, AV_LOG_INFO, "FAST_BILINEAR scaler, ");
else if (flags&SWS_BILINEAR)
else if (flags&SWS_POINT)
av_log(c, AV_LOG_INFO, "Nearest Neighbor / POINT scaler, ");
else if (flags&SWS_AREA)
- av_log(c, AV_LOG_INFO, "Area Averageing scaler, ");
+ av_log(c, AV_LOG_INFO, "Area Averaging scaler, ");
else if (flags&SWS_BICUBLIN)
av_log(c, AV_LOG_INFO, "luma BICUBIC / chroma BILINEAR scaler, ");
else if (flags&SWS_GAUSS)
else
av_log(c, AV_LOG_INFO, "ehh flags invalid?! ");
- if (dstFormat==PIX_FMT_BGR555 || dstFormat==PIX_FMT_BGR565)
- av_log(c, AV_LOG_INFO, "from %s to%s %s ",
- sws_format_name(srcFormat), dither, sws_format_name(dstFormat));
- else
- av_log(c, AV_LOG_INFO, "from %s to %s ",
- sws_format_name(srcFormat), sws_format_name(dstFormat));
+ av_log(c, AV_LOG_INFO, "from %s to %s%s ",
+ sws_format_name(srcFormat),
+#ifdef DITHER1XBPP
+ dstFormat == PIX_FMT_BGR555 || dstFormat == PIX_FMT_BGR565 ? "dithered " : "",
+#else
+ "",
+#endif
+ sws_format_name(dstFormat));
if (flags & SWS_CPU_CAPS_MMX2)
av_log(c, AV_LOG_INFO, "using MMX2\n");
return NULL;
}
-static void reset_ptr(uint8_t* src[], int format)
+static void reset_ptr(const uint8_t* src[], int format)
{
if(!isALPHA(format))
src[3]=NULL;
if(!isPlanarYUV(format)) {
src[3]=src[2]=NULL;
- if( format != PIX_FMT_PAL8
- && format != PIX_FMT_RGB8
- && format != PIX_FMT_BGR8
- && format != PIX_FMT_RGB4_BYTE
- && format != PIX_FMT_BGR4_BYTE
- )
+
+ if (!usePal(format))
src[1]= NULL;
}
}
* swscale wrapper, so we don't need to export the SwsContext.
* Assumes planar YUV to be in YUV order instead of YVU.
*/
-int sws_scale(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
- int srcSliceH, uint8_t* dst[], int dstStride[])
+int sws_scale(SwsContext *c, const uint8_t* const src[], const int srcStride[], int srcSliceY,
+ int srcSliceH, uint8_t* const dst[], const int dstStride[])
{
int i;
- uint8_t* src2[4]= {src[0], src[1], src[2], src[3]};
+ const uint8_t* src2[4]= {src[0], src[1], src[2], src[3]};
uint8_t* dst2[4]= {dst[0], dst[1], dst[2], dst[3]};
+ // do not mess up sliceDir if we have a "trailing" 0-size slice
+ if (srcSliceH == 0)
+ return 0;
+
if (c->sliceDir == 0 && srcSliceY != 0 && srcSliceY + srcSliceH != c->srcH) {
av_log(c, AV_LOG_ERROR, "Slices start in the middle!\n");
return 0;
for (i=0; i<256; i++) {
int p, r, g, b,y,u,v;
if(c->srcFormat == PIX_FMT_PAL8) {
- p=((uint32_t*)(src[1]))[i];
+ p=((const uint32_t*)(src[1]))[i];
r= (p>>16)&0xFF;
g= (p>> 8)&0xFF;
b= p &0xFF;
v= av_clip_uint8((RV*r + GV*g + BV*b + (257<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT);
c->pal_yuv[i]= y + (u<<8) + (v<<16);
-
switch(c->dstFormat) {
case PIX_FMT_BGR32:
#if !HAVE_BIGENDIAN
int dstStride2[4]= {dstStride[0], dstStride[1], dstStride[2], dstStride[3]};
reset_ptr(src2, c->srcFormat);
- reset_ptr(dst2, c->dstFormat);
+ reset_ptr((const uint8_t**)dst2, c->dstFormat);
/* reset slice direction at end of frame */
if (srcSliceY + srcSliceH == c->srcH)
dst2[3] += ( c->dstH -1)*dstStride[3];
reset_ptr(src2, c->srcFormat);
- reset_ptr(dst2, c->dstFormat);
+ reset_ptr((const uint8_t**)dst2, c->dstFormat);
/* reset slice direction at end of frame */
if (!srcSliceY)
}
#if LIBSWSCALE_VERSION_MAJOR < 1
-int sws_scale_ordered(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
+int sws_scale_ordered(SwsContext *c, const uint8_t* const src[], int srcStride[], int srcSliceY,
int srcSliceH, uint8_t* dst[], int dstStride[])
{
return sws_scale(c, src, srcStride, srcSliceY, srcSliceH, dst, dstStride);
return vec;
}
-
SwsVector *sws_getIdentityVec(void)
{
return sws_getConstVec(1.0, 1);
av_free(filter);
}
-
void sws_freeContext(SwsContext *c)
{
int i;
c->chrMmx2FilterCode=NULL;
#endif /* ARCH_X86 && CONFIG_GPL */
- av_freep(&c->lumMmx2Filter);
- av_freep(&c->chrMmx2Filter);
- av_freep(&c->lumMmx2FilterPos);
- av_freep(&c->chrMmx2FilterPos);
av_freep(&c->yuvTable);
av_free(c);