alpha: port to new video API

This commit is contained in:
Wim Taymans 2011-07-04 18:06:48 +02:00
parent 3c27f2435a
commit b9b007e1be
3 changed files with 289 additions and 296 deletions

View file

@ -31,7 +31,7 @@
* Sample pipeline:
* |[
* gst-launch videotestsrc pattern=smpte75 ! alpha method=green ! \
* videomixer name=mixer ! ffmpegcolorspace ! autovideosink \
* videomixer name=mixer ! videoconvert ! autovideosink \
* videotestsrc pattern=snow ! mixer.
* ]| This pipeline adds a alpha channel to the SMPTE color bars
* with green as the transparent color and mixes the output with
@ -548,12 +548,12 @@ gst_alpha_set_caps (GstBaseTransform * btrans,
" (passthrough: %d)", incaps, outcaps, passthrough);
gst_base_transform_set_passthrough (btrans, passthrough);
if (!gst_alpha_set_process_function (alpha) && !passthrough)
goto no_process;
alpha->in_info = in_info;
alpha->out_info = out_info;
if (!gst_alpha_set_process_function (alpha) && !passthrough)
goto no_process;
gst_alpha_init_params (alpha);
GST_ALPHA_UNLOCK (alpha);
@ -672,13 +672,13 @@ gst_alpha_set_argb_ayuv (const GstVideoFrame * in_frame,
src = GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0);
dest = GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0);
width = in_frame->info.width;
height = in_frame->info.height;
width = GST_VIDEO_FRAME_WIDTH (in_frame);
height = GST_VIDEO_FRAME_HEIGHT (in_frame);
o[0] = gst_video_format_get_component_offset (in_format, 3, width, height);
o[1] = gst_video_format_get_component_offset (in_format, 0, width, height);
o[2] = gst_video_format_get_component_offset (in_format, 1, width, height);
o[3] = gst_video_format_get_component_offset (in_format, 2, width, height);
o[0] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 3);
o[1] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 0);
o[2] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 1);
o[3] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 2);
memcpy (matrix,
alpha->out_sdtv ? cog_rgb_to_ycbcr_matrix_8bit_sdtv :
@ -727,13 +727,13 @@ gst_alpha_chroma_key_argb_ayuv (const GstVideoFrame * in_frame,
src = GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0);
dest = GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0);
width = in_frame->info.width;
height = in_frame->info.height;
width = GST_VIDEO_FRAME_WIDTH (in_frame);
height = GST_VIDEO_FRAME_HEIGHT (in_frame);
o[0] = gst_video_format_get_component_offset (in_format, 3, width, height);
o[1] = gst_video_format_get_component_offset (in_format, 0, width, height);
o[2] = gst_video_format_get_component_offset (in_format, 1, width, height);
o[3] = gst_video_format_get_component_offset (in_format, 2, width, height);
o[0] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 3);
o[1] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 0);
o[2] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 1);
o[3] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 2);
smin = 128 - alpha->black_sensitivity;
smax = 128 + alpha->white_sensitivity;
@ -785,18 +785,18 @@ gst_alpha_set_argb_argb (const GstVideoFrame * in_frame,
src = GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0);
dest = GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0);
width = in_frame->info.width;
height = in_frame->info.height;
width = GST_VIDEO_FRAME_WIDTH (in_frame);
height = GST_VIDEO_FRAME_HEIGHT (in_frame);
p[0] = gst_video_format_get_component_offset (out_format, 3, width, height);
p[1] = gst_video_format_get_component_offset (out_format, 0, width, height);
p[2] = gst_video_format_get_component_offset (out_format, 1, width, height);
p[3] = gst_video_format_get_component_offset (out_format, 2, width, height);
p[0] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 3);
p[1] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 0);
p[2] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 1);
p[3] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 2);
o[0] = gst_video_format_get_component_offset (in_format, 3, width, height);
o[1] = gst_video_format_get_component_offset (in_format, 0, width, height);
o[2] = gst_video_format_get_component_offset (in_format, 1, width, height);
o[3] = gst_video_format_get_component_offset (in_format, 2, width, height);
o[0] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 3);
o[1] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 0);
o[2] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 1);
o[3] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 2);
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
@ -837,18 +837,18 @@ gst_alpha_chroma_key_argb_argb (const GstVideoFrame * in_frame,
src = GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0);
dest = GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0);
width = in_frame->info.width;
height = in_frame->info.height;
width = GST_VIDEO_FRAME_WIDTH (in_frame);
height = GST_VIDEO_FRAME_HEIGHT (in_frame);
p[0] = gst_video_format_get_component_offset (out_format, 3, width, height);
p[1] = gst_video_format_get_component_offset (out_format, 0, width, height);
p[2] = gst_video_format_get_component_offset (out_format, 1, width, height);
p[3] = gst_video_format_get_component_offset (out_format, 2, width, height);
p[0] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 3);
p[1] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 0);
p[2] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 1);
p[3] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 2);
o[0] = gst_video_format_get_component_offset (in_format, 3, width, height);
o[1] = gst_video_format_get_component_offset (in_format, 0, width, height);
o[2] = gst_video_format_get_component_offset (in_format, 1, width, height);
o[3] = gst_video_format_get_component_offset (in_format, 2, width, height);
o[0] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 3);
o[1] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 0);
o[2] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 1);
o[3] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 2);
smin = 128 - alpha->black_sensitivity;
smax = 128 + alpha->white_sensitivity;
@ -905,13 +905,13 @@ gst_alpha_set_ayuv_argb (const GstVideoFrame * in_frame,
src = GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0);
dest = GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0);
width = in_frame->info.width;
height = in_frame->info.height;
width = GST_VIDEO_FRAME_WIDTH (in_frame);
height = GST_VIDEO_FRAME_HEIGHT (in_frame);
p[0] = gst_video_format_get_component_offset (out_format, 3, width, height);
p[1] = gst_video_format_get_component_offset (out_format, 0, width, height);
p[2] = gst_video_format_get_component_offset (out_format, 1, width, height);
p[3] = gst_video_format_get_component_offset (out_format, 2, width, height);
p[0] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 3);
p[1] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 0);
p[2] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 1);
p[3] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 2);
memcpy (matrix,
alpha->in_sdtv ? cog_ycbcr_to_rgb_matrix_8bit_sdtv :
@ -960,13 +960,13 @@ gst_alpha_chroma_key_ayuv_argb (const GstVideoFrame * in_frame,
src = GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0);
dest = GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0);
width = in_frame->info.width;
height = in_frame->info.height;
width = GST_VIDEO_FRAME_WIDTH (in_frame);
height = GST_VIDEO_FRAME_HEIGHT (in_frame);
p[0] = gst_video_format_get_component_offset (out_format, 3, width, height);
p[1] = gst_video_format_get_component_offset (out_format, 0, width, height);
p[2] = gst_video_format_get_component_offset (out_format, 1, width, height);
p[3] = gst_video_format_get_component_offset (out_format, 2, width, height);
p[0] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 3);
p[1] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 0);
p[2] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 1);
p[3] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 2);
smin = 128 - alpha->black_sensitivity;
smax = 128 + alpha->white_sensitivity;
@ -1017,8 +1017,8 @@ gst_alpha_set_ayuv_ayuv (const GstVideoFrame * in_frame,
src = GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0);
dest = GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0);
width = in_frame->info.width;
height = in_frame->info.height;
width = GST_VIDEO_FRAME_WIDTH (in_frame);
height = GST_VIDEO_FRAME_HEIGHT (in_frame);
if (alpha->in_sdtv == alpha->out_sdtv) {
for (y = 0; y < height; y++) {
@ -1075,8 +1075,8 @@ gst_alpha_chroma_key_ayuv_ayuv (const GstVideoFrame * in_frame,
src = GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0);
dest = GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0);
width = in_frame->info.width;
height = in_frame->info.height;
width = GST_VIDEO_FRAME_WIDTH (in_frame);
height = GST_VIDEO_FRAME_HEIGHT (in_frame);
smin = 128 - alpha->black_sensitivity;
smax = 128 + alpha->white_sensitivity;
@ -1155,14 +1155,13 @@ gst_alpha_set_rgb_ayuv (const GstVideoFrame * in_frame,
src = GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0);
dest = GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0);
width = in_frame->info.width;
height = in_frame->info.height;
width = GST_VIDEO_FRAME_WIDTH (in_frame);
height = GST_VIDEO_FRAME_HEIGHT (in_frame);
bpp = gst_video_format_get_pixel_stride (in_format, 0);
o[0] = gst_video_format_get_component_offset (in_format, 0, width, height);
o[1] = gst_video_format_get_component_offset (in_format, 1, width, height);
o[2] = gst_video_format_get_component_offset (in_format, 2, width, height);
bpp = GST_VIDEO_FRAME_COMP_PSTRIDE (in_frame, 0);
o[0] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 0);
o[1] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 1);
o[2] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 2);
memcpy (matrix,
alpha->out_sdtv ? cog_rgb_to_ycbcr_matrix_8bit_sdtv :
@ -1212,14 +1211,14 @@ gst_alpha_chroma_key_rgb_ayuv (const GstVideoFrame * in_frame,
src = GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0);
dest = GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0);
width = in_frame->info.width;
height = in_frame->info.height;
width = GST_VIDEO_FRAME_WIDTH (in_frame);
height = GST_VIDEO_FRAME_HEIGHT (in_frame);
bpp = gst_video_format_get_pixel_stride (in_format, 0);
bpp = GST_VIDEO_FRAME_COMP_PSTRIDE (in_frame, 0);
o[0] = gst_video_format_get_component_offset (in_format, 0, width, height);
o[1] = gst_video_format_get_component_offset (in_format, 1, width, height);
o[2] = gst_video_format_get_component_offset (in_format, 2, width, height);
o[0] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 0);
o[1] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 1);
o[2] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 2);
smin = 128 - alpha->black_sensitivity;
smax = 128 + alpha->white_sensitivity;
@ -1261,7 +1260,6 @@ static void
gst_alpha_set_rgb_argb (const GstVideoFrame * in_frame,
GstVideoFrame * out_frame, GstAlpha * alpha)
{
GstVideoFormat in_format, out_format;
const guint8 *src;
guint8 *dest;
gint width, height;
@ -1273,19 +1271,19 @@ gst_alpha_set_rgb_argb (const GstVideoFrame * in_frame,
src = GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0);
dest = GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0);
width = in_frame->info.width;
height = in_frame->info.height;
width = GST_VIDEO_FRAME_WIDTH (in_frame);
height = GST_VIDEO_FRAME_HEIGHT (in_frame);
bpp = gst_video_format_get_pixel_stride (in_format, 0);
bpp = GST_VIDEO_FRAME_COMP_PSTRIDE (in_frame, 0);
o[0] = gst_video_format_get_component_offset (in_format, 0, width, height);
o[1] = gst_video_format_get_component_offset (in_format, 1, width, height);
o[2] = gst_video_format_get_component_offset (in_format, 2, width, height);
o[0] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 0);
o[1] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 1);
o[2] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 2);
p[0] = gst_video_format_get_component_offset (out_format, 3, width, height);
p[1] = gst_video_format_get_component_offset (out_format, 0, width, height);
p[2] = gst_video_format_get_component_offset (out_format, 1, width, height);
p[3] = gst_video_format_get_component_offset (out_format, 2, width, height);
p[0] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 3);
p[1] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 0);
p[2] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 1);
p[3] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 2);
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
@ -1327,19 +1325,19 @@ gst_alpha_chroma_key_rgb_argb (const GstVideoFrame * in_frame,
src = GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0);
dest = GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0);
width = in_frame->info.width;
height = in_frame->info.height;
width = GST_VIDEO_FRAME_WIDTH (in_frame);
height = GST_VIDEO_FRAME_HEIGHT (in_frame);
bpp = gst_video_format_get_pixel_stride (in_format, 0);
bpp = GST_VIDEO_FRAME_COMP_PSTRIDE (in_frame, 0);
o[0] = gst_video_format_get_component_offset (in_format, 0, width, height);
o[1] = gst_video_format_get_component_offset (in_format, 1, width, height);
o[2] = gst_video_format_get_component_offset (in_format, 2, width, height);
o[0] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 0);
o[1] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 1);
o[2] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 2);
p[0] = gst_video_format_get_component_offset (out_format, 3, width, height);
p[1] = gst_video_format_get_component_offset (out_format, 0, width, height);
p[2] = gst_video_format_get_component_offset (out_format, 1, width, height);
p[3] = gst_video_format_get_component_offset (out_format, 2, width, height);
p[0] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 3);
p[1] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 0);
p[2] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 1);
p[3] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 2);
smin = 128 - alpha->black_sensitivity;
smax = 128 + alpha->white_sensitivity;
@ -1398,19 +1396,17 @@ gst_alpha_set_planar_yuv_ayuv (const GstVideoFrame * in_frame,
src = GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0);
dest = GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0);
width = in_frame->info.width;
height = in_frame->info.height;
width = GST_VIDEO_FRAME_WIDTH (in_frame);
height = GST_VIDEO_FRAME_HEIGHT (in_frame);
y_stride = gst_video_format_get_row_stride (in_format, 0, width);
uv_stride = gst_video_format_get_row_stride (in_format, 1, width);
y_stride = GST_VIDEO_FRAME_COMP_STRIDE (in_frame, 0);
uv_stride = GST_VIDEO_FRAME_COMP_STRIDE (in_frame, 1);
srcY_tmp = srcY = src;
srcU_tmp = srcU =
src + gst_video_format_get_component_offset (in_format, 1, width, height);
srcV_tmp = srcV =
src + gst_video_format_get_component_offset (in_format, 2, width, height);
srcU_tmp = srcU = src + GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 1);
srcV_tmp = srcV = src + GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 2);
switch (in_format) {
switch (GST_VIDEO_FRAME_FORMAT (in_frame)) {
case GST_VIDEO_FORMAT_I420:
case GST_VIDEO_FORMAT_YV12:
v_subs = h_subs = 2;
@ -1498,7 +1494,7 @@ gst_alpha_set_planar_yuv_ayuv (const GstVideoFrame * in_frame,
static void
gst_alpha_chroma_key_planar_yuv_ayuv (const GstVideoFrame * in_frame,
GstVideoFrame * out_frame, gint width, gint height, GstAlpha * alpha)
GstVideoFrame * out_frame, GstAlpha * alpha)
{
const guint8 *src;
guint8 *dest;
@ -1524,19 +1520,17 @@ gst_alpha_chroma_key_planar_yuv_ayuv (const GstVideoFrame * in_frame,
src = GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0);
dest = GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0);
width = in_frame->info.width;
height = in_frame->info.height;
width = GST_VIDEO_FRAME_WIDTH (in_frame);
height = GST_VIDEO_FRAME_HEIGHT (in_frame);
y_stride = gst_video_format_get_row_stride (in_format, 0, width);
uv_stride = gst_video_format_get_row_stride (in_format, 1, width);
y_stride = GST_VIDEO_FRAME_COMP_STRIDE (in_frame, 0);
uv_stride = GST_VIDEO_FRAME_COMP_STRIDE (in_frame, 1);
srcY_tmp = srcY = src;
srcU_tmp = srcU =
src + gst_video_format_get_component_offset (in_format, 1, width, height);
srcV_tmp = srcV =
src + gst_video_format_get_component_offset (in_format, 2, width, height);
srcU_tmp = srcU = src + GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 1);
srcV_tmp = srcV = src + GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 2);
switch (in_format) {
switch (GST_VIDEO_FRAME_FORMAT (in_frame)) {
case GST_VIDEO_FORMAT_I420:
case GST_VIDEO_FORMAT_YV12:
v_subs = h_subs = 2;
@ -1639,7 +1633,7 @@ gst_alpha_chroma_key_planar_yuv_ayuv (const GstVideoFrame * in_frame,
static void
gst_alpha_set_planar_yuv_argb (const GstVideoFrame * in_frame,
GstVideoFrame * out_frame, gint width, gint height, GstAlpha * alpha)
GstVideoFrame * out_frame, GstAlpha * alpha)
{
const guint8 *src;
guint8 *dest;
@ -1659,24 +1653,22 @@ gst_alpha_set_planar_yuv_argb (const GstVideoFrame * in_frame,
src = GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0);
dest = GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0);
width = in_frame->info.width;
height = in_frame->info.height;
width = GST_VIDEO_FRAME_WIDTH (in_frame);
height = GST_VIDEO_FRAME_HEIGHT (in_frame);
p[0] = gst_video_format_get_component_offset (out_format, 3, width, height);
p[1] = gst_video_format_get_component_offset (out_format, 0, width, height);
p[2] = gst_video_format_get_component_offset (out_format, 1, width, height);
p[3] = gst_video_format_get_component_offset (out_format, 2, width, height);
p[0] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 3);
p[1] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 0);
p[2] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 1);
p[3] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 2);
y_stride = gst_video_format_get_row_stride (in_format, 0, width);
uv_stride = gst_video_format_get_row_stride (in_format, 1, width);
y_stride = GST_VIDEO_FRAME_COMP_STRIDE (in_frame, 0);
uv_stride = GST_VIDEO_FRAME_COMP_STRIDE (in_frame, 1);
srcY_tmp = srcY = src;
srcU_tmp = srcU =
src + gst_video_format_get_component_offset (in_format, 1, width, height);
srcV_tmp = srcV =
src + gst_video_format_get_component_offset (in_format, 2, width, height);
srcU_tmp = srcU = src + GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 1);
srcV_tmp = srcV = src + GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 2);
switch (alpha->in_format) {
switch (GST_VIDEO_FRAME_FORMAT (in_frame)) {
case GST_VIDEO_FORMAT_I420:
case GST_VIDEO_FORMAT_YV12:
v_subs = h_subs = 2;
@ -1737,7 +1729,7 @@ gst_alpha_set_planar_yuv_argb (const GstVideoFrame * in_frame,
static void
gst_alpha_chroma_key_planar_yuv_argb (const GstVideoFrame * in_frame,
GstVideoFrame * out_frame, gint width, gint height, GstAlpha * alpha)
GstVideoFrame * out_frame, GstAlpha * alpha)
{
const guint8 *src;
guint8 *dest;
@ -1766,34 +1758,22 @@ gst_alpha_chroma_key_planar_yuv_argb (const GstVideoFrame * in_frame,
src = GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0);
dest = GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0);
width = in_frame->info.width;
height = in_frame->info.height;
width = GST_VIDEO_FRAME_WIDTH (in_frame);
height = GST_VIDEO_FRAME_HEIGHT (in_frame);
p[0] =
gst_video_format_get_component_offset (alpha->out_format, 3, width,
height);
p[1] =
gst_video_format_get_component_offset (alpha->out_format, 0, width,
height);
p[2] =
gst_video_format_get_component_offset (alpha->out_format, 1, width,
height);
p[3] =
gst_video_format_get_component_offset (alpha->out_format, 2, width,
height);
p[0] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 3);
p[1] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 0);
p[2] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 1);
p[3] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 2);
y_stride = gst_video_format_get_row_stride (alpha->in_format, 0, width);
uv_stride = gst_video_format_get_row_stride (alpha->in_format, 1, width);
y_stride = GST_VIDEO_FRAME_COMP_STRIDE (in_frame, 0);
uv_stride = GST_VIDEO_FRAME_COMP_STRIDE (in_frame, 1);
srcY_tmp = srcY = src;
srcU_tmp = srcU =
src + gst_video_format_get_component_offset (alpha->in_format, 1, width,
height);
srcV_tmp = srcV =
src + gst_video_format_get_component_offset (alpha->in_format, 2, width,
height);
srcU_tmp = srcU = src + GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 1);
srcV_tmp = srcV = src + GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 2);
switch (alpha->in_format) {
switch (GST_VIDEO_FRAME_FORMAT (in_frame)) {
case GST_VIDEO_FORMAT_I420:
case GST_VIDEO_FORMAT_YV12:
v_subs = h_subs = 2;
@ -1861,7 +1841,7 @@ gst_alpha_chroma_key_planar_yuv_argb (const GstVideoFrame * in_frame,
static void
gst_alpha_set_packed_422_ayuv (const GstVideoFrame * in_frame,
GstVideoFrame * out_frame, gint width, gint height, GstAlpha * alpha)
GstVideoFrame * out_frame, GstAlpha * alpha)
{
const guint8 *src;
guint8 *dest;
@ -1876,21 +1856,15 @@ gst_alpha_set_packed_422_ayuv (const GstVideoFrame * in_frame,
src = GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0);
dest = GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0);
width = in_frame->info.width;
height = in_frame->info.height;
width = GST_VIDEO_FRAME_WIDTH (in_frame);
height = GST_VIDEO_FRAME_HEIGHT (in_frame);
src_stride = gst_video_format_get_row_stride (alpha->in_format, 0, width);
src_stride = GST_VIDEO_FRAME_COMP_STRIDE (in_frame, 0);
p[0] =
gst_video_format_get_component_offset (alpha->in_format, 0, width,
height);
p[0] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 0);
p[2] = p[0] + 2;
p[1] =
gst_video_format_get_component_offset (alpha->in_format, 1, width,
height);
p[3] =
gst_video_format_get_component_offset (alpha->in_format, 2, width,
height);
p[1] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 1);
p[3] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 2);
if (alpha->in_sdtv != alpha->out_sdtv) {
gint matrix[12];
@ -1989,7 +1963,7 @@ gst_alpha_set_packed_422_ayuv (const GstVideoFrame * in_frame,
static void
gst_alpha_chroma_key_packed_422_ayuv (const GstVideoFrame * in_frame,
GstVideoFrame * out_frame, gint width, gint height, GstAlpha * alpha)
GstVideoFrame * out_frame, GstAlpha * alpha)
{
const guint8 *src;
guint8 *dest;
@ -2012,21 +1986,15 @@ gst_alpha_chroma_key_packed_422_ayuv (const GstVideoFrame * in_frame,
src = GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0);
dest = GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0);
width = in_frame->info.width;
height = in_frame->info.height;
width = GST_VIDEO_FRAME_WIDTH (in_frame);
height = GST_VIDEO_FRAME_HEIGHT (in_frame);
src_stride = gst_video_format_get_row_stride (alpha->in_format, 0, width);
src_stride = GST_VIDEO_FRAME_COMP_STRIDE (in_frame, 0);
p[0] =
gst_video_format_get_component_offset (alpha->in_format, 0, width,
height);
p[0] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 0);
p[2] = p[0] + 2;
p[1] =
gst_video_format_get_component_offset (alpha->in_format, 1, width,
height);
p[3] =
gst_video_format_get_component_offset (alpha->in_format, 2, width,
height);
p[1] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 1);
p[3] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 2);
smin = 128 - alpha->black_sensitivity;
smax = 128 + alpha->white_sensitivity;
@ -2166,34 +2134,20 @@ gst_alpha_set_packed_422_argb (const GstVideoFrame * in_frame,
src = GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0);
dest = GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0);
width = in_frame->info.width;
height = in_frame->info.height;
width = GST_VIDEO_FRAME_WIDTH (in_frame);
height = GST_VIDEO_FRAME_HEIGHT (in_frame);
src_stride = gst_video_format_get_row_stride (alpha->in_format, 0, width);
src_stride = GST_VIDEO_FRAME_COMP_STRIDE (in_frame, 0);
o[0] =
gst_video_format_get_component_offset (alpha->in_format, 0, width,
height);
o[0] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 0);
o[2] = o[0] + 2;
o[1] =
gst_video_format_get_component_offset (alpha->in_format, 1, width,
height);
o[3] =
gst_video_format_get_component_offset (alpha->in_format, 2, width,
height);
o[1] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 1);
o[3] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 2);
p[0] =
gst_video_format_get_component_offset (alpha->out_format, 3, width,
height);
p[1] =
gst_video_format_get_component_offset (alpha->out_format, 0, width,
height);
p[2] =
gst_video_format_get_component_offset (alpha->out_format, 1, width,
height);
p[3] =
gst_video_format_get_component_offset (alpha->out_format, 2, width,
height);
p[0] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 3);
p[1] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 0);
p[2] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 1);
p[3] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 2);
memcpy (matrix,
alpha->in_sdtv ? cog_ycbcr_to_rgb_matrix_8bit_sdtv :
@ -2244,7 +2198,7 @@ gst_alpha_set_packed_422_argb (const GstVideoFrame * in_frame,
static void
gst_alpha_chroma_key_packed_422_argb (const GstVideoFrame * in_frame,
GstVideoFrame * out_frame, gint width, gint height, GstAlpha * alpha)
GstVideoFrame * out_frame, GstAlpha * alpha)
{
const guint8 *src;
guint8 *dest;
@ -2269,34 +2223,20 @@ gst_alpha_chroma_key_packed_422_argb (const GstVideoFrame * in_frame,
src = GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0);
dest = GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0);
width = in_frame->info.width;
height = in_frame->info.height;
width = GST_VIDEO_FRAME_WIDTH (in_frame);
height = GST_VIDEO_FRAME_HEIGHT (in_frame);
src_stride = gst_video_format_get_row_stride (alpha->in_format, 0, width);
src_stride = GST_VIDEO_FRAME_COMP_STRIDE (in_frame, 0);
o[0] =
gst_video_format_get_component_offset (alpha->in_format, 0, width,
height);
o[0] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 0);
o[2] = o[0] + 2;
o[1] =
gst_video_format_get_component_offset (alpha->in_format, 1, width,
height);
o[3] =
gst_video_format_get_component_offset (alpha->in_format, 2, width,
height);
o[1] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 1);
o[3] = GST_VIDEO_FRAME_COMP_OFFSET (in_frame, 2);
p[0] =
gst_video_format_get_component_offset (alpha->out_format, 3, width,
height);
p[1] =
gst_video_format_get_component_offset (alpha->out_format, 0, width,
height);
p[2] =
gst_video_format_get_component_offset (alpha->out_format, 1, width,
height);
p[3] =
gst_video_format_get_component_offset (alpha->out_format, 2, width,
height);
p[0] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 3);
p[1] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 0);
p[2] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 1);
p[3] = GST_VIDEO_FRAME_COMP_OFFSET (out_frame, 2);
memcpy (matrix,
alpha->in_sdtv ? cog_ycbcr_to_rgb_matrix_8bit_sdtv :
@ -2386,23 +2326,27 @@ gst_alpha_init_params (GstAlpha * alpha)
gfloat tmp;
gfloat tmp1, tmp2;
gfloat y;
const GstVideoFormatInfo *in_info, *out_info;
const gint *matrix;
in_info = alpha->in_info.finfo;
out_info = alpha->out_info.finfo;
/* RGB->RGB: convert to SDTV YUV, chroma keying, convert back
* YUV->RGB: chroma keying, convert to RGB
* RGB->YUV: convert to YUV, chroma keying
* YUV->YUV: convert matrix, chroma keying
*/
if (gst_video_format_is_rgb (alpha->in_format)
&& gst_video_format_is_rgb (alpha->out_format))
if (GST_VIDEO_FORMAT_INFO_IS_RGB (in_info)
&& GST_VIDEO_FORMAT_INFO_IS_RGB (out_info))
matrix = cog_rgb_to_ycbcr_matrix_8bit_sdtv;
else if (gst_video_format_is_yuv (alpha->in_format)
&& gst_video_format_is_rgb (alpha->out_format))
else if (GST_VIDEO_FORMAT_INFO_IS_YUV (in_info)
&& GST_VIDEO_FORMAT_INFO_IS_RGB (out_info))
matrix =
(alpha->in_sdtv) ? cog_rgb_to_ycbcr_matrix_8bit_sdtv :
cog_rgb_to_ycbcr_matrix_8bit_hdtv;
else if (gst_video_format_is_rgb (alpha->in_format)
&& gst_video_format_is_yuv (alpha->out_format))
else if (GST_VIDEO_FORMAT_INFO_IS_RGB (in_info)
&& GST_VIDEO_FORMAT_INFO_IS_YUV (out_info))
matrix =
(alpha->out_sdtv) ? cog_rgb_to_ycbcr_matrix_8bit_sdtv :
cog_rgb_to_ycbcr_matrix_8bit_hdtv;
@ -2454,9 +2398,9 @@ gst_alpha_set_process_function (GstAlpha * alpha)
switch (alpha->method) {
case ALPHA_METHOD_SET:
switch (alpha->out_format) {
switch (GST_VIDEO_INFO_FORMAT (&alpha->out_info)) {
case GST_VIDEO_FORMAT_AYUV:
switch (alpha->in_format) {
switch (GST_VIDEO_INFO_FORMAT (&alpha->in_info)) {
case GST_VIDEO_FORMAT_AYUV:
alpha->process = gst_alpha_set_ayuv_ayuv;
break;
@ -2494,7 +2438,7 @@ gst_alpha_set_process_function (GstAlpha * alpha)
case GST_VIDEO_FORMAT_ABGR:
case GST_VIDEO_FORMAT_RGBA:
case GST_VIDEO_FORMAT_BGRA:
switch (alpha->in_format) {
switch (GST_VIDEO_INFO_FORMAT (&alpha->in_info)) {
case GST_VIDEO_FORMAT_AYUV:
alpha->process = gst_alpha_set_ayuv_argb;
break;
@ -2536,9 +2480,9 @@ gst_alpha_set_process_function (GstAlpha * alpha)
case ALPHA_METHOD_GREEN:
case ALPHA_METHOD_BLUE:
case ALPHA_METHOD_CUSTOM:
switch (alpha->out_format) {
switch (GST_VIDEO_INFO_FORMAT (&alpha->out_info)) {
case GST_VIDEO_FORMAT_AYUV:
switch (alpha->in_format) {
switch (GST_VIDEO_INFO_FORMAT (&alpha->in_info)) {
case GST_VIDEO_FORMAT_AYUV:
alpha->process = gst_alpha_chroma_key_ayuv_ayuv;
break;
@ -2576,7 +2520,7 @@ gst_alpha_set_process_function (GstAlpha * alpha)
case GST_VIDEO_FORMAT_ABGR:
case GST_VIDEO_FORMAT_RGBA:
case GST_VIDEO_FORMAT_BGRA:
switch (alpha->in_format) {
switch (GST_VIDEO_INFO_FORMAT (&alpha->in_info)) {
case GST_VIDEO_FORMAT_AYUV:
alpha->process = gst_alpha_chroma_key_ayuv_argb;
break;

View file

@ -26,8 +26,8 @@
*
* Sample pipeline:
* |[
* gst-launch videotestsrc ! "video/x-raw-yuv,format=(fourcc)AYUV" ! \
* alphacolor ! "video/x-raw-rgb" ! ffmpegcolorspace ! autovideosink
* gst-launch videotestsrc ! "video/x-raw,format=(fourcc)AYUV" ! \
* alphacolor ! videoconvert ! autovideosink
* ]|
*/
@ -49,17 +49,13 @@ GST_DEBUG_CATEGORY_STATIC (alpha_color_debug);
static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_VIDEO_CAPS_RGBA ";" GST_VIDEO_CAPS_BGRA ";"
GST_VIDEO_CAPS_ARGB ";" GST_VIDEO_CAPS_ABGR ";"
GST_VIDEO_CAPS_YUV ("AYUV"))
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("{ RGBA, BGRA, ARGB, ABGR, AYUV }"))
);
static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_VIDEO_CAPS_RGBA ";" GST_VIDEO_CAPS_BGRA ";"
GST_VIDEO_CAPS_ARGB ";" GST_VIDEO_CAPS_ABGR ";"
GST_VIDEO_CAPS_YUV ("AYUV"))
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("{ RGBA, BGRA, ARGB, ABGR, AYUV }"))
);
G_DEFINE_TYPE (GstAlphaColor, gst_alpha_color, GST_TYPE_VIDEO_FILTER);
@ -84,7 +80,7 @@ gst_alpha_color_class_init (GstAlphaColorClass * klass)
gst_element_class_set_details_simple (gstelement_class, "Alpha color filter",
"Filter/Converter/Video",
"ARGB from/to AYUV colorspace conversion preserving the alpha channel",
"Wim Taymans <wim@fluendo.com>");
"Wim Taymans <wim.taymans@gmail.com>");
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&sink_template));
@ -97,7 +93,6 @@ gst_alpha_color_class_init (GstAlphaColorClass * klass)
GST_DEBUG_FUNCPTR (gst_alpha_color_set_caps);
gstbasetransform_class->transform_ip =
GST_DEBUG_FUNCPTR (gst_alpha_color_transform_ip);
}
static void
@ -210,13 +205,18 @@ static const gint cog_ycbcr_hdtv_to_ycbcr_sdtv_matrix_8bit[] = {
#define DEFINE_ARGB_AYUV_FUNCTIONS(name, A, R, G, B) \
static void \
transform_##name##_ayuv (guint8 * data, gint size, const gint *matrix) \
transform_##name##_ayuv (GstVideoFrame * frame, const gint *matrix) \
{ \
guint8 *data; \
gsize size; \
gint y, u, v; \
gint yc[4]; \
gint uc[4]; \
gint vc[4]; \
\
data = GST_VIDEO_FRAME_PLANE_DATA (frame, 0);\
size = GST_VIDEO_FRAME_SIZE (frame);\
\
memcpy (yc, matrix, 4 * sizeof (gint)); \
memcpy (uc, matrix + 4, 4 * sizeof (gint)); \
memcpy (vc, matrix + 8, 4 * sizeof (gint)); \
@ -237,13 +237,18 @@ transform_##name##_ayuv (guint8 * data, gint size, const gint *matrix) \
} \
\
static void \
transform_ayuv_##name (guint8 * data, gint size, const gint *matrix) \
transform_ayuv_##name (GstVideoFrame * frame, const gint *matrix) \
{ \
guint8 *data; \
gsize size; \
gint r, g, b; \
gint rc[4]; \
gint gc[4]; \
gint bc[4]; \
\
data = GST_VIDEO_FRAME_PLANE_DATA (frame, 0);\
size = GST_VIDEO_FRAME_SIZE (frame);\
\
memcpy (rc, matrix, 4 * sizeof (gint)); \
memcpy (gc, matrix + 4, 4 * sizeof (gint)); \
memcpy (bc, matrix + 8, 4 * sizeof (gint)); \
@ -269,8 +274,10 @@ DEFINE_ARGB_AYUV_FUNCTIONS (argb, 0, 1, 2, 3);
DEFINE_ARGB_AYUV_FUNCTIONS (abgr, 0, 3, 2, 1);
static void
transform_ayuv_ayuv (guint8 * data, gint size, const gint * matrix)
transform_ayuv_ayuv (GstVideoFrame * frame, const gint * matrix)
{
guint8 *data;
gsize size;
gint y, u, v;
gint yc[4];
gint uc[4];
@ -279,6 +286,9 @@ transform_ayuv_ayuv (guint8 * data, gint size, const gint * matrix)
if (matrix == NULL)
return;
data = GST_VIDEO_FRAME_PLANE_DATA (frame, 0);
size = GST_VIDEO_FRAME_SIZE (frame);
memcpy (yc, matrix, 4 * sizeof (gint));
memcpy (uc, matrix + 4, 4 * sizeof (gint));
memcpy (vc, matrix + 8, 4 * sizeof (gint));
@ -299,10 +309,15 @@ transform_ayuv_ayuv (guint8 * data, gint size, const gint * matrix)
}
static void
transform_argb_bgra (guint8 * data, gint size, const gint * matrix)
transform_argb_bgra (GstVideoFrame * frame, const gint * matrix)
{
guint8 *data;
gsize size;
gint r, g, b;
data = GST_VIDEO_FRAME_PLANE_DATA (frame, 0);
size = GST_VIDEO_FRAME_SIZE (frame);
while (size > 0) {
r = data[1];
g = data[2];
@ -321,10 +336,15 @@ transform_argb_bgra (guint8 * data, gint size, const gint * matrix)
#define transform_abgr_rgba transform_argb_bgra
static void
transform_argb_abgr (guint8 * data, gint size, const gint * matrix)
transform_argb_abgr (GstVideoFrame * frame, const gint * matrix)
{
guint8 *data;
gsize size;
gint r, g, b;
data = GST_VIDEO_FRAME_PLANE_DATA (frame, 0);
size = GST_VIDEO_FRAME_SIZE (frame);
while (size > 0) {
r = data[1];
g = data[2];
@ -343,10 +363,15 @@ transform_argb_abgr (guint8 * data, gint size, const gint * matrix)
#define transform_abgr_argb transform_argb_abgr
static void
transform_rgba_bgra (guint8 * data, gint size, const gint * matrix)
transform_rgba_bgra (GstVideoFrame * frame, const gint * matrix)
{
guint8 *data;
gsize size;
gint r, g, b;
data = GST_VIDEO_FRAME_PLANE_DATA (frame, 0);
size = GST_VIDEO_FRAME_SIZE (frame);
while (size > 0) {
r = data[0];
g = data[1];
@ -365,10 +390,15 @@ transform_rgba_bgra (guint8 * data, gint size, const gint * matrix)
#define transform_bgra_rgba transform_rgba_bgra
static void
transform_argb_rgba (guint8 * data, gint size, const gint * matrix)
transform_argb_rgba (GstVideoFrame * frame, const gint * matrix)
{
guint8 *data;
gsize size;
gint r, g, b;
data = GST_VIDEO_FRAME_PLANE_DATA (frame, 0);
size = GST_VIDEO_FRAME_SIZE (frame);
while (size > 0) {
r = data[1];
g = data[2];
@ -387,10 +417,15 @@ transform_argb_rgba (guint8 * data, gint size, const gint * matrix)
#define transform_abgr_bgra transform_argb_rgba
static void
transform_bgra_argb (guint8 * data, gint size, const gint * matrix)
transform_bgra_argb (GstVideoFrame * frame, const gint * matrix)
{
guint8 *data;
gsize size;
gint r, g, b;
data = GST_VIDEO_FRAME_PLANE_DATA (frame, 0);
size = GST_VIDEO_FRAME_SIZE (frame);
while (size > 0) {
r = data[2];
g = data[1];
@ -409,10 +444,15 @@ transform_bgra_argb (guint8 * data, gint size, const gint * matrix)
#define transform_rgba_abgr transform_bgra_argb
static void
transform_rgba_argb (guint8 * data, gint size, const gint * matrix)
transform_rgba_argb (GstVideoFrame * frame, const gint * matrix)
{
guint8 *data;
gsize size;
gint r, g, b;
data = GST_VIDEO_FRAME_PLANE_DATA (frame, 0);
size = GST_VIDEO_FRAME_SIZE (frame);
while (size > 0) {
r = data[0];
g = data[1];
@ -436,36 +476,30 @@ gst_alpha_color_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
{
GstAlphaColor *alpha = GST_ALPHA_COLOR (btrans);
gboolean ret;
gint w, h;
gint w2, h2;
GstVideoFormat in_format, out_format;
const gchar *matrix;
GstVideoInfo in_info, out_info;
gboolean in_sdtv, out_sdtv;
alpha->process = NULL;
alpha->matrix = NULL;
ret = gst_video_format_parse_caps (incaps, &in_format, &w, &h);
ret &= gst_video_format_parse_caps (outcaps, &out_format, &w2, &h2);
ret = gst_video_info_from_caps (&in_info, incaps);
ret &= gst_video_info_from_caps (&out_info, outcaps);
if (!ret)
goto invalid_caps;
if (!ret || w != w2 || h != h2) {
GST_DEBUG_OBJECT (alpha, "incomplete or invalid caps!");
return FALSE;
}
if (GST_VIDEO_INFO_WIDTH (&in_info) != GST_VIDEO_INFO_WIDTH (&out_info) ||
GST_VIDEO_INFO_HEIGHT (&in_info) != GST_VIDEO_INFO_HEIGHT (&out_info))
goto invalid_caps;
matrix = gst_video_parse_caps_color_matrix (incaps);
in_sdtv = matrix ? g_str_equal (matrix, "sdtv") : TRUE;
matrix = gst_video_parse_caps_color_matrix (outcaps);
out_sdtv = matrix ? g_str_equal (matrix, "sdtv") : TRUE;
in_sdtv =
in_info.color_matrix ? g_str_equal (in_info.color_matrix, "sdtv") : TRUE;
out_sdtv =
out_info.color_matrix ? g_str_equal (out_info.color_matrix,
"sdtv") : TRUE;
alpha->in_format = in_format;
alpha->out_format = out_format;
alpha->width = w;
alpha->height = h;
switch (alpha->in_format) {
switch (GST_VIDEO_INFO_FORMAT (&in_info)) {
case GST_VIDEO_FORMAT_ARGB:
switch (alpha->out_format) {
switch (GST_VIDEO_INFO_FORMAT (&out_info)) {
case GST_VIDEO_FORMAT_ARGB:
alpha->process = NULL;
alpha->matrix = NULL;
@ -495,7 +529,7 @@ gst_alpha_color_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
}
break;
case GST_VIDEO_FORMAT_BGRA:
switch (alpha->out_format) {
switch (GST_VIDEO_INFO_FORMAT (&out_info)) {
case GST_VIDEO_FORMAT_BGRA:
alpha->process = NULL;
alpha->matrix = NULL;
@ -525,7 +559,7 @@ gst_alpha_color_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
}
break;
case GST_VIDEO_FORMAT_ABGR:
switch (alpha->out_format) {
switch (GST_VIDEO_INFO_FORMAT (&out_info)) {
case GST_VIDEO_FORMAT_ABGR:
alpha->process = NULL;
alpha->matrix = NULL;
@ -555,7 +589,7 @@ gst_alpha_color_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
}
break;
case GST_VIDEO_FORMAT_RGBA:
switch (alpha->out_format) {
switch (GST_VIDEO_INFO_FORMAT (&out_info)) {
case GST_VIDEO_FORMAT_RGBA:
alpha->process = NULL;
alpha->matrix = NULL;
@ -585,7 +619,7 @@ gst_alpha_color_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
}
break;
case GST_VIDEO_FORMAT_AYUV:
switch (alpha->out_format) {
switch (GST_VIDEO_INFO_FORMAT (&out_info)) {
case GST_VIDEO_FORMAT_AYUV:
if (in_sdtv == out_sdtv) {
alpha->process = transform_ayuv_ayuv;
@ -633,44 +667,60 @@ gst_alpha_color_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
break;
}
if (in_format == out_format && in_sdtv == out_sdtv)
if (GST_VIDEO_INFO_FORMAT (&in_info) == GST_VIDEO_INFO_FORMAT (&out_info)
&& in_sdtv == out_sdtv)
gst_base_transform_set_passthrough (btrans, TRUE);
else if (!alpha->process)
return FALSE;
goto no_process;
return TRUE;
/* ERRORS */
invalid_caps:
{
GST_DEBUG_OBJECT (alpha, "incomplete or invalid caps");
return FALSE;
}
no_process:
{
GST_DEBUG_OBJECT (alpha, "could not find process function");
return FALSE;
}
}
static GstFlowReturn
gst_alpha_color_transform_ip (GstBaseTransform * btrans, GstBuffer * inbuf)
{
GstAlphaColor *alpha = GST_ALPHA_COLOR (btrans);
guint8 *data;
gsize size;
GstVideoFrame frame;
if (gst_base_transform_is_passthrough (btrans))
return GST_FLOW_OK;
if (G_UNLIKELY (!alpha->process)) {
if (G_UNLIKELY (!alpha->process))
goto not_negotiated;
if (!gst_video_frame_map (&frame, &alpha->in_info, inbuf, GST_MAP_READWRITE))
goto invalid_buffer;
/* Transform in place */
alpha->process (&frame, alpha->matrix);
gst_video_frame_unmap (&frame);
return GST_FLOW_OK;
/* ERRORS */
not_negotiated:
{
GST_ERROR_OBJECT (alpha, "Not negotiated yet");
return GST_FLOW_NOT_NEGOTIATED;
}
data = gst_buffer_map (inbuf, &size, NULL, GST_MAP_READWRITE);
if (G_UNLIKELY (size != 4 * alpha->width * alpha->height)) {
GST_ERROR_OBJECT (alpha, "Invalid buffer size (was %u, expected %u)",
size, alpha->width * alpha->height);
gst_buffer_unmap (inbuf, data, size);
invalid_buffer:
{
GST_ERROR_OBJECT (alpha, "Invalid buffer received");
return GST_FLOW_ERROR;
}
/* Transform in place */
alpha->process (data, size, alpha->matrix);
gst_buffer_unmap (inbuf, data, size);
return GST_FLOW_OK;
}
static gboolean

View file

@ -43,10 +43,9 @@ struct _GstAlphaColor
/*< private >*/
/* caps */
GstVideoFormat in_format, out_format;
gint width, height;
GstVideoInfo in_info, out_info;
void (*process) (guint8 * data, gint size, const gint * matrix);
void (*process) (GstVideoFrame * frame, const gint * matrix);
const gint *matrix;
};