Commit e9e12f0e authored by Luca Abeni's avatar Luca Abeni

Remove the dependency of libswscale on img_format.h

Originally committed as revision 19878 to svn://svn.mplayerhq.hu/mplayer/trunk/libswscale
parent 5784b620
......@@ -22,24 +22,25 @@
#include <inttypes.h>
#include <stdarg.h>
#undef HAVE_AV_CONFIG_H
#include "avutil.h"
#include "swscale.h"
#include "libmpcodecs/img_format.h"
static int testFormat[]={
IMGFMT_YVU9,
IMGFMT_YV12,
PIX_FMT_YUV410P,
PIX_FMT_YUV420P,
//IMGFMT_IYUV,
IMGFMT_I420,
IMGFMT_BGR15,
IMGFMT_BGR16,
IMGFMT_BGR24,
IMGFMT_BGR32,
IMGFMT_RGB24,
IMGFMT_RGB32,
//IMGFMT_I420,
PIX_FMT_BGR555,
PIX_FMT_BGR565,
PIX_FMT_BGR24,
PIX_FMT_RGB32,
PIX_FMT_RGB24,
PIX_FMT_BGR32,
//IMGFMT_Y8,
IMGFMT_Y800,
PIX_FMT_GRAY8,
//IMGFMT_YUY2,
0
PIX_FMT_NONE
};
static uint64_t getSSD(uint8_t *src1, uint8_t *src2, int stride1, int stride2, int w, int h){
......@@ -73,12 +74,12 @@ static void doTest(uint8_t *ref[3], int refStride[3], int w, int h, int srcForma
for(i=0; i<3; i++){
// avoid stride % bpp != 0
if(srcFormat==IMGFMT_RGB24 || srcFormat==IMGFMT_BGR24)
if(srcFormat==PIX_FMT_RGB24 || srcFormat==PIX_FMT_BGR24)
srcStride[i]= srcW*3;
else
srcStride[i]= srcW*4;
if(dstFormat==IMGFMT_RGB24 || dstFormat==IMGFMT_BGR24)
if(dstFormat==PIX_FMT_RGB24 || dstFormat==PIX_FMT_BGR24)
dstStride[i]= dstW*3;
else
dstStride[i]= dstW*4;
......@@ -86,11 +87,16 @@ static void doTest(uint8_t *ref[3], int refStride[3], int w, int h, int srcForma
src[i]= (uint8_t*) malloc(srcStride[i]*srcH);
dst[i]= (uint8_t*) malloc(dstStride[i]*dstH);
out[i]= (uint8_t*) malloc(refStride[i]*h);
if ((src[i] == NULL) || (dst[i] == NULL) || (out[i] == NULL)) {
perror("Malloc");
goto end;
}
}
srcContext= sws_getContext(w, h, IMGFMT_YV12, srcW, srcH, srcFormat, flags, NULL, NULL, NULL);
srcContext= sws_getContext(w, h, PIX_FMT_YUV420P, srcW, srcH, srcFormat, flags, NULL, NULL, NULL);
dstContext= sws_getContext(srcW, srcH, srcFormat, dstW, dstH, dstFormat, flags, NULL, NULL, NULL);
outContext= sws_getContext(dstW, dstH, dstFormat, w, h, IMGFMT_YV12, flags, NULL, NULL, NULL);
outContext= sws_getContext(dstW, dstH, dstFormat, w, h, PIX_FMT_YUV420P, flags, NULL, NULL, NULL);
if(srcContext==NULL ||dstContext==NULL ||outContext==NULL){
printf("Failed allocating swsContext\n");
goto end;
......@@ -110,7 +116,7 @@ static void doTest(uint8_t *ref[3], int refStride[3], int w, int h, int srcForma
ssdU= getSSD(ref[1], out[1], refStride[1], refStride[1], (w+1)>>1, (h+1)>>1);
ssdV= getSSD(ref[2], out[2], refStride[2], refStride[2], (w+1)>>1, (h+1)>>1);
if(srcFormat == IMGFMT_Y800 || dstFormat==IMGFMT_Y800) ssdU=ssdV=0; //FIXME check that output is really gray
if(srcFormat == PIX_FMT_GRAY8 || dstFormat==PIX_FMT_GRAY8) ssdU=ssdV=0; //FIXME check that output is really gray
ssdY/= w*h;
ssdU/= w*h/4;
......@@ -155,10 +161,10 @@ static void selfTest(uint8_t *src[3], int stride[3], int w, int h){
for(srcFormatIndex=0; ;srcFormatIndex++){
srcFormat= testFormat[srcFormatIndex];
if(!srcFormat) break;
if(srcFormat == PIX_FMT_NONE) break;
for(dstFormatIndex=0; ;dstFormatIndex++){
dstFormat= testFormat[dstFormatIndex];
if(!dstFormat) break;
if(dstFormat == PIX_FMT_NONE) break;
// if(!isSupportedOut(dstFormat)) continue;
printf("%s -> %s\n",
sws_format_name(srcFormat),
......@@ -190,7 +196,7 @@ int main(int argc, char **argv){
int x, y;
struct SwsContext *sws;
sws= sws_getContext(W/12, H/12, IMGFMT_BGR32, W, H, IMGFMT_YV12, 2, NULL, NULL, NULL);
sws= sws_getContext(W/12, H/12, PIX_FMT_RGB32, W, H, PIX_FMT_YUV420P, 2, NULL, NULL, NULL);
for(y=0; y<H; y++){
for(x=0; x<W*4; x++){
......
This diff is collapsed.
......@@ -173,4 +173,52 @@ int yuv2rgb_c_init_tables (SwsContext *c, const int inv_table[4], int fullRange,
char *sws_format_name(int format);
//FIXME replace this with something faster
#define isPlanarYUV(x) ((x)==PIX_FMT_YUV410P || (x)==PIX_FMT_YUV420P \
|| (x)==PIX_FMT_YUV411P || (x)==PIX_FMT_YUV422P \
|| (x)==PIX_FMT_YUV444P || (x)==PIX_FMT_NV12 \
|| (x)==PIX_FMT_NV21)
#define isYUV(x) ((x)==PIX_FMT_UYVY422 || (x)==PIX_FMT_YUYV422 || isPlanarYUV(x))
#define isGray(x) ((x)==PIX_FMT_GRAY8)
#define isRGB(x) ((x)==PIX_FMT_BGR32 || (x)==PIX_FMT_RGB24 \
|| (x)==PIX_FMT_RGB565 || (x)==PIX_FMT_RGB555 \
|| (x)==PIX_FMT_RGB8 || (x)==PIX_FMT_RGB4 \
|| (x)==PIX_FMT_MONOBLACK)
#define isBGR(x) ((x)==PIX_FMT_RGB32 || (x)==PIX_FMT_BGR24 \
|| (x)==PIX_FMT_BGR565 || (x)==PIX_FMT_BGR555 \
|| (x)==PIX_FMT_BGR8 || (x)==PIX_FMT_BGR4 \
|| (x)==PIX_FMT_MONOBLACK)
static inline int fmt_depth(int fmt)
{
switch(fmt) {
case PIX_FMT_BGRA:
case PIX_FMT_ABGR:
case PIX_FMT_RGBA:
case PIX_FMT_ARGB:
return 32;
case PIX_FMT_BGR24:
case PIX_FMT_RGB24:
return 24;
case PIX_FMT_BGR565:
case PIX_FMT_RGB565:
return 16;
case PIX_FMT_BGR555:
case PIX_FMT_RGB555:
return 15;
case PIX_FMT_BGR8:
case PIX_FMT_RGB8:
return 8;
case PIX_FMT_BGR4:
case PIX_FMT_RGB4:
case PIX_FMT_BGR4_BYTE:
case PIX_FMT_RGB4_BYTE:
return 4;
case PIX_FMT_MONOBLACK:
return 1;
default:
return 0;
}
}
#endif
This diff is collapsed.
......@@ -39,7 +39,6 @@
#include "rgb2rgb.h"
#include "swscale.h"
#include "swscale_internal.h"
#include "libmpcodecs/img_format.h" //FIXME try to reduce dependency of such stuff
#ifdef HAVE_MLIB
#include "yuv2rgb_mlib.c"
......@@ -259,7 +258,7 @@ static int func_name(SwsContext *c, uint8_t* src[], int srcStride[], int srcSlic
int srcSliceH, uint8_t* dst[], int dstStride[]){\
int y;\
\
if(c->srcFormat == IMGFMT_422P){\
if(c->srcFormat == PIX_FMT_YUV422P){\
srcStride[1] *= 2;\
srcStride[2] *= 2;\
}\
......@@ -581,18 +580,18 @@ SwsFunc yuv2rgb_get_func_ptr (SwsContext *c)
#if defined(HAVE_MMX2) || defined(HAVE_MMX)
if(c->flags & SWS_CPU_CAPS_MMX2){
switch(c->dstFormat){
case IMGFMT_BGR32: return yuv420_rgb32_MMX2;
case IMGFMT_BGR24: return yuv420_rgb24_MMX2;
case IMGFMT_BGR16: return yuv420_rgb16_MMX2;
case IMGFMT_BGR15: return yuv420_rgb15_MMX2;
case PIX_FMT_RGB32: return yuv420_rgb32_MMX2;
case PIX_FMT_BGR24: return yuv420_rgb24_MMX2;
case PIX_FMT_BGR565: return yuv420_rgb16_MMX2;
case PIX_FMT_BGR555: return yuv420_rgb15_MMX2;
}
}
if(c->flags & SWS_CPU_CAPS_MMX){
switch(c->dstFormat){
case IMGFMT_BGR32: return yuv420_rgb32_MMX;
case IMGFMT_BGR24: return yuv420_rgb24_MMX;
case IMGFMT_BGR16: return yuv420_rgb16_MMX;
case IMGFMT_BGR15: return yuv420_rgb15_MMX;
case PIX_FMT_RGB32: return yuv420_rgb32_MMX;
case PIX_FMT_BGR24: return yuv420_rgb24_MMX;
case PIX_FMT_BGR565: return yuv420_rgb16_MMX;
case PIX_FMT_BGR555: return yuv420_rgb15_MMX;
}
}
#endif
......@@ -613,22 +612,21 @@ SwsFunc yuv2rgb_get_func_ptr (SwsContext *c)
MSG_WARN("No accelerated colorspace conversion found\n");
switch(c->dstFormat){
case IMGFMT_RGB32:
case IMGFMT_BGR32: return yuv2rgb_c_32;
case IMGFMT_RGB24: return yuv2rgb_c_24_rgb;
case IMGFMT_BGR24: return yuv2rgb_c_24_bgr;
case IMGFMT_RGB16:
case IMGFMT_BGR16:
case IMGFMT_RGB15:
case IMGFMT_BGR15: return yuv2rgb_c_16;
case IMGFMT_RGB8:
case IMGFMT_BGR8: return yuv2rgb_c_8_ordered_dither;
case IMGFMT_RGB4:
case IMGFMT_BGR4: return yuv2rgb_c_4_ordered_dither;
case IMGFMT_RG4B:
case IMGFMT_BG4B: return yuv2rgb_c_4b_ordered_dither;
case IMGFMT_RGB1:
case IMGFMT_BGR1: return yuv2rgb_c_1_ordered_dither;
case PIX_FMT_BGR32:
case PIX_FMT_RGB32: return yuv2rgb_c_32;
case PIX_FMT_RGB24: return yuv2rgb_c_24_rgb;
case PIX_FMT_BGR24: return yuv2rgb_c_24_bgr;
case PIX_FMT_RGB565:
case PIX_FMT_BGR565:
case PIX_FMT_RGB555:
case PIX_FMT_BGR555: return yuv2rgb_c_16;
case PIX_FMT_RGB8:
case PIX_FMT_BGR8: return yuv2rgb_c_8_ordered_dither;
case PIX_FMT_RGB4:
case PIX_FMT_BGR4: return yuv2rgb_c_4_ordered_dither;
case PIX_FMT_RGB4_BYTE:
case PIX_FMT_BGR4_BYTE: return yuv2rgb_c_4b_ordered_dither;
case PIX_FMT_MONOBLACK: return yuv2rgb_c_1_ordered_dither;
default:
assert(0);
}
......@@ -645,8 +643,8 @@ 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)
{
const int isRgb = IMGFMT_IS_BGR(c->dstFormat);
const int bpp = isRgb?IMGFMT_RGB_DEPTH(c->dstFormat):IMGFMT_BGR_DEPTH(c->dstFormat);
const int isRgb = isBGR(c->dstFormat);
const int bpp = fmt_depth(c->dstFormat);
int i;
uint8_t table_Y[1024];
uint32_t *table_32 = 0;
......
......@@ -88,7 +88,6 @@
#include "rgb2rgb.h"
#include "swscale.h"
#include "swscale_internal.h"
#include "libmpcodecs/img_format.h" //FIXME try to reduce dependency of such stuff
#undef PROFILE_THE_BEAST
#undef INC_SCALING
......@@ -697,45 +696,41 @@ SwsFunc yuv2rgb_init_altivec (SwsContext *c)
if ((c->srcW & 0xf) != 0) return NULL;
switch (c->srcFormat) {
case IMGFMT_YVU9:
case IMGFMT_IF09:
case IMGFMT_YV12:
case IMGFMT_I420:
case IMGFMT_IYUV:
case IMGFMT_CLPL:
case IMGFMT_Y800:
case IMGFMT_Y8:
case IMGFMT_NV12:
case IMGFMT_NV21:
case PIX_FMT_YUV410P:
case PIX_FMT_YUV420P:
/*case IMGFMT_CLPL: ??? */
case PIX_FMT_GRAY8:
case PIX_FMT_NV12:
case PIX_FMT_NV21:
if ((c->srcH & 0x1) != 0)
return NULL;
switch(c->dstFormat){
case IMGFMT_RGB24:
case PIX_FMT_RGB24:
MSG_WARN("ALTIVEC: Color Space RGB24\n");
return altivec_yuv2_rgb24;
case IMGFMT_BGR24:
case PIX_FMT_BGR24:
MSG_WARN("ALTIVEC: Color Space BGR24\n");
return altivec_yuv2_bgr24;
case IMGFMT_ARGB:
case PIX_FMT_ARGB:
MSG_WARN("ALTIVEC: Color Space ARGB\n");
return altivec_yuv2_argb;
case IMGFMT_ABGR:
case PIX_FMT_ABGR:
MSG_WARN("ALTIVEC: Color Space ABGR\n");
return altivec_yuv2_abgr;
case IMGFMT_RGBA:
case PIX_FMT_RGBA:
MSG_WARN("ALTIVEC: Color Space RGBA\n");
return altivec_yuv2_rgba;
case IMGFMT_BGRA:
case PIX_FMT_BGRA:
MSG_WARN("ALTIVEC: Color Space BGRA\n");
return altivec_yuv2_bgra;
default: return NULL;
}
break;
case IMGFMT_UYVY:
case PIX_FMT_UYVY422:
switch(c->dstFormat){
case IMGFMT_RGB32:
case PIX_FMT_BGR32:
MSG_WARN("ALTIVEC: Color Space UYVY -> RGB32\n");
return altivec_uyvy_rgb32;
default: return NULL;
......@@ -868,12 +863,12 @@ altivec_yuv2packedX (SwsContext *c,
B = vec_packclp (B0,B1);
switch(c->dstFormat) {
case IMGFMT_ABGR: out_abgr (R,G,B,out); break;
case IMGFMT_BGRA: out_bgra (R,G,B,out); break;
case IMGFMT_RGBA: out_rgba (R,G,B,out); break;
case IMGFMT_ARGB: out_argb (R,G,B,out); break;
case IMGFMT_RGB24: out_rgb24 (R,G,B,out); break;
case IMGFMT_BGR24: out_bgr24 (R,G,B,out); break;
case PIX_FMT_ABGR: out_abgr (R,G,B,out); break;
case PIX_FMT_BGRA: out_bgra (R,G,B,out); break;
case PIX_FMT_RGBA: out_rgba (R,G,B,out); break;
case PIX_FMT_ARGB: out_argb (R,G,B,out); break;
case PIX_FMT_RGB24: out_rgb24 (R,G,B,out); break;
case PIX_FMT_BGR24: out_bgr24 (R,G,B,out); break;
default:
{
/* If this is reached, the caller should have called yuv2packedXinC
......@@ -947,12 +942,12 @@ altivec_yuv2packedX (SwsContext *c,
nout = (vector unsigned char *)scratch;
switch(c->dstFormat) {
case IMGFMT_ABGR: out_abgr (R,G,B,nout); break;
case IMGFMT_BGRA: out_bgra (R,G,B,nout); break;
case IMGFMT_RGBA: out_rgba (R,G,B,nout); break;
case IMGFMT_ARGB: out_argb (R,G,B,nout); break;
case IMGFMT_RGB24: out_rgb24 (R,G,B,nout); break;
case IMGFMT_BGR24: out_bgr24 (R,G,B,nout); break;
case PIX_FMT_ABGR: out_abgr (R,G,B,nout); break;
case PIX_FMT_BGRA: out_bgra (R,G,B,nout); break;
case PIX_FMT_RGBA: out_rgba (R,G,B,nout); break;
case PIX_FMT_ARGB: out_argb (R,G,B,nout); break;
case PIX_FMT_RGB24: out_rgb24 (R,G,B,nout); break;
case PIX_FMT_BGR24: out_bgr24 (R,G,B,nout); break;
default:
/* Unreachable, I think. */
MSG_ERR("altivec_yuv2packedX doesn't support %s output\n",
......
......@@ -30,12 +30,11 @@
#include <stdlib.h>
#include <assert.h>
#include "libmpcodecs/img_format.h" //FIXME try to reduce dependency of such stuff
#include "swscale.h"
static int mlib_YUV2ARGB420_32(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
int srcSliceH, uint8_t* dst[], int dstStride[]){
if(c->srcFormat == IMGFMT_422P){
if(c->srcFormat == PIX_FMT_YUV422P){
srcStride[1] *= 2;
srcStride[2] *= 2;
}
......@@ -49,7 +48,7 @@ static int mlib_YUV2ARGB420_32(SwsContext *c, uint8_t* src[], int srcStride[], i
static int mlib_YUV2ABGR420_32(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
int srcSliceH, uint8_t* dst[], int dstStride[]){
if(c->srcFormat == IMGFMT_422P){
if(c->srcFormat == PIX_FMT_YUV422P){
srcStride[1] *= 2;
srcStride[2] *= 2;
}
......@@ -63,7 +62,7 @@ static int mlib_YUV2ABGR420_32(SwsContext *c, uint8_t* src[], int srcStride[], i
static int mlib_YUV2RGB420_24(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
int srcSliceH, uint8_t* dst[], int dstStride[]){
if(c->srcFormat == IMGFMT_422P){
if(c->srcFormat == PIX_FMT_YUV422P){
srcStride[1] *= 2;
srcStride[2] *= 2;
}
......@@ -79,9 +78,9 @@ static int mlib_YUV2RGB420_24(SwsContext *c, uint8_t* src[], int srcStride[], in
SwsFunc yuv2rgb_init_mlib(SwsContext *c)
{
switch(c->dstFormat){
case IMGFMT_RGB24: return mlib_YUV2RGB420_24;
case IMGFMT_RGB32: return mlib_YUV2ARGB420_32;
case IMGFMT_BGR32: return mlib_YUV2ABGR420_32;
case PIX_FMT_RGB24: return mlib_YUV2RGB420_24;
case PIX_FMT_BGR32: return mlib_YUV2ARGB420_32;
case PIX_FMT_RGB32: return mlib_YUV2ABGR420_32;
default: return NULL;
}
}
......
......@@ -127,7 +127,7 @@ static inline int RENAME(yuv420_rgb16)(SwsContext *c, uint8_t* src[], int srcStr
int srcSliceH, uint8_t* dst[], int dstStride[]){
int y, h_size;
if(c->srcFormat == IMGFMT_422P){
if(c->srcFormat == PIX_FMT_YUV422P){
srcStride[1] *= 2;
srcStride[2] *= 2;
}
......@@ -222,7 +222,7 @@ static inline int RENAME(yuv420_rgb15)(SwsContext *c, uint8_t* src[], int srcStr
int srcSliceH, uint8_t* dst[], int dstStride[]){
int y, h_size;
if(c->srcFormat == IMGFMT_422P){
if(c->srcFormat == PIX_FMT_YUV422P){
srcStride[1] *= 2;
srcStride[2] *= 2;
}
......@@ -311,7 +311,7 @@ static inline int RENAME(yuv420_rgb24)(SwsContext *c, uint8_t* src[], int srcStr
int srcSliceH, uint8_t* dst[], int dstStride[]){
int y, h_size;
if(c->srcFormat == IMGFMT_422P){
if(c->srcFormat == PIX_FMT_YUV422P){
srcStride[1] *= 2;
srcStride[2] *= 2;
}
......@@ -457,7 +457,7 @@ static inline int RENAME(yuv420_rgb32)(SwsContext *c, uint8_t* src[], int srcStr
int srcSliceH, uint8_t* dst[], int dstStride[]){
int y, h_size;
if(c->srcFormat == IMGFMT_422P){
if(c->srcFormat == PIX_FMT_YUV422P){
srcStride[1] *= 2;
srcStride[2] *= 2;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment