OLD | NEW |
1 /* | 1 /* |
2 * jdarith.c | 2 * jdarith.c |
3 * | 3 * |
| 4 * This file is part of the Independent JPEG Group's software: |
4 * Developed 1997-2009 by Guido Vollbeding. | 5 * Developed 1997-2009 by Guido Vollbeding. |
5 * This file is part of the Independent JPEG Group's software. | 6 * libjpeg-turbo Modifications: |
| 7 * Copyright (C) 2015, D. R. Commander. |
6 * For conditions of distribution and use, see the accompanying README file. | 8 * For conditions of distribution and use, see the accompanying README file. |
7 * | 9 * |
8 * This file contains portable arithmetic entropy decoding routines for JPEG | 10 * This file contains portable arithmetic entropy decoding routines for JPEG |
9 * (implementing the ISO/IEC IS 10918-1 and CCITT Recommendation ITU-T T.81). | 11 * (implementing the ISO/IEC IS 10918-1 and CCITT Recommendation ITU-T T.81). |
10 * | 12 * |
11 * Both sequential and progressive modes are supported in this single module. | 13 * Both sequential and progressive modes are supported in this single module. |
12 * | 14 * |
13 * Suspension is not currently supported in this module. | 15 * Suspension is not currently supported in this module. |
14 */ | 16 */ |
15 | 17 |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 if (entropy->restarts_to_go == 0) | 509 if (entropy->restarts_to_go == 0) |
508 process_restart(cinfo); | 510 process_restart(cinfo); |
509 entropy->restarts_to_go--; | 511 entropy->restarts_to_go--; |
510 } | 512 } |
511 | 513 |
512 if (entropy->ct == -1) return TRUE; /* if error do nothing */ | 514 if (entropy->ct == -1) return TRUE; /* if error do nothing */ |
513 | 515 |
514 /* Outer loop handles each block in the MCU */ | 516 /* Outer loop handles each block in the MCU */ |
515 | 517 |
516 for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { | 518 for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { |
517 block = MCU_data[blkn]; | 519 block = MCU_data ? MCU_data[blkn] : NULL; |
518 ci = cinfo->MCU_membership[blkn]; | 520 ci = cinfo->MCU_membership[blkn]; |
519 compptr = cinfo->cur_comp_info[ci]; | 521 compptr = cinfo->cur_comp_info[ci]; |
520 | 522 |
521 /* Sections F.2.4.1 & F.1.4.4.1: Decoding of DC coefficients */ | 523 /* Sections F.2.4.1 & F.1.4.4.1: Decoding of DC coefficients */ |
522 | 524 |
523 tbl = compptr->dc_tbl_no; | 525 tbl = compptr->dc_tbl_no; |
524 | 526 |
525 /* Table F.4: Point to statistics bin S0 for DC coefficient coding */ | 527 /* Table F.4: Point to statistics bin S0 for DC coefficient coding */ |
526 st = entropy->dc_stats[tbl] + entropy->dc_context[ci]; | 528 st = entropy->dc_stats[tbl] + entropy->dc_context[ci]; |
527 | 529 |
(...skipping 26 matching lines...) Expand all Loading... |
554 entropy->dc_context[ci] = 4 + (sign * 4); /* small diff category */ | 556 entropy->dc_context[ci] = 4 + (sign * 4); /* small diff category */ |
555 v = m; | 557 v = m; |
556 /* Figure F.24: Decoding the magnitude bit pattern of v */ | 558 /* Figure F.24: Decoding the magnitude bit pattern of v */ |
557 st += 14; | 559 st += 14; |
558 while (m >>= 1) | 560 while (m >>= 1) |
559 if (arith_decode(cinfo, st)) v |= m; | 561 if (arith_decode(cinfo, st)) v |= m; |
560 v += 1; if (sign) v = -v; | 562 v += 1; if (sign) v = -v; |
561 entropy->last_dc_val[ci] += v; | 563 entropy->last_dc_val[ci] += v; |
562 } | 564 } |
563 | 565 |
564 (*block)[0] = (JCOEF) entropy->last_dc_val[ci]; | 566 if (block) |
| 567 (*block)[0] = (JCOEF) entropy->last_dc_val[ci]; |
565 | 568 |
566 /* Sections F.2.4.2 & F.1.4.4.2: Decoding of AC coefficients */ | 569 /* Sections F.2.4.2 & F.1.4.4.2: Decoding of AC coefficients */ |
567 | 570 |
568 tbl = compptr->ac_tbl_no; | 571 tbl = compptr->ac_tbl_no; |
569 | 572 |
570 /* Figure F.20: Decode_AC_coefficients */ | 573 /* Figure F.20: Decode_AC_coefficients */ |
571 for (k = 1; k <= DCTSIZE2 - 1; k++) { | 574 for (k = 1; k <= DCTSIZE2 - 1; k++) { |
572 st = entropy->ac_stats[tbl] + 3 * (k - 1); | 575 st = entropy->ac_stats[tbl] + 3 * (k - 1); |
573 if (arith_decode(cinfo, st)) break; /* EOB flag */ | 576 if (arith_decode(cinfo, st)) break; /* EOB flag */ |
574 while (arith_decode(cinfo, st + 1) == 0) { | 577 while (arith_decode(cinfo, st + 1) == 0) { |
(...skipping 23 matching lines...) Expand all Loading... |
598 st += 1; | 601 st += 1; |
599 } | 602 } |
600 } | 603 } |
601 } | 604 } |
602 v = m; | 605 v = m; |
603 /* Figure F.24: Decoding the magnitude bit pattern of v */ | 606 /* Figure F.24: Decoding the magnitude bit pattern of v */ |
604 st += 14; | 607 st += 14; |
605 while (m >>= 1) | 608 while (m >>= 1) |
606 if (arith_decode(cinfo, st)) v |= m; | 609 if (arith_decode(cinfo, st)) v |= m; |
607 v += 1; if (sign) v = -v; | 610 v += 1; if (sign) v = -v; |
608 (*block)[jpeg_natural_order[k]] = (JCOEF) v; | 611 if (block) |
| 612 (*block)[jpeg_natural_order[k]] = (JCOEF) v; |
609 } | 613 } |
610 } | 614 } |
611 | 615 |
612 return TRUE; | 616 return TRUE; |
613 } | 617 } |
614 | 618 |
615 | 619 |
616 /* | 620 /* |
617 * Initialize for an arithmetic-compressed scan. | 621 * Initialize for an arithmetic-compressed scan. |
618 */ | 622 */ |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
752 int *coef_bit_ptr, ci; | 756 int *coef_bit_ptr, ci; |
753 cinfo->coef_bits = (int (*)[DCTSIZE2]) | 757 cinfo->coef_bits = (int (*)[DCTSIZE2]) |
754 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, | 758 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
755 cinfo->num_components*DCTSIZE2*SIZEOF(int)); | 759 cinfo->num_components*DCTSIZE2*SIZEOF(int)); |
756 coef_bit_ptr = & cinfo->coef_bits[0][0]; | 760 coef_bit_ptr = & cinfo->coef_bits[0][0]; |
757 for (ci = 0; ci < cinfo->num_components; ci++) | 761 for (ci = 0; ci < cinfo->num_components; ci++) |
758 for (i = 0; i < DCTSIZE2; i++) | 762 for (i = 0; i < DCTSIZE2; i++) |
759 *coef_bit_ptr++ = -1; | 763 *coef_bit_ptr++ = -1; |
760 } | 764 } |
761 } | 765 } |
OLD | NEW |