Mercurial > projects > dwt-mac
comparison dwt/internal/image/JPEGDecoder.d @ 7:e831403a80a9
Add 'cast' to casts
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 27 Aug 2008 14:30:35 +0200 |
parents | 380af2bdd8e5 |
children | 5123b17c98ef |
comparison
equal
deleted
inserted
replaced
6:b903c16b6f48 | 7:e831403a80a9 |
---|---|
464 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; | 464 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; |
465 } | 465 } |
466 } | 466 } |
467 // look = PEEK_BITS(HUFF_LOOKAHEAD); | 467 // look = PEEK_BITS(HUFF_LOOKAHEAD); |
468 if (nb !is 1) { | 468 if (nb !is 1) { |
469 look = (( (get_buffer >> (bits_left - (HUFF_LOOKAHEAD)))) & ((1<<(HUFF_LOOKAHEAD))-1)); | 469 look = (( (get_buffer >> (bits_left - cast(HUFF_LOOKAHEAD)))) & ((1<<cast(HUFF_LOOKAHEAD))-1)); |
470 if ((nb = dctbl.look_nbits[look]) !is 0) { | 470 if ((nb = dctbl.look_nbits[look]) !is 0) { |
471 // DROP_BITS(nb); | 471 // DROP_BITS(nb); |
472 bits_left -= nb; | 472 bits_left -= nb; |
473 s = dctbl.look_sym[look] & 0xFF; | 473 s = dctbl.look_sym[look] & 0xFF; |
474 } else { | 474 } else { |
502 /* Convert DC difference to actual value, update last_dc_val */ | 502 /* Convert DC difference to actual value, update last_dc_val */ |
503 int ci = cinfo.MCU_membership[blkn]; | 503 int ci = cinfo.MCU_membership[blkn]; |
504 s += state.last_dc_val[ci]; | 504 s += state.last_dc_val[ci]; |
505 state.last_dc_val[ci] = s; | 505 state.last_dc_val[ci] = s; |
506 /* Output the DC coefficient (assumes jpeg_natural_order[0] = 0) */ | 506 /* Output the DC coefficient (assumes jpeg_natural_order[0] = 0) */ |
507 block[0] = (short) s; | 507 block[0] = cast(short) s; |
508 } | 508 } |
509 | 509 |
510 if (entropy.ac_needed[blkn]) { | 510 if (entropy.ac_needed[blkn]) { |
511 | 511 |
512 /* Section F.2.2.2: decode the AC coefficients */ | 512 /* Section F.2.2.2: decode the AC coefficients */ |
529 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; | 529 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; |
530 } | 530 } |
531 } | 531 } |
532 if (nb !is 1) { | 532 if (nb !is 1) { |
533 // look = PEEK_BITS(HUFF_LOOKAHEAD); | 533 // look = PEEK_BITS(HUFF_LOOKAHEAD); |
534 look = (( (get_buffer >> (bits_left - (HUFF_LOOKAHEAD)))) & ((1<<(HUFF_LOOKAHEAD))-1)); | 534 look = (( (get_buffer >> (bits_left - cast(HUFF_LOOKAHEAD)))) & ((1<<cast(HUFF_LOOKAHEAD))-1)); |
535 if ((nb = actbl.look_nbits[look]) !is 0) { | 535 if ((nb = actbl.look_nbits[look]) !is 0) { |
536 // DROP_BITS(nb); | 536 // DROP_BITS(nb); |
537 bits_left -= (nb); | 537 bits_left -= (nb); |
538 s = actbl.look_sym[look] & 0xFF; | 538 s = actbl.look_sym[look] & 0xFF; |
539 } else { | 539 } else { |
570 * order. Note: the extra entries in | 570 * order. Note: the extra entries in |
571 * jpeg_natural_order[] will save us if k >= | 571 * jpeg_natural_order[] will save us if k >= |
572 * DCTSIZE2, which could happen if the data is | 572 * DCTSIZE2, which could happen if the data is |
573 * corrupted. | 573 * corrupted. |
574 */ | 574 */ |
575 block[jpeg_natural_order[k]] = (short) s; | 575 block[jpeg_natural_order[k]] = cast(short) s; |
576 } else { | 576 } else { |
577 if (r !is 15) | 577 if (r !is 15) |
578 break; | 578 break; |
579 k += 15; | 579 k += 15; |
580 } | 580 } |
602 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; | 602 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; |
603 } | 603 } |
604 } | 604 } |
605 if (nb !is 1) { | 605 if (nb !is 1) { |
606 // look = PEEK_BITS(HUFF_LOOKAHEAD); | 606 // look = PEEK_BITS(HUFF_LOOKAHEAD); |
607 look = (( (get_buffer >> (bits_left - (HUFF_LOOKAHEAD)))) & ((1<<(HUFF_LOOKAHEAD))-1)); | 607 look = (( (get_buffer >> (bits_left - cast(HUFF_LOOKAHEAD)))) & ((1<<cast(HUFF_LOOKAHEAD))-1)); |
608 if ((nb = actbl.look_nbits[look]) !is 0) { | 608 if ((nb = actbl.look_nbits[look]) !is 0) { |
609 // DROP_BITS(nb); | 609 // DROP_BITS(nb); |
610 bits_left -= (nb); | 610 bits_left -= (nb); |
611 s = actbl.look_sym[look] & 0xFF; | 611 s = actbl.look_sym[look] & 0xFF; |
612 } else { | 612 } else { |
935 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; | 935 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; |
936 } | 936 } |
937 } | 937 } |
938 if (nb !is 1) { | 938 if (nb !is 1) { |
939 // look = PEEK_BITS(HUFF_LOOKAHEAD); | 939 // look = PEEK_BITS(HUFF_LOOKAHEAD); |
940 look = (( (get_buffer >> (bits_left - (HUFF_LOOKAHEAD)))) & ((1<<(HUFF_LOOKAHEAD))-1)); | 940 look = (( (get_buffer >> (bits_left - cast(HUFF_LOOKAHEAD)))) & ((1<<cast(HUFF_LOOKAHEAD))-1)); |
941 if ((nb = tbl.look_nbits[look]) !is 0) { | 941 if ((nb = tbl.look_nbits[look]) !is 0) { |
942 // DROP_BITS(nb); | 942 // DROP_BITS(nb); |
943 bits_left -= nb; | 943 bits_left -= nb; |
944 s = tbl.look_sym[look] & 0xFF; | 944 s = tbl.look_sym[look] & 0xFF; |
945 } else { | 945 } else { |
1042 k++; | 1042 k++; |
1043 } while (k <= Se); | 1043 } while (k <= Se); |
1044 if (s !is 0) { | 1044 if (s !is 0) { |
1045 int pos = jpeg_natural_order[k]; | 1045 int pos = jpeg_natural_order[k]; |
1046 /* Output newly nonzero coefficient */ | 1046 /* Output newly nonzero coefficient */ |
1047 block[pos] = (short) s; | 1047 block[pos] = cast(short) s; |
1048 /* Remember its position in case we have to suspend */ | 1048 /* Remember its position in case we have to suspend */ |
1049 newnz_pos[num_newnz++] = pos; | 1049 newnz_pos[num_newnz++] = pos; |
1050 } | 1050 } |
1051 } | 1051 } |
1052 } | 1052 } |
1180 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; | 1180 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; |
1181 } | 1181 } |
1182 } | 1182 } |
1183 if (nb !is 1) { | 1183 if (nb !is 1) { |
1184 // look = PEEK_BITS(HUFF_LOOKAHEAD); | 1184 // look = PEEK_BITS(HUFF_LOOKAHEAD); |
1185 look = (( (get_buffer >> (bits_left - (HUFF_LOOKAHEAD)))) & ((1<<(HUFF_LOOKAHEAD))-1)); | 1185 look = (( (get_buffer >> (bits_left - cast(HUFF_LOOKAHEAD)))) & ((1<<cast(HUFF_LOOKAHEAD))-1)); |
1186 | 1186 |
1187 if ((nb = tbl.look_nbits[look]) !is 0) { | 1187 if ((nb = tbl.look_nbits[look]) !is 0) { |
1188 // DROP_BITS(nb); | 1188 // DROP_BITS(nb); |
1189 bits_left -= nb; | 1189 bits_left -= nb; |
1190 s = tbl.look_sym[look] & 0xFF; | 1190 s = tbl.look_sym[look] & 0xFF; |
1214 // r = GET_BITS(s); | 1214 // r = GET_BITS(s); |
1215 r = (( (get_buffer >> (bits_left -= (s)))) & ((1<<(s))-1)); | 1215 r = (( (get_buffer >> (bits_left -= (s)))) & ((1<<(s))-1)); |
1216 // s = HUFF_EXTEND(r, s); | 1216 // s = HUFF_EXTEND(r, s); |
1217 s = ((r) < extend_test[s] ? (r) + extend_offset[s] : (r)); | 1217 s = ((r) < extend_test[s] ? (r) + extend_offset[s] : (r)); |
1218 /* Scale and output coefficient in natural (dezigzagged) order */ | 1218 /* Scale and output coefficient in natural (dezigzagged) order */ |
1219 block[jpeg_natural_order[k]] = (short) (s << Al); | 1219 block[jpeg_natural_order[k]] = cast(short) (s << Al); |
1220 } else { | 1220 } else { |
1221 if (r is 15) { /* ZRL */ | 1221 if (r is 15) { /* ZRL */ |
1222 k += 15; /* skip 15 zeroes in band */ | 1222 k += 15; /* skip 15 zeroes in band */ |
1223 } else { /* EOBr, run length is 2^r + appended bits */ | 1223 } else { /* EOBr, run length is 2^r + appended bits */ |
1224 EOBRUN = 1 << r; | 1224 EOBRUN = 1 << r; |
1333 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; | 1333 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; |
1334 } | 1334 } |
1335 } | 1335 } |
1336 if (nb !is 1) { | 1336 if (nb !is 1) { |
1337 // look = PEEK_BITS(HUFF_LOOKAHEAD); | 1337 // look = PEEK_BITS(HUFF_LOOKAHEAD); |
1338 look = (( (get_buffer >> (bits_left - (HUFF_LOOKAHEAD)))) & ((1<<(HUFF_LOOKAHEAD))-1)); | 1338 look = (( (get_buffer >> (bits_left - cast(HUFF_LOOKAHEAD)))) & ((1<<cast(HUFF_LOOKAHEAD))-1)); |
1339 | 1339 |
1340 if ((nb = tbl.look_nbits[look]) !is 0) { | 1340 if ((nb = tbl.look_nbits[look]) !is 0) { |
1341 // DROP_BITS(nb); | 1341 // DROP_BITS(nb); |
1342 bits_left -= nb; | 1342 bits_left -= nb; |
1343 s = tbl.look_sym[look] & 0xFF; | 1343 s = tbl.look_sym[look] & 0xFF; |
1369 | 1369 |
1370 /* Convert DC difference to actual value, update last_dc_val */ | 1370 /* Convert DC difference to actual value, update last_dc_val */ |
1371 s += state.last_dc_val[ci]; | 1371 s += state.last_dc_val[ci]; |
1372 state.last_dc_val[ci] = s; | 1372 state.last_dc_val[ci] = s; |
1373 /* Scale and output the coefficient (assumes jpeg_natural_order[0]=0) */ | 1373 /* Scale and output the coefficient (assumes jpeg_natural_order[0]=0) */ |
1374 block[0] = (short) (s << Al); | 1374 block[0] = cast(short) (s << Al); |
1375 } | 1375 } |
1376 | 1376 |
1377 /* Completed MCU, so update state */ | 1377 /* Completed MCU, so update state */ |
1378 // BITREAD_SAVE_STATE(cinfo,entropy.bitstate); | 1378 // BITREAD_SAVE_STATE(cinfo,entropy.bitstate); |
1379 cinfo.buffer = br_state.buffer; | 1379 cinfo.buffer = br_state.buffer; |
1916 // }; | 1916 // }; |
1917 // | 1917 // |
1918 // i = 0; | 1918 // i = 0; |
1919 // for (row = 0; row < DCTSIZE; row++) { | 1919 // for (row = 0; row < DCTSIZE; row++) { |
1920 // for (col = 0; col < DCTSIZE; col++) { | 1920 // for (col = 0; col < DCTSIZE; col++) { |
1921 // fmtbl[i] = (FLOAT_MULT_TYPE) | 1921 // fmtbl[i] = cast(FLOAT_MULT_TYPE) |
1922 // ((double) qtbl.quantval[i] * | 1922 // (cast(double) qtbl.quantval[i] * |
1923 // aanscalefactor[row] * aanscalefactor[col]); | 1923 // aanscalefactor[row] * aanscalefactor[col]); |
1924 // i++; | 1924 // i++; |
1925 // } | 1925 // } |
1926 // } | 1926 // } |
1927 // } | 1927 // } |
1990 // * allocate a strip buffer. Use the virtual-array buffer as workspace. | 1990 // * allocate a strip buffer. Use the virtual-array buffer as workspace. |
1991 // */ | 1991 // */ |
1992 // if (post.buffer is null) { | 1992 // if (post.buffer is null) { |
1993 // post.buffer = (*cinfo.mem.access_virt_sarray) | 1993 // post.buffer = (*cinfo.mem.access_virt_sarray) |
1994 // ((j_common_ptr) cinfo, post.whole_image, | 1994 // ((j_common_ptr) cinfo, post.whole_image, |
1995 // (JDIMENSION) 0, post.strip_height, TRUE); | 1995 // cast(JDIMENSION) 0, post.strip_height, TRUE); |
1996 // } | 1996 // } |
1997 } else { | 1997 } else { |
1998 /* For single-pass processing without color quantization, | 1998 /* For single-pass processing without color quantization, |
1999 * I have no work to do; just call the upsampler directly. | 1999 * I have no work to do; just call the upsampler directly. |
2000 */ | 2000 */ |
2316 if (cinfo.progressive_mode) | 2316 if (cinfo.progressive_mode) |
2317 access_rows *= 3; | 2317 access_rows *= 3; |
2318 //#endif | 2318 //#endif |
2319 coef.whole_image[ci] = | 2319 coef.whole_image[ci] = |
2320 new short | 2320 new short |
2321 [(int)jround_up( compptr.height_in_blocks, compptr.v_samp_factor)] | 2321 [cast(int)jround_up( compptr.height_in_blocks, compptr.v_samp_factor)] |
2322 [(int)jround_up( compptr.width_in_blocks, compptr.h_samp_factor)] | 2322 [cast(int)jround_up( compptr.width_in_blocks, compptr.h_samp_factor)] |
2323 [DCTSIZE2]; | 2323 [DCTSIZE2]; |
2324 } | 2324 } |
2325 // coef.consume_data = consume_data; | 2325 // coef.consume_data = consume_data; |
2326 coef.decompress_data = DECOMPRESS_DATA; | 2326 coef.decompress_data = DECOMPRESS_DATA; |
2327 coef.coef_arrays = coef.whole_image[0]; /* link to virtual arrays */ | 2327 coef.coef_arrays = coef.whole_image[0]; /* link to virtual arrays */ |
2385 //#ifdef IDCT_SCALING_SUPPORTED | 2385 //#ifdef IDCT_SCALING_SUPPORTED |
2386 // | 2386 // |
2387 // /* Compute actual output image dimensions and DCT scaling choices. */ | 2387 // /* Compute actual output image dimensions and DCT scaling choices. */ |
2388 // if (cinfo.scale_num * 8 <= cinfo.scale_denom) { | 2388 // if (cinfo.scale_num * 8 <= cinfo.scale_denom) { |
2389 // /* Provide 1/8 scaling */ | 2389 // /* Provide 1/8 scaling */ |
2390 // cinfo.output_width = (int) | 2390 // cinfo.output_width = cast(int) |
2391 // jdiv_round_up(cinfo.image_width, 8L); | 2391 // jdiv_round_up(cinfo.image_width, 8L); |
2392 // cinfo.output_height = (int) | 2392 // cinfo.output_height = cast(int) |
2393 // jdiv_round_up(cinfo.image_height, 8L); | 2393 // jdiv_round_up(cinfo.image_height, 8L); |
2394 // cinfo.min_DCT_scaled_size = 1; | 2394 // cinfo.min_DCT_scaled_size = 1; |
2395 // } else if (cinfo.scale_num * 4 <= cinfo.scale_denom) { | 2395 // } else if (cinfo.scale_num * 4 <= cinfo.scale_denom) { |
2396 // /* Provide 1/4 scaling */ | 2396 // /* Provide 1/4 scaling */ |
2397 // cinfo.output_width = (int) | 2397 // cinfo.output_width = cast(int) |
2398 // jdiv_round_up(cinfo.image_width, 4L); | 2398 // jdiv_round_up(cinfo.image_width, 4L); |
2399 // cinfo.output_height = (int) | 2399 // cinfo.output_height = cast(int) |
2400 // jdiv_round_up(cinfo.image_height, 4L); | 2400 // jdiv_round_up(cinfo.image_height, 4L); |
2401 // cinfo.min_DCT_scaled_size = 2; | 2401 // cinfo.min_DCT_scaled_size = 2; |
2402 // } else if (cinfo.scale_num * 2 <= cinfo.scale_denom) { | 2402 // } else if (cinfo.scale_num * 2 <= cinfo.scale_denom) { |
2403 // /* Provide 1/2 scaling */ | 2403 // /* Provide 1/2 scaling */ |
2404 // cinfo.output_width = (int) | 2404 // cinfo.output_width = cast(int) |
2405 // jdiv_round_up(cinfo.image_width, 2L); | 2405 // jdiv_round_up(cinfo.image_width, 2L); |
2406 // cinfo.output_height = (int) | 2406 // cinfo.output_height = cast(int) |
2407 // jdiv_round_up(cinfo.image_height, 2L); | 2407 // jdiv_round_up(cinfo.image_height, 2L); |
2408 // cinfo.min_DCT_scaled_size = 4; | 2408 // cinfo.min_DCT_scaled_size = 4; |
2409 // } else { | 2409 // } else { |
2410 // /* Provide 1/1 scaling */ | 2410 // /* Provide 1/1 scaling */ |
2411 // cinfo.output_width = cinfo.image_width; | 2411 // cinfo.output_width = cinfo.image_width; |
2433 // * application needs to know these if using raw downsampled data. | 2433 // * application needs to know these if using raw downsampled data. |
2434 // */ | 2434 // */ |
2435 // for (ci = 0; ci < cinfo.num_components; ci++) { | 2435 // for (ci = 0; ci < cinfo.num_components; ci++) { |
2436 // compptr = cinfo.comp_info[ci]; | 2436 // compptr = cinfo.comp_info[ci]; |
2437 // /* Size in samples, after IDCT scaling */ | 2437 // /* Size in samples, after IDCT scaling */ |
2438 // compptr.downsampled_width = (int) | 2438 // compptr.downsampled_width = cast(int) |
2439 // jdiv_round_up((long) cinfo.image_width * (long) (compptr.h_samp_factor * compptr.DCT_scaled_size), | 2439 // jdiv_round_up(cast(long) cinfo.image_width * cast(long) (compptr.h_samp_factor * compptr.DCT_scaled_size), |
2440 // (cinfo.max_h_samp_factor * DCTSIZE)); | 2440 // (cinfo.max_h_samp_factor * DCTSIZE)); |
2441 // compptr.downsampled_height = (int) | 2441 // compptr.downsampled_height = cast(int) |
2442 // jdiv_round_up((long) cinfo.image_height * (long) (compptr.v_samp_factor * compptr.DCT_scaled_size), | 2442 // jdiv_round_up(cast(long) cinfo.image_height * cast(long) (compptr.v_samp_factor * compptr.DCT_scaled_size), |
2443 // (cinfo.max_v_samp_factor * DCTSIZE)); | 2443 // (cinfo.max_v_samp_factor * DCTSIZE)); |
2444 // } | 2444 // } |
2445 // | 2445 // |
2446 //#else /* !IDCT_SCALING_SUPPORTED */ | 2446 //#else /* !IDCT_SCALING_SUPPORTED */ |
2447 | 2447 |
2527 cinfo.sample_range_limit_offset = offset; | 2527 cinfo.sample_range_limit_offset = offset; |
2528 cinfo.sample_range_limit = table; | 2528 cinfo.sample_range_limit = table; |
2529 /* First segment of "simple" table: limit[x] = 0 for x < 0 */ | 2529 /* First segment of "simple" table: limit[x] = 0 for x < 0 */ |
2530 /* Main part of "simple" table: limit[x] = x */ | 2530 /* Main part of "simple" table: limit[x] = x */ |
2531 for (i = 0; i <= MAXJSAMPLE; i++) | 2531 for (i = 0; i <= MAXJSAMPLE; i++) |
2532 table[i + offset] = (byte)i; | 2532 table[i + offset] = cast(byte)i; |
2533 offset += CENTERJSAMPLE; /* Point to where post-IDCT table starts */ | 2533 offset += CENTERJSAMPLE; /* Point to where post-IDCT table starts */ |
2534 /* End of simple table, rest of first half of post-IDCT table */ | 2534 /* End of simple table, rest of first half of post-IDCT table */ |
2535 for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++) | 2535 for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++) |
2536 table[i+offset] = (byte)MAXJSAMPLE; | 2536 table[i+offset] = cast(byte)MAXJSAMPLE; |
2537 /* Second half of post-IDCT table */ | 2537 /* Second half of post-IDCT table */ |
2538 System.arraycopy(cinfo.sample_range_limit, cinfo.sample_range_limit_offset, table, offset + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE), CENTERJSAMPLE); | 2538 System.arraycopy(cinfo.sample_range_limit, cinfo.sample_range_limit_offset, table, offset + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE), CENTERJSAMPLE); |
2539 } | 2539 } |
2540 | 2540 |
2541 static void build_ycc_rgb_table (jpeg_decompress_struct cinfo) { | 2541 static void build_ycc_rgb_table (jpeg_decompress_struct cinfo) { |
2551 | 2551 |
2552 for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) { | 2552 for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) { |
2553 /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */ | 2553 /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */ |
2554 /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */ | 2554 /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */ |
2555 /* Cr=>R value is nearest int to 1.40200 * x */ | 2555 /* Cr=>R value is nearest int to 1.40200 * x */ |
2556 cconvert.Cr_r_tab[i] = ((int)(1.40200f * (1<<SCALEBITS) + 0.5f) * x + ONE_HALF) >> SCALEBITS; | 2556 cconvert.Cr_r_tab[i] = (cast(int)(1.40200f * (1<<SCALEBITS) + 0.5f) * x + ONE_HALF) >> SCALEBITS; |
2557 /* Cb=>B value is nearest int to 1.77200 * x */ | 2557 /* Cb=>B value is nearest int to 1.77200 * x */ |
2558 cconvert.Cb_b_tab[i] = ((int)(1.77200f * (1<<SCALEBITS) + 0.5f) * x + ONE_HALF) >> SCALEBITS; | 2558 cconvert.Cb_b_tab[i] = (cast(int)(1.77200f * (1<<SCALEBITS) + 0.5f) * x + ONE_HALF) >> SCALEBITS; |
2559 /* Cr=>G value is scaled-up -0.71414 * x */ | 2559 /* Cr=>G value is scaled-up -0.71414 * x */ |
2560 cconvert.Cr_g_tab[i] = ((int)(- (0.71414f * (1<<SCALEBITS) + 0.5f)) * x); | 2560 cconvert.Cr_g_tab[i] = (cast(int)(- (0.71414f * (1<<SCALEBITS) + 0.5f)) * x); |
2561 /* Cb=>G value is scaled-up -0.34414 * x */ | 2561 /* Cb=>G value is scaled-up -0.34414 * x */ |
2562 /* We also add in ONE_HALF so that need not do it in inner loop */ | 2562 /* We also add in ONE_HALF so that need not do it in inner loop */ |
2563 cconvert.Cb_g_tab[i] = ((int)(- (0.34414f* (1<<SCALEBITS) + 0.5f)) * x + ONE_HALF); | 2563 cconvert.Cb_g_tab[i] = (cast(int)(- (0.34414f* (1<<SCALEBITS) + 0.5f)) * x + ONE_HALF); |
2564 } | 2564 } |
2565 } | 2565 } |
2566 | 2566 |
2567 static void jinit_color_deconverter (jpeg_decompress_struct cinfo) { | 2567 static void jinit_color_deconverter (jpeg_decompress_struct cinfo) { |
2568 jpeg_color_deconverter cconvert = cinfo.cconvert = new jpeg_color_deconverter(); | 2568 jpeg_color_deconverter cconvert = cinfo.cconvert = new jpeg_color_deconverter(); |
2678 // /* We round up the number of rows to a multiple of the strip height. */ | 2678 // /* We round up the number of rows to a multiple of the strip height. */ |
2679 //#ifdef QUANT_2PASS_SUPPORTED | 2679 //#ifdef QUANT_2PASS_SUPPORTED |
2680 // post.whole_image = (*cinfo.mem.request_virt_sarray) | 2680 // post.whole_image = (*cinfo.mem.request_virt_sarray) |
2681 // ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, | 2681 // ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, |
2682 // cinfo.output_width * cinfo.out_color_components, | 2682 // cinfo.output_width * cinfo.out_color_components, |
2683 // (JDIMENSION) jround_up((long) cinfo.output_height, | 2683 // cast(JDIMENSION) jround_up(cast(long) cinfo.output_height, |
2684 // (long) post.strip_height), | 2684 // cast(long) post.strip_height), |
2685 // post.strip_height); | 2685 // post.strip_height); |
2686 //#else | 2686 //#else |
2687 // ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); | 2687 // ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); |
2688 //#endif /* QUANT_2PASS_SUPPORTED */ | 2688 //#endif /* QUANT_2PASS_SUPPORTED */ |
2689 // } else { | 2689 // } else { |
2873 } else | 2873 } else |
2874 upsample.methods[ci] = H2V2_UPSAMPLE; | 2874 upsample.methods[ci] = H2V2_UPSAMPLE; |
2875 } else if ((h_out_group % h_in_group) is 0 && (v_out_group % v_in_group) is 0) { | 2875 } else if ((h_out_group % h_in_group) is 0 && (v_out_group % v_in_group) is 0) { |
2876 /* Generic integral-factors upsampling method */ | 2876 /* Generic integral-factors upsampling method */ |
2877 upsample.methods[ci] = INT_UPSAMPLE; | 2877 upsample.methods[ci] = INT_UPSAMPLE; |
2878 upsample.h_expand[ci] = (byte) (h_out_group / h_in_group); | 2878 upsample.h_expand[ci] = cast(byte) (h_out_group / h_in_group); |
2879 upsample.v_expand[ci] = (byte) (v_out_group / v_in_group); | 2879 upsample.v_expand[ci] = cast(byte) (v_out_group / v_in_group); |
2880 } else | 2880 } else |
2881 error(); | 2881 error(); |
2882 // ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL); | 2882 // ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL); |
2883 if (need_buffer) { | 2883 if (need_buffer) { |
2884 upsample.color_buf[ci] = new byte[cinfo.max_v_samp_factor] | 2884 upsample.color_buf[ci] = new byte[cinfo.max_v_samp_factor] |
2885 [(int) jround_up(cinfo.output_width, cinfo.max_h_samp_factor)]; | 2885 [cast(int) jround_up(cinfo.output_width, cinfo.max_h_samp_factor)]; |
2886 } | 2886 } |
2887 } | 2887 } |
2888 } | 2888 } |
2889 | 2889 |
2890 static void jinit_phuff_decoder (jpeg_decompress_struct cinfo) { | 2890 static void jinit_phuff_decoder (jpeg_decompress_struct cinfo) { |
3248 /* Initialize dimensions and other stuff */ | 3248 /* Initialize dimensions and other stuff */ |
3249 jpeg_calc_output_dimensions(cinfo); | 3249 jpeg_calc_output_dimensions(cinfo); |
3250 prepare_range_limit_table(cinfo); | 3250 prepare_range_limit_table(cinfo); |
3251 | 3251 |
3252 /* Width of an output scanline must be representable as JDIMENSION. */ | 3252 /* Width of an output scanline must be representable as JDIMENSION. */ |
3253 samplesperrow = (long) cinfo.output_width * (long) cinfo.out_color_components; | 3253 samplesperrow = cast(long) cinfo.output_width * cast(long) cinfo.out_color_components; |
3254 jd_samplesperrow = (int) samplesperrow; | 3254 jd_samplesperrow = cast(int) samplesperrow; |
3255 if ( jd_samplesperrow !is samplesperrow) | 3255 if ( jd_samplesperrow !is samplesperrow) |
3256 error(); | 3256 error(); |
3257 // ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); | 3257 // ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); |
3258 | 3258 |
3259 /* Initialize my private state */ | 3259 /* Initialize my private state */ |
3367 // } else { | 3367 // } else { |
3368 // /* For a nonprogressive multiscan file, estimate 1 scan per component. */ | 3368 // /* For a nonprogressive multiscan file, estimate 1 scan per component. */ |
3369 // nscans = cinfo.num_components; | 3369 // nscans = cinfo.num_components; |
3370 // } | 3370 // } |
3371 // cinfo.progress.pass_counter = 0L; | 3371 // cinfo.progress.pass_counter = 0L; |
3372 // cinfo.progress.pass_limit = (long) cinfo.total_iMCU_rows * nscans; | 3372 // cinfo.progress.pass_limit = cast(long) cinfo.total_iMCU_rows * nscans; |
3373 // cinfo.progress.completed_passes = 0; | 3373 // cinfo.progress.completed_passes = 0; |
3374 // cinfo.progress.total_passes = (cinfo.enable_2pass_quant ? 3 : 2); | 3374 // cinfo.progress.total_passes = (cinfo.enable_2pass_quant ? 3 : 2); |
3375 // /* Count the input pass as done */ | 3375 // /* Count the input pass as done */ |
3376 // master.pass_number++; | 3376 // master.pass_number++; |
3377 // } | 3377 // } |
3441 break; | 3441 break; |
3442 /* Advance progress counter if appropriate */ | 3442 /* Advance progress counter if appropriate */ |
3443 // if (cinfo.progress !is null && (retcode is JPEG_ROW_COMPLETED || retcode is JPEG_REACHED_SOS)) { | 3443 // if (cinfo.progress !is null && (retcode is JPEG_ROW_COMPLETED || retcode is JPEG_REACHED_SOS)) { |
3444 // if (++cinfo.progress.pass_counter >= cinfo.progress.pass_limit) { | 3444 // if (++cinfo.progress.pass_counter >= cinfo.progress.pass_limit) { |
3445 // /* jdmaster underestimated number of scans; ratchet up one scan */ | 3445 // /* jdmaster underestimated number of scans; ratchet up one scan */ |
3446 // cinfo.progress.pass_limit += (long) cinfo.total_iMCU_rows; | 3446 // cinfo.progress.pass_limit += cast(long) cinfo.total_iMCU_rows; |
3447 // } | 3447 // } |
3448 // } | 3448 // } |
3449 } | 3449 } |
3450 //#else | 3450 //#else |
3451 // ERREXIT(cinfo, JERR_NOT_COMPILED); | 3451 // ERREXIT(cinfo, JERR_NOT_COMPILED); |
3958 pred = (((Q01<<7) - num) / (Q01<<8)); | 3958 pred = (((Q01<<7) - num) / (Q01<<8)); |
3959 if (Al > 0 && pred >= (1<<Al)) | 3959 if (Al > 0 && pred >= (1<<Al)) |
3960 pred = (1<<Al)-1; | 3960 pred = (1<<Al)-1; |
3961 pred = -pred; | 3961 pred = -pred; |
3962 } | 3962 } |
3963 workspace[1] = (short) pred; | 3963 workspace[1] = cast(short) pred; |
3964 } | 3964 } |
3965 /* AC10 */ | 3965 /* AC10 */ |
3966 if ((Al=coef_bits[2+coef_offset]) !is 0 && workspace[8] is 0) { | 3966 if ((Al=coef_bits[2+coef_offset]) !is 0 && workspace[8] is 0) { |
3967 num = 36 * Q00 * (DC2 - DC8); | 3967 num = 36 * Q00 * (DC2 - DC8); |
3968 if (num >= 0) { | 3968 if (num >= 0) { |
3973 pred = (((Q10<<7) - num) / (Q10<<8)); | 3973 pred = (((Q10<<7) - num) / (Q10<<8)); |
3974 if (Al > 0 && pred >= (1<<Al)) | 3974 if (Al > 0 && pred >= (1<<Al)) |
3975 pred = (1<<Al)-1; | 3975 pred = (1<<Al)-1; |
3976 pred = -pred; | 3976 pred = -pred; |
3977 } | 3977 } |
3978 workspace[8] = (short) pred; | 3978 workspace[8] = cast(short) pred; |
3979 } | 3979 } |
3980 /* AC20 */ | 3980 /* AC20 */ |
3981 if ((Al=coef_bits[3+coef_offset]) !is 0 && workspace[16] is 0) { | 3981 if ((Al=coef_bits[3+coef_offset]) !is 0 && workspace[16] is 0) { |
3982 num = 9 * Q00 * (DC2 + DC8 - 2*DC5); | 3982 num = 9 * Q00 * (DC2 + DC8 - 2*DC5); |
3983 if (num >= 0) { | 3983 if (num >= 0) { |
3988 pred = (((Q20<<7) - num) / (Q20<<8)); | 3988 pred = (((Q20<<7) - num) / (Q20<<8)); |
3989 if (Al > 0 && pred >= (1<<Al)) | 3989 if (Al > 0 && pred >= (1<<Al)) |
3990 pred = (1<<Al)-1; | 3990 pred = (1<<Al)-1; |
3991 pred = -pred; | 3991 pred = -pred; |
3992 } | 3992 } |
3993 workspace[16] = (short) pred; | 3993 workspace[16] = cast(short) pred; |
3994 } | 3994 } |
3995 /* AC11 */ | 3995 /* AC11 */ |
3996 if ((Al=coef_bits[4+coef_offset]) !is 0 && workspace[9] is 0) { | 3996 if ((Al=coef_bits[4+coef_offset]) !is 0 && workspace[9] is 0) { |
3997 num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9); | 3997 num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9); |
3998 if (num >= 0) { | 3998 if (num >= 0) { |
4003 pred = (((Q11<<7) - num) / (Q11<<8)); | 4003 pred = (((Q11<<7) - num) / (Q11<<8)); |
4004 if (Al > 0 && pred >= (1<<Al)) | 4004 if (Al > 0 && pred >= (1<<Al)) |
4005 pred = (1<<Al)-1; | 4005 pred = (1<<Al)-1; |
4006 pred = -pred; | 4006 pred = -pred; |
4007 } | 4007 } |
4008 workspace[9] = (short) pred; | 4008 workspace[9] = cast(short) pred; |
4009 } | 4009 } |
4010 /* AC02 */ | 4010 /* AC02 */ |
4011 if ((Al=coef_bits[5+coef_offset]) !is 0 && workspace[2] is 0) { | 4011 if ((Al=coef_bits[5+coef_offset]) !is 0 && workspace[2] is 0) { |
4012 num = 9 * Q00 * (DC4 + DC6 - 2*DC5); | 4012 num = 9 * Q00 * (DC4 + DC6 - 2*DC5); |
4013 if (num >= 0) { | 4013 if (num >= 0) { |
4018 pred = (((Q02<<7) - num) / (Q02<<8)); | 4018 pred = (((Q02<<7) - num) / (Q02<<8)); |
4019 if (Al > 0 && pred >= (1<<Al)) | 4019 if (Al > 0 && pred >= (1<<Al)) |
4020 pred = (1<<Al)-1; | 4020 pred = (1<<Al)-1; |
4021 pred = -pred; | 4021 pred = -pred; |
4022 } | 4022 } |
4023 workspace[2] = (short) pred; | 4023 workspace[2] = cast(short) pred; |
4024 } | 4024 } |
4025 /* OK, do the IDCT */ | 4025 /* OK, do the IDCT */ |
4026 jpeg_idct_islow(cinfo, compptr, workspace, output_ptr, output_ptr_offset, output_col); | 4026 jpeg_idct_islow(cinfo, compptr, workspace, output_ptr, output_ptr_offset, output_col); |
4027 /* Advance for next column */ | 4027 /* Advance for next column */ |
4028 DC1 = DC2; DC2 = DC3; | 4028 DC1 = DC2; DC2 = DC3; |
4303 return 0; | 4303 return 0; |
4304 } | 4304 } |
4305 | 4305 |
4306 /* Call progress monitor hook if present */ | 4306 /* Call progress monitor hook if present */ |
4307 // if (cinfo.progress !is NULL) { | 4307 // if (cinfo.progress !is NULL) { |
4308 // cinfo.progress.pass_counter = (long) cinfo.output_scanline; | 4308 // cinfo.progress.pass_counter = cast(long) cinfo.output_scanline; |
4309 // cinfo.progress.pass_limit = (long) cinfo.output_height; | 4309 // cinfo.progress.pass_limit = cast(long) cinfo.output_height; |
4310 // (*cinfo.progress.progress_monitor) ((j_common_ptr) cinfo); | 4310 // (*cinfo.progress.progress_monitor) ((j_common_ptr) cinfo); |
4311 // } | 4311 // } |
4312 | 4312 |
4313 /* Process some data */ | 4313 /* Process some data */ |
4314 cinfo.row_ctr[0] = 0; | 4314 cinfo.row_ctr[0] = 0; |
4343 // /* Crank through the dummy pass */ | 4343 // /* Crank through the dummy pass */ |
4344 // while (cinfo.output_scanline < cinfo.output_height) { | 4344 // while (cinfo.output_scanline < cinfo.output_height) { |
4345 // JDIMENSION last_scanline; | 4345 // JDIMENSION last_scanline; |
4346 // /* Call progress monitor hook if present */ | 4346 // /* Call progress monitor hook if present */ |
4347 // if (cinfo.progress !is NULL) { | 4347 // if (cinfo.progress !is NULL) { |
4348 // cinfo.progress.pass_counter = (long) cinfo.output_scanline; | 4348 // cinfo.progress.pass_counter = cast(long) cinfo.output_scanline; |
4349 // cinfo.progress.pass_limit = (long) cinfo.output_height; | 4349 // cinfo.progress.pass_limit = cast(long) cinfo.output_height; |
4350 // (*cinfo.progress.progress_monitor) ((j_common_ptr) cinfo); | 4350 // (*cinfo.progress.progress_monitor) ((j_common_ptr) cinfo); |
4351 // } | 4351 // } |
4352 // /* Process some data */ | 4352 // /* Process some data */ |
4353 // last_scanline = cinfo.output_scanline; | 4353 // last_scanline = cinfo.output_scanline; |
4354 // (*cinfo.main.process_data) (cinfo, (JSAMPARRAY) NULL, | 4354 // (*cinfo.main.process_data) (cinfo, cast(JSAMPARRAY) NULL, |
4355 // &cinfo.output_scanline, (JDIMENSION) 0); | 4355 // &cinfo.output_scanline, cast(JDIMENSION) 0); |
4356 // if (cinfo.output_scanline is last_scanline) | 4356 // if (cinfo.output_scanline is last_scanline) |
4357 // return FALSE; /* No progress made, must suspend */ | 4357 // return FALSE; /* No progress made, must suspend */ |
4358 // } | 4358 // } |
4359 // /* Finish up dummy pass, and set up for another one */ | 4359 // /* Finish up dummy pass, and set up for another one */ |
4360 // (*cinfo.master.finish_output_pass) (cinfo); | 4360 // (*cinfo.master.finish_output_pass) (cinfo); |
4485 } else { | 4485 } else { |
4486 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); | 4486 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); |
4487 tmp = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; | 4487 tmp = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; |
4488 } | 4488 } |
4489 /* We convert the zigzag-order table to natural array order. */ | 4489 /* We convert the zigzag-order table to natural array order. */ |
4490 quant_ptr.quantval[jpeg_natural_order[i]] = (short) tmp; | 4490 quant_ptr.quantval[jpeg_natural_order[i]] = cast(short) tmp; |
4491 } | 4491 } |
4492 | 4492 |
4493 // if (cinfo.err.trace_level >= 2) { | 4493 // if (cinfo.err.trace_level >= 2) { |
4494 // for (i = 0; i < DCTSIZE2; i += 8) { | 4494 // for (i = 0; i < DCTSIZE2; i += 8) { |
4495 // TRACEMS8(cinfo, 2, JTRC_QUANTVALS, | 4495 // TRACEMS8(cinfo, 2, JTRC_QUANTVALS, |
4562 if (index < 0 || index >= (2*NUM_ARITH_TBLS)) | 4562 if (index < 0 || index >= (2*NUM_ARITH_TBLS)) |
4563 error(); | 4563 error(); |
4564 // ERREXIT1(cinfo, JERR_DAC_INDEX, index); | 4564 // ERREXIT1(cinfo, JERR_DAC_INDEX, index); |
4565 | 4565 |
4566 if (index >= NUM_ARITH_TBLS) { /* define AC table */ | 4566 if (index >= NUM_ARITH_TBLS) { /* define AC table */ |
4567 cinfo.arith_ac_K[index-NUM_ARITH_TBLS] = (byte) val; | 4567 cinfo.arith_ac_K[index-NUM_ARITH_TBLS] = cast(byte) val; |
4568 } else { /* define DC table */ | 4568 } else { /* define DC table */ |
4569 cinfo.arith_dc_L[index] = (byte) (val & 0x0F); | 4569 cinfo.arith_dc_L[index] = cast(byte) (val & 0x0F); |
4570 cinfo.arith_dc_U[index] = (byte) (val >> 4); | 4570 cinfo.arith_dc_U[index] = cast(byte) (val >> 4); |
4571 if (cinfo.arith_dc_L[index] > cinfo.arith_dc_U[index]) | 4571 if (cinfo.arith_dc_L[index] > cinfo.arith_dc_U[index]) |
4572 error(); | 4572 error(); |
4573 // ERREXIT1(cinfo, JERR_DAC_VALUE, val); | 4573 // ERREXIT1(cinfo, JERR_DAC_VALUE, val); |
4574 } | 4574 } |
4575 } | 4575 } |
4686 cinfo.num_components = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; | 4686 cinfo.num_components = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; |
4687 | 4687 |
4688 length -= 8; | 4688 length -= 8; |
4689 | 4689 |
4690 // TRACEMS4(cinfo, 1, JTRC_SOF, cinfo.unread_marker, | 4690 // TRACEMS4(cinfo, 1, JTRC_SOF, cinfo.unread_marker, |
4691 // (int) cinfo.image_width, (int) cinfo.image_height, | 4691 // cast(int) cinfo.image_width, cast(int) cinfo.image_height, |
4692 // cinfo.num_components); | 4692 // cinfo.num_components); |
4693 | 4693 |
4694 if (cinfo.marker.saw_SOF) | 4694 if (cinfo.marker.saw_SOF) |
4695 error(); | 4695 error(); |
4696 // ERREXIT(cinfo, JERR_SOF_DUPLICATE); | 4696 // ERREXIT(cinfo, JERR_SOF_DUPLICATE); |
4870 inptr = input_data[inrow+input_data_offset]; | 4870 inptr = input_data[inrow+input_data_offset]; |
4871 outptr = output_data[inrow]; | 4871 outptr = output_data[inrow]; |
4872 int inptr_offset = 0, outptr_offset = 0; | 4872 int inptr_offset = 0, outptr_offset = 0; |
4873 /* Special case for first column */ | 4873 /* Special case for first column */ |
4874 invalue = inptr[inptr_offset++] & 0xFF; | 4874 invalue = inptr[inptr_offset++] & 0xFF; |
4875 outptr[outptr_offset++] = (byte) invalue; | 4875 outptr[outptr_offset++] = cast(byte) invalue; |
4876 outptr[outptr_offset++] = (byte) ((invalue * 3 + (inptr[inptr_offset] & 0xFF) + 2) >> 2); | 4876 outptr[outptr_offset++] = cast(byte) ((invalue * 3 + (inptr[inptr_offset] & 0xFF) + 2) >> 2); |
4877 | 4877 |
4878 for (colctr = compptr.downsampled_width - 2; colctr > 0; colctr--) { | 4878 for (colctr = compptr.downsampled_width - 2; colctr > 0; colctr--) { |
4879 /* General case: 3/4 * nearer pixel + 1/4 * further pixel */ | 4879 /* General case: 3/4 * nearer pixel + 1/4 * further pixel */ |
4880 invalue = (inptr[inptr_offset++] & 0xFF) * 3; | 4880 invalue = (inptr[inptr_offset++] & 0xFF) * 3; |
4881 outptr[outptr_offset++] = (byte) ((invalue + (inptr[inptr_offset-2] & 0xFF) + 1) >> 2); | 4881 outptr[outptr_offset++] = cast(byte) ((invalue + (inptr[inptr_offset-2] & 0xFF) + 1) >> 2); |
4882 outptr[outptr_offset++] = (byte) ((invalue + (inptr[inptr_offset] & 0xFF) + 2) >> 2); | 4882 outptr[outptr_offset++] = cast(byte) ((invalue + (inptr[inptr_offset] & 0xFF) + 2) >> 2); |
4883 } | 4883 } |
4884 | 4884 |
4885 /* Special case for last column */ | 4885 /* Special case for last column */ |
4886 invalue = (inptr[inptr_offset] & 0xFF); | 4886 invalue = (inptr[inptr_offset] & 0xFF); |
4887 outptr[outptr_offset++] = (byte) ((invalue * 3 + (inptr[inptr_offset-1] & 0xFF) + 1) >> 2); | 4887 outptr[outptr_offset++] = cast(byte) ((invalue * 3 + (inptr[inptr_offset-1] & 0xFF) + 1) >> 2); |
4888 outptr[outptr_offset++] = (byte) invalue; | 4888 outptr[outptr_offset++] = cast(byte) invalue; |
4889 } | 4889 } |
4890 } | 4890 } |
4891 | 4891 |
4892 static void h2v2_fancy_upsample (jpeg_decompress_struct cinfo, jpeg_component_info compptr, | 4892 static void h2v2_fancy_upsample (jpeg_decompress_struct cinfo, jpeg_component_info compptr, |
4893 byte[][] input_data, int input_data_offset, byte[][][] output_data_ptr, int[] output_data_offset, int output_data_index) | 4893 byte[][] input_data, int input_data_offset, byte[][][] output_data_ptr, int[] output_data_offset, int output_data_index) |
4913 int inptr0_offset = 0, inptr1_offset = 0, outptr_offset = 0; | 4913 int inptr0_offset = 0, inptr1_offset = 0, outptr_offset = 0; |
4914 | 4914 |
4915 /* Special case for first column */ | 4915 /* Special case for first column */ |
4916 thiscolsum = (inptr0[inptr0_offset++] & 0xFF) * 3 + (inptr1[inptr1_offset++] & 0xFF); | 4916 thiscolsum = (inptr0[inptr0_offset++] & 0xFF) * 3 + (inptr1[inptr1_offset++] & 0xFF); |
4917 nextcolsum = (inptr0[inptr0_offset++] & 0xFF) * 3 + (inptr1[inptr1_offset++] & 0xFF); | 4917 nextcolsum = (inptr0[inptr0_offset++] & 0xFF) * 3 + (inptr1[inptr1_offset++] & 0xFF); |
4918 outptr[outptr_offset++] = (byte) ((thiscolsum * 4 + 8) >> 4); | 4918 outptr[outptr_offset++] = cast(byte) ((thiscolsum * 4 + 8) >> 4); |
4919 outptr[outptr_offset++] = (byte) ((thiscolsum * 3 + nextcolsum + 7) >> 4); | 4919 outptr[outptr_offset++] = cast(byte) ((thiscolsum * 3 + nextcolsum + 7) >> 4); |
4920 lastcolsum = thiscolsum; thiscolsum = nextcolsum; | 4920 lastcolsum = thiscolsum; thiscolsum = nextcolsum; |
4921 | 4921 |
4922 for (colctr = compptr.downsampled_width - 2; colctr > 0; colctr--) { | 4922 for (colctr = compptr.downsampled_width - 2; colctr > 0; colctr--) { |
4923 /* General case: 3/4 * nearer pixel + 1/4 * further pixel in each */ | 4923 /* General case: 3/4 * nearer pixel + 1/4 * further pixel in each */ |
4924 /* dimension, thus 9/16, 3/16, 3/16, 1/16 overall */ | 4924 /* dimension, thus 9/16, 3/16, 3/16, 1/16 overall */ |
4925 nextcolsum = (inptr0[inptr0_offset++] & 0xFF) * 3 + (inptr1[inptr1_offset++] & 0xFF); | 4925 nextcolsum = (inptr0[inptr0_offset++] & 0xFF) * 3 + (inptr1[inptr1_offset++] & 0xFF); |
4926 outptr[outptr_offset++] = (byte) ((thiscolsum * 3 + lastcolsum + 8) >> 4); | 4926 outptr[outptr_offset++] = cast(byte) ((thiscolsum * 3 + lastcolsum + 8) >> 4); |
4927 outptr[outptr_offset++] = (byte) ((thiscolsum * 3 + nextcolsum + 7) >> 4); | 4927 outptr[outptr_offset++] = cast(byte) ((thiscolsum * 3 + nextcolsum + 7) >> 4); |
4928 lastcolsum = thiscolsum; thiscolsum = nextcolsum; | 4928 lastcolsum = thiscolsum; thiscolsum = nextcolsum; |
4929 } | 4929 } |
4930 | 4930 |
4931 /* Special case for last column */ | 4931 /* Special case for last column */ |
4932 outptr[outptr_offset++] = (byte) ((thiscolsum * 3 + lastcolsum + 8) >> 4); | 4932 outptr[outptr_offset++] = cast(byte) ((thiscolsum * 3 + lastcolsum + 8) >> 4); |
4933 outptr[outptr_offset++] = (byte) ((thiscolsum * 4 + 7) >> 4); | 4933 outptr[outptr_offset++] = cast(byte) ((thiscolsum * 4 + 7) >> 4); |
4934 } | 4934 } |
4935 inrow++; | 4935 inrow++; |
4936 } | 4936 } |
4937 } | 4937 } |
4938 | 4938 |
5108 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); | 5108 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); |
5109 length |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF; | 5109 length |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF; |
5110 | 5110 |
5111 length -= 2; | 5111 length -= 2; |
5112 | 5112 |
5113 // TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo.unread_marker, (int) length); | 5113 // TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo.unread_marker, cast(int) length); |
5114 | 5114 |
5115 if (length > 0) { | 5115 if (length > 0) { |
5116 skip_input_data (cinfo, length); | 5116 skip_input_data (cinfo, length); |
5117 } | 5117 } |
5118 | 5118 |
5183 (data[4] & 0xFF) is 0) | 5183 (data[4] & 0xFF) is 0) |
5184 { | 5184 { |
5185 /* Found JFIF APP0 marker: save info */ | 5185 /* Found JFIF APP0 marker: save info */ |
5186 cinfo.saw_JFIF_marker = true; | 5186 cinfo.saw_JFIF_marker = true; |
5187 cinfo.JFIF_major_version = (data[5]); | 5187 cinfo.JFIF_major_version = (data[5]); |
5188 cinfo.JFIF_minor_version = (byte)(data[6] & 0xFF); | 5188 cinfo.JFIF_minor_version = cast(byte)(data[6] & 0xFF); |
5189 cinfo.density_unit = (byte)(data[7] & 0xFF); | 5189 cinfo.density_unit = cast(byte)(data[7] & 0xFF); |
5190 cinfo.X_density = (short)(((data[8] & 0xFF) << 8) + (data[9] & 0xFF)); | 5190 cinfo.X_density = cast(short)(((data[8] & 0xFF) << 8) + (data[9] & 0xFF)); |
5191 cinfo.Y_density = (short)(((data[10] & 0xFF) << 8) + (data[11] & 0xFF)); | 5191 cinfo.Y_density = cast(short)(((data[10] & 0xFF) << 8) + (data[11] & 0xFF)); |
5192 /* Check version. | 5192 /* Check version. |
5193 * Major version must be 1, anything else signals an incompatible change. | 5193 * Major version must be 1, anything else signals an incompatible change. |
5194 * (We used to treat this as an error, but now it's a nonfatal warning, | 5194 * (We used to treat this as an error, but now it's a nonfatal warning, |
5195 * because some bozo at Hijaak couldn't read the spec.) | 5195 * because some bozo at Hijaak couldn't read the spec.) |
5196 * Minor version should be 0..2, but process anyway if newer. | 5196 * Minor version should be 0..2, but process anyway if newer. |
5208 // TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL, | 5208 // TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL, |
5209 // GETJOCTET(data[12]), GETJOCTET(data[13])); | 5209 // GETJOCTET(data[12]), GETJOCTET(data[13])); |
5210 } | 5210 } |
5211 totallen -= APP0_DATA_LEN; | 5211 totallen -= APP0_DATA_LEN; |
5212 if (totallen != ((data[12] & 0xFF) * (data[13] & 0xFF) * 3)) { | 5212 if (totallen != ((data[12] & 0xFF) * (data[13] & 0xFF) * 3)) { |
5213 // TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int) totallen); | 5213 // TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, cast(int) totallen); |
5214 } | 5214 } |
5215 } else if (datalen >= 6 && | 5215 } else if (datalen >= 6 && |
5216 (data[0] & 0xFF) is 0x4A && | 5216 (data[0] & 0xFF) is 0x4A && |
5217 (data[1] & 0xFF) is 0x46 && | 5217 (data[1] & 0xFF) is 0x46 && |
5218 (data[2] & 0xFF) is 0x58 && | 5218 (data[2] & 0xFF) is 0x58 && |
5223 /* The library doesn't actually do anything with these, | 5223 /* The library doesn't actually do anything with these, |
5224 * but we try to produce a helpful trace message. | 5224 * but we try to produce a helpful trace message. |
5225 */ | 5225 */ |
5226 switch ((data[5]) & 0xFF) { | 5226 switch ((data[5]) & 0xFF) { |
5227 case 0x10: | 5227 case 0x10: |
5228 // TRACEMS1(cinfo, 1, JTRC_THUMB_JPEG, (int) totallen); | 5228 // TRACEMS1(cinfo, 1, JTRC_THUMB_JPEG, cast(int) totallen); |
5229 break; | 5229 break; |
5230 case 0x11: | 5230 case 0x11: |
5231 // TRACEMS1(cinfo, 1, JTRC_THUMB_PALETTE, (int) totallen); | 5231 // TRACEMS1(cinfo, 1, JTRC_THUMB_PALETTE, cast(int) totallen); |
5232 break; | 5232 break; |
5233 case 0x13: | 5233 case 0x13: |
5234 // TRACEMS1(cinfo, 1, JTRC_THUMB_RGB, (int) totallen); | 5234 // TRACEMS1(cinfo, 1, JTRC_THUMB_RGB, cast(int) totallen); |
5235 break; | 5235 break; |
5236 default: | 5236 default: |
5237 // TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION, GETJOCTET(data[5]), (int) totallen); | 5237 // TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION, GETJOCTET(data[5]), cast(int) totallen); |
5238 break; | 5238 break; |
5239 } | 5239 } |
5240 } else { | 5240 } else { |
5241 /* Start of APP0 does not match "JFIF" or "JFXX", or too short */ | 5241 /* Start of APP0 does not match "JFIF" or "JFXX", or too short */ |
5242 // TRACEMS1(cinfo, 1, JTRC_APP0, (int) totallen); | 5242 // TRACEMS1(cinfo, 1, JTRC_APP0, cast(int) totallen); |
5243 } | 5243 } |
5244 } | 5244 } |
5245 | 5245 |
5246 static void examine_app14 (jpeg_decompress_struct cinfo, byte[] data, int datalen, int remaining) | 5246 static void examine_app14 (jpeg_decompress_struct cinfo, byte[] data, int datalen, int remaining) |
5247 /* Examine first few bytes from an APP14. | 5247 /* Examine first few bytes from an APP14. |
5263 // flags0 = ((data[7] & 0xFF) << 8) + (data[8] & 0xFF); | 5263 // flags0 = ((data[7] & 0xFF) << 8) + (data[8] & 0xFF); |
5264 // flags1 = ((data[9] & 0xFF) << 8) + (data[10] & 0xFF); | 5264 // flags1 = ((data[9] & 0xFF) << 8) + (data[10] & 0xFF); |
5265 transform = (data[11] & 0xFF); | 5265 transform = (data[11] & 0xFF); |
5266 // TRACEMS4(cinfo, 1, JTRC_ADOBE, version, flags0, flags1, transform); | 5266 // TRACEMS4(cinfo, 1, JTRC_ADOBE, version, flags0, flags1, transform); |
5267 cinfo.saw_Adobe_marker = true; | 5267 cinfo.saw_Adobe_marker = true; |
5268 cinfo.Adobe_transform = (byte) transform; | 5268 cinfo.Adobe_transform = cast(byte) transform; |
5269 } else { | 5269 } else { |
5270 /* Start of APP14 does not match "Adobe", or too short */ | 5270 /* Start of APP14 does not match "Adobe", or too short */ |
5271 // TRACEMS1(cinfo, 1, JTRC_APP14, (int) (datalen + remaining)); | 5271 // TRACEMS1(cinfo, 1, JTRC_APP14, cast(int) (datalen + remaining)); |
5272 } | 5272 } |
5273 } | 5273 } |
5274 | 5274 |
5275 static bool get_soi (jpeg_decompress_struct cinfo) /* Process an SOI marker */ { | 5275 static bool get_soi (jpeg_decompress_struct cinfo) /* Process an SOI marker */ { |
5276 int i; | 5276 int i; |
5556 if (cinfo.start_of_file) /* Treat empty input file as fatal error */ | 5556 if (cinfo.start_of_file) /* Treat empty input file as fatal error */ |
5557 error(); | 5557 error(); |
5558 // ERREXIT(cinfo, JERR_INPUT_EMPTY); | 5558 // ERREXIT(cinfo, JERR_INPUT_EMPTY); |
5559 // WARNMS(cinfo, JWRN_JPEG_EOF); | 5559 // WARNMS(cinfo, JWRN_JPEG_EOF); |
5560 /* Insert a fake EOI marker */ | 5560 /* Insert a fake EOI marker */ |
5561 cinfo.buffer[0] = (byte)0xFF; | 5561 cinfo.buffer[0] = cast(byte)0xFF; |
5562 cinfo.buffer[1] = (byte)M_EOI; | 5562 cinfo.buffer[1] = cast(byte)M_EOI; |
5563 nbytes = 2; | 5563 nbytes = 2; |
5564 } | 5564 } |
5565 cinfo.bytes_in_buffer = nbytes; | 5565 cinfo.bytes_in_buffer = nbytes; |
5566 cinfo.bytes_offset = 0; | 5566 cinfo.bytes_offset = 0; |
5567 cinfo.start_of_file = false; | 5567 cinfo.start_of_file = false; |
5833 /* Compute dimensions of components */ | 5833 /* Compute dimensions of components */ |
5834 for (ci = 0; ci < cinfo.num_components; ci++) { | 5834 for (ci = 0; ci < cinfo.num_components; ci++) { |
5835 compptr = cinfo.comp_info[ci]; | 5835 compptr = cinfo.comp_info[ci]; |
5836 compptr.DCT_scaled_size = DCTSIZE; | 5836 compptr.DCT_scaled_size = DCTSIZE; |
5837 /* Size in DCT blocks */ | 5837 /* Size in DCT blocks */ |
5838 compptr.width_in_blocks = (int)jdiv_round_up((long) cinfo.image_width * (long) compptr.h_samp_factor, (cinfo.max_h_samp_factor * DCTSIZE)); | 5838 compptr.width_in_blocks = cast(int)jdiv_round_up(cast(long) cinfo.image_width * cast(long) compptr.h_samp_factor, (cinfo.max_h_samp_factor * DCTSIZE)); |
5839 compptr.height_in_blocks = (int)jdiv_round_up((long) cinfo.image_height * (long) compptr.v_samp_factor, (cinfo.max_v_samp_factor * DCTSIZE)); | 5839 compptr.height_in_blocks = cast(int)jdiv_round_up(cast(long) cinfo.image_height * cast(long) compptr.v_samp_factor, (cinfo.max_v_samp_factor * DCTSIZE)); |
5840 /* downsampled_width and downsampled_height will also be overridden by | 5840 /* downsampled_width and downsampled_height will also be overridden by |
5841 * jdmaster.c if we are doing full decompression. The transcoder library | 5841 * jdmaster.c if we are doing full decompression. The transcoder library |
5842 * doesn't use these values, but the calling application might. | 5842 * doesn't use these values, but the calling application might. |
5843 */ | 5843 */ |
5844 /* Size in samples */ | 5844 /* Size in samples */ |
5845 compptr.downsampled_width = (int)jdiv_round_up((long) cinfo.image_width * (long) compptr.h_samp_factor, cinfo.max_h_samp_factor); | 5845 compptr.downsampled_width = cast(int)jdiv_round_up(cast(long) cinfo.image_width * cast(long) compptr.h_samp_factor, cinfo.max_h_samp_factor); |
5846 compptr.downsampled_height = (int)jdiv_round_up((long) cinfo.image_height * (long) compptr.v_samp_factor, cinfo.max_v_samp_factor); | 5846 compptr.downsampled_height = cast(int)jdiv_round_up(cast(long) cinfo.image_height * cast(long) compptr.v_samp_factor, cinfo.max_v_samp_factor); |
5847 /* Mark component needed, until color conversion says otherwise */ | 5847 /* Mark component needed, until color conversion says otherwise */ |
5848 compptr.component_needed = true; | 5848 compptr.component_needed = true; |
5849 /* Mark no quantization table yet saved for component */ | 5849 /* Mark no quantization table yet saved for component */ |
5850 compptr.quant_table = null; | 5850 compptr.quant_table = null; |
5851 } | 5851 } |
5852 | 5852 |
5853 /* Compute number of fully interleaved MCU rows. */ | 5853 /* Compute number of fully interleaved MCU rows. */ |
5854 cinfo.total_iMCU_rows = (int)jdiv_round_up( cinfo.image_height, (cinfo.max_v_samp_factor*DCTSIZE)); | 5854 cinfo.total_iMCU_rows = cast(int)jdiv_round_up( cinfo.image_height, (cinfo.max_v_samp_factor*DCTSIZE)); |
5855 | 5855 |
5856 /* Decide whether file contains multiple scans */ | 5856 /* Decide whether file contains multiple scans */ |
5857 if (cinfo.comps_in_scan < cinfo.num_components || cinfo.progressive_mode) | 5857 if (cinfo.comps_in_scan < cinfo.num_components || cinfo.progressive_mode) |
5858 cinfo.inputctl.has_multiple_scans = true; | 5858 cinfo.inputctl.has_multiple_scans = true; |
5859 else | 5859 else |
5900 if (cinfo.comps_in_scan <= 0 || cinfo.comps_in_scan > MAX_COMPS_IN_SCAN) | 5900 if (cinfo.comps_in_scan <= 0 || cinfo.comps_in_scan > MAX_COMPS_IN_SCAN) |
5901 error(); | 5901 error(); |
5902 // ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo.comps_in_scan, MAX_COMPS_IN_SCAN); | 5902 // ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo.comps_in_scan, MAX_COMPS_IN_SCAN); |
5903 | 5903 |
5904 /* Overall image size in MCUs */ | 5904 /* Overall image size in MCUs */ |
5905 cinfo.MCUs_per_row = (int)jdiv_round_up( cinfo.image_width, (cinfo.max_h_samp_factor*DCTSIZE)); | 5905 cinfo.MCUs_per_row = cast(int)jdiv_round_up( cinfo.image_width, (cinfo.max_h_samp_factor*DCTSIZE)); |
5906 cinfo.MCU_rows_in_scan = (int)jdiv_round_up( cinfo.image_height, (cinfo.max_v_samp_factor*DCTSIZE)); | 5906 cinfo.MCU_rows_in_scan = cast(int)jdiv_round_up( cinfo.image_height, (cinfo.max_v_samp_factor*DCTSIZE)); |
5907 | 5907 |
5908 cinfo.blocks_in_MCU = 0; | 5908 cinfo.blocks_in_MCU = 0; |
5909 | 5909 |
5910 for (ci = 0; ci < cinfo.comps_in_scan; ci++) { | 5910 for (ci = 0; ci < cinfo.comps_in_scan; ci++) { |
5911 compptr = cinfo.cur_comp_info[ci]; | 5911 compptr = cinfo.cur_comp_info[ci]; |
5988 i = htbl.bits[l] & 0xFF; | 5988 i = htbl.bits[l] & 0xFF; |
5989 if (i < 0 || p + i > 256) /* protect against table overrun */ | 5989 if (i < 0 || p + i > 256) /* protect against table overrun */ |
5990 error(); | 5990 error(); |
5991 // ERREXIT(cinfo, JERR_BAD_HUFF_TABLE); | 5991 // ERREXIT(cinfo, JERR_BAD_HUFF_TABLE); |
5992 while (i-- !is 0) | 5992 while (i-- !is 0) |
5993 huffsize[p++] = (byte) l; | 5993 huffsize[p++] = cast(byte) l; |
5994 } | 5994 } |
5995 huffsize[p] = 0; | 5995 huffsize[p] = 0; |
5996 numsymbols = p; | 5996 numsymbols = p; |
5997 | 5997 |
5998 /* Figure C.2: generate the codes themselves */ | 5998 /* Figure C.2: generate the codes themselves */ |
6346 int offset = row_stride * cinfo.output_scanline; | 6346 int offset = row_stride * cinfo.output_scanline; |
6347 jpeg_read_scanlines(cinfo, buffer, 1); | 6347 jpeg_read_scanlines(cinfo, buffer, 1); |
6348 System.arraycopy(buffer[0], 0, data, offset, row_stride); | 6348 System.arraycopy(buffer[0], 0, data, offset, row_stride); |
6349 } | 6349 } |
6350 jpeg_finish_output(cinfo); | 6350 jpeg_finish_output(cinfo); |
6351 loader.notifyListeners(new ImageLoaderEvent(loader, (ImageData)imageData.clone(), incrementCount, done = jpeg_input_complete(cinfo))); | 6351 loader.notifyListeners(new ImageLoaderEvent(loader, cast(ImageData)imageData.clone(), incrementCount, done = jpeg_input_complete(cinfo))); |
6352 } while (!done); | 6352 } while (!done); |
6353 } else { | 6353 } else { |
6354 while (cinfo.output_scanline < cinfo.output_height) { | 6354 while (cinfo.output_scanline < cinfo.output_height) { |
6355 int offset = row_stride * cinfo.output_scanline; | 6355 int offset = row_stride * cinfo.output_scanline; |
6356 jpeg_read_scanlines(cinfo, buffer, 1); | 6356 jpeg_read_scanlines(cinfo, buffer, 1); |