+ }
+
+ st->codec->codec_tag = format;
+
+ return id;
+}
+
+static void mov_parse_stsd_video(MOVContext *c, AVIOContext *pb,
+ AVStream *st, MOVStreamContext *sc)
+{
+ uint8_t codec_name[32];
+ unsigned int color_depth, len, j;
+ int color_greyscale;
+ int color_table_id;
+
+ avio_rb16(pb); /* version */
+ avio_rb16(pb); /* revision level */
+ avio_rb32(pb); /* vendor */
+ avio_rb32(pb); /* temporal quality */
+ avio_rb32(pb); /* spatial quality */
+
+ st->codec->width = avio_rb16(pb); /* width */
+ st->codec->height = avio_rb16(pb); /* height */
+
+ avio_rb32(pb); /* horiz resolution */
+ avio_rb32(pb); /* vert resolution */
+ avio_rb32(pb); /* data size, always 0 */
+ avio_rb16(pb); /* frames per samples */
+
+ len = avio_r8(pb); /* codec name, pascal string */
+ if (len > 31)
+ len = 31;
+ mov_read_mac_string(c, pb, len, codec_name, sizeof(codec_name));
+ if (len < 31)
+ avio_skip(pb, 31 - len);
+
+ if (codec_name[0])
+ av_dict_set(&st->metadata, "encoder", codec_name, 0);
+
+ /* codec_tag YV12 triggers an UV swap in rawdec.c */
+ if (!memcmp(codec_name, "Planar Y'CbCr 8-bit 4:2:0", 25))
+ st->codec->codec_tag = MKTAG('I', '4', '2', '0');
+ /* Flash Media Server uses tag H263 with Sorenson Spark */
+ if (st->codec->codec_tag == MKTAG('H','2','6','3') &&
+ !memcmp(codec_name, "Sorenson H263", 13))
+ st->codec->codec_id = AV_CODEC_ID_FLV1;
+
+ st->codec->bits_per_coded_sample = avio_rb16(pb); /* depth */
+ color_table_id = avio_rb16(pb); /* colortable id */
+ av_dlog(c->fc, "depth %d, ctab id %d\n",
+ st->codec->bits_per_coded_sample, color_table_id);
+ /* figure out the palette situation */
+ color_depth = st->codec->bits_per_coded_sample & 0x1F;
+ color_greyscale = st->codec->bits_per_coded_sample & 0x20;
+
+ /* if the depth is 2, 4, or 8 bpp, file is palettized */
+ if ((color_depth == 2) || (color_depth == 4) || (color_depth == 8)) {
+ /* for palette traversal */
+ unsigned int color_start, color_count, color_end;
+ unsigned char r, g, b;
+
+ if (color_greyscale) {
+ int color_index, color_dec;
+ /* compute the greyscale palette */
+ st->codec->bits_per_coded_sample = color_depth;
+ color_count = 1 << color_depth;
+ color_index = 255;
+ color_dec = 256 / (color_count - 1);
+ for (j = 0; j < color_count; j++) {
+ r = g = b = color_index;
+ sc->palette[j] = (r << 16) | (g << 8) | (b);
+ color_index -= color_dec;
+ if (color_index < 0)
+ color_index = 0;
+ }
+ } else if (color_table_id) {
+ const uint8_t *color_table;
+ /* if flag bit 3 is set, use the default palette */
+ color_count = 1 << color_depth;
+ if (color_depth == 2)
+ color_table = ff_qt_default_palette_4;
+ else if (color_depth == 4)
+ color_table = ff_qt_default_palette_16;
+ else
+ color_table = ff_qt_default_palette_256;
+
+ for (j = 0; j < color_count; j++) {
+ r = color_table[j * 3 + 0];
+ g = color_table[j * 3 + 1];
+ b = color_table[j * 3 + 2];
+ sc->palette[j] = (r << 16) | (g << 8) | (b);
+ }