From d73dcb6af32440efa80456b9932cfce6417f3cf9 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 15 Oct 2012 16:33:24 +0200 Subject: [PATCH] videotestsrc: make and copy palette --- gst/videotestsrc/gstvideotestsrc.c | 36 ++++++++++++++++++++++++++++++++++++ gst/videotestsrc/gstvideotestsrc.h | 1 + 2 files changed, 37 insertions(+) diff --git a/gst/videotestsrc/gstvideotestsrc.c b/gst/videotestsrc/gstvideotestsrc.c index 9c2a303..ff175c4 100644 --- a/gst/videotestsrc/gstvideotestsrc.c +++ b/gst/videotestsrc/gstvideotestsrc.c @@ -654,6 +654,28 @@ gst_video_test_src_decide_allocation (GstBaseSrc * bsrc, GstQuery * query) return GST_BASE_SRC_CLASS (parent_class)->decide_allocation (bsrc, query); } +static void +fill_palette_RGB8P (guint32 * palette) +{ + /* build poor man's palette, taken from ffmpegcolorspace */ + static const guint8 pal_value[6] = { 0x00, 0x33, 0x66, 0x99, 0xcc, 0xff }; + gint i, r, g, b; + + i = 0; + for (r = 0; r < 6; r++) { + for (g = 0; g < 6; g++) { + for (b = 0; b < 6; b++) { + palette[i++] = + (0xffU << 24) | (pal_value[r] << 16) | (pal_value[g] << 8) | + pal_value[b]; + } + } + } + palette[i++] = 0; /* 100% transparent, i == 6*6*6 */ + while (i < 256) + palette[i++] = 0xff000000; +} + static gboolean gst_video_test_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps) { @@ -699,11 +721,19 @@ gst_video_test_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps) g_free (videotestsrc->tmpline2); g_free (videotestsrc->tmpline_u8); g_free (videotestsrc->tmpline_u16); + g_free (videotestsrc->palette); videotestsrc->tmpline_u8 = g_malloc (info.width + 8); videotestsrc->tmpline = g_malloc ((info.width + 8) * 4); videotestsrc->tmpline2 = g_malloc ((info.width + 8) * 4); videotestsrc->tmpline_u16 = g_malloc ((info.width + 16) * 8); + if (GST_VIDEO_INFO_FORMAT (&info) == GST_VIDEO_FORMAT_RGB8P) { + videotestsrc->palette = g_new (guint32, 256); + fill_palette_RGB8P (videotestsrc->palette); + } else { + videotestsrc->palette = NULL; + } + videotestsrc->accum_rtime += videotestsrc->running_time; videotestsrc->accum_frames += videotestsrc->n_frames; @@ -836,6 +866,10 @@ gst_video_test_src_fill (GstPushSrc * psrc, GstBuffer * buffer) src->make_image (src, &frame); + if (src->palette) { + memcpy (GST_VIDEO_FRAME_PLANE_DATA (&frame, 1), src->palette, 256 * 4); + } + gst_video_frame_unmap (&frame); GST_BUFFER_DTS (buffer) = @@ -909,6 +943,8 @@ gst_video_test_src_stop (GstBaseSrc * basesrc) src->tmpline_u8 = NULL; g_free (src->tmpline_u16); src->tmpline_u16 = NULL; + g_free (src->palette); + src->palette = NULL; return TRUE; } diff --git a/gst/videotestsrc/gstvideotestsrc.h b/gst/videotestsrc/gstvideotestsrc.h index a09e210..c365c5d 100644 --- a/gst/videotestsrc/gstvideotestsrc.h +++ b/gst/videotestsrc/gstvideotestsrc.h @@ -162,6 +162,7 @@ struct _GstVideoTestSrc { gint horizontal_speed; void (*make_image) (GstVideoTestSrc *v, GstVideoFrame *frame); + guint32 *palette; /* temporary AYUV/ARGB scanline */ guint8 *tmpline_u8; -- 2.7.4