mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-03-01 17:31:10 +00:00
Fixed problem with color conversion
Original commit message from CVS: Fixed problem with color conversion Added conversion between YV12 and I420
This commit is contained in:
parent
43d17ede7a
commit
9251ed656a
5 changed files with 57 additions and 11 deletions
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
#include "gstcolorspace.h"
|
#include "gstcolorspace.h"
|
||||||
#include "yuv2rgb.h"
|
#include "yuv2rgb.h"
|
||||||
|
#include "yuv2yuv.h"
|
||||||
|
|
||||||
|
|
||||||
static GstElementDetails colorspace_details = {
|
static GstElementDetails colorspace_details = {
|
||||||
|
@ -54,6 +55,7 @@ GST_PAD_TEMPLATE_FACTORY (colorspace_src_template_factory,
|
||||||
"video/raw",
|
"video/raw",
|
||||||
"format", GST_PROPS_LIST (
|
"format", GST_PROPS_LIST (
|
||||||
GST_PROPS_FOURCC (GST_STR_FOURCC ("I420")),
|
GST_PROPS_FOURCC (GST_STR_FOURCC ("I420")),
|
||||||
|
GST_PROPS_FOURCC (GST_STR_FOURCC ("YV12")),
|
||||||
GST_PROPS_FOURCC (GST_STR_FOURCC ("YUY2")),
|
GST_PROPS_FOURCC (GST_STR_FOURCC ("YUY2")),
|
||||||
GST_PROPS_FOURCC (GST_STR_FOURCC ("RGB "))
|
GST_PROPS_FOURCC (GST_STR_FOURCC ("RGB "))
|
||||||
),
|
),
|
||||||
|
@ -71,6 +73,7 @@ GST_PAD_TEMPLATE_FACTORY (colorspace_sink_template_factory,
|
||||||
"video/raw",
|
"video/raw",
|
||||||
"format", GST_PROPS_LIST (
|
"format", GST_PROPS_LIST (
|
||||||
GST_PROPS_FOURCC (GST_STR_FOURCC ("I420")),
|
GST_PROPS_FOURCC (GST_STR_FOURCC ("I420")),
|
||||||
|
GST_PROPS_FOURCC (GST_STR_FOURCC ("YV12")),
|
||||||
GST_PROPS_FOURCC (GST_STR_FOURCC ("YUY2")),
|
GST_PROPS_FOURCC (GST_STR_FOURCC ("YUY2")),
|
||||||
GST_PROPS_FOURCC (GST_STR_FOURCC ("RGB "))
|
GST_PROPS_FOURCC (GST_STR_FOURCC ("RGB "))
|
||||||
),
|
),
|
||||||
|
@ -98,8 +101,6 @@ static GstElementStateReturn
|
||||||
gst_colorspace_change_state (GstElement *element);
|
gst_colorspace_change_state (GstElement *element);
|
||||||
|
|
||||||
/* FIXME */
|
/* FIXME */
|
||||||
extern void gst_colorspace_yuy2_to_i420 (unsigned char *src, unsigned char *dest,
|
|
||||||
guint width, guint height);
|
|
||||||
extern void gst_colorspace_rgb32_to_i420 (unsigned char *src, unsigned char *dest,
|
extern void gst_colorspace_rgb32_to_i420 (unsigned char *src, unsigned char *dest,
|
||||||
guint width, guint height);
|
guint width, guint height);
|
||||||
extern void gst_colorspace_rgb32_to_yv12 (unsigned char *src, unsigned char *dest,
|
extern void gst_colorspace_rgb32_to_yv12 (unsigned char *src, unsigned char *dest,
|
||||||
|
@ -218,6 +219,10 @@ colorspace_setup_converter (GstColorspace *space, GstCaps *from_caps, GstCaps *t
|
||||||
space->type = GST_COLORSPACE_NONE;
|
space->type = GST_COLORSPACE_NONE;
|
||||||
space->destbpp = 12;
|
space->destbpp = 12;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
case GST_MAKE_FOURCC ('Y','V','1','2'):
|
||||||
|
space->type = GST_COLORSPACE_420_SWAP;
|
||||||
|
space->destbpp = 12;
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -231,6 +236,17 @@ colorspace_setup_converter (GstColorspace *space, GstCaps *from_caps, GstCaps *t
|
||||||
space->type = GST_COLORSPACE_NONE;
|
space->type = GST_COLORSPACE_NONE;
|
||||||
space->destbpp = 16;
|
space->destbpp = 16;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
case GST_MAKE_FOURCC ('R','G','B',' '):
|
||||||
|
GST_INFO (GST_CAT_NEGOTIATION, "colorspace: YUY2 to RGB not implemented!!");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case GST_MAKE_FOURCC ('Y','V','1','2'):
|
||||||
|
switch (to_space) {
|
||||||
|
case GST_MAKE_FOURCC ('I','4','2','0'):
|
||||||
|
space->type = GST_COLORSPACE_420_SWAP;
|
||||||
|
space->destbpp = 12;
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -279,7 +295,7 @@ gst_colorspace_sinkconnect (GstPad *pad, GstCaps *caps)
|
||||||
|
|
||||||
peer = gst_pad_get_peer (pad);
|
peer = gst_pad_get_peer (pad);
|
||||||
if (peer) {
|
if (peer) {
|
||||||
if (!gst_colorspace_srcconnect_func (pad, gst_pad_get_allowed_caps (space->srcpad), FALSE)) {
|
if (gst_colorspace_srcconnect_func (pad, gst_pad_get_allowed_caps (space->srcpad), FALSE) < 1) {
|
||||||
space->sinkcaps = NULL;
|
space->sinkcaps = NULL;
|
||||||
return GST_PAD_CONNECT_REFUSED;
|
return GST_PAD_CONNECT_REFUSED;
|
||||||
}
|
}
|
||||||
|
@ -347,7 +363,6 @@ gst_colorspace_srcconnect_func (GstPad *pad, GstCaps *caps, gboolean newcaps)
|
||||||
peercaps = peercaps->next;
|
peercaps = peercaps->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
gst_element_error (GST_ELEMENT (space), "could not agree on caps with peer pads");
|
|
||||||
/* we disable ourself here */
|
/* we disable ourself here */
|
||||||
space->disabled = TRUE;
|
space->disabled = TRUE;
|
||||||
|
|
||||||
|
@ -475,6 +490,12 @@ gst_colorspace_chain (GstPad *pad,GstBuffer *buf)
|
||||||
space->width,
|
space->width,
|
||||||
space->height);
|
space->height);
|
||||||
}
|
}
|
||||||
|
else if (space->type == GST_COLORSPACE_420_SWAP) {
|
||||||
|
gst_colorspace_i420_to_yv12 (GST_BUFFER_DATA (buf),
|
||||||
|
GST_BUFFER_DATA (outbuf),
|
||||||
|
space->width,
|
||||||
|
space->height);
|
||||||
|
}
|
||||||
else if (space->type == GST_COLORSPACE_RGB32_I420) {
|
else if (space->type == GST_COLORSPACE_RGB32_I420) {
|
||||||
gst_colorspace_rgb32_to_i420 (GST_BUFFER_DATA (buf),
|
gst_colorspace_rgb32_to_i420 (GST_BUFFER_DATA (buf),
|
||||||
GST_BUFFER_DATA (outbuf),
|
GST_BUFFER_DATA (outbuf),
|
||||||
|
|
|
@ -59,6 +59,7 @@ typedef enum {
|
||||||
GST_COLORSPACE_YUY2_I420,
|
GST_COLORSPACE_YUY2_I420,
|
||||||
GST_COLORSPACE_RGB32_I420,
|
GST_COLORSPACE_RGB32_I420,
|
||||||
GST_COLORSPACE_RGB32_YV12,
|
GST_COLORSPACE_RGB32_YV12,
|
||||||
|
GST_COLORSPACE_420_SWAP,
|
||||||
} GstColorSpaceConverterType;
|
} GstColorSpaceConverterType;
|
||||||
|
|
||||||
struct _GstColorspace {
|
struct _GstColorspace {
|
||||||
|
|
|
@ -24,10 +24,10 @@
|
||||||
|
|
||||||
#include "yuv2rgb.h"
|
#include "yuv2rgb.h"
|
||||||
|
|
||||||
/*#undef HAVE_LIBMMX */
|
/* #define HAVE_LIBMMX */
|
||||||
|
|
||||||
#ifdef HAVE_LIBMMX
|
#ifdef HAVE_LIBMMX
|
||||||
#include "mmx.h"
|
#include <mmx.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define CB_BASE 1
|
#define CB_BASE 1
|
||||||
|
@ -187,8 +187,8 @@ static void gst_colorspace_yuv420P_to_rgb32(GstColorSpaceConverter *space, unsig
|
||||||
|
|
||||||
gst_colorspace_yuv_to_rgb32(space->color_tables,
|
gst_colorspace_yuv_to_rgb32(space->color_tables,
|
||||||
src, /* Y component */
|
src, /* Y component */
|
||||||
src+size+(size>>2), /* cb component */
|
|
||||||
src+size, /* cr component */
|
src+size, /* cr component */
|
||||||
|
src+size+(size>>2), /* cb component */
|
||||||
dest,
|
dest,
|
||||||
space->height,
|
space->height,
|
||||||
space->width);
|
space->width);
|
||||||
|
@ -203,8 +203,8 @@ static void gst_colorspace_yuv420P_to_rgb24(GstColorSpaceConverter *space, unsig
|
||||||
|
|
||||||
gst_colorspace_yuv_to_rgb24(space->color_tables,
|
gst_colorspace_yuv_to_rgb24(space->color_tables,
|
||||||
src, /* Y component */
|
src, /* Y component */
|
||||||
src+size+(size>>2), /* cb component */
|
|
||||||
src+size, /* cr component */
|
src+size, /* cr component */
|
||||||
|
src+size+(size>>2), /* cb component */
|
||||||
dest,
|
dest,
|
||||||
space->height,
|
space->height,
|
||||||
space->width);
|
space->width);
|
||||||
|
@ -219,8 +219,8 @@ static void gst_colorspace_yuv420P_to_rgb16(GstColorSpaceConverter *space, unsig
|
||||||
|
|
||||||
gst_colorspace_yuv_to_rgb16(space->color_tables,
|
gst_colorspace_yuv_to_rgb16(space->color_tables,
|
||||||
src, /* Y component */
|
src, /* Y component */
|
||||||
src+size+(size>>2), /* cb component */
|
|
||||||
src+size, /* cr component */
|
src+size, /* cr component */
|
||||||
|
src+size+(size>>2), /* cb component */
|
||||||
dest,
|
dest,
|
||||||
space->height,
|
space->height,
|
||||||
space->width);
|
space->width);
|
||||||
|
|
|
@ -53,3 +53,26 @@ void gst_colorspace_yuy2_to_i420(unsigned char *src, unsigned char *dest, guint
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void gst_colorspace_i420_to_yv12(unsigned char *src, unsigned char *dest, guint width, guint height)
|
||||||
|
{
|
||||||
|
int size, i;
|
||||||
|
guint8 *destcr, *destcb;
|
||||||
|
|
||||||
|
size = width * height;
|
||||||
|
|
||||||
|
memcpy (dest, src, size);
|
||||||
|
|
||||||
|
src += size;
|
||||||
|
destcr = dest + size;
|
||||||
|
size >>=2;
|
||||||
|
destcb = destcr + size;
|
||||||
|
|
||||||
|
i=size;
|
||||||
|
while (i--)
|
||||||
|
*destcb++ = *src++;
|
||||||
|
i=size;
|
||||||
|
while (i--)
|
||||||
|
*destcr++ = *src++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
|
|
||||||
void gst_colorspace_yuy2_to_i420 (guchar *src, guchar *dest, guint width, guint height);
|
void gst_colorspace_yuy2_to_i420 (guchar *src, guchar *dest, guint width, guint height);
|
||||||
|
void gst_colorspace_i420_to_yv12 (guchar *src, guchar *dest, guint width, guint height);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue