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()
This commit is contained in:
Sebastian Dröge 2010-11-02 11:57:09 +01:00
parent 1abb8257a0
commit ea7446e5b5
2 changed files with 89 additions and 15 deletions

View File

@ -349,19 +349,22 @@ gst_video_format_parse_caps (GstCaps * caps, GstVideoFormat * format,
} else if (gst_structure_has_name (structure, "video/x-raw-rgb")) { } else if (gst_structure_has_name (structure, "video/x-raw-rgb")) {
int depth; int depth;
int bpp; int bpp;
int endianness; int endianness = 0;
int red_mask; int red_mask = 0;
int green_mask; int green_mask = 0;
int blue_mask; int blue_mask = 0;
int alpha_mask; int alpha_mask = 0;
gboolean have_alpha; gboolean have_alpha;
ok &= gst_structure_get_int (structure, "depth", &depth); ok &= gst_structure_get_int (structure, "depth", &depth);
ok &= gst_structure_get_int (structure, "bpp", &bpp); ok &= gst_structure_get_int (structure, "bpp", &bpp);
if (bpp != 8) {
ok &= gst_structure_get_int (structure, "endianness", &endianness); ok &= gst_structure_get_int (structure, "endianness", &endianness);
ok &= gst_structure_get_int (structure, "red_mask", &red_mask); 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, "green_mask", &green_mask);
ok &= gst_structure_get_int (structure, "blue_mask", &blue_mask); ok &= gst_structure_get_int (structure, "blue_mask", &blue_mask);
}
have_alpha = gst_structure_get_int (structure, "alpha_mask", &alpha_mask); have_alpha = gst_structure_get_int (structure, "alpha_mask", &alpha_mask);
if (depth == 24 && bpp == 32 && endianness == G_BIG_ENDIAN) { 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) { if (*format == GST_VIDEO_FORMAT_UNKNOWN) {
ok = FALSE; ok = FALSE;
} }
} else if (depth == 8 && bpp == 8) {
*format = GST_VIDEO_FORMAT_RGB8_PALETTED;
} else { } else {
ok = FALSE; ok = FALSE;
} }
@ -605,6 +610,10 @@ gst_video_format_new_caps (GstVideoFormat format, int width,
depth = 15; depth = 15;
have_alpha = FALSE; have_alpha = FALSE;
break; break;
case GST_VIDEO_FORMAT_RGB8_PALETTED:
bpp = 8;
depth = 8;
have_alpha = FALSE;
default: default:
return NULL; return NULL;
} }
@ -649,21 +658,26 @@ gst_video_format_new_caps (GstVideoFormat format, int width,
default: default:
return NULL; return NULL;
} }
} else { } else if (bpp != 8) {
return NULL; return NULL;
} }
caps = gst_caps_new_simple ("video/x-raw-rgb", caps = gst_caps_new_simple ("video/x-raw-rgb",
"bpp", G_TYPE_INT, bpp, "bpp", G_TYPE_INT, bpp,
"depth", G_TYPE_INT, depth, "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, "width", G_TYPE_INT, width,
"height", G_TYPE_INT, height, "height", G_TYPE_INT, height,
"framerate", GST_TYPE_FRACTION, framerate_n, framerate_d, "framerate", GST_TYPE_FRACTION, framerate_n, framerate_d,
"pixel-aspect-ratio", GST_TYPE_FRACTION, par_n, par_d, NULL); "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) { if (have_alpha) {
alpha_mask = alpha_mask =
mask >> (8 * gst_video_format_get_component_offset (format, 3, 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_BGR16:
case GST_VIDEO_FORMAT_RGB15: case GST_VIDEO_FORMAT_RGB15:
case GST_VIDEO_FORMAT_BGR15: case GST_VIDEO_FORMAT_BGR15:
case GST_VIDEO_FORMAT_RGB8_PALETTED:
return TRUE; return TRUE;
default: default:
return FALSE; return FALSE;
@ -1038,6 +1053,7 @@ gst_video_format_is_yuv (GstVideoFormat format)
case GST_VIDEO_FORMAT_BGR16: case GST_VIDEO_FORMAT_BGR16:
case GST_VIDEO_FORMAT_RGB15: case GST_VIDEO_FORMAT_RGB15:
case GST_VIDEO_FORMAT_BGR15: case GST_VIDEO_FORMAT_BGR15:
case GST_VIDEO_FORMAT_RGB8_PALETTED:
return FALSE; return FALSE;
default: default:
return FALSE; return FALSE;
@ -1107,6 +1123,7 @@ gst_video_format_has_alpha (GstVideoFormat format)
case GST_VIDEO_FORMAT_ARGB: case GST_VIDEO_FORMAT_ARGB:
case GST_VIDEO_FORMAT_ABGR: case GST_VIDEO_FORMAT_ABGR:
case GST_VIDEO_FORMAT_A420: case GST_VIDEO_FORMAT_A420:
case GST_VIDEO_FORMAT_RGB8_PALETTED:
return TRUE; return TRUE;
case GST_VIDEO_FORMAT_RGBx: case GST_VIDEO_FORMAT_RGBx:
case GST_VIDEO_FORMAT_BGRx: case GST_VIDEO_FORMAT_BGRx:
@ -1217,6 +1234,8 @@ gst_video_format_get_row_stride (GstVideoFormat format, int component,
} else { } else {
return GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2); return GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2);
} }
case GST_VIDEO_FORMAT_RGB8_PALETTED:
return GST_ROUND_UP_4 (width);
default: default:
return 0; return 0;
} }
@ -1303,6 +1322,8 @@ gst_video_format_get_pixel_stride (GstVideoFormat format, int component)
case GST_VIDEO_FORMAT_UYVP: case GST_VIDEO_FORMAT_UYVP:
/* UYVP is packed at the bit level, so pixel stride doesn't make sense */ /* UYVP is packed at the bit level, so pixel stride doesn't make sense */
return 0; return 0;
case GST_VIDEO_FORMAT_RGB8_PALETTED:
return 1;
default: default:
return 0; return 0;
} }
@ -1375,6 +1396,7 @@ gst_video_format_get_component_width (GstVideoFormat format,
case GST_VIDEO_FORMAT_GRAY16_LE: case GST_VIDEO_FORMAT_GRAY16_LE:
case GST_VIDEO_FORMAT_Y800: case GST_VIDEO_FORMAT_Y800:
case GST_VIDEO_FORMAT_Y16: case GST_VIDEO_FORMAT_Y16:
case GST_VIDEO_FORMAT_RGB8_PALETTED:
return width; return width;
case GST_VIDEO_FORMAT_A420: case GST_VIDEO_FORMAT_A420:
if (component == 0 || component == 3) { 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_Y800:
case GST_VIDEO_FORMAT_Y16: case GST_VIDEO_FORMAT_Y16:
case GST_VIDEO_FORMAT_UYVP: case GST_VIDEO_FORMAT_UYVP:
case GST_VIDEO_FORMAT_RGB8_PALETTED:
return height; return height;
case GST_VIDEO_FORMAT_A420: case GST_VIDEO_FORMAT_A420:
if (component == 0 || component == 3) { 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) * 2 * GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2) *
(GST_ROUND_UP_2 (height) / 2); (GST_ROUND_UP_2 (height) / 2);
} }
case GST_VIDEO_FORMAT_RGB8_PALETTED:
return 0;
default: default:
return 0; 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; return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height) * 3 / 2;
case GST_VIDEO_FORMAT_GRAY8: case GST_VIDEO_FORMAT_GRAY8:
case GST_VIDEO_FORMAT_Y800: case GST_VIDEO_FORMAT_Y800:
case GST_VIDEO_FORMAT_RGB8_PALETTED:
return GST_ROUND_UP_4 (width) * height; return GST_ROUND_UP_4 (width) * height;
case GST_VIDEO_FORMAT_GRAY16_BE: case GST_VIDEO_FORMAT_GRAY16_BE:
case GST_VIDEO_FORMAT_GRAY16_LE: 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; *in_still = ev_still_state;
return TRUE; 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;
}

View File

@ -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_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_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_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. * Enum value describing the most common video formats.
*/ */
@ -104,7 +105,8 @@ typedef enum {
GST_VIDEO_FORMAT_RGB15, GST_VIDEO_FORMAT_RGB15,
GST_VIDEO_FORMAT_BGR15, GST_VIDEO_FORMAT_BGR15,
GST_VIDEO_FORMAT_UYVP, GST_VIDEO_FORMAT_UYVP,
GST_VIDEO_FORMAT_A420 GST_VIDEO_FORMAT_A420,
GST_VIDEO_FORMAT_RGB8_PALETTED
} GstVideoFormat; } GstVideoFormat;
#define GST_VIDEO_BYTE1_MASK_32 "0xFF000000" #define GST_VIDEO_BYTE1_MASK_32 "0xFF000000"
@ -288,6 +290,19 @@ typedef enum {
#define GST_VIDEO_CAPS_BGR_15 \ #define GST_VIDEO_CAPS_BGR_15 \
__GST_VIDEO_CAPS_MAKE_15 (3, 2, 1) __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: * GST_VIDEO_CAPS_YUV:
* @fourcc: YUV fourcc format that describes the pixel layout, as string * @fourcc: YUV fourcc format that describes the pixel layout, as string
@ -387,6 +402,7 @@ gboolean gst_video_parse_caps_pixel_aspect_ratio (GstCaps *caps,
int *par_n, int *par_d); int *par_n, int *par_d);
const char *gst_video_parse_caps_color_matrix (GstCaps * caps); const char *gst_video_parse_caps_color_matrix (GstCaps * caps);
const char *gst_video_parse_caps_chroma_site (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, GstCaps * gst_video_format_new_caps (GstVideoFormat format,
int width, int height, int framerate_n, int framerate_d, int width, int height, int framerate_n, int framerate_d,
int par_n, int par_d); int par_n, int par_d);