1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

rgb32 & rgb24 input support

squished a endianness bug in the 15/16bgr output

Originally committed as revision 4559 to svn://svn.mplayerhq.hu/mplayer/trunk/postproc
This commit is contained in:
Michael Niedermayer 2002-02-06 22:55:57 +00:00
parent b6654a5464
commit a861d4d7f3
2 changed files with 98 additions and 17 deletions

View File

@ -17,9 +17,14 @@
*/ */
/* /*
supported Input formats: YV12, I420, IYUV, YUY2, BGR32, BGR24, Y8, Y800 supported Input formats: YV12, I420, IYUV, YUY2, BGR32, BGR24, RGB32, RGB24, Y8, Y800
supported output formats: YV12, I420, IYUV, BGR15, BGR16, BGR24, BGR32 (grayscale soon too) supported output formats: YV12, I420, IYUV, BGR15, BGR16, BGR24, BGR32 (grayscale soon too)
BGR15/16 support dithering BGR15/16 support dithering
unscaled special converters
YV12/I420/IYUV -> BGR15/BGR16/BGR24/BGR32
YV12/I420/IYUV -> YV12/I420/IYUV
YUY2/BGR15/BGR16/BGR24/BGR32/RGB24/RGB32 -> same format
*/ */
#include <inttypes.h> #include <inttypes.h>
@ -33,6 +38,7 @@
#endif #endif
#include "swscale.h" #include "swscale.h"
#include "../cpudetect.h" #include "../cpudetect.h"
#include "../bswap.h"
#include "../libvo/img_format.h" #include "../libvo/img_format.h"
#include "rgb2rgb.h" #include "rgb2rgb.h"
#undef MOVNTQ #undef MOVNTQ
@ -63,10 +69,11 @@
#define isYUV(x) ((x)==IMGFMT_YUY2 || isPlanarYUV(x)) #define isYUV(x) ((x)==IMGFMT_YUY2 || isPlanarYUV(x))
#define isHalfChrV(x) ((x)==IMGFMT_YV12 || (x)==IMGFMT_I420) #define isHalfChrV(x) ((x)==IMGFMT_YV12 || (x)==IMGFMT_I420)
#define isHalfChrH(x) ((x)==IMGFMT_YUY2 || (x)==IMGFMT_YV12 || (x)==IMGFMT_I420) #define isHalfChrH(x) ((x)==IMGFMT_YUY2 || (x)==IMGFMT_YV12 || (x)==IMGFMT_I420)
#define isPacked(x) ((x)==IMGFMT_YUY2 || (x)==IMGFMT_BGR32|| (x)==IMGFMT_BGR24) #define isPacked(x) ((x)==IMGFMT_YUY2 || ((x)&IMGFMT_BGR_MASK)==IMGFMT_BGR || ((x)&IMGFMT_RGB_MASK)==IMGFMT_RGB)
#define isGray(x) ((x)==IMGFMT_Y800) #define isGray(x) ((x)==IMGFMT_Y800)
#define isSupportedIn(x) ((x)==IMGFMT_YV12 || (x)==IMGFMT_I420 || (x)==IMGFMT_YUY2 \ #define isSupportedIn(x) ((x)==IMGFMT_YV12 || (x)==IMGFMT_I420 || (x)==IMGFMT_YUY2 \
|| (x)==IMGFMT_BGR32|| (x)==IMGFMT_BGR24\ || (x)==IMGFMT_BGR32|| (x)==IMGFMT_BGR24\
|| (x)==IMGFMT_RGB32|| (x)==IMGFMT_RGB24\
|| (x)==IMGFMT_Y800) || (x)==IMGFMT_Y800)
#define isSupportedOut(x) ((x)==IMGFMT_YV12 || (x)==IMGFMT_I420 \ #define isSupportedOut(x) ((x)==IMGFMT_YV12 || (x)==IMGFMT_I420 \
|| (x)==IMGFMT_BGR32|| (x)==IMGFMT_BGR24|| (x)==IMGFMT_BGR16|| (x)==IMGFMT_BGR15) || (x)==IMGFMT_BGR32|| (x)==IMGFMT_BGR24|| (x)==IMGFMT_BGR16|| (x)==IMGFMT_BGR15)
@ -1066,12 +1073,12 @@ static void globalInit(){
for(i=0; i<768; i++) for(i=0; i<768; i++)
{ {
int v= clip_table[i]; int v= clip_table[i];
clip_table16b[i]= v>>3; clip_table16b[i]= le2me_16( v>>3);
clip_table16g[i]= (v<<3)&0x07E0; clip_table16g[i]= le2me_16((v<<3)&0x07E0);
clip_table16r[i]= (v<<8)&0xF800; clip_table16r[i]= le2me_16((v<<8)&0xF800);
clip_table15b[i]= v>>3; clip_table15b[i]= le2me_16( v>>3);
clip_table15g[i]= (v<<2)&0x03E0; clip_table15g[i]= le2me_16((v<<2)&0x03E0);
clip_table15r[i]= (v<<7)&0x7C00; clip_table15r[i]= le2me_16((v<<7)&0x7C00);
} }
cpuCaps= gCpuCaps; cpuCaps= gCpuCaps;
@ -1173,14 +1180,12 @@ static void simpleCopy(SwsContext *c, uint8_t* srcParam[], int srcStrideParam[],
int i; int i;
uint8_t *srcPtr= src[0]; uint8_t *srcPtr= src[0];
uint8_t *dstPtr= dst[0] + dstStride[0]*srcSliceY; uint8_t *dstPtr= dst[0] + dstStride[0]*srcSliceY;
int length; int length=0;
if(c->srcFormat==IMGFMT_YUY2) length= c->srcW*2; /* universal length finder */
else if(c->srcFormat==IMGFMT_BGR15) length= c->srcW*2; while(length+c->srcW <= dstStride[0]
else if(c->srcFormat==IMGFMT_BGR16) length= c->srcW*2; && length+c->srcW <= srcStride[0]) length+= c->srcW;
else if(c->srcFormat==IMGFMT_BGR24) length= c->srcW*3; ASSERT(length!=0);
else if(c->srcFormat==IMGFMT_BGR32) length= c->srcW*4;
else return; /* that shouldnt happen */
for(i=0; i<srcSliceH; i++) for(i=0; i<srcSliceH; i++)
{ {
@ -1198,7 +1203,7 @@ static void simpleCopy(SwsContext *c, uint8_t* srcParam[], int srcStrideParam[],
int length= plane==0 ? c->srcW : ((c->srcW+1)>>1); int length= plane==0 ? c->srcW : ((c->srcW+1)>>1);
int y= plane==0 ? srcSliceY: ((srcSliceY+1)>>1); int y= plane==0 ? srcSliceY: ((srcSliceY+1)>>1);
int height= plane==0 ? srcSliceH: ((srcSliceH+1)>>1); int height= plane==0 ? srcSliceH: ((srcSliceH+1)>>1);
printf("%d %d %d %d %d %d\n", plane, length, y, height, dstStride[plane], srcStride[plane] );
if(dstStride[plane]==srcStride[plane]) if(dstStride[plane]==srcStride[plane])
memcpy(dst[plane] + dstStride[plane]*y, src[plane], height*dstStride[plane]); memcpy(dst[plane] + dstStride[plane]*y, src[plane], height*dstStride[plane]);
else else

View File

@ -1666,6 +1666,60 @@ static inline void RENAME(bgr24ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1
#endif #endif
} }
static inline void RENAME(rgb32ToY)(uint8_t *dst, uint8_t *src, int width)
{
int i;
for(i=0; i<width; i++)
{
int r= src[i*4+0];
int g= src[i*4+1];
int b= src[i*4+2];
dst[i]= ((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16;
}
}
static inline void RENAME(rgb32ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, int width)
{
int i;
for(i=0; i<width; i++)
{
int r= src1[8*i + 0] + src1[8*i + 4] + src2[8*i + 0] + src2[8*i + 4];
int g= src1[8*i + 1] + src1[8*i + 5] + src2[8*i + 1] + src2[8*i + 5];
int b= src1[8*i + 2] + src1[8*i + 6] + src2[8*i + 2] + src2[8*i + 6];
dstU[i]= ((RU*r + GU*g + BU*b)>>(RGB2YUV_SHIFT+2)) + 128;
dstV[i]= ((RV*r + GV*g + BV*b)>>(RGB2YUV_SHIFT+2)) + 128;
}
}
static inline void RENAME(rgb24ToY)(uint8_t *dst, uint8_t *src, int width)
{
int i;
for(i=0; i<width; i++)
{
int r= src[i*3+0];
int g= src[i*3+1];
int b= src[i*3+2];
dst[i]= ((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16;
}
}
static inline void RENAME(rgb24ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, int width)
{
int i;
for(i=0; i<width; i++)
{
int r= src1[6*i + 0] + src1[6*i + 3] + src2[6*i + 0] + src2[6*i + 3];
int g= src1[6*i + 1] + src1[6*i + 4] + src2[6*i + 1] + src2[6*i + 4];
int b= src1[6*i + 2] + src1[6*i + 5] + src2[6*i + 2] + src2[6*i + 5];
dstU[i]= ((RU*r + GU*g + BU*b)>>(RGB2YUV_SHIFT+2)) + 128;
dstV[i]= ((RV*r + GV*g + BV*b)>>(RGB2YUV_SHIFT+2)) + 128;
}
}
// Bilinear / Bicubic scaling // Bilinear / Bicubic scaling
static inline void RENAME(hScale)(int16_t *dst, int dstW, uint8_t *src, int srcW, int xInc, static inline void RENAME(hScale)(int16_t *dst, int dstW, uint8_t *src, int srcW, int xInc,
@ -1849,6 +1903,16 @@ static inline void RENAME(hyscale)(uint16_t *dst, int dstWidth, uint8_t *src, in
RENAME(bgr24ToY)(formatConvBuffer, src, srcW); RENAME(bgr24ToY)(formatConvBuffer, src, srcW);
src= formatConvBuffer; src= formatConvBuffer;
} }
else if(srcFormat==IMGFMT_RGB32)
{
RENAME(rgb32ToY)(formatConvBuffer, src, srcW);
src= formatConvBuffer;
}
else if(srcFormat==IMGFMT_RGB24)
{
RENAME(rgb24ToY)(formatConvBuffer, src, srcW);
src= formatConvBuffer;
}
#ifdef HAVE_MMX #ifdef HAVE_MMX
// use the new MMX scaler if th mmx2 cant be used (its faster than the x86asm one) // use the new MMX scaler if th mmx2 cant be used (its faster than the x86asm one)
@ -1996,6 +2060,18 @@ inline static void RENAME(hcscale)(uint16_t *dst, int dstWidth, uint8_t *src1, u
src1= formatConvBuffer; src1= formatConvBuffer;
src2= formatConvBuffer+2048; src2= formatConvBuffer+2048;
} }
else if(srcFormat==IMGFMT_RGB32)
{
RENAME(rgb32ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
src1= formatConvBuffer;
src2= formatConvBuffer+2048;
}
else if(srcFormat==IMGFMT_RGB24)
{
RENAME(rgb24ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
src1= formatConvBuffer;
src2= formatConvBuffer+2048;
}
else if(isGray(srcFormat)) else if(isGray(srcFormat))
{ {
return; return;