[FFmpeg-devel] [PATCH] libswcale: PIX_FMT_BGR48LE and PIX_FMT_BGR48BE scaler implementation
Peter Ross
pross at xvid.org
Fri Mar 18 12:57:35 CET 2011
---
On Thu, Mar 17, 2011 at 08:38:22PM +0100, Reimar Döffinger wrote:
> On 17 Mar 2011, at 15:16, Michael Niedermayer <michaelni at gmx.at> wrote:
> > On Thu, Mar 17, 2011 at 09:20:30PM +1100, Peter Ross wrote:
> >> ---
> >> libswscale/swscale.c | 49 +++++++++++++++++++++++++++++++++++++++++
> >> libswscale/swscale.h | 2 +-
> >> libswscale/swscale_internal.h | 10 ++++++-
> >> libswscale/swscale_template.c | 7 ++++++
> >> libswscale/utils.c | 2 +
> >> libswscale/yuv2rgb.c | 12 ++++++++++
> >> 6 files changed, 79 insertions(+), 3 deletions(-)
> >
> > LGTM if tested
Yep, BGR48LE has been tested with the Phantom Cine demuxer (work in progress)
BGR48BE has been tested using synthesised input.
> Shouldn't it rather use one of the av_asserts instead of just assert?
The asserts are removed in patch below. They are not needed, src2 is never used.
libswscale/swscale.c | 47 +++++++++++++++++++++++++++++++++++++++++
libswscale/swscale.h | 2 +-
libswscale/swscale_internal.h | 10 +++++++-
libswscale/swscale_template.c | 7 ++++++
libswscale/utils.c | 2 +
libswscale/yuv2rgb.c | 12 ++++++++++
6 files changed, 77 insertions(+), 3 deletions(-)
diff --git a/libswscale/swscale.c b/libswscale/swscale.c
index 375171f..4698a5f 100644
--- a/libswscale/swscale.c
+++ b/libswscale/swscale.c
@@ -682,6 +682,8 @@ static inline void yuv2nv12XinC(const int16_t *lumFilter, const int16_t **lumSrc
switch(c->dstFormat) {\
case PIX_FMT_RGB48BE:\
case PIX_FMT_RGB48LE:\
+ case PIX_FMT_BGR48BE:\
+ case PIX_FMT_BGR48LE:\
func(uint8_t,0)\
((uint8_t*)dest)[ 0]= r[Y1];\
((uint8_t*)dest)[ 1]= r[Y1];\
@@ -1035,6 +1037,49 @@ static inline void rgb48ToUV_half(uint8_t *dstU, uint8_t *dstV,
}
}
+static inline void bgr48ToY(uint8_t *dst, const uint8_t *src, long width,
+ uint32_t *unused)
+{
+ int i;
+ for (i = 0; i < width; i++) {
+ int b = src[i*6+0];
+ int g = src[i*6+2];
+ int r = src[i*6+4];
+
+ dst[i] = (RY*r + GY*g + BY*b + (33<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
+ }
+}
+
+static inline void bgr48ToUV(uint8_t *dstU, uint8_t *dstV,
+ const uint8_t *src1, const uint8_t *src2,
+ long width, uint32_t *unused)
+{
+ int i;
+ for (i = 0; i < width; i++) {
+ int b = src1[6*i + 0];
+ int g = src1[6*i + 2];
+ int r = src1[6*i + 4];
+
+ dstU[i] = (RU*r + GU*g + BU*b + (257<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
+ dstV[i] = (RV*r + GV*g + BV*b + (257<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
+ }
+}
+
+static inline void bgr48ToUV_half(uint8_t *dstU, uint8_t *dstV,
+ const uint8_t *src1, const uint8_t *src2,
+ long width, uint32_t *unused)
+{
+ int i;
+ for (i = 0; i < width; i++) {
+ int b= src1[12*i + 0] + src1[12*i + 6];
+ int g= src1[12*i + 2] + src1[12*i + 8];
+ int r= src1[12*i + 4] + src1[12*i + 10];
+
+ dstU[i]= (RU*r + GU*g + BU*b + (257<<RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT+1);
+ dstV[i]= (RV*r + GV*g + BV*b + (257<<RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT+1);
+ }
+}
+
#define BGR2Y(type, name, shr, shg, shb, maskr, maskg, maskb, RY, GY, BY, S)\
static inline void name(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused)\
{\
@@ -1788,6 +1833,8 @@ void ff_get_unscaled_swscale(SwsContext *c)
&& srcFormat != PIX_FMT_MONOWHITE && dstFormat != PIX_FMT_MONOWHITE
&& srcFormat != PIX_FMT_RGB48LE && dstFormat != PIX_FMT_RGB48LE
&& srcFormat != PIX_FMT_RGB48BE && dstFormat != PIX_FMT_RGB48BE
+ && srcFormat != PIX_FMT_BGR48LE && dstFormat != PIX_FMT_BGR48LE
+ && srcFormat != PIX_FMT_BGR48BE && dstFormat != PIX_FMT_BGR48BE
&& (!needsDither || (c->flags&(SWS_FAST_BILINEAR|SWS_POINT))))
c->swScale= rgbToRgbWrapper;
diff --git a/libswscale/swscale.h b/libswscale/swscale.h
index 3cc3202..563d85c 100644
--- a/libswscale/swscale.h
+++ b/libswscale/swscale.h
@@ -30,7 +30,7 @@
#include "libavutil/avutil.h"
#define LIBSWSCALE_VERSION_MAJOR 0
-#define LIBSWSCALE_VERSION_MINOR 12
+#define LIBSWSCALE_VERSION_MINOR 13
#define LIBSWSCALE_VERSION_MICRO 0
#define LIBSWSCALE_VERSION_INT AV_VERSION_INT(LIBSWSCALE_VERSION_MAJOR, \
diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h
index 19dff8f..daa6731 100644
--- a/libswscale/swscale_internal.h
+++ b/libswscale/swscale_internal.h
@@ -341,6 +341,8 @@ const char *sws_format_name(enum PixelFormat format);
#define is16BPS(x) ( \
(x)==PIX_FMT_GRAY16BE \
|| (x)==PIX_FMT_GRAY16LE \
+ || (x)==PIX_FMT_BGR48BE \
+ || (x)==PIX_FMT_BGR48LE \
|| (x)==PIX_FMT_RGB48BE \
|| (x)==PIX_FMT_RGB48LE \
|| (x)==PIX_FMT_YUV420P16LE \
@@ -405,7 +407,9 @@ const char *sws_format_name(enum PixelFormat format);
|| (x)==PIX_FMT_MONOWHITE \
)
#define isBGRinInt(x) ( \
- (x)==PIX_FMT_BGR32 \
+ (x)==PIX_FMT_BGR48BE \
+ || (x)==PIX_FMT_BGR48LE \
+ || (x)==PIX_FMT_BGR32 \
|| (x)==PIX_FMT_BGR32_1 \
|| (x)==PIX_FMT_BGR24 \
|| (x)==PIX_FMT_BGR565BE \
@@ -428,7 +432,9 @@ const char *sws_format_name(enum PixelFormat format);
|| (x)==PIX_FMT_RGB24 \
)
#define isBGRinBytes(x) ( \
- (x)==PIX_FMT_BGRA \
+ (x)==PIX_FMT_BGR48BE \
+ || (x)==PIX_FMT_BGR48LE \
+ || (x)==PIX_FMT_BGRA \
|| (x)==PIX_FMT_ABGR \
|| (x)==PIX_FMT_BGR24 \
)
diff --git a/libswscale/swscale_template.c b/libswscale/swscale_template.c
index 9863a7c..b1eeb37 100644
--- a/libswscale/swscale_template.c
+++ b/libswscale/swscale_template.c
@@ -2966,6 +2966,8 @@ static void RENAME(sws_init_swScale)(SwsContext *c)
switch(srcFormat) {
case PIX_FMT_RGB48BE:
case PIX_FMT_RGB48LE: c->chrToYV12 = rgb48ToUV_half; break;
+ case PIX_FMT_BGR48BE:
+ case PIX_FMT_BGR48LE: c->chrToYV12 = bgr48ToUV_half; break;
case PIX_FMT_RGB32 : c->chrToYV12 = bgr32ToUV_half; break;
case PIX_FMT_RGB32_1: c->chrToYV12 = bgr321ToUV_half; break;
case PIX_FMT_BGR24 : c->chrToYV12 = RENAME(bgr24ToUV_half); break;
@@ -2981,6 +2983,8 @@ static void RENAME(sws_init_swScale)(SwsContext *c)
switch(srcFormat) {
case PIX_FMT_RGB48BE:
case PIX_FMT_RGB48LE: c->chrToYV12 = rgb48ToUV; break;
+ case PIX_FMT_BGR48BE:
+ case PIX_FMT_BGR48LE: c->chrToYV12 = bgr48ToUV; break;
case PIX_FMT_RGB32 : c->chrToYV12 = bgr32ToUV; break;
case PIX_FMT_RGB32_1: c->chrToYV12 = bgr321ToUV; break;
case PIX_FMT_BGR24 : c->chrToYV12 = RENAME(bgr24ToUV); break;
@@ -3027,6 +3031,8 @@ static void RENAME(sws_init_swScale)(SwsContext *c)
case PIX_FMT_BGR32_1: c->lumToYV12 = rgb321ToY; break;
case PIX_FMT_RGB48BE:
case PIX_FMT_RGB48LE: c->lumToYV12 = rgb48ToY; break;
+ case PIX_FMT_BGR48BE:
+ case PIX_FMT_BGR48LE: c->lumToYV12 = bgr48ToY; break;
}
if (c->alpPixBuf) {
switch (srcFormat) {
@@ -3047,6 +3053,7 @@ static void RENAME(sws_init_swScale)(SwsContext *c)
c->alpSrcOffset = 3;
break;
case PIX_FMT_RGB48LE:
+ case PIX_FMT_BGR48LE:
c->lumSrcOffset = 1;
c->chrSrcOffset = 1;
c->alpSrcOffset = 1;
diff --git a/libswscale/utils.c b/libswscale/utils.c
index 166e983..9accfda 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -73,6 +73,8 @@ const char *swscale_license(void)
|| (x)==PIX_FMT_RGB48LE \
|| (x)==PIX_FMT_RGB32 \
|| (x)==PIX_FMT_RGB32_1 \
+ || (x)==PIX_FMT_BGR48BE \
+ || (x)==PIX_FMT_BGR48LE \
|| (x)==PIX_FMT_BGR24 \
|| (x)==PIX_FMT_BGR565 \
|| (x)==PIX_FMT_BGR555 \
diff --git a/libswscale/yuv2rgb.c b/libswscale/yuv2rgb.c
index 77d3d39..46dbe11 100644
--- a/libswscale/yuv2rgb.c
+++ b/libswscale/yuv2rgb.c
@@ -99,6 +99,16 @@ const int *sws_getCoefficients(int colorspace)
dst[12*i+ 8] = dst[12*i+ 9] = g[Y]; \
dst[12*i+10] = dst[12*i+11] = b[Y];
+#define PUTBGR48(dst,src,i) \
+ Y = src[2*i]; \
+ dst[12*i+ 0] = dst[12*i+ 1] = b[Y]; \
+ dst[12*i+ 2] = dst[12*i+ 3] = g[Y]; \
+ dst[12*i+ 4] = dst[12*i+ 5] = r[Y]; \
+ Y = src[2*i+1]; \
+ dst[12*i+ 6] = dst[12*i+ 7] = b[Y]; \
+ dst[12*i+ 8] = dst[12*i+ 9] = g[Y]; \
+ dst[12*i+10] = dst[12*i+11] = r[Y];
+
#define YUV2RGBFUNC(func_name, dst_type, alpha) \
static int func_name(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, \
int srcSliceH, uint8_t* dst[], int dstStride[]) \
@@ -568,6 +578,8 @@ SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c)
av_log(c, AV_LOG_WARNING, "No accelerated colorspace conversion found from %s to %s.\n", sws_format_name(c->srcFormat), sws_format_name(c->dstFormat));
switch (c->dstFormat) {
+ case PIX_FMT_BGR48BE:
+ case PIX_FMT_BGR48LE:
case PIX_FMT_RGB48BE:
case PIX_FMT_RGB48LE: return yuv2rgb_c_48;
case PIX_FMT_ARGB:
--
1.7.4.1
-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20110318/07499280/attachment-0001.asc>
More information about the ffmpeg-devel
mailing list