Mercurial > libavcodec.hg
comparison mjpeg.c @ 832:ff66fdb1d092 libavcodec
fixed some bugs in app parser - some jfif and adobe jpgs fixed
author | al3x |
---|---|
date | Sat, 02 Nov 2002 22:49:13 +0000 |
parents | 972c8ee102d6 |
children | 4c22dcf3ba65 |
comparison
equal
deleted
inserted
replaced
831:14f4598ec793 | 832:ff66fdb1d092 |
---|---|
606 int quant_index[4]; /* quant table index for each component */ | 606 int quant_index[4]; /* quant table index for each component */ |
607 int last_dc[MAX_COMPONENTS]; /* last DEQUANTIZED dc (XXX: am I right to do that ?) */ | 607 int last_dc[MAX_COMPONENTS]; /* last DEQUANTIZED dc (XXX: am I right to do that ?) */ |
608 UINT8 *current_picture[MAX_COMPONENTS]; /* picture structure */ | 608 UINT8 *current_picture[MAX_COMPONENTS]; /* picture structure */ |
609 int linesize[MAX_COMPONENTS]; | 609 int linesize[MAX_COMPONENTS]; |
610 DCTELEM block[64] __align8; | 610 DCTELEM block[64] __align8; |
611 | 611 ScanTable scantable; |
612 int buggy_avid; | 612 void (*idct_put)(UINT8 *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/); |
613 | |
613 int restart_interval; | 614 int restart_interval; |
614 int restart_count; | 615 int restart_count; |
616 | |
617 int buggy_avid; | |
615 int interlace_polarity; | 618 int interlace_polarity; |
616 ScanTable scantable; | |
617 void (*idct_put)(UINT8 *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/); | |
618 } MJpegDecodeContext; | 619 } MJpegDecodeContext; |
619 | 620 |
620 static int mjpeg_decode_dht(MJpegDecodeContext *s); | 621 static int mjpeg_decode_dht(MJpegDecodeContext *s); |
621 | 622 |
622 static void build_vlc(VLC *vlc, const UINT8 *bits_table, const UINT8 *val_table, | 623 static void build_vlc(VLC *vlc, const UINT8 *bits_table, const UINT8 *val_table, |
1030 x = 0; | 1031 x = 0; |
1031 y++; | 1032 y++; |
1032 } | 1033 } |
1033 } | 1034 } |
1034 } | 1035 } |
1035 if ((s->restart_interval <= 8) && !--s->restart_count) { | 1036 /* (< 1350) buggy workaround for Spectralfan.mov, should be fixed */ |
1037 | |
1038 if ((s->restart_interval < 1350) && !--s->restart_count) { | |
1036 align_get_bits(&s->gb); | 1039 align_get_bits(&s->gb); |
1037 skip_bits(&s->gb, 16); /* skip RSTn */ | 1040 skip_bits(&s->gb, 16); /* skip RSTn */ |
1038 for (j=0; j<nb_components; j++) /* reset dc */ | 1041 for (j=0; j<nb_components; j++) /* reset dc */ |
1039 s->last_dc[j] = 1024; | 1042 s->last_dc[j] = 1024; |
1040 } | 1043 } |
1071 id = (get_bits(&s->gb, 16) << 16) | get_bits(&s->gb, 16); | 1074 id = (get_bits(&s->gb, 16) << 16) | get_bits(&s->gb, 16); |
1072 id = be2me_32(id); | 1075 id = be2me_32(id); |
1073 len -= 6; | 1076 len -= 6; |
1074 | 1077 |
1075 /* buggy AVID, it puts EOI only at every 10th frame */ | 1078 /* buggy AVID, it puts EOI only at every 10th frame */ |
1076 /* also this fourcc is used by non-avid files too, it means | 1079 /* also this fourcc is used by non-avid files too, it holds some |
1077 interleaving, but it's always present in AVID files */ | 1080 informations, but it's always present in AVID creates files */ |
1078 if (id == ff_get_fourcc("AVI1")) | 1081 if (id == ff_get_fourcc("AVI1")) |
1079 { | 1082 { |
1080 /* structure: | 1083 /* structure: |
1081 4bytes AVI1 | 1084 4bytes AVI1 |
1082 1bytes polarity | 1085 1bytes polarity |
1097 // if (s->interlace_polarity) | 1100 // if (s->interlace_polarity) |
1098 // printf("mjpeg: interlace polarity: %d\n", s->interlace_polarity); | 1101 // printf("mjpeg: interlace polarity: %d\n", s->interlace_polarity); |
1099 goto out; | 1102 goto out; |
1100 } | 1103 } |
1101 | 1104 |
1102 len -= 2; | 1105 // len -= 2; |
1103 | 1106 |
1104 if (id == ff_get_fourcc("JFIF")) | 1107 if (id == ff_get_fourcc("JFIF")) |
1105 { | 1108 { |
1109 int t_w, t_h; | |
1106 skip_bits(&s->gb, 8); /* the trailing zero-byte */ | 1110 skip_bits(&s->gb, 8); /* the trailing zero-byte */ |
1107 printf("mjpeg: JFIF header found (version: %x.%x)\n", | 1111 printf("mjpeg: JFIF header found (version: %x.%x)\n", |
1108 get_bits(&s->gb, 8), get_bits(&s->gb, 8)); | 1112 get_bits(&s->gb, 8), get_bits(&s->gb, 8)); |
1109 if (get_bits(&s->gb, 8) == 0) | 1113 if (get_bits(&s->gb, 8) == 0) |
1110 { | 1114 { |
1115 else | 1119 else |
1116 { | 1120 { |
1117 skip_bits(&s->gb, 16); | 1121 skip_bits(&s->gb, 16); |
1118 skip_bits(&s->gb, 16); | 1122 skip_bits(&s->gb, 16); |
1119 } | 1123 } |
1120 skip_bits(&s->gb, 8); | 1124 t_w = get_bits(&s->gb, 8); |
1121 skip_bits(&s->gb, 8); | 1125 t_h = get_bits(&s->gb, 8); |
1126 if (t_w && t_h) | |
1127 { | |
1128 /* skip thumbnail */ | |
1129 if (len-10-(t_w*t_h*3) > 0) | |
1130 len -= t_w*t_h*3; | |
1131 } | |
1132 len -= 10; | |
1133 goto out; | |
1134 } | |
1135 | |
1136 if (id == ff_get_fourcc("Adob") && (get_bits(&s->gb, 8) == 'e')) | |
1137 { | |
1138 printf("mjpeg: Adobe header found\n"); | |
1139 skip_bits(&s->gb, 16); /* version */ | |
1140 skip_bits(&s->gb, 16); /* flags0 */ | |
1141 skip_bits(&s->gb, 16); /* flags1 */ | |
1142 skip_bits(&s->gb, 8); /* transform */ | |
1143 len -= 7; | |
1122 goto out; | 1144 goto out; |
1123 } | 1145 } |
1124 | 1146 |
1125 /* Apple MJPEG-A */ | 1147 /* Apple MJPEG-A */ |
1126 if ((s->start_code == APP1) && (len > (0x28 - 8))) | 1148 if ((s->start_code == APP1) && (len > (0x28 - 8))) |
1144 printf("mjpeg: Apple MJPEG-A header found\n"); | 1166 printf("mjpeg: Apple MJPEG-A header found\n"); |
1145 } | 1167 } |
1146 } | 1168 } |
1147 | 1169 |
1148 out: | 1170 out: |
1171 /* slow but needed for extreme adobe jpegs */ | |
1172 if (len < 0) | |
1173 printf("mjpeg: error, decode_app parser read over the end\n"); | |
1174 while(--len > 0) | |
1175 skip_bits(&s->gb, 8); | |
1176 | |
1149 return 0; | 1177 return 0; |
1150 } | 1178 } |
1151 | 1179 |
1152 static int mjpeg_decode_com(MJpegDecodeContext *s) | 1180 static int mjpeg_decode_com(MJpegDecodeContext *s) |
1153 { | 1181 { |
1278 UINT8 *dst = s->buffer; | 1306 UINT8 *dst = s->buffer; |
1279 | 1307 |
1280 while (src<buf_end) | 1308 while (src<buf_end) |
1281 { | 1309 { |
1282 UINT8 x = *(src++); | 1310 UINT8 x = *(src++); |
1283 | 1311 |
1312 #if 0 | |
1313 if (x == 0xff && *src == 0xff) | |
1314 break; | |
1315 #endif | |
1284 *(dst++) = x; | 1316 *(dst++) = x; |
1285 if (x == 0xff) | 1317 if (x == 0xff) |
1286 { | 1318 { |
1287 x = *(src++); | 1319 x = *(src++); |
1288 if (x >= 0xd0 && x <= 0xd7) | 1320 if (x >= 0xd0 && x <= 0xd7) |
1290 else if (x) | 1322 else if (x) |
1291 break; | 1323 break; |
1292 } | 1324 } |
1293 } | 1325 } |
1294 init_get_bits(&s->gb, s->buffer, dst - s->buffer); | 1326 init_get_bits(&s->gb, s->buffer, dst - s->buffer); |
1327 | |
1328 dprintf("escaping removed %d bytes\n", | |
1329 (buf_end - buf_ptr) - (dst - s->buffer)); | |
1295 } | 1330 } |
1296 else | 1331 else |
1297 init_get_bits(&s->gb, buf_ptr, buf_end - buf_ptr); | 1332 init_get_bits(&s->gb, buf_ptr, buf_end - buf_ptr); |
1298 | 1333 |
1299 s->start_code = start_code; | 1334 s->start_code = start_code; |