From ea7446e5b5ad7e2ea15e23d9e7a6bf0746d7c8fa Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 2 Nov 2010 11:57:09 +0100 Subject: [PATCH] video: Add 8-bit paletted RGB API: Add GST_VIDEO_FORMAT_RGB8_PALETTED API: Add GST_VIDEO_CAPS_RGB8_PALETTED API: Add gst_video_parse_caps_palette() --- gst-libs/gst/video/video.c | 86 ++++++++++++++++++++++++++++++++++++++-------- gst-libs/gst/video/video.h | 18 +++++++++- 2 files changed, 89 insertions(+), 15 deletions(-) diff --git a/gst-libs/gst/video/video.c b/gst-libs/gst/video/video.c index ab491d0..f367128 100644 --- a/gst-libs/gst/video/video.c +++ b/gst-libs/gst/video/video.c @@ -349,19 +349,22 @@ gst_video_format_parse_caps (GstCaps * caps, GstVideoFormat * format, } else if (gst_structure_has_name (structure, "video/x-raw-rgb")) { int depth; int bpp; - int endianness; - int red_mask; - int green_mask; - int blue_mask; - int alpha_mask; + int endianness = 0; + int red_mask = 0; + int green_mask = 0; + int blue_mask = 0; + int alpha_mask = 0; gboolean have_alpha; ok &= gst_structure_get_int (structure, "depth", &depth); ok &= gst_structure_get_int (structure, "bpp", &bpp); - ok &= gst_structure_get_int (structure, "endianness", &endianness); - ok &= gst_structure_get_int (structure, "red_mask", &red_mask); - ok &= gst_structure_get_int (structure, "green_mask", &green_mask); - ok &= gst_structure_get_int (structure, "blue_mask", &blue_mask); + + if (bpp != 8) { + ok &= gst_structure_get_int (structure, "endianness", &endianness); + ok &= gst_structure_get_int (structure, "red_mask", &red_mask); + ok &= gst_structure_get_int (structure, "green_mask", &green_mask); + ok &= gst_structure_get_int (structure, "blue_mask", &blue_mask); + } have_alpha = gst_structure_get_int (structure, "alpha_mask", &alpha_mask); if (depth == 24 && bpp == 32 && endianness == G_BIG_ENDIAN) { @@ -390,6 +393,8 @@ gst_video_format_parse_caps (GstCaps * caps, GstVideoFormat * format, if (*format == GST_VIDEO_FORMAT_UNKNOWN) { ok = FALSE; } + } else if (depth == 8 && bpp == 8) { + *format = GST_VIDEO_FORMAT_RGB8_PALETTED; } else { ok = FALSE; } @@ -605,6 +610,10 @@ gst_video_format_new_caps (GstVideoFormat format, int width, depth = 15; have_alpha = FALSE; break; + case GST_VIDEO_FORMAT_RGB8_PALETTED: + bpp = 8; + depth = 8; + have_alpha = FALSE; default: return NULL; } @@ -649,21 +658,26 @@ gst_video_format_new_caps (GstVideoFormat format, int width, default: return NULL; } - } else { + } else if (bpp != 8) { return NULL; } caps = gst_caps_new_simple ("video/x-raw-rgb", "bpp", G_TYPE_INT, bpp, "depth", G_TYPE_INT, depth, - "endianness", G_TYPE_INT, G_BIG_ENDIAN, - "red_mask", G_TYPE_INT, red_mask, - "green_mask", G_TYPE_INT, green_mask, - "blue_mask", G_TYPE_INT, blue_mask, "width", G_TYPE_INT, width, "height", G_TYPE_INT, height, "framerate", GST_TYPE_FRACTION, framerate_n, framerate_d, "pixel-aspect-ratio", GST_TYPE_FRACTION, par_n, par_d, NULL); + + if (bpp != 8) { + gst_caps_set_simple (caps, + "endianness", G_TYPE_INT, G_BIG_ENDIAN, + "red_mask", G_TYPE_INT, red_mask, + "green_mask", G_TYPE_INT, green_mask, + "blue_mask", G_TYPE_INT, blue_mask, NULL); + } + if (have_alpha) { alpha_mask = mask >> (8 * gst_video_format_get_component_offset (format, 3, @@ -985,6 +999,7 @@ gst_video_format_is_rgb (GstVideoFormat format) case GST_VIDEO_FORMAT_BGR16: case GST_VIDEO_FORMAT_RGB15: case GST_VIDEO_FORMAT_BGR15: + case GST_VIDEO_FORMAT_RGB8_PALETTED: return TRUE; default: return FALSE; @@ -1038,6 +1053,7 @@ gst_video_format_is_yuv (GstVideoFormat format) case GST_VIDEO_FORMAT_BGR16: case GST_VIDEO_FORMAT_RGB15: case GST_VIDEO_FORMAT_BGR15: + case GST_VIDEO_FORMAT_RGB8_PALETTED: return FALSE; default: return FALSE; @@ -1107,6 +1123,7 @@ gst_video_format_has_alpha (GstVideoFormat format) case GST_VIDEO_FORMAT_ARGB: case GST_VIDEO_FORMAT_ABGR: case GST_VIDEO_FORMAT_A420: + case GST_VIDEO_FORMAT_RGB8_PALETTED: return TRUE; case GST_VIDEO_FORMAT_RGBx: case GST_VIDEO_FORMAT_BGRx: @@ -1217,6 +1234,8 @@ gst_video_format_get_row_stride (GstVideoFormat format, int component, } else { return GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2); } + case GST_VIDEO_FORMAT_RGB8_PALETTED: + return GST_ROUND_UP_4 (width); default: return 0; } @@ -1303,6 +1322,8 @@ gst_video_format_get_pixel_stride (GstVideoFormat format, int component) case GST_VIDEO_FORMAT_UYVP: /* UYVP is packed at the bit level, so pixel stride doesn't make sense */ return 0; + case GST_VIDEO_FORMAT_RGB8_PALETTED: + return 1; default: return 0; } @@ -1375,6 +1396,7 @@ gst_video_format_get_component_width (GstVideoFormat format, case GST_VIDEO_FORMAT_GRAY16_LE: case GST_VIDEO_FORMAT_Y800: case GST_VIDEO_FORMAT_Y16: + case GST_VIDEO_FORMAT_RGB8_PALETTED: return width; case GST_VIDEO_FORMAT_A420: if (component == 0 || component == 3) { @@ -1449,6 +1471,7 @@ gst_video_format_get_component_height (GstVideoFormat format, case GST_VIDEO_FORMAT_Y800: case GST_VIDEO_FORMAT_Y16: case GST_VIDEO_FORMAT_UYVP: + case GST_VIDEO_FORMAT_RGB8_PALETTED: return height; case GST_VIDEO_FORMAT_A420: if (component == 0 || component == 3) { @@ -1673,6 +1696,8 @@ gst_video_format_get_component_offset (GstVideoFormat format, 2 * GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2) * (GST_ROUND_UP_2 (height) / 2); } + case GST_VIDEO_FORMAT_RGB8_PALETTED: + return 0; default: return 0; } @@ -1746,6 +1771,7 @@ gst_video_format_get_size (GstVideoFormat format, int width, int height) return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height) * 3 / 2; case GST_VIDEO_FORMAT_GRAY8: case GST_VIDEO_FORMAT_Y800: + case GST_VIDEO_FORMAT_RGB8_PALETTED: return GST_ROUND_UP_4 (width) * height; case GST_VIDEO_FORMAT_GRAY16_BE: case GST_VIDEO_FORMAT_GRAY16_LE: @@ -1958,3 +1984,35 @@ gst_video_event_parse_still_frame (GstEvent * event, gboolean * in_still) *in_still = ev_still_state; return TRUE; } + +/** + * gst_video_parse_caps_palette: + * @caps: #GstCaps to parse + * + * Returns the palette data from the caps as a #GstBuffer. For + * #GST_VIDEO_FORMAT_RGB8_PALETTED this is containing 256 #guint32 + * values, each containing ARGB colors in native endianness. + * + * Returns: a #GstBuffer containing the palette data. Unref after usage. + * Since: 0.10.32 + */ +GstBuffer * +gst_video_parse_caps_palette (GstCaps * caps) +{ + GstStructure *s; + const GValue *p_v; + GstBuffer *p; + + if (!gst_caps_is_fixed (caps)) + return NULL; + + s = gst_caps_get_structure (caps, 0); + + p_v = gst_structure_get_value (s, "palette_data"); + if (!p_v || !GST_VALUE_HOLDS_BUFFER (p_v)) + return NULL; + + p = gst_buffer_ref (gst_value_get_buffer (p_v)); + + return p; +} diff --git a/gst-libs/gst/video/video.h b/gst-libs/gst/video/video.h index 85937a1..fd8e659 100644 --- a/gst-libs/gst/video/video.h +++ b/gst-libs/gst/video/video.h @@ -65,6 +65,7 @@ G_BEGIN_DECLS * @GST_VIDEO_FORMAT_BGR15: reverse rgb 5-5-5 bits per component (Since: 0.10.30) * @GST_VIDEO_FORMAT_UYVP: packed 10-bit 4:2:2 YUV (U0-Y0-V0-Y1 U2-Y2-V2-Y3 U4 ...) (Since: 0.10.31) * @GST_VIDEO_FORMAT_A420: planar 4:4:2:0 AYUV (Since: 0.10.31) + * @GST_VIDEO_FORMAT_RGB8_PALETTED: 8-bit paletted RGB (Since: 0.10.32) * * Enum value describing the most common video formats. */ @@ -104,7 +105,8 @@ typedef enum { GST_VIDEO_FORMAT_RGB15, GST_VIDEO_FORMAT_BGR15, GST_VIDEO_FORMAT_UYVP, - GST_VIDEO_FORMAT_A420 + GST_VIDEO_FORMAT_A420, + GST_VIDEO_FORMAT_RGB8_PALETTED } GstVideoFormat; #define GST_VIDEO_BYTE1_MASK_32 "0xFF000000" @@ -289,6 +291,19 @@ typedef enum { __GST_VIDEO_CAPS_MAKE_15 (3, 2, 1) /** + * GST_VIDEO_CAPS_RGB8_PALETTED: + * + * Generic caps string for 8-bit paletted RGB video, for use in pad templates. + * + * Since: 0.10.32 + */ +#define GST_VIDEO_CAPS_RGB8_PALETTED \ + "video/x-raw-rgb, bpp = (int)8, depth = (int)8, " \ + "width = "GST_VIDEO_SIZE_RANGE" , " \ + "height = " GST_VIDEO_SIZE_RANGE ", " \ + "framerate = "GST_VIDEO_FPS_RANGE + +/** * GST_VIDEO_CAPS_YUV: * @fourcc: YUV fourcc format that describes the pixel layout, as string * (e.g. "I420", "YV12", "YUY2", "AYUV", etc.) @@ -387,6 +402,7 @@ gboolean gst_video_parse_caps_pixel_aspect_ratio (GstCaps *caps, int *par_n, int *par_d); const char *gst_video_parse_caps_color_matrix (GstCaps * caps); const char *gst_video_parse_caps_chroma_site (GstCaps * caps); +GstBuffer *gst_video_parse_caps_palette (GstCaps * caps); GstCaps * gst_video_format_new_caps (GstVideoFormat format, int width, int height, int framerate_n, int framerate_d, int par_n, int par_d); -- 2.7.4