comparison mov.c @ 302:6949df67922d libavformat

added palette support to the QT demuxer; registered SMC video decoder with QT system
author melanson
date Mon, 10 Nov 2003 03:17:32 +0000
parents 4513d5ab9eb5
children e73e7b5f2599
comparison
equal deleted inserted replaced
301:4513d5ab9eb5 302:6949df67922d
52 //#define DEBUG 52 //#define DEBUG
53 #ifdef DEBUG 53 #ifdef DEBUG
54 #include <stdio.h> 54 #include <stdio.h>
55 #include <fcntl.h> 55 #include <fcntl.h>
56 #endif 56 #endif
57
58 #include "qtpalette.h"
57 59
58 /* allows chunk splitting - should work now... */ 60 /* allows chunk splitting - should work now... */
59 /* in case you can't read a file, try commenting */ 61 /* in case you can't read a file, try commenting */
60 #define MOV_SPLIT_CHUNKS 62 #define MOV_SPLIT_CHUNKS
61 63
100 /* { CODEC_ID_DVVIDEO, MKTAG('A', 'V', 'd', 'v') }, *//* AVID dv */ 102 /* { CODEC_ID_DVVIDEO, MKTAG('A', 'V', 'd', 'v') }, *//* AVID dv */
101 { CODEC_ID_VP3, MKTAG('V', 'P', '3', '1') }, /* On2 VP3 */ 103 { CODEC_ID_VP3, MKTAG('V', 'P', '3', '1') }, /* On2 VP3 */
102 { CODEC_ID_RPZA, MKTAG('r', 'p', 'z', 'a') }, /* Apple Video (RPZA) */ 104 { CODEC_ID_RPZA, MKTAG('r', 'p', 'z', 'a') }, /* Apple Video (RPZA) */
103 { CODEC_ID_CINEPAK, MKTAG('c', 'v', 'i', 'd') }, /* Cinepak */ 105 { CODEC_ID_CINEPAK, MKTAG('c', 'v', 'i', 'd') }, /* Cinepak */
104 { CODEC_ID_8BPS, MKTAG('8', 'B', 'P', 'S') }, /* Planar RGB (8BPS) */ 106 { CODEC_ID_8BPS, MKTAG('8', 'B', 'P', 'S') }, /* Planar RGB (8BPS) */
107 { CODEC_ID_SMC, MKTAG('s', 'm', 'c', ' ') }, /* Apple Graphics (SMC) */
105 { CODEC_ID_NONE, 0 }, 108 { CODEC_ID_NONE, 0 },
106 }; 109 };
107 110
108 static const CodecTag mov_audio_tags[] = { 111 static const CodecTag mov_audio_tags[] = {
109 /* { CODEC_ID_PCM_S16BE, MKTAG('N', 'O', 'N', 'E') }, *//* uncompressed */ 112 /* { CODEC_ID_PCM_S16BE, MKTAG('N', 'O', 'N', 'E') }, *//* uncompressed */
244 MOVStreamContext *partial; /* != 0 : there is still to read in the current chunk */ 247 MOVStreamContext *partial; /* != 0 : there is still to read in the current chunk */
245 int ctab_size; 248 int ctab_size;
246 MOV_ctab_t **ctab; /* color tables */ 249 MOV_ctab_t **ctab; /* color tables */
247 const struct MOVParseTableEntry *parse_table; /* could be eventually used to change the table */ 250 const struct MOVParseTableEntry *parse_table; /* could be eventually used to change the table */
248 /* NOTE: for recursion save to/ restore from local variable! */ 251 /* NOTE: for recursion save to/ restore from local variable! */
252
253 AVPaletteControl palette_control;
249 } MOVContext; 254 } MOVContext;
250 255
251 256
252 /* XXX: it's the first time I make a recursive parser I think... sorry if it's ugly :P */ 257 /* XXX: it's the first time I make a recursive parser I think... sorry if it's ugly :P */
253 258
711 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; 716 AVStream *st = c->fc->streams[c->fc->nb_streams-1];
712 //MOVStreamContext *sc = (MOVStreamContext *)st->priv_data; 717 //MOVStreamContext *sc = (MOVStreamContext *)st->priv_data;
713 int entries, frames_per_sample; 718 int entries, frames_per_sample;
714 uint32_t format; 719 uint32_t format;
715 720
721 /* for palette traversal */
722 int color_depth;
723 int color_start;
724 int color_count;
725 int color_end;
726 int color_index;
727 int color_dec;
728 int color_greyscale;
729 unsigned char *color_table;
730 int j;
731 unsigned char r, g, b;
732
716 print_atom("stsd", atom); 733 print_atom("stsd", atom);
717 734
718 get_byte(pb); /* version */ 735 get_byte(pb); /* version */
719 get_byte(pb); get_byte(pb); get_byte(pb); /* flags */ 736 get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
720 737
849 if (size > 0) { 866 if (size > 0) {
850 /* unknown extension */ 867 /* unknown extension */
851 url_fskip(pb, size); 868 url_fskip(pb, size);
852 } 869 }
853 #else 870 #else
871
872 /* figure out the palette situation */
873 color_depth = st->codec.bits_per_sample & 0x1F;
874 color_greyscale = st->codec.bits_per_sample & 0x20;
875
876 /* if the depth is 2, 4, or 8 bpp, file is palettized */
877 if ((color_depth == 2) || (color_depth == 4) ||
878 (color_depth == 8)) {
879
880 if (color_greyscale) {
881
882 /* compute the greyscale palette */
883 color_count = 1 << color_depth;
884 color_index = 255;
885 color_dec = 256 / (color_count - 1);
886 for (j = 0; j < color_count; j++) {
887 r = g = b = color_index;
888 c->palette_control.palette[j] =
889 (r << 16) | (g << 8) | (b);
890 color_index -= color_dec;
891 if (color_index < 0)
892 color_index = 0;
893 }
894
895 } else if (st->codec.color_table_id & 0x08) {
896
897 /* if flag bit 3 is set, use the default palette */
898 color_count = 1 << color_depth;
899 if (color_depth == 2)
900 color_table = qt_default_palette_4;
901 else if (color_depth == 4)
902 color_table = qt_default_palette_16;
903 else
904 color_table = qt_default_palette_256;
905
906 for (j = 0; j < color_count; j++) {
907 r = color_table[j * 4 + 0];
908 g = color_table[j * 4 + 1];
909 b = color_table[j * 4 + 2];
910 c->palette_control.palette[j] =
911 (r << 16) | (g << 8) | (b);
912 }
913
914 } else {
915
916 /* load the palette from the file */
917 color_start = get_be32(pb);
918 color_count = get_be16(pb);
919 color_end = get_be16(pb);
920 for (j = color_start; j <= color_end; j++) {
921 /* each R, G, or B component is 16 bits;
922 * only use the top 8 bits; skip alpha bytes
923 * up front */
924 get_byte(pb);
925 get_byte(pb);
926 r = get_byte(pb);
927 get_byte(pb);
928 g = get_byte(pb);
929 get_byte(pb);
930 b = get_byte(pb);
931 get_byte(pb);
932 c->palette_control.palette[j] =
933 (r << 16) | (g << 8) | (b);
934 }
935 }
936
937 st->codec.palctrl = &c->palette_control;
938 st->codec.palctrl->palette_changed = 1;
939 } else
940 st->codec.palctrl = NULL;
941
854 a.size = size; 942 a.size = size;
855 mov_read_default(c, pb, a); 943 mov_read_default(c, pb, a);
856 #endif 944 #endif
857 } else { 945 } else {
858 st->codec.codec_id = codec_get_id(mov_audio_tags, format); 946 st->codec.codec_id = codec_get_id(mov_audio_tags, format);