mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-04 22:48:54 +00:00
video: fix paletted format
RGB8_PALETTED -> RGB8P Fix the definition of paletted formats, store the palette in the second plane. Make sure we copy the palette correctly in gst_video_frame_copy() Don't do alignment on the palette in videopool
This commit is contained in:
parent
225d19aa10
commit
7f134c1441
5 changed files with 46 additions and 56 deletions
|
@ -101,7 +101,7 @@ gst_video_info_align (GstVideoInfo * info, GstVideoAlignment * align)
|
|||
const GstVideoFormatInfo *vinfo = info->finfo;
|
||||
gint width, height;
|
||||
gint padded_width, padded_height;
|
||||
gint i;
|
||||
gint i, n_comp;
|
||||
|
||||
width = GST_VIDEO_INFO_WIDTH (info);
|
||||
height = GST_VIDEO_INFO_HEIGHT (info);
|
||||
|
@ -119,9 +119,13 @@ gst_video_info_align (GstVideoInfo * info, GstVideoAlignment * align)
|
|||
info->width = width;
|
||||
info->height = height;
|
||||
|
||||
n_comp = GST_VIDEO_INFO_N_COMPONENTS (info);
|
||||
if (GST_VIDEO_FORMAT_INFO_HAS_PALETTE (vinfo))
|
||||
n_comp--;
|
||||
|
||||
/* FIXME, not quite correct, NV12 would apply the vedge twice on the second
|
||||
* plane */
|
||||
for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (info); i++) {
|
||||
for (i = 0; i < n_comp; i++) {
|
||||
gint vedge, hedge, plane;
|
||||
|
||||
hedge = GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (vinfo, i, align->padding_left);
|
||||
|
|
|
@ -1270,6 +1270,7 @@ typedef struct
|
|||
/* depths: bits, n_components, shift, depth */
|
||||
#define DPTH0 0, 0, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
|
||||
#define DPTH8 8, 1, { 0, 0, 0, 0 }, { 8, 0, 0, 0 }
|
||||
#define DPTH8_32 8, 2, { 0, 0, 0, 0 }, { 8, 32, 0, 0 }
|
||||
#define DPTH888 8, 3, { 0, 0, 0, 0 }, { 8, 8, 8, 0 }
|
||||
#define DPTH8888 8, 4, { 0, 0, 0, 0 }, { 8, 8, 8, 8 }
|
||||
#define DPTH10_10_10 10, 3, { 0, 0, 0, 0 }, { 10, 10, 10, 0 }
|
||||
|
@ -1282,6 +1283,7 @@ typedef struct
|
|||
/* pixel strides */
|
||||
#define PSTR0 { 0, 0, 0, 0 }
|
||||
#define PSTR1 { 1, 0, 0, 0 }
|
||||
#define PSTR14 { 1, 4, 0, 0 }
|
||||
#define PSTR111 { 1, 1, 1, 0 }
|
||||
#define PSTR1111 { 1, 1, 1, 1 }
|
||||
#define PSTR122 { 1, 2, 2, 0 }
|
||||
|
@ -1297,6 +1299,7 @@ typedef struct
|
|||
/* planes */
|
||||
#define PLANE_NA 0, { 0, 0, 0, 0 }
|
||||
#define PLANE0 1, { 0, 0, 0, 0 }
|
||||
#define PLANE01 2, { 0, 1, 0, 0 }
|
||||
#define PLANE011 2, { 0, 1, 1, 0 }
|
||||
#define PLANE012 3, { 0, 1, 2, 0 }
|
||||
#define PLANE0123 4, { 0, 1, 2, 3 }
|
||||
|
@ -1327,6 +1330,7 @@ typedef struct
|
|||
#define SUB420 { 0, 1, 1, 0 }, { 0, 1, 1, 0 }
|
||||
#define SUB422 { 0, 1, 1, 0 }, { 0, 0, 0, 0 }
|
||||
#define SUB4 { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
|
||||
#define SUB44 { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
|
||||
#define SUB444 { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
|
||||
#define SUB4444 { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
|
||||
#define SUB4204 { 0, 1, 1, 0 }, { 0, 1, 1, 0 }
|
||||
|
@ -1346,6 +1350,8 @@ typedef struct
|
|||
{ 0x00000000, {GST_VIDEO_FORMAT_ ##name, G_STRINGIFY(name), desc, GST_VIDEO_FORMAT_FLAG_RGB | GST_VIDEO_FORMAT_FLAG_LE, depth, pstride, plane, offs, sub, pack } }
|
||||
#define MAKE_RGBA_FORMAT(name, desc, depth, pstride, plane, offs, sub, pack) \
|
||||
{ 0x00000000, {GST_VIDEO_FORMAT_ ##name, G_STRINGIFY(name), desc, GST_VIDEO_FORMAT_FLAG_RGB | GST_VIDEO_FORMAT_FLAG_ALPHA, depth, pstride, plane, offs, sub, pack } }
|
||||
#define MAKE_RGBAP_FORMAT(name, desc, depth, pstride, plane, offs, sub, pack) \
|
||||
{ 0x00000000, {GST_VIDEO_FORMAT_ ##name, G_STRINGIFY(name), desc, GST_VIDEO_FORMAT_FLAG_RGB | GST_VIDEO_FORMAT_FLAG_ALPHA | GST_VIDEO_FORMAT_FLAG_PALETTE, depth, pstride, plane, offs, sub, pack } }
|
||||
|
||||
#define MAKE_GRAY_FORMAT(name, desc, depth, pstride, plane, offs, sub, pack) \
|
||||
{ 0x00000000, {GST_VIDEO_FORMAT_ ##name, G_STRINGIFY(name), desc, GST_VIDEO_FORMAT_FLAG_GRAY, depth, pstride, plane, offs, sub, pack } }
|
||||
|
@ -1457,8 +1463,8 @@ static VideoFormat formats[] = {
|
|||
MAKE_YUVA_FORMAT (A420, "raw video", GST_MAKE_FOURCC ('A', '4', '2', '0'),
|
||||
DPTH8888,
|
||||
PSTR1111, PLANE0123, OFFS0, SUB4204, PACK_A420),
|
||||
MAKE_RGBA_FORMAT (RGB8_PALETTED, "raw video", DPTH8888, PSTR1111, PLANE0,
|
||||
OFFS0, SUB4444, PACK_RGB8P),
|
||||
MAKE_RGBAP_FORMAT (RGB8P, "raw video", DPTH8_32, PSTR14, PLANE01,
|
||||
OFFS0, SUB44, PACK_RGB8P),
|
||||
MAKE_YUV_FORMAT (YUV9, "raw video", GST_MAKE_FOURCC ('Y', 'U', 'V', '9'),
|
||||
DPTH888, PSTR111,
|
||||
PLANE012, OFFS0, SUB410, PACK_410),
|
||||
|
@ -1686,7 +1692,7 @@ gst_video_format_from_masks (gint depth, gint bpp, gint endianness,
|
|||
format = gst_video_format_from_rgb16_masks (red_mask, green_mask,
|
||||
blue_mask);
|
||||
} else if (depth == 8 && bpp == 8) {
|
||||
format = GST_VIDEO_FORMAT_RGB8_PALETTED;
|
||||
format = GST_VIDEO_FORMAT_RGB8P;
|
||||
} else if (depth == 64 && bpp == 64) {
|
||||
format = gst_video_format_from_rgba32_masks (red_mask, green_mask,
|
||||
blue_mask, alpha_mask);
|
||||
|
@ -2491,6 +2497,10 @@ gst_video_frame_copy (GstVideoFrame * dest, const GstVideoFrame * src)
|
|||
&& dinfo->height == sinfo->height, FALSE);
|
||||
|
||||
n_planes = dinfo->finfo->n_planes;
|
||||
if (GST_VIDEO_FORMAT_INFO_HAS_PALETTE (sinfo->finfo)) {
|
||||
memcpy (dest->data[1], src->data[1], 256 * 4);
|
||||
n_planes = 1;
|
||||
}
|
||||
|
||||
for (i = 0; i < n_planes; i++)
|
||||
gst_video_frame_copy_plane (dest, src, i);
|
||||
|
@ -2569,10 +2579,12 @@ fill_planes (GstVideoInfo * info)
|
|||
info->offset[0] = 0;
|
||||
info->size = info->stride[0] * height;
|
||||
break;
|
||||
case GST_VIDEO_FORMAT_RGB8_PALETTED:
|
||||
case GST_VIDEO_FORMAT_RGB8P:
|
||||
info->stride[0] = GST_ROUND_UP_4 (width);
|
||||
info->stride[1] = 4;
|
||||
info->offset[0] = 0;
|
||||
info->size = info->stride[0] * height;
|
||||
info->offset[1] = info->stride[0] * height;
|
||||
info->size = info->offset[1] + (4 * 256);
|
||||
break;
|
||||
case GST_VIDEO_FORMAT_IYU1:
|
||||
info->stride[0] = GST_ROUND_UP_4 (GST_ROUND_UP_4 (width) +
|
||||
|
@ -2877,38 +2889,6 @@ gst_video_event_parse_still_frame (GstEvent * event, gboolean * in_still)
|
|||
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 = g_value_dup_boxed (p_v);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
#define GST_VIDEO_EVENT_FORCE_KEY_UNIT_NAME "GstForceKeyUnit"
|
||||
|
||||
/**
|
||||
|
|
|
@ -63,7 +63,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)
|
||||
* @GST_VIDEO_FORMAT_RGB8P: 8-bit paletted RGB (Since: 0.10.32)
|
||||
* @GST_VIDEO_FORMAT_YUV9: planar 4:1:0 YUV (Since: 0.10.32)
|
||||
* @GST_VIDEO_FORMAT_YVU9: planar 4:1:0 YUV (like YUV9 but UV planes swapped) (Since: 0.10.32)
|
||||
* @GST_VIDEO_FORMAT_IYU1: packed 4:1:1 YUV (Cb-Y0-Y1-Cr-Y2-Y3 ...) (Since: 0.10.32)
|
||||
|
@ -111,7 +111,7 @@ typedef enum {
|
|||
GST_VIDEO_FORMAT_BGR15,
|
||||
GST_VIDEO_FORMAT_UYVP,
|
||||
GST_VIDEO_FORMAT_A420,
|
||||
GST_VIDEO_FORMAT_RGB8_PALETTED,
|
||||
GST_VIDEO_FORMAT_RGB8P,
|
||||
GST_VIDEO_FORMAT_YUV9,
|
||||
GST_VIDEO_FORMAT_YVU9,
|
||||
GST_VIDEO_FORMAT_IYU1,
|
||||
|
@ -167,7 +167,8 @@ typedef enum {
|
|||
* the number 3.
|
||||
* @GST_VIDEO_FORMAT_FLAG_LE: The video format has data stored in little
|
||||
* endianness.
|
||||
* @GST_VIDEO_FORMAT_FLAG_PALETTE: The video format has a palette.
|
||||
* @GST_VIDEO_FORMAT_FLAG_PALETTE: The video format has a palette. The palette
|
||||
* is stored in the second plane and indexes are stored in the first plane.
|
||||
* @GST_VIDEO_FORMAT_FLAG_COMPLEX: The video format has a complex layout that
|
||||
* can't be described with the usual information in the #GstVideoFormatInfo.
|
||||
*
|
||||
|
@ -184,16 +185,23 @@ typedef enum
|
|||
GST_VIDEO_FORMAT_FLAG_COMPLEX = (1 << 6)
|
||||
} GstVideoFormatFlags;
|
||||
|
||||
/* YUV components */
|
||||
#define GST_VIDEO_COMP_Y 0
|
||||
#define GST_VIDEO_COMP_U 1
|
||||
#define GST_VIDEO_COMP_V 2
|
||||
|
||||
/* RGB components */
|
||||
#define GST_VIDEO_COMP_R 0
|
||||
#define GST_VIDEO_COMP_G 1
|
||||
#define GST_VIDEO_COMP_B 2
|
||||
|
||||
/* alpha component */
|
||||
#define GST_VIDEO_COMP_A 3
|
||||
|
||||
/* palette components */
|
||||
#define GST_VIDEO_COMP_INDEX 0
|
||||
#define GST_VIDEO_COMP_PALETTE 1
|
||||
|
||||
/**
|
||||
* GstVideoPackFlags:
|
||||
* @GST_VIDEO_PACK_FLAG_NONE: No flag
|
||||
|
@ -534,7 +542,6 @@ gchar * gst_video_colorimetry_to_string (GstVideoColorimetry *cinfo);
|
|||
* @size: the default size of one frame
|
||||
* @chroma_site: a #GstVideoChromaSite.
|
||||
* @colorimetry: the colorimetry info
|
||||
* @palette: a buffer with palette data
|
||||
* @par_n: the pixel-aspect-ratio numerator
|
||||
* @par_d: the pixel-aspect-ratio demnominator
|
||||
* @fps_n: the framerate numerator
|
||||
|
@ -562,8 +569,6 @@ struct _GstVideoInfo {
|
|||
GstVideoChromaSite chroma_site;
|
||||
GstVideoColorimetry colorimetry;
|
||||
|
||||
GstBuffer *palette;
|
||||
|
||||
gint par_n;
|
||||
gint par_d;
|
||||
gint fps_n;
|
||||
|
@ -719,8 +724,8 @@ gboolean gst_video_frame_copy_plane (GstVideoFrame *dest, const GstVideoFr
|
|||
#define GST_VIDEO_FORMATS_ALL "{ I420, YV12, YUY2, UYVY, AYUV, RGBx, " \
|
||||
"BGRx, xRGB, xBGR, RGBA, BGRA, ARGB, ABGR, RGB, BGR, Y41B, Y42B, " \
|
||||
"YVYU, Y444, v210, v216, NV12, NV21, GRAY8, GRAY16_BE, GRAY16_LE, " \
|
||||
"v308, RGB16, BGR16, RGB15, BGR15, UYVP, A420, RGB8_PALETTED, " \
|
||||
"YUV9, YVU9, IYU1, ARGB64, AYUV64, r210, I420_10LE, I420_10BE }"
|
||||
"v308, RGB16, BGR16, RGB15, BGR15, UYVP, A420, RGB8P, YUV9, YVU9, " \
|
||||
"IYU1, ARGB64, AYUV64, r210, I420_10LE, I420_10BE }"
|
||||
|
||||
/**
|
||||
* GST_VIDEO_CAPS_MAKE:
|
||||
|
@ -770,8 +775,6 @@ gboolean gst_video_calculate_display_ratio (guint * dar_n,
|
|||
guint display_par_n,
|
||||
guint display_par_d);
|
||||
|
||||
GstBuffer * gst_video_parse_caps_palette (GstCaps * caps);
|
||||
|
||||
/* video still frame event creation and parsing */
|
||||
|
||||
GstEvent * gst_video_event_new_still_frame (gboolean in_still);
|
||||
|
|
|
@ -127,7 +127,7 @@ gst_video_convert_caps_remove_format_info (GstCaps * caps)
|
|||
continue;
|
||||
|
||||
st = gst_structure_copy (st);
|
||||
gst_structure_remove_fields (st, "format", "palette_data",
|
||||
gst_structure_remove_fields (st, "format",
|
||||
"colorimetry", "chroma-site", NULL);
|
||||
|
||||
gst_caps_append_structure (res, st);
|
||||
|
@ -277,12 +277,12 @@ gst_video_convert_set_info (GstVideoFilter * filter,
|
|||
|
||||
videoconvert_convert_set_interlaced (space->convert, interlaced);
|
||||
|
||||
#if 0
|
||||
/* palette, only for from data */
|
||||
if (GST_VIDEO_INFO_FORMAT (in_info) ==
|
||||
GST_VIDEO_FORMAT_RGB8_PALETTED
|
||||
&& GST_VIDEO_INFO_FORMAT (out_info) == GST_VIDEO_FORMAT_RGB8_PALETTED) {
|
||||
if (GST_VIDEO_INFO_FORMAT (in_info) == GST_VIDEO_FORMAT_RGB8P
|
||||
&& GST_VIDEO_INFO_FORMAT (out_info) == GST_VIDEO_FORMAT_RGB8P) {
|
||||
goto format_mismatch;
|
||||
} else if (GST_VIDEO_INFO_FORMAT (in_info) == GST_VIDEO_FORMAT_RGB8_PALETTED) {
|
||||
} else if (GST_VIDEO_INFO_FORMAT (in_info) == GST_VIDEO_FORMAT_RGB8P) {
|
||||
GstBuffer *palette;
|
||||
GstMapInfo map;
|
||||
|
||||
|
@ -299,7 +299,7 @@ gst_video_convert_set_info (GstVideoFilter * filter,
|
|||
gst_buffer_unmap (palette, &map);
|
||||
|
||||
gst_buffer_unref (palette);
|
||||
} else if (GST_VIDEO_INFO_FORMAT (out_info) == GST_VIDEO_FORMAT_RGB8_PALETTED) {
|
||||
} else if (GST_VIDEO_INFO_FORMAT (out_info) == GST_VIDEO_FORMAT_RGB8P) {
|
||||
const guint32 *palette;
|
||||
GstBuffer *p_buf;
|
||||
|
||||
|
@ -310,6 +310,7 @@ gst_video_convert_set_info (GstVideoFilter * filter,
|
|||
gst_caps_set_simple (outcaps, "palette_data", GST_TYPE_BUFFER, p_buf, NULL);
|
||||
gst_buffer_unref (p_buf);
|
||||
}
|
||||
#endif
|
||||
|
||||
GST_DEBUG ("reconfigured %d %d", GST_VIDEO_INFO_FORMAT (in_info),
|
||||
GST_VIDEO_INFO_FORMAT (out_info));
|
||||
|
@ -327,11 +328,13 @@ no_convert:
|
|||
GST_ERROR_OBJECT (space, "could not create converter");
|
||||
return FALSE;
|
||||
}
|
||||
#if 0
|
||||
invalid_palette:
|
||||
{
|
||||
GST_ERROR_OBJECT (space, "invalid palette");
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -94,7 +94,7 @@ videoconvert_convert_new (GstVideoFormat to_format, ColorSpaceColorSpec to_spec,
|
|||
convert->tmpline16 = g_malloc (sizeof (guint16) * (width + 8) * 4);
|
||||
convert->errline = g_malloc (sizeof (guint16) * width * 4);
|
||||
|
||||
if (to_format == GST_VIDEO_FORMAT_RGB8_PALETTED) {
|
||||
if (to_format == GST_VIDEO_FORMAT_RGB8P) {
|
||||
/* build poor man's palette, taken from ffmpegcolorspace */
|
||||
static const guint8 pal_value[6] = { 0x00, 0x33, 0x66, 0x99, 0xcc, 0xff };
|
||||
guint32 *palette;
|
||||
|
|
Loading…
Reference in a new issue