gst/qtdemux/qtdemux.c: Add support for palettised Apple SMC videos (#327075, based on

Original commit message from CVS:
* gst/qtdemux/qtdemux.c: (gst_qtdemux_add_stream),
(qtdemux_parse_trak), (qtdemux_video_caps):
Add support for palettised Apple SMC videos (#327075, based on
patch by: Fabrizio Gennari <fabrizio dot ge at tiscali dot it>).
This commit is contained in:
Fabrizio Gennari 2006-02-24 19:49:32 +00:00 committed by Tim-Philipp Müller
parent 73ce8c5b9e
commit 96c1cd6e0a

View file

@ -97,6 +97,8 @@ struct _QtDemuxStream
guint bytes_per_frame;
guint compression;
guint samples_per_packet;
guint16 bits_per_sample;
guint16 color_table_id;
};
enum QtDemuxState
@ -138,6 +140,94 @@ GST_STATIC_PAD_TEMPLATE ("video_%02d",
static GstElementClass *parent_class = NULL;
/* we could generate these programmatically, but the generation code
* is only a few lines shorter than the tables, and much uglier */
static const guint32 ff_qt_default_palette_256[256] = {
0xFFFFFF, 0xFFFFCC, 0xFFFF99, 0xFFFF66, 0xFFFF33, 0xFFFF00,
0xFFCCFF, 0xFFCCCC, 0xFFCC99, 0xFFCC66, 0xFFCC33, 0xFFCC00,
0xFF99FF, 0xFF99CC, 0xFF9999, 0xFF9966, 0xFF9933, 0xFF9900,
0xFF66FF, 0xFF66CC, 0xFF6699, 0xFF6666, 0xFF6633, 0xFF6600,
0xFF33FF, 0xFF33CC, 0xFF3399, 0xFF3366, 0xFF3333, 0xFF3300,
0xFF00FF, 0xFF00CC, 0xFF0099, 0xFF0066, 0xFF0033, 0xFF0000,
0xCCFFFF, 0xCCFFCC, 0xCCFF99, 0xCCFF66, 0xCCFF33, 0xCCFF00,
0xCCCCFF, 0xCCCCCC, 0xCCCC99, 0xCCCC66, 0xCCCC33, 0xCCCC00,
0xCC99FF, 0xCC99CC, 0xCC9999, 0xCC9966, 0xCC9933, 0xCC9900,
0xCC66FF, 0xCC66CC, 0xCC6699, 0xCC6666, 0xCC6633, 0xCC6600,
0xCC33FF, 0xCC33CC, 0xCC3399, 0xCC3366, 0xCC3333, 0xCC3300,
0xCC00FF, 0xCC00CC, 0xCC0099, 0xCC0066, 0xCC0033, 0xCC0000,
0x99FFFF, 0x99FFCC, 0x99FF99, 0x99FF66, 0x99FF33, 0x99FF00,
0x99CCFF, 0x99CCCC, 0x99CC99, 0x99CC66, 0x99CC33, 0x99CC00,
0x9999FF, 0x9999CC, 0x999999, 0x999966, 0x999933, 0x999900,
0x9966FF, 0x9966CC, 0x996699, 0x996666, 0x996633, 0x996600,
0x9933FF, 0x9933CC, 0x993399, 0x993366, 0x993333, 0x993300,
0x9900FF, 0x9900CC, 0x990099, 0x990066, 0x990033, 0x990000,
0x66FFFF, 0x66FFCC, 0x66FF99, 0x66FF66, 0x66FF33, 0x66FF00,
0x66CCFF, 0x66CCCC, 0x66CC99, 0x66CC66, 0x66CC33, 0x66CC00,
0x6699FF, 0x6699CC, 0x669999, 0x669966, 0x669933, 0x669900,
0x6666FF, 0x6666CC, 0x666699, 0x666666, 0x666633, 0x666600,
0x6633FF, 0x6633CC, 0x663399, 0x663366, 0x663333, 0x663300,
0x6600FF, 0x6600CC, 0x660099, 0x660066, 0x660033, 0x660000,
0x33FFFF, 0x33FFCC, 0x33FF99, 0x33FF66, 0x33FF33, 0x33FF00,
0x33CCFF, 0x33CCCC, 0x33CC99, 0x33CC66, 0x33CC33, 0x33CC00,
0x3399FF, 0x3399CC, 0x339999, 0x339966, 0x339933, 0x339900,
0x3366FF, 0x3366CC, 0x336699, 0x336666, 0x336633, 0x336600,
0x3333FF, 0x3333CC, 0x333399, 0x333366, 0x333333, 0x333300,
0x3300FF, 0x3300CC, 0x330099, 0x330066, 0x330033, 0x330000,
0x00FFFF, 0x00FFCC, 0x00FF99, 0x00FF66, 0x00FF33, 0x00FF00,
0x00CCFF, 0x00CCCC, 0x00CC99, 0x00CC66, 0x00CC33, 0x00CC00,
0x0099FF, 0x0099CC, 0x009999, 0x009966, 0x009933, 0x009900,
0x0066FF, 0x0066CC, 0x006699, 0x006666, 0x006633, 0x006600,
0x0033FF, 0x0033CC, 0x003399, 0x003366, 0x003333, 0x003300,
0x0000FF, 0x0000CC, 0x000099, 0x000066, 0x000033, 0xEE0000,
0xDD0000, 0xBB0000, 0xAA0000, 0x880000, 0x770000, 0x550000,
0x440000, 0x220000, 0x110000, 0x00EE00, 0x00DD00, 0x00BB00,
0x00AA00, 0x008800, 0x007700, 0x005500, 0x004400, 0x002200,
0x001100, 0x0000EE, 0x0000DD, 0x0000BB, 0x0000AA, 0x000088,
0x000077, 0x000055, 0x000044, 0x000022, 0x000011, 0xEEEEEE,
0xDDDDDD, 0xBBBBBB, 0xAAAAAA, 0x888888, 0x777777, 0x555555,
0x444444, 0x222222, 0x111111, 0x000000
};
static const guint32 ff_qt_grayscale_palette_256[256] = {
0xffffff, 0xfefefe, 0xfdfdfd, 0xfcfcfc, 0xfbfbfb, 0xfafafa, 0xf9f9f9,
0xf8f8f8, 0xf7f7f7, 0xf6f6f6, 0xf5f5f5, 0xf4f4f4, 0xf3f3f3, 0xf2f2f2,
0xf1f1f1, 0xf0f0f0, 0xefefef, 0xeeeeee, 0xededed, 0xececec, 0xebebeb,
0xeaeaea, 0xe9e9e9, 0xe8e8e8, 0xe7e7e7, 0xe6e6e6, 0xe5e5e5, 0xe4e4e4,
0xe3e3e3, 0xe2e2e2, 0xe1e1e1, 0xe0e0e0, 0xdfdfdf, 0xdedede, 0xdddddd,
0xdcdcdc, 0xdbdbdb, 0xdadada, 0xd9d9d9, 0xd8d8d8, 0xd7d7d7, 0xd6d6d6,
0xd5d5d5, 0xd4d4d4, 0xd3d3d3, 0xd2d2d2, 0xd1d1d1, 0xd0d0d0, 0xcfcfcf,
0xcecece, 0xcdcdcd, 0xcccccc, 0xcbcbcb, 0xcacaca, 0xc9c9c9, 0xc8c8c8,
0xc7c7c7, 0xc6c6c6, 0xc5c5c5, 0xc4c4c4, 0xc3c3c3, 0xc2c2c2, 0xc1c1c1,
0xc0c0c0, 0xbfbfbf, 0xbebebe, 0xbdbdbd, 0xbcbcbc, 0xbbbbbb, 0xbababa,
0xb9b9b9, 0xb8b8b8, 0xb7b7b7, 0xb6b6b6, 0xb5b5b5, 0xb4b4b4, 0xb3b3b3,
0xb2b2b2, 0xb1b1b1, 0xb0b0b0, 0xafafaf, 0xaeaeae, 0xadadad, 0xacacac,
0xababab, 0xaaaaaa, 0xa9a9a9, 0xa8a8a8, 0xa7a7a7, 0xa6a6a6, 0xa5a5a5,
0xa4a4a4, 0xa3a3a3, 0xa2a2a2, 0xa1a1a1, 0xa0a0a0, 0x9f9f9f, 0x9e9e9e,
0x9d9d9d, 0x9c9c9c, 0x9b9b9b, 0x9a9a9a, 0x999999, 0x989898, 0x979797,
0x969696, 0x959595, 0x949494, 0x939393, 0x929292, 0x919191, 0x909090,
0x8f8f8f, 0x8e8e8e, 0x8d8d8d, 0x8c8c8c, 0x8b8b8b, 0x8a8a8a, 0x898989,
0x888888, 0x878787, 0x868686, 0x858585, 0x848484, 0x838383, 0x828282,
0x818181, 0x808080, 0x7f7f7f, 0x7e7e7e, 0x7d7d7d, 0x7c7c7c, 0x7b7b7b,
0x7a7a7a, 0x797979, 0x787878, 0x777777, 0x767676, 0x757575, 0x747474,
0x737373, 0x727272, 0x717171, 0x707070, 0x6f6f6f, 0x6e6e6e, 0x6d6d6d,
0x6c6c6c, 0x6b6b6b, 0x6a6a6a, 0x696969, 0x686868, 0x676767, 0x666666,
0x656565, 0x646464, 0x636363, 0x626262, 0x616161, 0x606060, 0x5f5f5f,
0x5e5e5e, 0x5d5d5d, 0x5c5c5c, 0x5b5b5b, 0x5a5a5a, 0x595959, 0x585858,
0x575757, 0x565656, 0x555555, 0x545454, 0x535353, 0x525252, 0x515151,
0x505050, 0x4f4f4f, 0x4e4e4e, 0x4d4d4d, 0x4c4c4c, 0x4b4b4b, 0x4a4a4a,
0x494949, 0x484848, 0x474747, 0x464646, 0x454545, 0x444444, 0x434343,
0x424242, 0x414141, 0x404040, 0x3f3f3f, 0x3e3e3e, 0x3d3d3d, 0x3c3c3c,
0x3b3b3b, 0x3a3a3a, 0x393939, 0x383838, 0x373737, 0x363636, 0x353535,
0x343434, 0x333333, 0x323232, 0x313131, 0x303030, 0x2f2f2f, 0x2e2e2e,
0x2d2d2d, 0x2c2c2c, 0x2b2b2b, 0x2a2a2a, 0x292929, 0x282828, 0x272727,
0x262626, 0x252525, 0x242424, 0x232323, 0x222222, 0x212121, 0x202020,
0x1f1f1f, 0x1e1e1e, 0x1d1d1d, 0x1c1c1c, 0x1b1b1b, 0x1a1a1a, 0x191919,
0x181818, 0x171717, 0x161616, 0x151515, 0x141414, 0x131313, 0x121212,
0x111111, 0x101010, 0x0f0f0f, 0x0e0e0e, 0x0d0d0d, 0x0c0c0c, 0x0b0b0b,
0x0a0a0a, 0x090909, 0x080808, 0x070707, 0x060606, 0x050505, 0x040404,
0x030303, 0x020202, 0x010101, 0x000000
};
static void gst_qtdemux_class_init (GstQTDemuxClass * klass);
static void gst_qtdemux_base_init (GstQTDemuxClass * klass);
static void gst_qtdemux_init (GstQTDemux * quicktime_demux);
@ -1079,7 +1169,7 @@ qtdemux_sink_activate_push (GstPad * sinkpad, gboolean active)
return TRUE;
}
void
static void
gst_qtdemux_add_stream (GstQTDemux * qtdemux,
QtDemuxStream * stream, GstTagList * list)
{
@ -1107,6 +1197,24 @@ gst_qtdemux_add_stream (GstQTDemux * qtdemux,
"width", G_TYPE_INT, stream->width,
"height", G_TYPE_INT, stream->height,
"framerate", GST_TYPE_FRACTION, stream->fps_n, stream->fps_d, NULL);
if ((stream->bits_per_sample & 0x1F) == 8) {
const guint32 *palette_data = NULL;
if ((stream->bits_per_sample & 0x20) != 0)
palette_data = ff_qt_grayscale_palette_256;
if ((stream->color_table_id & 0x08) != 0)
palette_data = ff_qt_default_palette_256;
if (palette_data) {
GstBuffer *palette = gst_buffer_new ();
GST_BUFFER_DATA (palette) = (guint8 *) palette_data;
GST_BUFFER_SIZE (palette) = sizeof (guint32) * 256;
gst_caps_set_simple (stream->caps, "palette_data",
GST_TYPE_BUFFER, palette, NULL);
gst_buffer_unref (palette);
}
}
}
qtdemux->n_video_streams++;
} else {
@ -2329,6 +2437,8 @@ qtdemux_parse_trak (GstQTDemux * qtdemux, GNode * trak)
stream->height = QTDEMUX_GUINT16_GET (stsd->data + offset + 34);
stream->fps_n = 0; /* this is filled in later */
stream->fps_d = 0; /* this is filled in later */
stream->bits_per_sample = QTDEMUX_GUINT16_GET (stsd->data + offset + 82);
stream->color_table_id = QTDEMUX_GUINT16_GET (stsd->data + offset + 84);
GST_LOG ("frame count: %u",
QTDEMUX_GUINT16_GET (stsd->data + offset + 48));