mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-24 01:00:37 +00:00
gst/alpha/gstalphacolor.c: Add BGRA handling (#165736).
Original commit message from CVS: Reviewed by: Ronald S. Bultje <rbultje@ronald.bitfreak.net> * gst/alpha/gstalphacolor.c: (gst_alpha_color_sink_link), (transform_rgb), (transform_bgr), (gst_alpha_color_chain): Add BGRA handling (#165736).
This commit is contained in:
parent
e23f9bb4e9
commit
883da03b7c
2 changed files with 46 additions and 4 deletions
|
@ -1,3 +1,11 @@
|
|||
2005-02-08 Gergely Nagy <algernon@bonehunter.rulez.org>
|
||||
|
||||
Reviewed by: Ronald S. Bultje <rbultje@ronald.bitfreak.net>
|
||||
|
||||
* gst/alpha/gstalphacolor.c: (gst_alpha_color_sink_link),
|
||||
(transform_rgb), (transform_bgr), (gst_alpha_color_chain):
|
||||
Add BGRA handling (#165736).
|
||||
|
||||
2005-02-08 Francis Labonte <francis_labonte@hotmail.com>
|
||||
|
||||
Reviewed by: Ronald S. Bultje <rbultje@ronald.bitfreak.net>
|
||||
|
|
|
@ -49,6 +49,7 @@ struct _GstAlphaColor
|
|||
|
||||
/* caps */
|
||||
gint in_width, in_height;
|
||||
gboolean in_rgba;
|
||||
gint out_width, out_height;
|
||||
};
|
||||
|
||||
|
@ -79,10 +80,10 @@ enum
|
|||
};
|
||||
|
||||
static GstStaticPadTemplate gst_alpha_color_sink_template =
|
||||
GST_STATIC_PAD_TEMPLATE ("sink",
|
||||
GST_STATIC_PAD_TEMPLATE ("sink",
|
||||
GST_PAD_SINK,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS (GST_VIDEO_CAPS_RGBA)
|
||||
GST_STATIC_CAPS (GST_VIDEO_CAPS_RGBA ";" GST_VIDEO_CAPS_BGRA)
|
||||
);
|
||||
|
||||
static GstStaticPadTemplate gst_alpha_color_src_template =
|
||||
|
@ -230,6 +231,7 @@ gst_alpha_color_sink_link (GstPad * pad, const GstCaps * caps)
|
|||
GstStructure *structure;
|
||||
gboolean ret;
|
||||
gdouble fps;
|
||||
gint red_mask;
|
||||
|
||||
alpha = GST_ALPHA_COLOR (gst_pad_get_parent (pad));
|
||||
structure = gst_caps_get_structure (caps, 0);
|
||||
|
@ -237,10 +239,19 @@ gst_alpha_color_sink_link (GstPad * pad, const GstCaps * caps)
|
|||
ret = gst_structure_get_int (structure, "width", &alpha->in_width);
|
||||
ret &= gst_structure_get_int (structure, "height", &alpha->in_height);
|
||||
ret &= gst_structure_get_double (structure, "framerate", &fps);
|
||||
ret &= gst_structure_get_int (structure, "red_mask", &red_mask);
|
||||
|
||||
if (!ret)
|
||||
return GST_PAD_LINK_REFUSED;
|
||||
|
||||
alpha->in_rgba = TRUE;
|
||||
#if (G_BYTE_ORDER == G_BIG_ENDIAN)
|
||||
if (red_mask != 0x000000ff)
|
||||
#else
|
||||
if (red_mask != 0x00ff0000)
|
||||
#endif
|
||||
alpha->in_rgba = FALSE;
|
||||
|
||||
caps = gst_caps_new_simple ("video/x-raw-yuv",
|
||||
"format", GST_TYPE_FOURCC, GST_STR_FOURCC ("AYUV"),
|
||||
"framerate", G_TYPE_DOUBLE, fps,
|
||||
|
@ -251,7 +262,7 @@ gst_alpha_color_sink_link (GstPad * pad, const GstCaps * caps)
|
|||
}
|
||||
|
||||
static void
|
||||
transform (guint8 * data, gint size)
|
||||
transform_rgb (guint8 * data, gint size)
|
||||
{
|
||||
guint8 y, u, v;
|
||||
|
||||
|
@ -270,6 +281,26 @@ transform (guint8 * data, gint size)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
transform_bgr (guint8 * data, gint size)
|
||||
{
|
||||
guint8 y, u, v;
|
||||
|
||||
while (size > 0) {
|
||||
y = data[2] * 0.299 + data[1] * 0.587 + data[0] * 0.114 + 0;
|
||||
u = data[2] * -0.169 + data[1] * -0.332 + data[0] * 0.500 + 128;
|
||||
v = data[2] * 0.500 + data[1] * -0.419 + data[0] * -0.0813 + 128;
|
||||
|
||||
data[0] = data[3];
|
||||
data[1] = y;
|
||||
data[2] = u;
|
||||
data[3] = v;
|
||||
|
||||
data += 4;
|
||||
size -= 4;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gst_alpha_color_chain (GstPad * pad, GstData * _data)
|
||||
{
|
||||
|
@ -298,7 +329,10 @@ gst_alpha_color_chain (GstPad * pad, GstData * _data)
|
|||
|
||||
outbuf = gst_buffer_copy_on_write (buffer);
|
||||
|
||||
transform (GST_BUFFER_DATA (outbuf), GST_BUFFER_SIZE (outbuf));
|
||||
if (alpha->in_rgba)
|
||||
transform_rgb (GST_BUFFER_DATA (outbuf), GST_BUFFER_SIZE (outbuf));
|
||||
else
|
||||
transform_bgr (GST_BUFFER_DATA (outbuf), GST_BUFFER_SIZE (outbuf));
|
||||
|
||||
gst_pad_push (alpha->srcpad, GST_DATA (outbuf));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue