mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-12 10:25:33 +00:00
tests: image: allow creation of images with interleaved patterns.
Add image_generate_full() function to create interleaved color rectangles. If flags is zero, the whole frame is generated with a unique pattern. If flags is non-zero, then each field is handled individually.
This commit is contained in:
parent
dd6a0d87ff
commit
b1085b57d5
2 changed files with 100 additions and 28 deletions
113
tests/image.c
113
tests/image.c
|
@ -21,6 +21,40 @@
|
||||||
|
|
||||||
#include "image.h"
|
#include "image.h"
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
image_draw_rectangle(
|
||||||
|
GstVaapiImage *image,
|
||||||
|
gint x,
|
||||||
|
gint y,
|
||||||
|
guint width,
|
||||||
|
guint height,
|
||||||
|
guint32 color,
|
||||||
|
guint32 flags
|
||||||
|
);
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
image_draw_color_rectangles(
|
||||||
|
GstVaapiImage *image,
|
||||||
|
guint width,
|
||||||
|
guint height,
|
||||||
|
const guint32 colors[4],
|
||||||
|
guint32 flags
|
||||||
|
)
|
||||||
|
{
|
||||||
|
const guint w = width / 2;
|
||||||
|
const guint h = height / 2;
|
||||||
|
|
||||||
|
if (!image_draw_rectangle(image, 0, 0, w, h, colors[0], flags))
|
||||||
|
return FALSE;
|
||||||
|
if (!image_draw_rectangle(image, w, 0, w, h, colors[1], flags))
|
||||||
|
return FALSE;
|
||||||
|
if (!image_draw_rectangle(image, 0, h, w, h, colors[2], flags))
|
||||||
|
return FALSE;
|
||||||
|
if (!image_draw_rectangle(image, w, h, w, h, colors[3], flags))
|
||||||
|
return FALSE;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
GstVaapiImage *
|
GstVaapiImage *
|
||||||
image_generate(
|
image_generate(
|
||||||
GstVaapiDisplay *display,
|
GstVaapiDisplay *display,
|
||||||
|
@ -29,20 +63,49 @@ image_generate(
|
||||||
guint height
|
guint height
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
const guint w = width;
|
return image_generate_full(display, format, width, height, 0);
|
||||||
const guint h = height;
|
}
|
||||||
|
|
||||||
|
GstVaapiImage *
|
||||||
|
image_generate_full(
|
||||||
|
GstVaapiDisplay *display,
|
||||||
|
GstVideoFormat format,
|
||||||
|
guint width,
|
||||||
|
guint height,
|
||||||
|
guint32 flags
|
||||||
|
)
|
||||||
|
{
|
||||||
GstVaapiImage *image;
|
GstVaapiImage *image;
|
||||||
|
|
||||||
image = gst_vaapi_image_new(display, format, w, h);
|
static const guint32 rgb_colors[4] =
|
||||||
|
{ 0xffff0000, 0xff00ff00, 0xff0000ff, 0xff000000 };
|
||||||
|
static const guint32 bgr_colors[4] =
|
||||||
|
{ 0xff000000, 0xff0000ff, 0xff00ff00, 0xffff0000 };
|
||||||
|
static const guint32 inv_colors[4] =
|
||||||
|
{ 0xffdeadc0, 0xffdeadc0, 0xffdeadc0, 0xffdeadc0 };
|
||||||
|
|
||||||
|
image = gst_vaapi_image_new(display, format, width, height);
|
||||||
if (!image)
|
if (!image)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (image_draw_rectangle(image, 0, 0, w/2, h/2, 0xffff0000) &&
|
if (flags) {
|
||||||
image_draw_rectangle(image, w/2, 0, w/2, h/2, 0xff00ff00) &&
|
if (!image_draw_color_rectangles(image, width, height,
|
||||||
image_draw_rectangle(image, 0, h/2, w/2, h/2, 0xff0000ff) &&
|
((flags & GST_VAAPI_PICTURE_STRUCTURE_TOP_FIELD) ?
|
||||||
image_draw_rectangle(image, w/2, h/2, w/2, h/2, 0xff000000))
|
rgb_colors : inv_colors),
|
||||||
return image;
|
GST_VAAPI_PICTURE_STRUCTURE_TOP_FIELD))
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
if (!image_draw_color_rectangles(image, width, height,
|
||||||
|
((flags & GST_VAAPI_PICTURE_STRUCTURE_BOTTOM_FIELD) ?
|
||||||
|
bgr_colors : inv_colors),
|
||||||
|
GST_VAAPI_PICTURE_STRUCTURE_BOTTOM_FIELD))
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
else if (!image_draw_color_rectangles(image, width, height, rgb_colors, 0))
|
||||||
|
goto error;
|
||||||
|
return image;
|
||||||
|
|
||||||
|
error:
|
||||||
gst_vaapi_object_unref(image);
|
gst_vaapi_object_unref(image);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -290,7 +353,8 @@ image_draw_rectangle(
|
||||||
gint y,
|
gint y,
|
||||||
guint width,
|
guint width,
|
||||||
guint height,
|
guint height,
|
||||||
guint32 color
|
guint32 color,
|
||||||
|
guint32 flags
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
const GstVideoFormat image_format = gst_vaapi_image_get_format(image);
|
const GstVideoFormat image_format = gst_vaapi_image_get_format(image);
|
||||||
|
@ -328,6 +392,15 @@ image_draw_rectangle(
|
||||||
if (!draw_rect)
|
if (!draw_rect)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
if (x < 0)
|
||||||
|
x = 0;
|
||||||
|
if (y < 0)
|
||||||
|
y = 0;
|
||||||
|
if (width > image_width - x)
|
||||||
|
width = image_width - x;
|
||||||
|
if (height > image_height - y)
|
||||||
|
height = image_height - y;
|
||||||
|
|
||||||
display = gst_vaapi_object_get_display(GST_VAAPI_OBJECT(image));
|
display = gst_vaapi_object_get_display(GST_VAAPI_OBJECT(image));
|
||||||
if (!display)
|
if (!display)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -338,23 +411,23 @@ image_draw_rectangle(
|
||||||
for (i = 0; i < gst_vaapi_image_get_plane_count(image); i++) {
|
for (i = 0; i < gst_vaapi_image_get_plane_count(image); i++) {
|
||||||
pixels[i] = gst_vaapi_image_get_plane(image, i);
|
pixels[i] = gst_vaapi_image_get_plane(image, i);
|
||||||
stride[i] = gst_vaapi_image_get_pitch(image, i);
|
stride[i] = gst_vaapi_image_get_pitch(image, i);
|
||||||
|
switch (flags) {
|
||||||
|
case GST_VAAPI_PICTURE_STRUCTURE_BOTTOM_FIELD:
|
||||||
|
pixels[i] += stride[i];
|
||||||
|
// fall-through
|
||||||
|
case GST_VAAPI_PICTURE_STRUCTURE_TOP_FIELD:
|
||||||
|
stride[i] *= 2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (flags)
|
||||||
|
y /= 2, height /= 2;
|
||||||
|
|
||||||
if (gst_vaapi_video_format_is_yuv(image_format))
|
if (gst_vaapi_video_format_is_yuv(image_format))
|
||||||
color = argb2yuv(color);
|
color = argb2yuv(color);
|
||||||
|
|
||||||
if (x < 0)
|
|
||||||
x = 0;
|
|
||||||
if (y < 0)
|
|
||||||
y = 0;
|
|
||||||
if (width > image_width - x)
|
|
||||||
width = image_width - x;
|
|
||||||
if (height > image_height - y)
|
|
||||||
height = image_height - y;
|
|
||||||
|
|
||||||
gst_vaapi_display_lock(display);
|
|
||||||
draw_rect(pixels, stride, x, y, width, height, color);
|
draw_rect(pixels, stride, x, y, width, height, color);
|
||||||
gst_vaapi_display_unlock(display);
|
|
||||||
return gst_vaapi_image_unmap(image);
|
return gst_vaapi_image_unmap(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,14 +33,13 @@ image_generate(
|
||||||
guint height
|
guint height
|
||||||
);
|
);
|
||||||
|
|
||||||
gboolean
|
GstVaapiImage *
|
||||||
image_draw_rectangle(
|
image_generate_full(
|
||||||
GstVaapiImage *image,
|
GstVaapiDisplay *display,
|
||||||
gint x,
|
GstVideoFormat format,
|
||||||
gint y,
|
guint width,
|
||||||
guint width,
|
guint height,
|
||||||
guint height,
|
guint32 flags
|
||||||
guint32 color
|
|
||||||
);
|
);
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
|
|
Loading…
Reference in a new issue