00001 #include "fastjpg.h"
00002 #include "fastjpgmacro.h"
00003
00004
00005
00006
00007 #define M_SOF0 0xc0
00008 #define M_SOF1 0xc1
00009 #define M_SOF2 0xc2
00010 #define M_SOF3 0xc3
00011 #define M_SOF5 0xc5
00012 #define M_SOF6 0xc6
00013 #define M_SOF7 0xc7
00014 #define M_JPG 0xc8
00015 #define M_SOF9 0xc9
00016 #define M_SOF10 0xca
00017 #define M_SOF11 0xcb
00018 #define M_SOF13 0xcd
00019 #define M_SOF14 0xce
00020 #define M_SOF15 0xcf
00021 #define M_DHT 0xc4
00022 #define M_DAC 0xcc
00023 #define M_RST0 0xd0
00024 #define M_RST1 0xd1
00025 #define M_RST2 0xd2
00026 #define M_RST3 0xd3
00027 #define M_RST4 0xd4
00028 #define M_RST5 0xd5
00029 #define M_RST6 0xd6
00030 #define M_RST7 0xd7
00031 #define M_SOI 0xd8
00032 #define M_EOI 0xd9
00033 #define M_SOS 0xda
00034 #define M_DQT 0xdb
00035 #define M_DNL 0xdc
00036 #define M_DRI 0xdd
00037 #define M_DHP 0xde
00038 #define M_EXP 0xdf
00039 #define M_APP0 0xe0
00040 #define M_APP1 0xe1
00041 #define M_APP2 0xe2
00042 #define M_APP3 0xe3
00043 #define M_APP4 0xe4
00044 #define M_APP5 0xe5
00045 #define M_APP6 0xe6
00046 #define M_APP7 0xe7
00047 #define M_APP8 0xe8
00048 #define M_APP9 0xe9
00049 #define M_APP10 0xea
00050 #define M_APP11 0xeb
00051 #define M_APP12 0xec
00052 #define M_APP13 0xed
00053 #define M_APP14 0xee
00054 #define M_APP15 0xef
00055 #define M_JPG0 0xf0
00056 #define M_JPG13 0xfd
00057 #define M_COM 0xfe
00058 #define M_TEM 0x01
00059 #define M_ERROR 0x100
00060
00061 static long JJ_ZAG[DCTSIZE2 + 16] =
00062 {
00063 0, 1, 8, 16, 9, 2, 3, 10,
00064 17, 24, 32, 25, 18, 11, 4, 5,
00065 12, 19, 26, 33, 40, 48, 41, 34,
00066 27, 20, 13, 6, 7, 14, 21, 28,
00067 35, 42, 49, 56, 57, 50, 43, 36,
00068 29, 22, 15, 23, 30, 37, 44, 51,
00069 58, 59, 52, 45, 38, 31, 39, 46,
00070 53, 60, 61, 54, 47, 55, 62, 63,
00071 0, 0, 0, 0, 0, 0, 0, 0,
00072 0, 0, 0, 0, 0, 0, 0, 0
00073 };
00074
00075 static char std_luminance_quant_tbl[64] = {
00076 16, 11, 12, 14, 12, 10, 16, 14,
00077 13, 14, 18, 17, 16, 19, 24, 40,
00078 26, 24, 22, 22, 24, 49, 35, 37,
00079 29, 40, 58, 51, 61, 60, 57, 51,
00080 56, 55, 64, 72, 92, 78, 64, 68,
00081 87, 69, 55, 56, 80, 109, 81, 87,
00082 95, 98, 103, 104, 103, 62, 77, 113,
00083 121, 112, 100, 120, 92, 101, 103, 99
00084 };
00085
00086 static char std_chrominance_quant_tbl[64] = {
00087 17, 18, 18, 24, 21, 24, 47, 26,
00088 26, 47, 99, 66, 56, 66, 99, 99,
00089 99, 99, 99, 99, 99, 99, 99, 99,
00090 99, 99, 99, 99, 99, 99, 99, 99,
00091 99, 99, 99, 99, 99, 99, 99, 99,
00092 99, 99, 99, 99, 99, 99, 99, 99,
00093 99, 99, 99, 99, 99, 99, 99, 99,
00094 99, 99, 99, 99, 99, 99, 99, 99
00095 };
00096
00097 int quicktime_fastjpg_skip(quicktime_jpeg_t *jpeg_info, long len)
00098 {
00099 if(len > jpeg_info->chunk_size)
00100 jpeg_info->chunk += jpeg_info->chunk_size;
00101 else
00102 jpeg_info->chunk += len;
00103
00104 return 0;
00105 }
00106
00107 int quicktime_fastjpg_readbyte(quicktime_jpeg_t *jpeg_info)
00108 {
00109 if(jpeg_info->chunk_size > 0)
00110 {
00111 jpeg_info->chunk_size--;
00112 return *(jpeg_info->chunk++);
00113 }
00114 else
00115 return 0;
00116 }
00117
00118 int quicktime_fastjpg_readint16(quicktime_jpeg_t *jpeg_info)
00119 {
00120 if(jpeg_info->chunk_size > 1)
00121 {
00122 jpeg_info->chunk_size -= 2;
00123 jpeg_info->chunk += 2;
00124 return ((int)jpeg_info->chunk[-2] << 8) | (unsigned char)jpeg_info->chunk[-1];
00125 }
00126 else
00127 return 0;
00128 }
00129
00130 int quicktime_fastjpg_readint32(quicktime_jpeg_t *jpeg_info)
00131 {
00132 if(jpeg_info->chunk_size > 3)
00133 {
00134 jpeg_info->chunk_size -= 4;
00135 return (((unsigned long)*(jpeg_info->chunk++) << 24) |
00136 ((unsigned long)*(jpeg_info->chunk++) << 16) |
00137 ((unsigned long)*(jpeg_info->chunk++) << 8) |
00138 ((unsigned long)*(jpeg_info->chunk++)));
00139 }
00140 else
00141 return 0;
00142 }
00143
00144 int quicktime_fastjpg_eof(quicktime_jpeg_t *jpeg_info)
00145 {
00146 if(jpeg_info->chunk_size > 0)
00147 return 0;
00148 else
00149 return 1;
00150 }
00151
00152 int quicktime_fastjpg_init_limittable(quicktime_jpeg_t *jpeg_info)
00153 {
00154 unsigned char *table;
00155 int i;
00156
00157 jpeg_info->jpg_samp_limit = (unsigned char *)malloc((5 * (MAXJSAMPLE + 1) + CENTERJSAMPLE));
00158 jpeg_info->byte_limit = jpeg_info->jpg_samp_limit + MAXJSAMPLE + 1;
00159
00160
00161 table = jpeg_info->jpg_samp_limit + MAXJSAMPLE + 1;
00162
00163
00164 memset(table - (MAXJSAMPLE + 1), 0, (MAXJSAMPLE + 1));
00165
00166
00167 for(i = 0; i <= MAXJSAMPLE; i++) table[i] = (unsigned char)i;
00168
00169
00170 table += CENTERJSAMPLE;
00171
00172
00173
00174 for(i = CENTERJSAMPLE; i < 2 * (MAXJSAMPLE + 1); i++) table[i] = MAXJSAMPLE;
00175
00176
00177 memset(table + (2 * (MAXJSAMPLE + 1)), 0, (2 * (MAXJSAMPLE + 1) - CENTERJSAMPLE));
00178 memcpy(table + (4 * (MAXJSAMPLE + 1) - CENTERJSAMPLE),
00179 (char*)(jpeg_info->jpg_samp_limit + (MAXJSAMPLE + 1)), CENTERJSAMPLE);
00180 }
00181
00182 int quicktime_fastjpg_init_yuv(quicktime_jpeg_t *jpeg_info)
00183 {
00184 long i;
00185 float t_ub, t_vr, t_ug, t_vg;
00186 float t2_ub, t2_vr, t2_ug, t2_vg;
00187
00188 jpeg_info->yuvtabs.YUV_Y_tab = (long*)malloc(256 * sizeof(long));
00189 jpeg_info->yuvtabs.YUV_UB_tab = (long*)malloc(256 * sizeof(long));
00190 jpeg_info->yuvtabs.YUV_VR_tab = (long*)malloc(256 * sizeof(long));
00191 jpeg_info->yuvtabs.YUV_UG_tab = (long*)malloc(256 * sizeof(long));
00192 jpeg_info->yuvtabs.YUV_VG_tab = (long*)malloc(256 * sizeof(long));
00193
00194 t_ub = (1.77200 / 2.0) * (float)(1 << 6) + 0.5;
00195 t_vr = (1.40200 / 2.0) * (float)(1 << 6) + 0.5;
00196 t_ug = (0.34414 / 2.0) * (float)(1 << 6) + 0.5;
00197 t_vg = (0.71414 / 2.0) * (float)(1 << 6) + 0.5;
00198 t2_ub = (1.4 * 1.77200 / 2.0) * (float)(1 << 6) + 0.5;
00199 t2_vr = (1.4 * 1.40200 / 2.0) * (float)(1 << 6) + 0.5;
00200 t2_ug = (1.4 * 0.34414 / 2.0) * (float)(1 << 6) + 0.5;
00201 t2_vg = (1.4 * 0.71414 / 2.0) * (float)(1 << 6) + 0.5;
00202
00203 for(i = 0; i < 256; i++)
00204 {
00205 float x = (float)(2 * i - 255);
00206
00207 jpeg_info->yuvtabs.YUV_UB_tab[i] = (long)(( t_ub * x) + (1 << 5));
00208 jpeg_info->yuvtabs.YUV_VR_tab[i] = (long)(( t_vr * x) + (1 << 5));
00209 jpeg_info->yuvtabs.YUV_UG_tab[i] = (long)((-t_ug * x));
00210 jpeg_info->yuvtabs.YUV_VG_tab[i] = (long)((-t_vg * x) + (1 << 5));
00211 jpeg_info->yuvtabs.YUV_Y_tab[i] = (long)((i << 6) | (i >> 2));
00212 }
00213 return 0;
00214 }
00215
00216 int quicktime_fastjpg_init(quicktime_jpeg_t *jpeg_info)
00217 {
00218 int i;
00219 for(i = 0; i < TOTAL_QUANT_TBLS; i++) jpeg_info->quant_tables[i] = 0;
00220 quicktime_fastjpg_init_limittable(jpeg_info);
00221 jpeg_info->mjpg_kludge = 0;
00222 jpeg_info->jpg_std_DHT_flag = 0;
00223 jpeg_info->mjpa_info.valid = 0;
00224 jpeg_info->yuvbufs.allocated = 0;
00225 jpeg_info->yuvbufs.ybuf = 0;
00226 jpeg_info->yuvbufs.ubuf = 0;
00227 jpeg_info->yuvbufs.vbuf = 0;
00228 quicktime_fastjpg_init_yuv(jpeg_info);
00229 return 0;
00230 }
00231
00232 int quicktime_fastjpg_deleteMCU(quicktime_jpeg_t *jpeg_info)
00233 {
00234 if(jpeg_info->yuvbufs.allocated)
00235 {
00236 free(jpeg_info->yuvbufs.ybuf);
00237 free(jpeg_info->yuvbufs.ubuf);
00238 free(jpeg_info->yuvbufs.vbuf);
00239 }
00240 jpeg_info->yuvbufs.ybuf = 0;
00241 jpeg_info->yuvbufs.ubuf = 0;
00242 jpeg_info->yuvbufs.vbuf = 0;
00243
00244 return 0;
00245 }
00246
00247
00248 int quicktime_fastjpg_delete(quicktime_jpeg_t *jpeg_info)
00249 {
00250 int i;
00251 for(i = 0; i < TOTAL_QUANT_TBLS; i++)
00252 if(jpeg_info->quant_tables[i])
00253 {
00254 free(jpeg_info->quant_tables[i]);
00255 jpeg_info->quant_tables[i] = 0;
00256 }
00257
00258 if(jpeg_info->jpg_samp_limit)
00259 {
00260 free(jpeg_info->jpg_samp_limit);
00261 jpeg_info->jpg_samp_limit = 0;
00262 }
00263
00264 quicktime_fastjpg_deleteMCU(jpeg_info);
00265
00266 free(jpeg_info->yuvtabs.YUV_Y_tab);
00267 free(jpeg_info->yuvtabs.YUV_UB_tab);
00268 free(jpeg_info->yuvtabs.YUV_VR_tab);
00269 free(jpeg_info->yuvtabs.YUV_UG_tab);
00270 free(jpeg_info->yuvtabs.YUV_VG_tab);
00271 }
00272
00273 int quicktime_fastjpg_resethuffman(quicktime_jpeg_t *jpeg_info)
00274 {
00275 jpeg_info->jpg_comps[0].dc = 0;
00276 jpeg_info->jpg_comps[1].dc = 0;
00277 jpeg_info->jpg_comps[2].dc = 0;
00278 jpeg_info->jpg_h_bbuf = 0;
00279 jpeg_info->jpg_h_bnum = 0;
00280 }
00281
00282 int quicktime_fastjpg_buildhuffman(quicktime_jpeg_t *jpeg_info,
00283 quicktime_jpeg_huffman *htable,
00284 unsigned char *hbits,
00285 unsigned char *hvals)
00286 {
00287 unsigned long clen, num_syms, p, i, si, code, lookbits;
00288 unsigned long l, ctr;
00289 unsigned char huffsize[257];
00290 unsigned long huffcode[257];
00291
00292
00293 num_syms = 0;
00294 for(clen = 1; clen <= 16; clen++)
00295 {
00296 for(i = 1; i <= (unsigned long)(hbits[clen]); i++)
00297 huffsize[num_syms++] = (unsigned char)(clen);
00298 }
00299 huffsize[num_syms] = 0;
00300
00301
00302 code = 0;
00303 si = huffsize[0];
00304 p = 0;
00305 while(huffsize[p])
00306 {
00307 while(((unsigned long)huffsize[p]) == si)
00308 {
00309 huffcode[p++] = code;
00310 code++;
00311 }
00312 code <<= 1;
00313 si++;
00314 }
00315
00316
00317 p = 0;
00318 for(l = 1; l <= 16; l++)
00319 {
00320 if (htable->bits[l])
00321 {
00322 htable->valptr[l] = p;
00323 htable->mincode[l] = huffcode[p];
00324 p += (unsigned long)(htable->bits[l]);
00325 htable->maxcode[l] = huffcode[p-1];
00326 }
00327 else
00328 {
00329 htable->valptr[l] = 0;
00330 htable->mincode[l] = 0;
00331 htable->maxcode[l] = 0;
00332 }
00333 }
00334 htable->maxcode[17] = 0xFFFFFL;
00335
00336
00337
00338 memset((char *)htable->cache, 0, ((1 << HUFF_LOOKAHEAD) * sizeof(unsigned int16_t)));
00339 p = 0;
00340 for (l = 1; l <= HUFF_LOOKAHEAD; l++)
00341 {
00342 for (i = 1; i <= (unsigned long) htable->bits[l]; i++, p++)
00343 {
00344 int16_t the_code = (unsigned int16_t)((l << 8) | htable->vals[p]);
00345
00346
00347
00348
00349 lookbits = huffcode[p] << (HUFF_LOOKAHEAD - l);
00350 for(ctr = 1 << (HUFF_LOOKAHEAD - l); ctr > 0; ctr--)
00351 {
00352 htable->cache[lookbits] = the_code;
00353 lookbits++;
00354 }
00355 }
00356 }
00357 }
00358
00359 int quicktime_fastjpg_buildstdhuffman(quicktime_jpeg_t *jpeg_info)
00360 {
00361 long ttt, len;
00362 quicktime_jpeg_huffman *htable;
00363 unsigned char *hbits, *Sbits;
00364 unsigned char *hvals, *Svals;
00365
00366 static unsigned char dc_luminance_bits[] =
00367 { 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
00368 static unsigned char dc_luminance_vals[] =
00369 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
00370
00371 static unsigned char dc_chrominance_bits[] =
00372 { 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
00373 static unsigned char dc_chrominance_vals[] =
00374 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
00375
00376 static unsigned char ac_luminance_bits[] =
00377 { 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d };
00378 static unsigned char ac_luminance_vals[] =
00379 { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
00380 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
00381 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
00382 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
00383 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
00384 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
00385 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
00386 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
00387 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
00388 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
00389 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
00390 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
00391 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
00392 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
00393 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
00394 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
00395 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
00396 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
00397 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
00398 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
00399 0xf9, 0xfa };
00400
00401 static unsigned char ac_chrominance_bits[] =
00402 { 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 };
00403 static unsigned char ac_chrominance_vals[] =
00404 { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
00405 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
00406 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
00407 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
00408 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
00409 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
00410 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
00411 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
00412 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
00413 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
00414 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
00415 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
00416 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
00417 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
00418 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
00419 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
00420 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
00421 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
00422 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
00423 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
00424 0xf9, 0xfa };
00425
00426 for(ttt = 0; ttt < 4; ttt++)
00427 {
00428 unsigned long index = ttt & 1;
00429 unsigned long i, count;
00430
00431 if (ttt <= 1)
00432 {
00433 htable = &(jpeg_info->jpg_dc_huff[index]);
00434 hbits = jpeg_info->jpg_dc_huff[index].bits;
00435 hvals = jpeg_info->jpg_dc_huff[index].vals;
00436 if(index == 0)
00437 {
00438 Sbits = dc_luminance_bits;
00439 Svals = dc_luminance_vals;
00440 }
00441 else
00442 {
00443 Sbits = dc_chrominance_bits;
00444 Svals = dc_chrominance_vals;
00445 }
00446 }
00447 else
00448 {
00449 htable = &(jpeg_info->jpg_ac_huff[index]);
00450 hbits = jpeg_info->jpg_ac_huff[index].bits;
00451 hvals = jpeg_info->jpg_ac_huff[index].vals;
00452 if(index == 0)
00453 {
00454 Sbits = ac_luminance_bits;
00455 Svals = ac_luminance_vals;
00456 }
00457 else
00458 {
00459 Sbits = ac_chrominance_bits;
00460 Svals = ac_chrominance_vals;
00461 }
00462 }
00463 hbits[0] = 0;
00464 count = 0;
00465 for(i = 1; i <= 16; i++)
00466 {
00467 hbits[i] = Sbits[i];
00468 count += hbits[i];
00469 }
00470 len -= 17;
00471 if(count > 256)
00472 {
00473 printf("quicktime_fastjpg_buildstdhuffman: STD DHT bad count %d\n", count);
00474 return 1;
00475 }
00476
00477 for(i = 0; i < count; i++) hvals[i] = Svals[i];
00478 len -= count;
00479
00480 quicktime_fastjpg_buildhuffman(jpeg_info,
00481 htable,
00482 hbits,
00483 hvals);
00484 }
00485 jpeg_info->jpg_std_DHT_flag = 1;
00486 return 0;
00487 }
00488
00489 int quicktime_fastjpg_buildstdDQT(quicktime_jpeg_t *jpeg_info, long scale)
00490 {
00491 long i, tbl_num;
00492 long *quant_table;
00493 unsigned int *table;
00494 unsigned int std_luminance_quant_tbl[DCTSIZE2] =
00495 {
00496 16, 11, 10, 16, 24, 40, 51, 61,
00497 12, 12, 14, 19, 26, 58, 60, 55,
00498 14, 13, 16, 24, 40, 57, 69, 56,
00499 14, 17, 22, 29, 51, 87, 80, 62,
00500 18, 22, 37, 56, 68, 109, 103, 77,
00501 24, 35, 55, 64, 81, 104, 113, 92,
00502 49, 64, 78, 87, 103, 121, 120, 101,
00503 72, 92, 95, 98, 112, 100, 103, 99
00504 };
00505 unsigned int std_chrominance_quant_tbl[DCTSIZE2] =
00506 {
00507 17, 18, 24, 47, 99, 99, 99, 99,
00508 18, 21, 26, 66, 99, 99, 99, 99,
00509 24, 26, 56, 99, 99, 99, 99, 99,
00510 47, 66, 99, 99, 99, 99, 99, 99,
00511 99, 99, 99, 99, 99, 99, 99, 99,
00512 99, 99, 99, 99, 99, 99, 99, 99,
00513 99, 99, 99, 99, 99, 99, 99, 99,
00514 99, 99, 99, 99, 99, 99, 99, 99
00515 };
00516
00517 tbl_num = 0;
00518 for(tbl_num = 0; tbl_num <= 1; tbl_num++)
00519 {
00520 if(jpeg_info->quant_tables[tbl_num] == 0)
00521 {
00522 jpeg_info->quant_tables[tbl_num] = (long*)malloc(64 * sizeof(long));
00523 }
00524
00525 if (tbl_num == 0)
00526 table = std_luminance_quant_tbl;
00527 else
00528 table = std_chrominance_quant_tbl;
00529 quant_table = jpeg_info->quant_tables[tbl_num];
00530
00531 for (i = 0; i < DCTSIZE2; i++)
00532 {
00533 long tmp;
00534 tmp = ((long)table[i] * scale + 50L) / 100L;
00535 if(tmp <= 0) tmp = 1;
00536 if(tmp > 255) tmp = 255;
00537 quant_table[i] = (long)tmp;
00538 }
00539 }
00540 return 0;
00541 }
00542
00543 int quicktime_fastjpg_get_marker(quicktime_jpeg_t *jpeg_info)
00544 {
00545 int c, done = 0;
00546
00547 while(!done)
00548 {
00549 c = quicktime_fastjpg_readbyte(jpeg_info);
00550
00551 while(c != 0xFF)
00552 {
00553 if(quicktime_fastjpg_eof(jpeg_info)) done = 2;
00554 c = quicktime_fastjpg_readbyte(jpeg_info);
00555 }
00556
00557
00558 do
00559 {
00560 if(quicktime_fastjpg_eof(jpeg_info)) done = 2;
00561 c = quicktime_fastjpg_readbyte(jpeg_info);
00562 }while (c == 0xFF);
00563
00564
00565 if (c != 0) done = 1;
00566 }
00567
00568 if(done == 1)
00569 return c;
00570 else
00571 return 0;
00572 }
00573
00574 int quicktime_fastjpg_skip_marker(quicktime_jpeg_t *jpeg_info)
00575 {
00576 long len, tmp;
00577 len = quicktime_fastjpg_readint16(jpeg_info);
00578 len -= 2;
00579 if(len <= 0) return 1;
00580 if(quicktime_fastjpg_eof(jpeg_info)) return 1;
00581 while(len--) quicktime_fastjpg_readbyte(jpeg_info);
00582 return 0;
00583 }
00584
00585 int quicktime_fastjpg_check_for_marker(quicktime_jpeg_t *jpeg_info)
00586 {
00587 if(jpeg_info->marker) return(jpeg_info->marker);
00588 if(jpeg_info->chunk_size < 2) return(0);
00589 if((jpeg_info->chunk[0] == 0xff) && (jpeg_info->chunk[1] != 0x00))
00590 {
00591 jpeg_info->marker = jpeg_info->chunk[1];
00592 {
00593 if(jpeg_info->jpg_h_bnum)
00594 {
00595 printf("quicktime_fastjpg_check_for_marker: check marker positive - lost %d bits\n",
00596 jpeg_info->jpg_h_bnum);
00597 }
00598 }
00599 jpeg_info->jpg_h_bnum = 0;
00600 jpeg_info->jpg_h_bbuf = 0;
00601 jpeg_info->chunk += 2;
00602 jpeg_info->chunk_size -= 2;
00603 }
00604 return(jpeg_info->marker);
00605 }
00606
00607 int quicktime_fastjpg_readSOI(quicktime_jpeg_t *jpeg_info)
00608 {
00609 jpeg_info->jpg_rst_interval = 0;
00610 return 0;
00611 }
00612
00613 int quicktime_fastjpg_readSOF(quicktime_jpeg_t *jpeg_info)
00614 {
00615 int result = 0;
00616 int len, i, c;
00617 quicktime_jpeg_comp_header *comp;
00618
00619 len = quicktime_fastjpg_readint16(jpeg_info);
00620 if(jpeg_info->mjpg_kludge)
00621 len -= 6;
00622 else
00623 len -= 8;
00624
00625 jpeg_info->jpg_dprec = quicktime_fastjpg_readbyte(jpeg_info);
00626 jpeg_info->jpg_height = quicktime_fastjpg_readint16(jpeg_info);
00627 jpeg_info->jpg_width = quicktime_fastjpg_readint16(jpeg_info);
00628 jpeg_info->jpg_num_comps = quicktime_fastjpg_readbyte(jpeg_info);
00629
00630 for(i = 0; i < jpeg_info->jpg_num_comps; i++)
00631 {
00632 if(i > MAX_COMPS)
00633 comp = &(jpeg_info->jpg_comps[DUMMY_COMP]);
00634 else
00635 comp = &(jpeg_info->jpg_comps[i]);
00636
00637 comp->id = quicktime_fastjpg_readbyte(jpeg_info);
00638 comp->hvsample = quicktime_fastjpg_readbyte(jpeg_info);
00639 comp->qtbl_num = quicktime_fastjpg_readbyte(jpeg_info);
00640 }
00641 return(quicktime_fastjpg_eof(jpeg_info));
00642 }
00643
00644 int quicktime_fastjpg_readSOS(quicktime_jpeg_t *jpeg_info)
00645 {
00646 int len, i, j;
00647 int comp_id, htbl_num;
00648 int jpg_Ss, jpg_Se, jpg_AhAl;
00649
00650 len = quicktime_fastjpg_readint16(jpeg_info);
00651 jpeg_info->jpg_comps_in_scan = quicktime_fastjpg_readbyte(jpeg_info);
00652
00653 for(i = 0; i < jpeg_info->jpg_comps_in_scan; i++)
00654 {
00655 quicktime_jpeg_comp_header *comp = 0;
00656 comp_id = quicktime_fastjpg_readbyte(jpeg_info);
00657 for(j = 0; j < jpeg_info->jpg_num_comps; )
00658 {
00659 comp = &(jpeg_info->jpg_comps[j]);
00660 if(comp->id == comp_id) break;
00661 j++;
00662 }
00663
00664 if (j > jpeg_info->jpg_num_comps)
00665 {
00666 printf("quicktime_fastjpg_readSOS: bad id %x", comp_id);
00667 return 1;
00668 }
00669
00670 htbl_num = quicktime_fastjpg_readbyte(jpeg_info);
00671 comp->dc_htbl_num = (htbl_num >> 4) & 0x0f;
00672 comp->ac_htbl_num = (htbl_num ) & 0x0f;
00673 }
00674 jpg_Ss = quicktime_fastjpg_readbyte(jpeg_info);
00675 jpg_Se = quicktime_fastjpg_readbyte(jpeg_info);
00676 jpg_AhAl = quicktime_fastjpg_readbyte(jpeg_info);
00677 return(quicktime_fastjpg_eof(jpeg_info));
00678 }
00679
00680 int quicktime_fastjpg_readDHT(quicktime_jpeg_t *jpeg_info)
00681 {
00682 int len, i, index, count;
00683 unsigned long result = 1;
00684 quicktime_jpeg_huffman *htable;
00685 unsigned char *hbits;
00686 unsigned char *hvals;
00687
00688 jpeg_info->jpg_std_DHT_flag = 0;
00689 len = quicktime_fastjpg_readint16(jpeg_info);
00690
00691 if(jpeg_info->mjpg_kludge) len += 2;
00692
00693 len -= 2;
00694
00695 if(quicktime_fastjpg_eof(jpeg_info)) return 1;
00696
00697 while(len > 0)
00698 {
00699 index = quicktime_fastjpg_readbyte(jpeg_info);
00700 len--;
00701
00702 if (index & 0x10)
00703 {
00704 index &= 0x0f;
00705 if (index >= TOTAL_HUFF_TBLS) break;
00706 htable = &(jpeg_info->jpg_ac_huff[index]);
00707 hbits = jpeg_info->jpg_ac_huff[index].bits;
00708 hvals = jpeg_info->jpg_ac_huff[index].vals;
00709 }
00710 else
00711 {
00712 index &= 0x0f;
00713 if (index >= TOTAL_HUFF_TBLS) break;
00714 htable = &(jpeg_info->jpg_dc_huff[index]);
00715 hbits = jpeg_info->jpg_dc_huff[index].bits;
00716 hvals = jpeg_info->jpg_dc_huff[index].vals;
00717 }
00718
00719 hbits[0] = 0;
00720 count = 0;
00721
00722 if(len < 16) break;
00723 for (i = 1; i <= 16; i++)
00724 {
00725 hbits[i] = quicktime_fastjpg_readbyte(jpeg_info);
00726 count += hbits[i];
00727 }
00728 len -= 16;
00729
00730 if(count > 256)
00731 {
00732 printf("quicktime_fastjpg_readDHT: DHT bad count %d using default.\n", count);
00733 break;
00734 }
00735
00736 if(len < count)
00737 {
00738 printf("quicktime_fastjpg_readDHT: DHT count(%d) > len(%d).\n", count, len);
00739 break;
00740 }
00741
00742 for(i = 0; i < count; i++) hvals[i] = quicktime_fastjpg_readbyte(jpeg_info);
00743 len -= count;
00744
00745 quicktime_fastjpg_buildhuffman(jpeg_info, htable, hbits, hvals);
00746 result = 0;
00747 }
00748
00749 if(result)
00750 {
00751
00752 while(len > 0)
00753 {
00754 len--;
00755 quicktime_fastjpg_readbyte(jpeg_info);
00756 }
00757 quicktime_fastjpg_buildstdhuffman(jpeg_info);
00758 result = 0;
00759 }
00760
00761 return result;
00762 }
00763
00764 int quicktime_fastjpg_readDQT(quicktime_jpeg_t *jpeg_info)
00765 {
00766 long len;
00767 len = quicktime_fastjpg_readint16(jpeg_info);
00768 if(!jpeg_info->mjpg_kludge) len -= 2;
00769
00770 while(len > 0)
00771 {
00772 long i, tbl_num, prec;
00773 long *quant_table;
00774
00775 tbl_num = quicktime_fastjpg_readbyte(jpeg_info);
00776 len -= 1;
00777
00778 prec = (tbl_num >> 4) & 0x0f;
00779 prec = (prec)?(2 * DCTSIZE2) : (DCTSIZE2);
00780 tbl_num &= 0x0f;
00781 if (tbl_num > 4)
00782 {
00783 printf("quicktime_fastjpg_readDQT: bad DQT tnum %x\n", tbl_num);
00784 return 1;
00785 }
00786
00787 if(jpeg_info->quant_tables[tbl_num] == 0)
00788 {
00789 jpeg_info->quant_tables[tbl_num] = (long *)malloc(64 * sizeof(long));
00790 }
00791 len -= prec;
00792
00793 if(quicktime_fastjpg_eof(jpeg_info)) return 1;
00794 quant_table = jpeg_info->quant_tables[tbl_num];
00795 if(prec == 128)
00796 {
00797 unsigned long tmp;
00798 for(i = 0; i < DCTSIZE2; i++)
00799 {
00800 tmp = quicktime_fastjpg_readint16(jpeg_info);
00801 quant_table[JJ_ZAG[i]] = (long)tmp;
00802 }
00803 }
00804 else
00805 {
00806 unsigned long tmp;
00807 for(i = 0; i < DCTSIZE2; i++)
00808 {
00809 tmp = quicktime_fastjpg_readbyte(jpeg_info);
00810 quant_table[JJ_ZAG[i]] = (long)tmp;
00811 }
00812 }
00813 }
00814 return 0;
00815 }
00816
00817 int quicktime_fastjpg_readAPPX(quicktime_jpeg_t *jpeg_info)
00818 {
00819 long len;
00820 len = quicktime_fastjpg_readint32(jpeg_info);
00821 len -= 2;
00822 if(len > 4)
00823 {
00824 unsigned long first;
00825 first = quicktime_fastjpg_readint32(jpeg_info);
00826 len -= 4;
00827 */
00828
00829
00830
00831
00832
00833
00834
00835
00836 if(len > (0x28 - 4))
00837 {
00838 unsigned long jid;
00839 jid = quicktime_fastjpg_readint32(jpeg_info);
00840 len -= 4;
00841 if(jid == JPEG_APP1_MJPA)
00842 {
00843 jpeg_info->mjpa_info.valid = 1;
00844 jpeg_info->mjpa_info.field_sz = quicktime_fastjpg_readint32(jpeg_info);
00845 jpeg_info->mjpa_info.pad_field_sz = quicktime_fastjpg_readint32(jpeg_info);
00846 jpeg_info->mjpa_info.next_off = quicktime_fastjpg_readint32(jpeg_info);
00847 jpeg_info->mjpa_info.quant_off = quicktime_fastjpg_readint32(jpeg_info);
00848 jpeg_info->mjpa_info.huff_off = quicktime_fastjpg_readint32(jpeg_info);
00849 jpeg_info->mjpa_info.image_off = quicktime_fastjpg_readint32(jpeg_info);
00850 jpeg_info->mjpa_info.scan_off = quicktime_fastjpg_readint32(jpeg_info);
00851 jpeg_info->mjpa_info.data_off = quicktime_fastjpg_readint32(jpeg_info);
00852 len -= 32;
00853 }
00854 }
00855 }
00856 if(len) quicktime_fastjpg_skip(jpeg_info, len);
00857 return 0;
00858 }
00859
00860 int quicktime_fastjpg_readDRI(quicktime_jpeg_t *jpeg_info)
00861 {
00862 long len;
00863 len = quicktime_fastjpg_readint16(jpeg_info);
00864 jpeg_info->jpg_rst_interval = quicktime_fastjpg_readint16(jpeg_info);
00865 return 0;
00866
00867 }
00868
00869 int quicktime_fastjpg_readEOI(quicktime_jpeg_t *jpeg_info)
00870 {
00871 while(jpeg_info->marker = quicktime_fastjpg_get_marker(jpeg_info))
00872 {
00873 if(jpeg_info->marker == M_EOI)
00874 {
00875 jpeg_info->jpg_saw_EOI = 1;
00876 return 1;
00877 }
00878 }
00879 return 0;
00880 }
00881
00882
00883
00884
00885 int quicktime_fastjpg_read_markers(quicktime_jpeg_t *jpeg_info)
00886 {
00887 int done = 0;
00888
00889 while(!done)
00890 {
00891 if(!(jpeg_info->marker = quicktime_fastjpg_get_marker(jpeg_info)))
00892 done = 2;
00893 else
00894 {
00895
00896 switch(jpeg_info->marker)
00897 {
00898 case M_SOI:
00899 if(quicktime_fastjpg_readSOI(jpeg_info)) done = 2;
00900 else
00901 jpeg_info->jpg_saw_SOI = 1;
00902 break;
00903
00904 case M_SOF0:
00905 case M_SOF1:
00906 case M_SOF2:
00907 if(quicktime_fastjpg_readSOF(jpeg_info)) done = 2;
00908 else
00909 jpeg_info->jpg_saw_SOF = 1;
00910 break;
00911
00912
00913 case M_SOF3:
00914 case M_SOF5:
00915 case M_SOF6:
00916 case M_SOF7:
00917 case M_SOF9:
00918 case M_SOF10:
00919 case M_SOF11:
00920 case M_SOF13:
00921 case M_SOF14:
00922 case M_SOF15:
00923 done = 2;
00924 break;
00925
00926 case M_SOS:
00927 if(quicktime_fastjpg_readSOS(jpeg_info)) done = 2;
00928 else
00929 {
00930 jpeg_info->jpg_saw_SOS = 1;
00931 jpeg_info->jpg_nxt_rst_num = 0;
00932 done = 1;
00933 }
00934 break;
00935
00936 case M_DHT:
00937 if(quicktime_fastjpg_readDHT(jpeg_info)) done = 2;
00938 else
00939 jpeg_info->jpg_saw_DHT = 1;
00940 break;
00941
00942 case M_DQT:
00943 if(quicktime_fastjpg_readDQT(jpeg_info)) done = 2;
00944 else
00945 jpeg_info->jpg_saw_DQT = 1;
00946 break;
00947
00948 case M_DRI:
00949 if(quicktime_fastjpg_readDRI(jpeg_info)) done = 2;
00950 break;
00951
00952 case M_COM:
00953 {
00954
00955 int len;
00956 len = quicktime_fastjpg_readint16(jpeg_info);
00957 len -= 2;
00958
00959 while(len > 0)
00960 {
00961 quicktime_fastjpg_readbyte(jpeg_info); len--;
00962 }
00963 }
00964 break;
00965
00966 case M_APP0:
00967 case M_APP1:
00968 if(quicktime_fastjpg_readAPPX(jpeg_info)) done = 2;
00969 break;
00970
00971 case M_EOI:
00972 printf("quicktime_fastjpg_read_markers: reached EOI without data\n");
00973 done = 2;
00974 break;
00975
00976 case M_RST0:
00977 case M_RST1:
00978 case M_RST2:
00979 case M_RST3:
00980 case M_RST4:
00981 case M_RST5:
00982 case M_RST6:
00983 case M_RST7:
00984 case M_TEM:
00985 break;
00986
00987 default:
00988 printf("quicktime_fastjpg_read_markers: unknown marker %x\n", jpeg_info->marker);
00989 if(quicktime_fastjpg_skip_marker(jpeg_info)) done = 2;
00990 break;
00991 }
00992 }
00993 }
00994 if(done == 2) return 1; else return 0;
00995 }
00996
00997 int quicktime_fastjpg_initMCU(quicktime_jpeg_t *jpeg_info,
00998 int width,
00999 int height,
01000 int full_flag)
01001 {
01002 int twidth = (width + 15) / 16;
01003 int theight = (height + 15) / 16;
01004 if(theight & 1) theight++;
01005
01006 if(full_flag)
01007 twidth *= (theight << 2);
01008 else
01009 twidth <<= 2;
01010
01011 if(!jpeg_info->yuvbufs.allocated)
01012 {
01013 jpeg_info->yuvbufs.allocated = 1;
01014 jpeg_info->yuvbufs.ybuf = (unsigned char*)malloc(twidth * DCTSIZE2);
01015 jpeg_info->yuvbufs.ubuf = (unsigned char*)malloc(twidth * DCTSIZE2);
01016 jpeg_info->yuvbufs.vbuf = (unsigned char*)malloc(twidth * DCTSIZE2);
01017 }
01018 }
01019
01020 int quicktime_fastjpg_skip_to_next_rst(quicktime_jpeg_t *jpeg_info)
01021 {
01022 unsigned long d, last_ff = 0;
01023 jpeg_info->jpg_h_bnum = 0;
01024 jpeg_info->jpg_h_bbuf = 0;
01025 while(jpeg_info->chunk_size)
01026 {
01027 d = *(jpeg_info->chunk++);
01028 jpeg_info->chunk_size--;
01029 if(last_ff)
01030 {
01031 if((d != 0) && (d != 0xff)) return d;
01032 }
01033 last_ff = (d == 0xff) ? 1 : 0;
01034 }
01035 return M_EOI;
01036 }
01037
01038
01039
01040
01041 int quicktime_fastjpg_huffparse(quicktime_jpeg_t *jpeg_info,
01042 quicktime_jpeg_comp_header *comp,
01043 int16_t *dct_buf,
01044 unsigned long *qtab,
01045 unsigned char *OBuf)
01046 {
01047 unsigned long tmp_, tmp__, hcode_, t1_, shift_, minbits_;
01048 long i, dcval, level;
01049 unsigned long size, run, tmp, coeff;
01050 quicktime_jpeg_huffman *huff_hdr = &(jpeg_info->jpg_dc_huff[comp->dc_htbl_num]);
01051 unsigned int16_t *huff_tbl = huff_hdr->cache;
01052 unsigned char *rnglimit = jpeg_info->jpg_samp_limit + (CENTERJSAMPLE + MAXJSAMPLE + 1);
01053 unsigned long c_cnt, pos = 0;
01054
01055 QUICKTIME_FASTJPG_HUFF_DECODE(huff_hdr, huff_tbl, jpeg_info->jpg_h_bnum, jpeg_info->jpg_h_bbuf, size);
01056
01057 if(size)
01058 {
01059 unsigned long bits;
01060 QUICKTIME_FASTJPG_GET_BITS(size, jpeg_info->jpg_h_bnum, jpeg_info->jpg_h_bbuf, bits);
01061 dcval = QUICKTIME_FASTJPG_HUFF_EXTEND(bits, size);
01062 comp->dc += dcval;
01063 }
01064 dcval = comp->dc;
01065
01066
01067 memset((char *)(dct_buf), 0, (DCTSIZE2 * sizeof(int16_t)));
01068 dcval *= (long)qtab[0];
01069 dct_buf[0] = (int16_t)dcval;
01070 c_cnt = 0;
01071
01072 huff_hdr = &(jpeg_info->jpg_ac_huff[comp->ac_htbl_num]);
01073 huff_tbl = huff_hdr->cache;
01074 for(i = 1; i < 64; )
01075 {
01076 QUICKTIME_FASTJPG_HUFF_DECODE(huff_hdr, huff_tbl, jpeg_info->jpg_h_bnum, jpeg_info->jpg_h_bbuf, tmp);
01077 size = tmp & 0x0f;
01078 run = (tmp >> 4) & 0x0f;
01079
01080 if(size)
01081 {
01082 i += run;
01083 QUICKTIME_FASTJPG_GET_BITS(size, jpeg_info->jpg_h_bnum, jpeg_info->jpg_h_bbuf, level);
01084 coeff = (long)QUICKTIME_FASTJPG_HUFF_EXTEND(level, size);
01085 pos = JJ_ZAG[i];
01086 coeff *= (long)qtab[pos];
01087 if(coeff)
01088 {
01089 c_cnt++;
01090 dct_buf[pos] = (int16_t)(coeff);
01091 }
01092 i++;
01093 }
01094 else
01095 {
01096 if(run != 15) break;
01097 i += 16;
01098 }
01099 }
01100
01101 if(c_cnt) quicktime_rev_dct(dct_buf, OBuf, rnglimit);
01102 else
01103 {
01104 register unsigned char *op = OBuf;
01105 register int jj = 8;
01106 int16_t v = *dct_buf;
01107 register unsigned char dc;
01108
01109 v = (v < 0) ? ((v - 3) >> 3) : ((v + 4) >> 3);
01110 dc = rnglimit[(int)(v & RANGE_MASK)];
01111 while(jj--)
01112 {
01113 op[0] = op[1] = op[2] = op[3] = op[4] = op[5] = op[6] = op[7] = dc;
01114 op += 8;
01115 }
01116 }
01117 return 0;
01118 }
01119
01120
01121 int quicktime_fastjpg_MCU411111_to_RGB(QUICKTIME_MCU_ARGS)
01122 {
01123 QUICKTIME_MCU_VARS
01124 QUICKTIME_MCU111111_MID_VARS
01125 QUICKTIME_MCU_INNER_VARS
01126
01127 while(frame_height > 0)
01128 {
01129 yptr = ybuf;
01130 uptr = ubuf;
01131 vptr = vbuf;
01132 for(yi = 0; yi < 8; yi++)
01133 {
01134 QUICKTIME_MCU111111_MID_DECL;
01135 if(frame_height <= 0) return 0;
01136 while(xi--)
01137 {
01138 QUICKTIME_MCU_INNER_INIT;
01139 QUICKTIME_MCU_YUV_TO_RGB(YTab[*yp++], cr, cg, cb, ip);
01140 QUICKTIME_MCU_YUV_TO_RGB(YTab[*yp++], cr, cg, cb, ip);
01141 QUICKTIME_MCU_YUV_TO_RGB(YTab[*yp++], cr, cg, cb, ip);
01142 QUICKTIME_MCU_YUV_TO_RGB(YTab[*yp++], cr, cg, cb, ip);
01143 QUICKTIME_MCU4H_INNER_TAIL(56, 56);
01144 }
01145 yptr += 8;
01146 uptr += 8;
01147 vptr += 8;
01148 frame_height--;
01149 row_pointers += interlaced ? 2 : 1;
01150 }
01151 ybuf += mcu_row_size << 2;
01152 ubuf += mcu_row_size;
01153 vbuf += mcu_row_size;
01154 }
01155 }
01156
01157 int quicktime_fastjpg_decode_411111(quicktime_jpeg_t *jpeg_info,
01158 unsigned char **output_rows,
01159 int jpeg_width,
01160 int jpeg_height,
01161 int interlaced,
01162 int row_offset,
01163 int frame_width,
01164 int frame_height)
01165 {
01166 long x, mcu_cols, mcu_rows;
01167 long *qtab0, *qtab1, *qtab2;
01168 unsigned char *Ybuf, *Ubuf, *Vbuf;
01169 unsigned long rst_count;
01170 unsigned long rst_skip = 0;
01171 unsigned long orow_size = frame_width * 3 * (interlaced ? 2 : 1);
01172
01173 if(interlaced) frame_height >>= 1;
01174 frame_width += 3;
01175 frame_width >>= 2;
01176 qtab0 = jpeg_info->quant_tables[jpeg_info->jpg_comps[0].qtbl_num];
01177 qtab1 = jpeg_info->quant_tables[jpeg_info->jpg_comps[1].qtbl_num];
01178 qtab2 = jpeg_info->quant_tables[jpeg_info->jpg_comps[2].qtbl_num];
01179
01180 mcu_cols = (jpeg_width + 31) / 32;
01181 mcu_rows = (jpeg_height + 7) / 8;
01182 jpeg_info->marker = 0x00;
01183
01184 rst_count = jpeg_info->jpg_rst_interval;
01185 output_rows += row_offset;
01186 while(mcu_rows--)
01187 {
01188 Ybuf = jpeg_info->yuvbufs.ybuf;
01189 Ubuf = jpeg_info->yuvbufs.ubuf;
01190 Vbuf = jpeg_info->yuvbufs.vbuf;
01191 x = mcu_cols;
01192 while(x--)
01193 {
01194 if(rst_skip)
01195 {
01196 rst_skip--;
01197 memset(Ybuf, 0, (DCTSIZE2 << 2));
01198 memset(Ubuf, 0x80, DCTSIZE2);
01199 memset(Vbuf, 0x80, DCTSIZE2);
01200 Ybuf += (DCTSIZE2 << 2);
01201 Ubuf += DCTSIZE2;
01202 Vbuf += DCTSIZE2;
01203 }
01204 else
01205 {
01206 QUICKTIME_FASTJPG_HANDLE_RST(jpeg_info->jpg_rst_interval, rst_count);
01207
01208
01209 quicktime_fastjpg_huffparse(jpeg_info, &(jpeg_info->jpg_comps[0]), jpeg_info->jpg_dct_buf, qtab0, Ybuf); Ybuf += DCTSIZE2;
01210 quicktime_fastjpg_huffparse(jpeg_info, &(jpeg_info->jpg_comps[0]), jpeg_info->jpg_dct_buf, qtab0, Ybuf); Ybuf += DCTSIZE2;
01211 quicktime_fastjpg_huffparse(jpeg_info, &(jpeg_info->jpg_comps[0]), jpeg_info->jpg_dct_buf, qtab0, Ybuf); Ybuf += DCTSIZE2;
01212 quicktime_fastjpg_huffparse(jpeg_info, &(jpeg_info->jpg_comps[0]), jpeg_info->jpg_dct_buf, qtab0, Ybuf); Ybuf += DCTSIZE2;
01213 quicktime_fastjpg_huffparse(jpeg_info, &(jpeg_info->jpg_comps[1]), jpeg_info->jpg_dct_buf, qtab1, Ubuf); Ubuf += DCTSIZE2;
01214 quicktime_fastjpg_huffparse(jpeg_info, &(jpeg_info->jpg_comps[2]), jpeg_info->jpg_dct_buf, qtab2, Vbuf); Vbuf += DCTSIZE2;
01215
01216 if(jpeg_info->marker == 0)
01217 jpeg_info->marker = quicktime_fastjpg_check_for_marker(jpeg_info);
01218 QUICKTIME_FASTJPG_TEST_MARKER;
01219 }
01220 }
01221
01222 quicktime_fastjpg_MCU411111_to_RGB(jpeg_info,
01223 output_rows,
01224 frame_width,
01225 (frame_height < 8 ? frame_height : 8),
01226 (mcu_cols * DCTSIZE2),
01227 orow_size,
01228 &(jpeg_info->yuvbufs),
01229 interlaced);
01230 frame_height -= 8;
01231 output_rows += interlaced ? 16 : 8;
01232 }
01233
01234 if(jpeg_info->marker)
01235 {
01236 jpeg_info->jpg_h_bbuf = 0;
01237 jpeg_info->jpg_h_bnum = 0;
01238 }
01239 return 0;
01240 }
01241
01242 int quicktime_fastjpg_MCU221111_to_RGB(QUICKTIME_MCU_ARGS)
01243 {
01244 QUICKTIME_MCU_VARS
01245 QUICKTIME_MCU221111_MID_VARS
01246 QUICKTIME_MCU_INNER_VARS
01247
01248 while(frame_height > 0)
01249 {
01250 yptr = ybuf;
01251 uptr = ubuf;
01252 vptr = vbuf;
01253 for(yi = 0; yi < 8; yi++)
01254 {
01255 QUICKTIME_MCU221111_MID_DECL;
01256 while(xi--)
01257 {
01258 QUICKTIME_MCU_INNER_INIT;
01259 QUICKTIME_MCU_YUV_TO_RGB(YTab[yp[8]], cr, cg, cb, ip1);
01260 QUICKTIME_MCU_YUV_TO_RGB(YTab[*yp++], cr, cg, cb, ip0);
01261 QUICKTIME_MCU_YUV_TO_RGB(YTab[yp[8]], cr, cg, cb, ip1);
01262 QUICKTIME_MCU_YUV_TO_RGB(YTab[*yp++], cr, cg, cb, ip0);
01263 QUICKTIME_MCU2H_INNER_TAIL(56, 184);
01264 }
01265 yptr += 16;
01266 uptr += 8;
01267 vptr += 8;
01268 frame_height -= 2;
01269 }
01270 ybuf += mcu_row_size << 2;
01271 ubuf += mcu_row_size;
01272 vbuf += mcu_row_size;
01273 }
01274 }
01275
01276 int quicktime_fastjpg_decode_221111(quicktime_jpeg_t *jpeg_info,
01277 unsigned char **output_rows,
01278 int jpeg_width,
01279 int jpeg_height,
01280 int interlaced,
01281 int row_offset,
01282 int frame_width,
01283 int frame_height)
01284 {
01285 long x, mcu_cols, mcu_rows;
01286 long *qtab0, *qtab1, *qtab2;
01287 unsigned char *Ybuf, *Ubuf, *Vbuf;
01288 unsigned long rst_count;
01289 unsigned long rst_skip = 0;
01290 unsigned long orow_size = frame_width * 3 * (interlaced ? 2 : 1);
01291
01292 if(interlaced) frame_height >>= 1;
01293 frame_width += 1;
01294 frame_width >>= 1;
01295 qtab0 = jpeg_info->quant_tables[jpeg_info->jpg_comps[0].qtbl_num];
01296 qtab1 = jpeg_info->quant_tables[jpeg_info->jpg_comps[1].qtbl_num];
01297 qtab2 = jpeg_info->quant_tables[jpeg_info->jpg_comps[2].qtbl_num];
01298
01299 mcu_cols = (jpeg_width + 15) / 16;
01300 mcu_rows = (jpeg_height + 15) / 16;
01301 jpeg_info->marker = 0x00;
01302
01303 rst_count = jpeg_info->jpg_rst_interval;
01304 output_rows += row_offset;
01305 while(mcu_rows--)
01306 {
01307 Ybuf = jpeg_info->yuvbufs.ybuf;
01308 Ubuf = jpeg_info->yuvbufs.ubuf;
01309 Vbuf = jpeg_info->yuvbufs.vbuf;
01310 x = mcu_cols;
01311 while(x--)
01312 {
01313 if(rst_skip)
01314 {
01315 rst_skip--;
01316 memset(Ybuf, 0, (DCTSIZE2 << 2));
01317 memset(Ubuf, 0x80, DCTSIZE2);
01318 memset(Vbuf, 0x80, DCTSIZE2);
01319 Ybuf += (DCTSIZE2 << 2);
01320 Ubuf += DCTSIZE2;
01321 Vbuf += DCTSIZE2;
01322 }
01323 else
01324 {
01325 QUICKTIME_FASTJPG_HANDLE_RST(jpeg_info->jpg_rst_interval, rst_count);
01326
01327
01328 quicktime_fastjpg_huffparse(jpeg_info, &(jpeg_info->jpg_comps[0]), jpeg_info->jpg_dct_buf, qtab0, Ybuf); Ybuf += DCTSIZE2;
01329 quicktime_fastjpg_huffparse(jpeg_info, &(jpeg_info->jpg_comps[0]), jpeg_info->jpg_dct_buf, qtab0, Ybuf); Ybuf += DCTSIZE2;
01330 quicktime_fastjpg_huffparse(jpeg_info, &(jpeg_info->jpg_comps[0]), jpeg_info->jpg_dct_buf, qtab0, Ybuf); Ybuf += DCTSIZE2;
01331 quicktime_fastjpg_huffparse(jpeg_info, &(jpeg_info->jpg_comps[0]), jpeg_info->jpg_dct_buf, qtab0, Ybuf); Ybuf += DCTSIZE2;
01332 quicktime_fastjpg_huffparse(jpeg_info, &(jpeg_info->jpg_comps[1]), jpeg_info->jpg_dct_buf, qtab1, Ubuf); Ubuf += DCTSIZE2;
01333 quicktime_fastjpg_huffparse(jpeg_info, &(jpeg_info->jpg_comps[2]), jpeg_info->jpg_dct_buf, qtab2, Vbuf); Vbuf += DCTSIZE2;
01334
01335 if(jpeg_info->marker == 0)
01336 jpeg_info->marker = quicktime_fastjpg_check_for_marker(jpeg_info);
01337 QUICKTIME_FASTJPG_TEST_MARKER;
01338 }
01339 }
01340
01341 quicktime_fastjpg_MCU221111_to_RGB(jpeg_info,
01342 output_rows,
01343 frame_width,
01344 (frame_height < 16 ? frame_height : 16),
01345 (mcu_cols * DCTSIZE2),
01346 orow_size,
01347 &(jpeg_info->yuvbufs),
01348 interlaced);
01349 frame_height -= 16;
01350 output_rows += interlaced ? 32 : 16;
01351 }
01352
01353 if(jpeg_info->marker)
01354 {
01355 jpeg_info->jpg_h_bbuf = 0;
01356 jpeg_info->jpg_h_bnum = 0;
01357 }
01358 return 0;
01359 }
01360
01361 int quicktime_fastjpg_double_mcu(unsigned char *ptr, int mcus)
01362 {
01363 unsigned char *sblk, *dblk;
01364 int blks = mcus * 8;
01365 int flag = 0;
01366
01367 sblk = ptr + (blks * 8) - 8;
01368 dblk = ptr + (blks * 16) - 8;
01369 while(blks--)
01370 {
01371 dblk[7] = dblk[6] = sblk[7];
01372 dblk[5] = dblk[4] = sblk[6];
01373 dblk[3] = dblk[2] = sblk[5];
01374 dblk[1] = dblk[0] = sblk[4];
01375 dblk -= 64;
01376 dblk[7] = dblk[6] = sblk[3];
01377 dblk[5] = dblk[4] = sblk[2];
01378 dblk[3] = dblk[2] = sblk[1];
01379 dblk[1] = dblk[0] = sblk[0];
01380 flag++;
01381 if(flag >= 8)
01382 {
01383 flag = 0;
01384 dblk -= 8;
01385 }
01386 else
01387 {
01388 dblk += 56;
01389 }
01390 sblk -= 8;
01391 }
01392 }
01393
01394 int quicktime_fastjpg_MCU211111_to_RGB(QUICKTIME_MCU_ARGS)
01395 {
01396 QUICKTIME_MCU_VARS
01397 QUICKTIME_MCU111111_MID_VARS
01398 QUICKTIME_MCU_INNER_VARS
01399
01400 while(frame_height > 0)
01401 {
01402 yptr = ybuf;
01403 uptr = ubuf;
01404 vptr = vbuf;
01405 for(yi = 0; yi < 8; yi++)
01406 {
01407 QUICKTIME_MCU111111_MID_DECL;
01408 if(frame_height <= 0) return;
01409 while(xi--)
01410 {
01411 QUICKTIME_MCU_INNER_INIT;
01412 QUICKTIME_MCU_YUV_TO_RGB(YTab[*yp++], cr, cg, cb, ip);
01413 QUICKTIME_MCU_YUV_TO_RGB(YTab[*yp++], cr, cg, cb, ip);
01414 QUICKTIME_MCU2H_INNER_TAIL(56, 56);
01415 }
01416 yptr += 8;
01417 uptr += 8;
01418 vptr += 8;
01419 frame_height -= 2;
01420 row_pointers += interlaced ? 2 : 1;
01421 }
01422 ybuf += mcu_row_size << 1;
01423 ubuf += mcu_row_size;
01424 vbuf += mcu_row_size;
01425 }
01426 }
01427
01428 int quicktime_fastjpg_decode_211111(quicktime_jpeg_t *jpeg_info,
01429 unsigned char **output_rows,
01430 int jpeg_width,
01431 int jpeg_height,
01432 int interlaced,
01433 int row_offset,
01434 int frame_width,
01435 int frame_height)
01436 {
01437 long x, mcu_cols, mcu_rows;
01438 long *qtab0, *qtab1, *qtab2;
01439 unsigned char *Ybuf, *Ubuf, *Vbuf;
01440 unsigned long rst_count;
01441 unsigned long rst_skip = 0;
01442 unsigned long orow_size = frame_width * 3 * (interlaced ? 2 : 1);
01443
01444 if(interlaced) frame_height >>= 1;
01445 frame_width += 1;
01446 frame_width >>= 1;
01447 qtab0 = jpeg_info->quant_tables[jpeg_info->jpg_comps[0].qtbl_num];
01448 qtab1 = jpeg_info->quant_tables[jpeg_info->jpg_comps[1].qtbl_num];
01449 qtab2 = jpeg_info->quant_tables[jpeg_info->jpg_comps[2].qtbl_num];
01450
01451 mcu_cols = (jpeg_width + 15) / 16;
01452 mcu_rows = (jpeg_height + 7) / 8;
01453 jpeg_info->marker = 0x00;
01454
01455 rst_count = jpeg_info->jpg_rst_interval;
01456 output_rows += row_offset;
01457 while(mcu_rows--)
01458 {
01459 Ybuf = jpeg_info->yuvbufs.ybuf;
01460 Ubuf = jpeg_info->yuvbufs.ubuf;
01461 Vbuf = jpeg_info->yuvbufs.vbuf;
01462 x = mcu_cols;
01463 while(x--)
01464 {
01465 if(rst_skip)
01466 {
01467 rst_skip--;
01468 memset(Ybuf, 0, (DCTSIZE2 << 1));
01469 memset(Ubuf, 0x80, DCTSIZE2);
01470 memset(Vbuf, 0x80, DCTSIZE2);
01471 Ybuf += (DCTSIZE2 << 1);
01472 Ubuf += DCTSIZE2;
01473 Vbuf += DCTSIZE2;
01474 }
01475 else
01476 {
01477 QUICKTIME_FASTJPG_HANDLE_RST(jpeg_info->jpg_rst_interval, rst_count);
01478
01479 quicktime_fastjpg_huffparse(jpeg_info, &(jpeg_info->jpg_comps[0]), jpeg_info->jpg_dct_buf, qtab0, Ybuf); Ybuf += DCTSIZE2;
01480 quicktime_fastjpg_huffparse(jpeg_info, &(jpeg_info->jpg_comps[0]), jpeg_info->jpg_dct_buf, qtab0, Ybuf); Ybuf += DCTSIZE2;
01481 quicktime_fastjpg_huffparse(jpeg_info, &(jpeg_info->jpg_comps[1]), jpeg_info->jpg_dct_buf, qtab1, Ubuf); Ubuf += DCTSIZE2;
01482 quicktime_fastjpg_huffparse(jpeg_info, &(jpeg_info->jpg_comps[2]), jpeg_info->jpg_dct_buf, qtab2, Vbuf); Vbuf += DCTSIZE2;
01483
01484 if(jpeg_info->marker == 0)
01485 jpeg_info->marker = quicktime_fastjpg_check_for_marker(jpeg_info);
01486 QUICKTIME_FASTJPG_TEST_MARKER;
01487 }
01488 }
01489
01490
01491 if(jpeg_width <= frame_width)
01492 {
01493 quicktime_fastjpg_double_mcu(jpeg_info->yuvbufs.ybuf, (mcu_cols << 1));
01494 quicktime_fastjpg_double_mcu(jpeg_info->yuvbufs.ubuf, mcu_cols);
01495 quicktime_fastjpg_double_mcu(jpeg_info->yuvbufs.vbuf, mcu_cols);
01496 }
01497
01498 quicktime_fastjpg_MCU211111_to_RGB(jpeg_info,
01499 output_rows,
01500 frame_width,
01501 (frame_height < 8 ? frame_height : 8),
01502 ((mcu_cols << 1) * DCTSIZE2),
01503 orow_size,
01504 &(jpeg_info->yuvbufs),
01505 interlaced);
01506
01507 frame_height -= 8;
01508 output_rows += interlaced ? 16 : 8;
01509 }
01510
01511 if(jpeg_info->marker)
01512 {
01513 jpeg_info->jpg_h_bbuf = 0;
01514 jpeg_info->jpg_h_bnum = 0;
01515 }
01516 return 0;
01517 }
01518
01519 int quicktime_fastjpg_MCU111111_to_RGB(QUICKTIME_MCU_ARGS)
01520 {
01521 QUICKTIME_MCU_VARS
01522 QUICKTIME_MCU111111_MID_VARS
01523 QUICKTIME_MCU_INNER_VARS
01524
01525 while(frame_height > 0)
01526 {
01527 yptr = ybuf;
01528 uptr = ubuf;
01529 vptr = vbuf;
01530 for(yi = 0; yi < 8; yi++)
01531 {
01532 QUICKTIME_MCU111111_MID_DECL;
01533 if(frame_height <= 0) return;
01534 while(xi--)
01535 {
01536 QUICKTIME_MCU_INNER_INIT;
01537 QUICKTIME_MCU_YUV_TO_RGB(YTab[*yp++], cr, cg, cb, ip);
01538 QUICKTIME_MCU1H_INNER_TAIL(56);
01539 }
01540 yptr += 8;
01541 uptr += 8;
01542 vptr += 8;
01543 frame_height--;
01544 row_pointers += interlaced ? 2 : 1;
01545 }
01546 ybuf += mcu_row_size;
01547 ubuf += mcu_row_size;
01548 vbuf += mcu_row_size;
01549 }
01550 }
01551
01552 int quicktime_fastjpg_decode_111111(quicktime_jpeg_t *jpeg_info,
01553 unsigned char **output_rows,
01554 int jpeg_width,
01555 int jpeg_height,
01556 int interlaced,
01557 int row_offset,
01558 int frame_width,
01559 int frame_height,
01560 int grey)
01561 {
01562 long x, mcu_cols, mcu_rows;
01563 long *qtab0, *qtab1, *qtab2;
01564 unsigned char *Ybuf, *Ubuf, *Vbuf;
01565 unsigned long rst_count;
01566 unsigned long rst_skip = 0;
01567 unsigned long orow_size = frame_width * 3 * (interlaced ? 2 : 1);
01568
01569 if(interlaced) frame_height >>= 1;
01570 qtab0 = jpeg_info->quant_tables[jpeg_info->jpg_comps[0].qtbl_num];
01571 qtab1 = jpeg_info->quant_tables[jpeg_info->jpg_comps[1].qtbl_num];
01572 qtab2 = jpeg_info->quant_tables[jpeg_info->jpg_comps[2].qtbl_num];
01573
01574 mcu_cols = (jpeg_width + 7) / 8;
01575 mcu_rows = (jpeg_height + 7) / 8;
01576 jpeg_info->marker = 0x00;
01577
01578 rst_count = jpeg_info->jpg_rst_interval;
01579 output_rows += row_offset;
01580 while(mcu_rows--)
01581 {
01582 Ybuf = jpeg_info->yuvbufs.ybuf;
01583 Ubuf = jpeg_info->yuvbufs.ubuf;
01584 Vbuf = jpeg_info->yuvbufs.vbuf;
01585 x = mcu_cols;
01586 while(x--)
01587 {
01588 if(rst_skip)
01589 {
01590 rst_skip--;
01591
01592 if(Ybuf != jpeg_info->yuvbufs.ybuf)
01593 {
01594 unsigned char *prev;
01595 prev = Ybuf - DCTSIZE2;
01596 memcpy(Ybuf, prev, DCTSIZE2);
01597 Ybuf += DCTSIZE2;
01598 prev = Ubuf - DCTSIZE2;
01599 memcpy(Ubuf, prev, DCTSIZE2);
01600 prev = Vbuf - DCTSIZE2;
01601 memcpy(Vbuf, prev, DCTSIZE2);
01602 Ubuf += DCTSIZE2;
01603 Vbuf += DCTSIZE2;
01604 }
01605 else
01606 {
01607 memset(Ybuf, 0, DCTSIZE2);
01608 Ybuf += DCTSIZE2;
01609 memset(Ubuf, 0x80, DCTSIZE2);
01610 memset(Vbuf, 0x80, DCTSIZE2);
01611 Ubuf += DCTSIZE2;
01612 Vbuf += DCTSIZE2;
01613 }
01614 }
01615 else
01616 {
01617 QUICKTIME_FASTJPG_HANDLE_RST(jpeg_info->jpg_rst_interval, rst_count);
01618
01619 quicktime_fastjpg_huffparse(jpeg_info, &(jpeg_info->jpg_comps[0]), jpeg_info->jpg_dct_buf, qtab0, Ybuf); Ybuf += DCTSIZE2;
01620 quicktime_fastjpg_huffparse(jpeg_info, &(jpeg_info->jpg_comps[1]), jpeg_info->jpg_dct_buf, qtab1, Ubuf); Ubuf += DCTSIZE2;
01621 quicktime_fastjpg_huffparse(jpeg_info, &(jpeg_info->jpg_comps[2]), jpeg_info->jpg_dct_buf, qtab2, Vbuf); Vbuf += DCTSIZE2;
01622
01623 if(jpeg_info->marker == 0)
01624 jpeg_info->marker = quicktime_fastjpg_check_for_marker(jpeg_info);
01625 QUICKTIME_FASTJPG_TEST_MARKER;
01626 }
01627 }
01628
01629
01630 quicktime_fastjpg_MCU111111_to_RGB(jpeg_info,
01631 output_rows,
01632 frame_width,
01633 (frame_height < 8 ? frame_height : 8),
01634 (mcu_cols * DCTSIZE2),
01635 orow_size,
01636 &(jpeg_info->yuvbufs),
01637 interlaced);
01638
01639 frame_height -= 8;
01640 output_rows += interlaced ? 16 : 8;
01641 }
01642
01643 if(jpeg_info->marker)
01644 {
01645 jpeg_info->jpg_h_bbuf = 0;
01646 jpeg_info->jpg_h_bnum = 0;
01647 }
01648 return 0;
01649 }
01650
01651 int quicktime_fastjpg_decode(unsigned char *chunk,
01652 long chunk_size,
01653 unsigned char **output_rows,
01654 quicktime_jpeg_t *jpeg_info,
01655 int frame_width,
01656 int frame_height,
01657 int interlaced)
01658 {
01659 int base_y, row_offset;
01660 int ijpeg = 0;
01661 int result = 0;
01662 jpeg_info->mjpa_info.valid = 0;
01663
01664 jpeg_info->chunk = chunk;
01665 jpeg_info->chunk_size = chunk_size;
01666
01667 for(base_y = 0; base_y < (interlaced ? 2 : 1); base_y++)
01668 {
01669
01670 jpeg_info->jpg_saw_EOI = 0;
01671 jpeg_info->jpg_saw_SOI = jpeg_info->jpg_saw_SOF = jpeg_info->jpg_saw_SOS = jpeg_info->jpg_saw_DHT = jpeg_info->jpg_saw_DQT = 0;
01672
01673 if(quicktime_fastjpg_read_markers(jpeg_info))
01674 {
01675 printf("quicktime_fastjpg_decode read markers failed\n");
01676 }
01677
01678 quicktime_fastjpg_resethuffman(jpeg_info);
01679 if(interlaced)
01680 {
01681 row_offset = (base_y == 0) ? 0 : 1;
01682 }
01683 else
01684 row_offset = 0;
01685
01686 if((!jpeg_info->jpg_saw_DHT) && (!jpeg_info->jpg_std_DHT_flag))
01687 {
01688 quicktime_fastjpg_buildstdhuffman(jpeg_info);
01689 }
01690
01691 if(!jpeg_info->jpg_saw_DQT)
01692 {
01693 quicktime_fastjpg_buildstdDQT(jpeg_info, 100);
01694 }
01695
01696 jpeg_info->marker = 0x00;
01697
01698 quicktime_fastjpg_initMCU(jpeg_info, jpeg_info->jpg_width, 0, 0);
01699
01700
01701 if((jpeg_info->jpg_num_comps == 3) && (jpeg_info->jpg_comps_in_scan == 3) &&
01702 (jpeg_info->jpg_comps[1].hvsample == 0x11) && (jpeg_info->jpg_comps[2].hvsample== 0x11))
01703 {
01704 if(jpeg_info->jpg_comps[0].hvsample == 0x41)
01705 {
01706 quicktime_fastjpg_decode_411111(jpeg_info,
01707 output_rows,
01708 jpeg_info->jpg_width,
01709 jpeg_info->jpg_height,
01710 interlaced,
01711 row_offset,
01712 frame_width,
01713 frame_height);
01714 }
01715 else
01716 if(jpeg_info->jpg_comps[0].hvsample == 0x22)
01717 {
01718 quicktime_fastjpg_decode_221111(jpeg_info,
01719 output_rows,
01720 jpeg_info->jpg_width,
01721 jpeg_info->jpg_height,
01722 interlaced,
01723 row_offset,
01724 frame_width,
01725 frame_height);
01726 }
01727 else
01728 if(jpeg_info->jpg_comps[0].hvsample == 0x21)
01729 {
01730 quicktime_fastjpg_decode_211111(jpeg_info,
01731 output_rows,
01732 jpeg_info->jpg_width,
01733 jpeg_info->jpg_height,
01734 interlaced,
01735 row_offset,
01736 frame_width,
01737 frame_height);
01738 }
01739 else if(jpeg_info->jpg_comps[0].hvsample == 0x11)
01740 {
01741 quicktime_fastjpg_decode_111111(jpeg_info,
01742 output_rows,
01743 jpeg_info->jpg_width,
01744 jpeg_info->jpg_height,
01745 interlaced,
01746 row_offset,
01747 frame_width,
01748 frame_height,
01749 0);
01750 }
01751 else
01752 {
01753 printf("quicktime_fastjpg_decode: cmps %d %d mcu %04x %04x %04x unsupported\n",
01754 jpeg_info->jpg_num_comps,
01755 jpeg_info->jpg_comps_in_scan,
01756 jpeg_info->jpg_comps[0].hvsample,
01757 jpeg_info->jpg_comps[1].hvsample,
01758 jpeg_info->jpg_comps[2].hvsample);
01759 break;
01760 }
01761 }
01762 else
01763 if((jpeg_info->jpg_num_comps == 1) || (jpeg_info->jpg_comps_in_scan == 1))
01764 {
01765
01766 quicktime_fastjpg_decode_111111(jpeg_info,
01767 output_rows,
01768 jpeg_info->jpg_width,
01769 jpeg_info->jpg_height,
01770 interlaced,
01771 row_offset,
01772 frame_width,
01773 frame_height,
01774 1);
01775 }
01776 else
01777 {
01778 printf("quicktime_fastjpg_decode: cmps %d %d mcu %04x %04x %04x unsupported.\n",
01779 jpeg_info->jpg_num_comps,
01780 jpeg_info->jpg_comps_in_scan,
01781 jpeg_info->jpg_comps[0].hvsample,
01782 jpeg_info->jpg_comps[1].hvsample,
01783 jpeg_info->jpg_comps[2].hvsample);
01784 break;
01785 }
01786
01787 if(jpeg_info->marker == M_EOI)
01788 {
01789 jpeg_info->jpg_saw_EOI = 1;
01790 jpeg_info->marker = 0x00;
01791 }
01792 else
01793 if(!jpeg_info->jpg_saw_EOI)
01794 if(quicktime_fastjpg_readEOI(jpeg_info))
01795 break;
01796
01797 }
01798 return result;
01799 }