Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1528)

Side by Side Diff: core/src/fxcodec/fx_libopenjpeg/libopenjpeg20/tcd.c

Issue 758593002: Update to openjpeg r2944 (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: tab Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/src/fxcodec/fx_libopenjpeg/libopenjpeg20/tcd.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * The copyright in this software is being made available under the 2-clauses 2 * The copyright in this software is being made available under the 2-clauses
3 * BSD License, included below. This software may be subject to other third 3 * BSD License, included below. This software may be subject to other third
4 * party and contributor rights, including patent rights, and no such rights 4 * party and contributor rights, including patent rights, and no such rights
5 * are granted under this license. 5 * are granted under this license.
6 * 6 *
7 * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium 7 * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
8 * Copyright (c) 2002-2014, Professor Benoit Macq 8 * Copyright (c) 2002-2014, Professor Benoit Macq
9 * Copyright (c) 2001-2003, David Janssens 9 * Copyright (c) 2001-2003, David Janssens
10 * Copyright (c) 2002-2003, Yannick Verschueren 10 * Copyright (c) 2002-2003, Yannick Verschueren
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 } 96 }
97 fprintf(fd, " }\n"); 97 fprintf(fd, " }\n");
98 } 98 }
99 fprintf(fd, " }\n"); 99 fprintf(fd, " }\n");
100 } 100 }
101 fprintf(fd, " }\n"); 101 fprintf(fd, " }\n");
102 } 102 }
103 fprintf(fd, "}\n"); 103 fprintf(fd, "}\n");
104 } 104 }
105 #endif 105 #endif
106
107 /**
108 * Initializes tile coding/decoding
109 */
110 static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, OPJ_BOOL isEncoder, OPJ_FLOAT32 fraction, OPJ_SIZE_T sizeof_block);
111
106 /** 112 /**
107 * Allocates memory for a decoding code block. 113 * Allocates memory for a decoding code block.
108 */ 114 */
109 static OPJ_BOOL opj_tcd_code_block_dec_allocate (opj_tcd_cblk_dec_t * p_code_blo ck); 115 static OPJ_BOOL opj_tcd_code_block_dec_allocate (opj_tcd_cblk_dec_t * p_code_blo ck);
110 116
111 /** 117 /**
112 * Deallocates the decoding data of the given precinct. 118 * Deallocates the decoding data of the given precinct.
113 */ 119 */
114 static void opj_tcd_code_block_dec_deallocate (opj_tcd_precinct_t * p_precinct); 120 static void opj_tcd_code_block_dec_deallocate (opj_tcd_precinct_t * p_precinct);
115 121
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 opj_tcd_free_tile(tcd); 610 opj_tcd_free_tile(tcd);
605 611
606 if (tcd->tcd_image) { 612 if (tcd->tcd_image) {
607 opj_free(tcd->tcd_image); 613 opj_free(tcd->tcd_image);
608 tcd->tcd_image = 00; 614 tcd->tcd_image = 00;
609 } 615 }
610 opj_free(tcd); 616 opj_free(tcd);
611 } 617 }
612 } 618 }
613 619
620 OPJ_BOOL opj_alloc_tile_component_data(opj_tcd_tilecomp_t *l_tilec)
621 {
622 if ((l_tilec->data == 00) || ((l_tilec->data_size_needed > l_tilec->data _size) && (l_tilec->ownsData == OPJ_FALSE))) {
623 l_tilec->data = (OPJ_INT32 *) opj_malloc(l_tilec->data_size_need ed);
624 if (! l_tilec->data ) {
625 return OPJ_FALSE;
626 }
627 /*fprintf(stderr, "tAllocate data of tilec (int): %d x OPJ_UINT3 2n",l_data_size);*/
628 l_tilec->data_size = l_tilec->data_size_needed;
629 l_tilec->ownsData = OPJ_TRUE;
630 }
631 else if (l_tilec->data_size_needed > l_tilec->data_size) {
632 OPJ_INT32 * new_data = (OPJ_INT32 *) opj_realloc(l_tilec->data, l_tilec->data_size_needed);
633 /* opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to han dle tile datan"); */
634 /* fprintf(stderr, "Not enough memory to handle tile data"); */
635 if (! new_data) {
636 opj_free(l_tilec->data);
637 l_tilec->data = NULL;
638 l_tilec->data_size = 0;
639 l_tilec->data_size_needed = 0;
640 l_tilec->ownsData = OPJ_FALSE;
641 return OPJ_FALSE;
642 }
643 l_tilec->data = new_data;
644 /*fprintf(stderr, "tReallocate data of tilec (int): from %d to % d x OPJ_UINT32n", l_tilec->data_size, l_data_size);*/
645 l_tilec->data_size = l_tilec->data_size_needed;
646 l_tilec->ownsData = OPJ_TRUE;
647 }
648 return OPJ_TRUE;
649 }
650
614 /* ----------------------------------------------------------------------- */ 651 /* ----------------------------------------------------------------------- */
615 #define OPJ_MACRO_TCD_ALLOCATE(FUNCTION,TYPE,FRACTION,ELEMENT,FUNCTION_ELEMENT) \ 652
616 OPJ_BOOL FUNCTION ( opj_tcd_t *p_tcd, \ 653 static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, OPJ_BOOL isEncoder, OPJ_FLOAT32 fraction, OPJ_SIZE_T sizeof_block)
617 OPJ_UINT32 p_tile_no \ 654 {
618 ) \ 655 OPJ_UINT32 (*l_gain_ptr)(OPJ_UINT32) = 00;
619 { \ 656 OPJ_UINT32 compno, resno, bandno, precno, cblkno;
620 OPJ_UINT32 (*l_gain_ptr)(OPJ_UINT32) = 00; \ 657 opj_tcp_t * l_tcp = 00;
621 OPJ_UINT32 compno, resno, bandno, precno, cblkno; \ 658 opj_cp_t * l_cp = 00;
622 opj_tcp_t * l_tcp = 00; \ 659 opj_tcd_tile_t * l_tile = 00;
623 opj_cp_t * l_cp = 00; \ 660 opj_tccp_t *l_tccp = 00;
624 opj_tcd_tile_t * l_tile = 00; \ 661 opj_tcd_tilecomp_t *l_tilec = 00;
625 opj_tccp_t *l_tccp = 00; \ 662 opj_image_comp_t * l_image_comp = 00;
626 opj_tcd_tilecomp_t *l_tilec = 00; \ 663 opj_tcd_resolution_t *l_res = 00;
627 opj_image_comp_t * l_image_comp = 00; \ 664 opj_tcd_band_t *l_band = 00;
628 opj_tcd_resolution_t *l_res = 00; \ 665 opj_stepsize_t * l_step_size = 00;
629 opj_tcd_band_t *l_band = 00; \ 666 opj_tcd_precinct_t *l_current_precinct = 00;
630 opj_stepsize_t * l_step_size = 00; \ 667 opj_image_t *l_image = 00;
631 opj_tcd_precinct_t *l_current_precinct = 00; \ 668 OPJ_UINT32 p,q;
632 TYPE* l_code_block = 00; \ 669 OPJ_UINT32 l_level_no;
633 opj_image_t *l_image = 00; \ 670 OPJ_UINT32 l_pdx, l_pdy;
634 OPJ_UINT32 p,q; \ 671 OPJ_UINT32 l_gain;
635 OPJ_UINT32 l_level_no; \ 672 OPJ_INT32 l_x0b, l_y0b;
636 OPJ_UINT32 l_pdx, l_pdy; \ 673 /* extent of precincts , top left, bottom right**/
637 OPJ_UINT32 l_gain; \ 674 OPJ_INT32 l_tl_prc_x_start, l_tl_prc_y_start, l_br_prc_x_end, l_br_prc_y _end;
638 OPJ_INT32 l_x0b, l_y0b; \ 675 /* number of precinct for a resolution */
639 /* extent of precincts , top left, bottom right**/ \ 676 OPJ_UINT32 l_nb_precincts;
640 OPJ_INT32 l_tl_prc_x_start, l_tl_prc_y_start, l_br_prc_x_end, l_br_prc_y _end; \ 677 /* room needed to store l_nb_precinct precinct for a resolution */
641 /* number of precinct for a resolution */ \ 678 OPJ_UINT32 l_nb_precinct_size;
642 OPJ_UINT32 l_nb_precincts; \ 679 /* number of code blocks for a precinct*/
643 /* room needed to store l_nb_precinct precinct for a resolution */ \ 680 OPJ_UINT32 l_nb_code_blocks;
644 OPJ_UINT32 l_nb_precinct_size; \ 681 /* room needed to store l_nb_code_blocks code blocks for a precinct*/
645 /* number of code blocks for a precinct*/ \ 682 OPJ_UINT32 l_nb_code_blocks_size;
646 OPJ_UINT32 l_nb_code_blocks; \ 683 /* size of data for a tile */
647 /* room needed to store l_nb_code_blocks code blocks for a precinct*/ \ 684 OPJ_UINT32 l_data_size;
648 OPJ_UINT32 l_nb_code_blocks_size; \ 685
649 /* size of data for a tile */ \ 686 l_cp = p_tcd->cp;
650 OPJ_UINT32 l_data_size; \ 687 l_tcp = &(l_cp->tcps[p_tile_no]);
651 \ 688 l_tile = p_tcd->tcd_image->tiles;
652 l_cp = p_tcd->cp; \ 689 l_tccp = l_tcp->tccps;
653 l_tcp = &(l_cp->tcps[p_tile_no]); \ 690 l_tilec = l_tile->comps;
654 l_tile = p_tcd->tcd_image->tiles; \ 691 l_image = p_tcd->image;
655 l_tccp = l_tcp->tccps; \ 692 l_image_comp = p_tcd->image->comps;
656 l_tilec = l_tile->comps; \ 693
657 l_image = p_tcd->image; \ 694 p = p_tile_no % l_cp->tw; /* tile coordinates */
658 l_image_comp = p_tcd->image->comps; \ 695 q = p_tile_no / l_cp->tw;
659 \ 696 /*fprintf(stderr, "Tile coordinate = %d,%d\n", p, q);*/
660 p = p_tile_no % l_cp->tw; /* tile coordinates */ \ 697
661 q = p_tile_no / l_cp->tw; \ 698 /* 4 borders of the tile rescale on the image if necessary */
662 /*fprintf(stderr, "Tile coordinate = %d,%d\n", p, q);*/ \ 699 l_tile->x0 = opj_int_max((OPJ_INT32)(l_cp->tx0 + p * l_cp->tdx), (OPJ_IN T32)l_image->x0);
663 \ 700 l_tile->y0 = opj_int_max((OPJ_INT32)(l_cp->ty0 + q * l_cp->tdy), (OPJ_IN T32)l_image->y0);
664 /* 4 borders of the tile rescale on the image if necessary */ \ 701 l_tile->x1 = opj_int_min((OPJ_INT32)(l_cp->tx0 + (p + 1) * l_cp->tdx), ( OPJ_INT32)l_image->x1);
665 l_tile->x0 = opj_int_max((OPJ_INT32)(l_cp->tx0 + p * l_cp->tdx), (OPJ_IN T32)l_image->x0); \ 702 l_tile->y1 = opj_int_min((OPJ_INT32)(l_cp->ty0 + (q + 1) * l_cp->tdy), ( OPJ_INT32)l_image->y1);
666 l_tile->y0 = opj_int_max((OPJ_INT32)(l_cp->ty0 + q * l_cp->tdy), (OPJ_IN T32)l_image->y0); \ 703 /* testcase 1888.pdf.asan.35.988 */
667 l_tile->x1 = opj_int_min((OPJ_INT32)(l_cp->tx0 + (p + 1) * l_cp->tdx), ( OPJ_INT32)l_image->x1); \ 704 if (l_tccp->numresolutions == 0) {
668 l_tile->y1 = opj_int_min((OPJ_INT32)(l_cp->ty0 + (q + 1) * l_cp->tdy), ( OPJ_INT32)l_image->y1); \ 705 fprintf(stderr, "tiles require at least one resolution\n");
669 /* testcase 1888.pdf.asan.35.988 */ \ 706 return OPJ_FALSE;
670 if (l_tccp->numresolutions == 0) { \ 707 }
671 fprintf(stderr, "tiles require at least one resolution\n"); \ 708 /*fprintf(stderr, "Tile border = %d,%d,%d,%d\n", l_tile->x0, l_tile->y0, l_tile->x1,l_tile->y1);*/
672 return OPJ_FALSE; \ 709
673 } \ 710 /*tile->numcomps = image->numcomps; */
674 /*fprintf(stderr, "Tile border = %d,%d,%d,%d\n", l_tile->x0, l_tile->y0, l_tile->x1,l_tile->y1);*/ \ 711 for (compno = 0; compno < l_tile->numcomps; ++compno) {
675 \ 712 /*fprintf(stderr, "compno = %d/%d\n", compno, l_tile->numcomps); */
676 /*tile->numcomps = image->numcomps; */ \ 713 l_image_comp->resno_decoded = 0;
677 for(compno = 0; compno < l_tile->numcomps; ++compno) { \ 714 /* border of each l_tile component (global) */
678 /*fprintf(stderr, "compno = %d/%d\n", compno, l_tile->numcomps); */ \ 715 l_tilec->x0 = opj_int_ceildiv(l_tile->x0, (OPJ_INT32)l_image_com p->dx);
679 l_image_comp->resno_decoded = 0; \ 716 l_tilec->y0 = opj_int_ceildiv(l_tile->y0, (OPJ_INT32)l_image_com p->dy);
680 /* border of each l_tile component (global) */ \ 717 l_tilec->x1 = opj_int_ceildiv(l_tile->x1, (OPJ_INT32)l_image_com p->dx);
681 l_tilec->x0 = opj_int_ceildiv(l_tile->x0, (OPJ_INT32)l_image_com p->dx); \ 718 l_tilec->y1 = opj_int_ceildiv(l_tile->y1, (OPJ_INT32)l_image_com p->dy);
682 l_tilec->y0 = opj_int_ceildiv(l_tile->y0, (OPJ_INT32)l_image_com p->dy); \ 719 /*fprintf(stderr, "\tTile compo border = %d,%d,%d,%d\n", l_tilec ->x0, l_tilec->y0,l_tilec->x1,l_tilec->y1);*/
683 l_tilec->x1 = opj_int_ceildiv(l_tile->x1, (OPJ_INT32)l_image_com p->dx); \ 720
684 l_tilec->y1 = opj_int_ceildiv(l_tile->y1, (OPJ_INT32)l_image_com p->dy); \ 721 /* compute l_data_size with overflow check */
685 /*fprintf(stderr, "\tTile compo border = %d,%d,%d,%d\n", l_tilec ->x0, l_tilec->y0,l_tilec->x1,l_tilec->y1);*/ \ 722 l_data_size = (OPJ_UINT32)(l_tilec->x1 - l_tilec->x0);
686 \ 723 if ((((OPJ_UINT32)-1) / l_data_size) < (OPJ_UINT32)(l_tilec->y1 - l_tilec->y0)) {
687 l_data_size = (OPJ_UINT32)(l_tilec->x1 - l_tilec->x0) \ 724 /* TODO event */
688 * (OPJ_UINT32)(l_tilec->y1 - l_tilec->y0) * (OPJ_UINT32)sizeof(O PJ_UINT32 );\ 725 return OPJ_FALSE;
689 l_tilec->numresolutions = l_tccp->numresolutions; \ 726 }
690 if (l_tccp->numresolutions < l_cp->m_specific_param.m_dec.m_redu ce) { \ 727 l_data_size = l_data_size * (OPJ_UINT32)(l_tilec->y1 - l_tilec-> y0);
691 l_tilec->minimum_num_resolutions = 1; \ 728
692 } \ 729 if ((((OPJ_UINT32)-1) / (OPJ_UINT32)sizeof(OPJ_UINT32)) < l_data _size) {
693 else { \ 730 /* TODO event */
694 l_tilec->minimum_num_resolutions = l_tccp->numresolution s \ 731 return OPJ_FALSE;
695 - l_cp->m_specific_param.m_dec.m_reduce; \ 732 }
696 } \ 733 l_data_size = l_data_size * (OPJ_UINT32)sizeof(OPJ_UINT32);
697 \ 734 l_tilec->numresolutions = l_tccp->numresolutions;
698 if (l_tilec->data == 00) { \ 735 if (l_tccp->numresolutions < l_cp->m_specific_param.m_dec.m_redu ce) {
699 l_tilec->data = (OPJ_INT32 *) opj_malloc(l_data_size); \ 736 l_tilec->minimum_num_resolutions = 1;
700 if (! l_tilec->data ) { \ 737 }
701 return OPJ_FALSE; \ 738 else {
702 } \ 739 l_tilec->minimum_num_resolutions = l_tccp->numresolution s - l_cp->m_specific_param.m_dec.m_reduce;
703 /*fprintf(stderr, "\tAllocate data of tilec (int): %d x OPJ_UINT32\n",l_data_size);*/ \ 740 }
704 \ 741
705 l_tilec->data_size = l_data_size; \ 742 l_tilec->data_size_needed = l_data_size;
706 } \ 743 if (p_tcd->m_is_decoder && !opj_alloc_tile_component_data(l_tile c)) {
707 else if (l_data_size > l_tilec->data_size) { \ 744 return OPJ_FALSE;
708 OPJ_INT32 * new_data = (OPJ_INT32 *) opj_realloc(l_tilec ->data, l_data_size); \ 745 }
709 /* opj_event_msg(p_manager, EVT_ERROR, "Not enough memor y to handle tile data\n"); */ \ 746
710 fprintf(stderr, "Not enough memory to handle tile data\n "); \ 747 l_data_size = l_tilec->numresolutions * (OPJ_UINT32)sizeof(opj_t cd_resolution_t);
711 if (! new_data) { \ 748
712 opj_free(l_tilec->data); \ 749 if (l_tilec->resolutions == 00) {
713 l_tilec->data = NULL; \ 750 l_tilec->resolutions = (opj_tcd_resolution_t *) opj_mall oc(l_data_size);
714 l_tilec->data_size = 0; \ 751 if (! l_tilec->resolutions ) {
715 return OPJ_FALSE; \ 752 return OPJ_FALSE;
716 } \ 753 }
717 l_tilec->data = new_data; \ 754 /*fprintf(stderr, "\tAllocate resolutions of tilec (opj_ tcd_resolution_t): %d\n",l_data_size);*/
718 /*fprintf(stderr, "\tReallocate data of tilec (int): fro m %d to %d x OPJ_UINT32\n", l_tilec->data_size, l_data_size);*/ \ 755 l_tilec->resolutions_size = l_data_size;
719 l_tilec->data_size = l_data_size; \ 756 memset(l_tilec->resolutions,0,l_data_size);
720 } \ 757 }
721 \ 758 else if (l_data_size > l_tilec->resolutions_size) {
722 l_data_size = l_tilec->numresolutions * (OPJ_UINT32)sizeof(opj_t cd_resolution_t); \ 759 opj_tcd_resolution_t* new_resolutions = (opj_tcd_resolut ion_t *) opj_realloc(l_tilec->resolutions, l_data_size);
723 \ 760 if (! new_resolutions) {
724 if (l_tilec->resolutions == 00) { \ 761 /* opj_event_msg(p_manager, EVT_ERROR, "Not enou gh memory to tile resolutions\n"); */
725 l_tilec->resolutions = (opj_tcd_resolution_t *) opj_mall oc(l_data_size); \ 762 fprintf(stderr, "Not enough memory to tile resol utions\n");
726 if (! l_tilec->resolutions ) { \ 763 opj_free(l_tilec->resolutions);
727 return OPJ_FALSE; \ 764 l_tilec->resolutions = NULL;
728 } \ 765 l_tilec->resolutions_size = 0;
729 /*fprintf(stderr, "\tAllocate resolutions of tilec (opj_ tcd_resolution_t): %d\n",l_data_size);*/ \ 766 return OPJ_FALSE;
730 l_tilec->resolutions_size = l_data_size; \ 767 }
731 memset(l_tilec->resolutions,0,l_data_size); \ 768 l_tilec->resolutions = new_resolutions;
732 } \ 769 /*fprintf(stderr, "\tReallocate data of tilec (int): fro m %d to %d x OPJ_UINT32\n", l_tilec->resolutions_size, l_data_size);*/
733 else if (l_data_size > l_tilec->resolutions_size) { \ 770 memset(((OPJ_BYTE*) l_tilec->resolutions)+l_tilec->resol utions_size,0,l_data_size - l_tilec->resolutions_size);
734 opj_tcd_resolution_t* new_resolutions = (opj_tcd_resolut ion_t *) opj_realloc(l_tilec->resolutions, l_data_size); \ 771 l_tilec->resolutions_size = l_data_size;
735 if (! new_resolutions) { \ 772 }
736 /* opj_event_msg(p_manager, EVT_ERROR, "Not enou gh memory to tile resolutions\n"); */ \ 773
737 fprintf(stderr, "Not enough memory to tile resol utions\n"); \ 774 l_level_no = l_tilec->numresolutions - 1;
738 opj_free(l_tilec->resolutions); \ 775 l_res = l_tilec->resolutions;
739 l_tilec->resolutions = NULL; \ 776 l_step_size = l_tccp->stepsizes;
740 l_tilec->resolutions_size = 0; \ 777 if (l_tccp->qmfbid == 0) {
741 return OPJ_FALSE; \ 778 l_gain_ptr = &opj_dwt_getgain_real;
742 } \ 779 }
743 l_tilec->resolutions = new_resolutions; \ 780 else {
744 /*fprintf(stderr, "\tReallocate data of tilec (int): fro m %d to %d x OPJ_UINT32\n", l_tilec->resolutions_size, l_data_size);*/ \ 781 l_gain_ptr = &opj_dwt_getgain;
745 memset(((OPJ_BYTE*) l_tilec->resolutions)+l_tilec->resol utions_size,0,l_data_size - l_tilec->resolutions_size); \ 782 }
746 l_tilec->resolutions_size = l_data_size; \ 783 /*fprintf(stderr, "\tlevel_no=%d\n",l_level_no);*/
747 } \ 784
748 \ 785 for (resno = 0; resno < l_tilec->numresolutions; ++resno) {
749 l_level_no = l_tilec->numresolutions - 1; \ 786 /*fprintf(stderr, "\t\tresno = %d/%d\n", resno, l_tilec- >numresolutions);*/
750 l_res = l_tilec->resolutions; \ 787 OPJ_INT32 tlcbgxstart, tlcbgystart /*, brcbgxend, brcbgy end*/;
751 l_step_size = l_tccp->stepsizes; \ 788 OPJ_UINT32 cbgwidthexpn, cbgheightexpn;
752 if (l_tccp->qmfbid == 0) { \ 789 OPJ_UINT32 cblkwidthexpn, cblkheightexpn;
753 l_gain_ptr = &opj_dwt_getgain_real; \ 790
754 } \ 791 /* border for each resolution level (global) */
755 else { \ 792 l_res->x0 = opj_int_ceildivpow2(l_tilec->x0, (OPJ_INT32) l_level_no);
756 l_gain_ptr = &opj_dwt_getgain; \ 793 l_res->y0 = opj_int_ceildivpow2(l_tilec->y0, (OPJ_INT32) l_level_no);
757 } \ 794 l_res->x1 = opj_int_ceildivpow2(l_tilec->x1, (OPJ_INT32) l_level_no);
758 /*fprintf(stderr, "\tlevel_no=%d\n",l_level_no);*/ \ 795 l_res->y1 = opj_int_ceildivpow2(l_tilec->y1, (OPJ_INT32) l_level_no);
759 \ 796 /*fprintf(stderr, "\t\t\tres_x0= %d, res_y0 =%d, res_x1= %d, res_y1=%d\n", l_res->x0, l_res->y0, l_res->x1, l_res->y1);*/
760 for(resno = 0; resno < l_tilec->numresolutions; ++resno) { \ 797 /* p. 35, table A-23, ISO/IEC FDIS154444-1 : 2000 (18 au gust 2000) */
761 /*fprintf(stderr, "\t\tresno = %d/%d\n", resno, l_tilec- >numresolutions);*/ \ 798 l_pdx = l_tccp->prcw[resno];
762 OPJ_INT32 tlcbgxstart, tlcbgystart /*, brcbgxend, brcbgy end*/; \ 799 l_pdy = l_tccp->prch[resno];
763 OPJ_UINT32 cbgwidthexpn, cbgheightexpn; \ 800 /*fprintf(stderr, "\t\t\tpdx=%d, pdy=%d\n", l_pdx, l_pdy );*/
764 OPJ_UINT32 cblkwidthexpn, cblkheightexpn; \ 801 /* p. 64, B.6, ISO/IEC FDIS15444-1 : 2000 (18 august 200 0) */
765 \ 802 l_tl_prc_x_start = opj_int_floordivpow2(l_res->x0, (OPJ_ INT32)l_pdx) << l_pdx;
766 /* border for each resolution level (global) */ \ 803 l_tl_prc_y_start = opj_int_floordivpow2(l_res->y0, (OPJ_ INT32)l_pdy) << l_pdy;
767 l_res->x0 = opj_int_ceildivpow2(l_tilec->x0, (OPJ_INT32) l_level_no); \ 804 l_br_prc_x_end = opj_int_ceildivpow2(l_res->x1, (OPJ_INT 32)l_pdx) << l_pdx;
768 l_res->y0 = opj_int_ceildivpow2(l_tilec->y0, (OPJ_INT32) l_level_no); \ 805 l_br_prc_y_end = opj_int_ceildivpow2(l_res->y1, (OPJ_INT 32)l_pdy) << l_pdy;
769 l_res->x1 = opj_int_ceildivpow2(l_tilec->x1, (OPJ_INT32) l_level_no); \ 806 /*fprintf(stderr, "\t\t\tprc_x_start=%d, prc_y_start=%d, br_prc_x_end=%d, br_prc_y_end=%d \n", l_tl_prc_x_start, l_tl_prc_y_start, l_br_ prc_x_end ,l_br_prc_y_end );*/
770 l_res->y1 = opj_int_ceildivpow2(l_tilec->y1, (OPJ_INT32) l_level_no); \ 807
771 /*fprintf(stderr, "\t\t\tres_x0= %d, res_y0 =%d, res_x1= %d, res_y1=%d\n", l_res->x0, l_res->y0, l_res->x1, l_res->y1);*/ \ 808 l_res->pw = (l_res->x0 == l_res->x1) ? 0 : (OPJ_UINT32)( (l_br_prc_x_end - l_tl_prc_x_start) >> l_pdx);
772 /* p. 35, table A-23, ISO/IEC FDIS154444-1 : 2000 (18 au gust 2000) */ \ 809 l_res->ph = (l_res->y0 == l_res->y1) ? 0 : (OPJ_UINT32)( (l_br_prc_y_end - l_tl_prc_y_start) >> l_pdy);
773 l_pdx = l_tccp->prcw[resno]; \ 810 /*fprintf(stderr, "\t\t\tres_pw=%d, res_ph=%d\n", l_res- >pw, l_res->ph );*/
774 l_pdy = l_tccp->prch[resno]; \ 811
775 /*fprintf(stderr, "\t\t\tpdx=%d, pdy=%d\n", l_pdx, l_pdy );*/ \ 812 l_nb_precincts = l_res->pw * l_res->ph;
776 /* p. 64, B.6, ISO/IEC FDIS15444-1 : 2000 (18 august 200 0) */ \ 813 l_nb_precinct_size = l_nb_precincts * (OPJ_UINT32)sizeof (opj_tcd_precinct_t);
777 l_tl_prc_x_start = opj_int_floordivpow2(l_res->x0, (OPJ_ INT32)l_pdx) << l_pdx; \ 814 if (resno == 0) {
778 l_tl_prc_y_start = opj_int_floordivpow2(l_res->y0, (OPJ_ INT32)l_pdy) << l_pdy; \ 815 tlcbgxstart = l_tl_prc_x_start;
779 l_br_prc_x_end = opj_int_ceildivpow2(l_res->x1, (OPJ_INT 32)l_pdx) << l_pdx; \ 816 tlcbgystart = l_tl_prc_y_start;
780 l_br_prc_y_end = opj_int_ceildivpow2(l_res->y1, (OPJ_INT 32)l_pdy) << l_pdy; \ 817 /*brcbgxend = l_br_prc_x_end;*/
781 /*fprintf(stderr, "\t\t\tprc_x_start=%d, prc_y_start=%d, br_prc_x_end=%d, br_prc_y_end=%d \n", l_tl_prc_x_start, l_tl_prc_y_start, l_br_ prc_x_end ,l_br_prc_y_end );*/ \ 818 /* brcbgyend = l_br_prc_y_end;*/
782 \ 819 cbgwidthexpn = l_pdx;
783 l_res->pw = (l_res->x0 == l_res->x1) ? 0 : (OPJ_UINT32)( (l_br_prc_x_end - l_tl_prc_x_start) >> l_pdx); \ 820 cbgheightexpn = l_pdy;
784 l_res->ph = (l_res->y0 == l_res->y1) ? 0 : (OPJ_UINT32)( (l_br_prc_y_end - l_tl_prc_y_start) >> l_pdy); \ 821 l_res->numbands = 1;
785 /*fprintf(stderr, "\t\t\tres_pw=%d, res_ph=%d\n", l_res- >pw, l_res->ph );*/ \ 822 }
786 \ 823 else {
787 l_nb_precincts = l_res->pw * l_res->ph; \ 824 tlcbgxstart = opj_int_ceildivpow2(l_tl_prc_x_sta rt, 1);
788 l_nb_precinct_size = l_nb_precincts * (OPJ_UINT32)sizeof (opj_tcd_precinct_t); \ 825 tlcbgystart = opj_int_ceildivpow2(l_tl_prc_y_sta rt, 1);
789 if (resno == 0) { \ 826 /*brcbgxend = opj_int_ceildivpow2(l_br_prc_x_end , 1);*/
790 tlcbgxstart = l_tl_prc_x_start; \ 827 /*brcbgyend = opj_int_ceildivpow2(l_br_prc_y_end , 1);*/
791 tlcbgystart = l_tl_prc_y_start; \ 828 cbgwidthexpn = l_pdx - 1;
792 /*brcbgxend = l_br_prc_x_end;*/ \ 829 cbgheightexpn = l_pdy - 1;
793 /* brcbgyend = l_br_prc_y_end;*/ \ 830 l_res->numbands = 3;
794 cbgwidthexpn = l_pdx; \ 831 }
795 cbgheightexpn = l_pdy; \ 832
796 l_res->numbands = 1; \ 833 cblkwidthexpn = opj_uint_min(l_tccp->cblkw, cbgwidthexpn );
797 } \ 834 cblkheightexpn = opj_uint_min(l_tccp->cblkh, cbgheightex pn);
798 else { \ 835 l_band = l_res->bands;
799 tlcbgxstart = opj_int_ceildivpow2(l_tl_prc_x_sta rt, 1); \ 836
800 tlcbgystart = opj_int_ceildivpow2(l_tl_prc_y_sta rt, 1); \ 837 for (bandno = 0; bandno < l_res->numbands; ++bandno) {
801 /*brcbgxend = opj_int_ceildivpow2(l_br_prc_x_end , 1);*/ \ 838 OPJ_INT32 numbps;
802 /*brcbgyend = opj_int_ceildivpow2(l_br_prc_y_end , 1);*/ \ 839 /*fprintf(stderr, "\t\t\tband_no=%d/%d\n", bandn o, l_res->numbands );*/
803 cbgwidthexpn = l_pdx - 1; \ 840
804 cbgheightexpn = l_pdy - 1; \ 841 if (resno == 0) {
805 l_res->numbands = 3; \ 842 l_band->bandno = 0 ;
806 } \ 843 l_band->x0 = opj_int_ceildivpow2(l_tilec ->x0, (OPJ_INT32)l_level_no);
807 \ 844 l_band->y0 = opj_int_ceildivpow2(l_tilec ->y0, (OPJ_INT32)l_level_no);
808 cblkwidthexpn = opj_uint_min(l_tccp->cblkw, cbgwidthexpn ); \ 845 l_band->x1 = opj_int_ceildivpow2(l_tilec ->x1, (OPJ_INT32)l_level_no);
809 cblkheightexpn = opj_uint_min(l_tccp->cblkh, cbgheightex pn); \ 846 l_band->y1 = opj_int_ceildivpow2(l_tilec ->y1, (OPJ_INT32)l_level_no);
810 l_band = l_res->bands; \ 847 }
811 \ 848 else {
812 for (bandno = 0; bandno < l_res->numbands; ++bandno) { \ 849 l_band->bandno = bandno + 1;
813 OPJ_INT32 numbps; \ 850 /* x0b = 1 if bandno = 1 or 3 */
814 /*fprintf(stderr, "\t\t\tband_no=%d/%d\n", bandn o, l_res->numbands );*/ \ 851 l_x0b = l_band->bandno&1;
815 \ 852 /* y0b = 1 if bandno = 2 or 3 */
816 if (resno == 0) { \ 853 l_y0b = (OPJ_INT32)((l_band->bandno)>>1) ;
817 l_band->bandno = 0 ; \ 854 /* l_band border (global) */
818 l_band->x0 = opj_int_ceildivpow2(l_tilec ->x0, (OPJ_INT32)l_level_no); \ 855 l_band->x0 = opj_int_ceildivpow2(l_tilec ->x0 - (1 << l_level_no) * l_x0b, (OPJ_INT32)(l_level_no + 1));
819 l_band->y0 = opj_int_ceildivpow2(l_tilec ->y0, (OPJ_INT32)l_level_no); \ 856 l_band->y0 = opj_int_ceildivpow2(l_tilec ->y0 - (1 << l_level_no) * l_y0b, (OPJ_INT32)(l_level_no + 1));
820 l_band->x1 = opj_int_ceildivpow2(l_tilec ->x1, (OPJ_INT32)l_level_no); \ 857 l_band->x1 = opj_int_ceildivpow2(l_tilec ->x1 - (1 << l_level_no) * l_x0b, (OPJ_INT32)(l_level_no + 1));
821 l_band->y1 = opj_int_ceildivpow2(l_tilec ->y1, (OPJ_INT32)l_level_no); \ 858 l_band->y1 = opj_int_ceildivpow2(l_tilec ->y1 - (1 << l_level_no) * l_y0b, (OPJ_INT32)(l_level_no + 1));
822 } \ 859 }
823 else { \ 860
824 l_band->bandno = bandno + 1; \ 861 /** avoid an if with storing function pointer */
825 /* x0b = 1 if bandno = 1 or 3 */ \ 862 l_gain = (*l_gain_ptr) (l_band->bandno);
826 l_x0b = l_band->bandno&1; \ 863 numbps = (OPJ_INT32)(l_image_comp->prec + l_gain );
827 /* y0b = 1 if bandno = 2 or 3 */ \ 864 l_band->stepsize = (OPJ_FLOAT32)(((1.0 + l_step_ size->mant / 2048.0) * pow(2.0, (OPJ_INT32) (numbps - l_step_size->expn)))) * fr action;
828 l_y0b = (OPJ_INT32)((l_band->bandno)>>1) ; \ 865 l_band->numbps = l_step_size->expn + (OPJ_INT32) l_tccp->numgbits - 1; /* WHY -1 ? */
829 /* l_band border (global) */ \ 866
830 l_band->x0 = opj_int_ceildivpow2(l_tilec ->x0 - (1 << l_level_no) * l_x0b, (OPJ_INT32)(l_level_no + 1)); \ 867 if (! l_band->precincts) {
831 l_band->y0 = opj_int_ceildivpow2(l_tilec ->y0 - (1 << l_level_no) * l_y0b, (OPJ_INT32)(l_level_no + 1)); \ 868 l_band->precincts = (opj_tcd_precinct_t *) opj_malloc( /*3 * */ l_nb_precinct_size);
832 l_band->x1 = opj_int_ceildivpow2(l_tilec ->x1 - (1 << l_level_no) * l_x0b, (OPJ_INT32)(l_level_no + 1)); \ 869 if (! l_band->precincts) {
833 l_band->y1 = opj_int_ceildivpow2(l_tilec ->y1 - (1 << l_level_no) * l_y0b, (OPJ_INT32)(l_level_no + 1)); \ 870 return OPJ_FALSE;
834 } \ 871 }
835 \ 872 /*fprintf(stderr, "\t\t\t\tAllocate prec incts of a band (opj_tcd_precinct_t): %d\n",l_nb_precinct_size); */
836 /** avoid an if with storing function pointer */ \ 873 memset(l_band->precincts,0,l_nb_precinct _size);
837 l_gain = (*l_gain_ptr) (l_band->bandno); \ 874 l_band->precincts_data_size = l_nb_preci nct_size;
838 numbps = (OPJ_INT32)(l_image_comp->prec + l_gain ); \ 875 }
839 l_band->stepsize = (OPJ_FLOAT32)(((1.0 + l_step_ size->mant / 2048.0) * pow(2.0, (OPJ_INT32) (numbps - l_step_size->expn)))) * FR ACTION; \ 876 else if (l_band->precincts_data_size < l_nb_prec inct_size) {
840 l_band->numbps = l_step_size->expn + (OPJ_INT32) l_tccp->numgbits - 1; /* WHY -1 ? */ \ 877
841 \ 878 opj_tcd_precinct_t * new_precincts = (op j_tcd_precinct_t *) opj_realloc(l_band->precincts,/*3 * */ l_nb_precinct_size);
842 if (! l_band->precincts) { \ 879 if (! new_precincts) {
843 l_band->precincts = (opj_tcd_precinct_t *) opj_malloc( /*3 * */ l_nb_precinct_size); \ 880 /* opj_event_msg(p_manager, EVT_ ERROR, "Not enough memory to handle band precints\n"); */
844 if (! l_band->precincts) { \ 881 fprintf(stderr, "Not enough memo ry to handle band precints\n");
845 return OPJ_FALSE; \ 882 opj_free(l_band->precincts);
846 } \ 883 l_band->precincts = NULL;
847 /*fprintf(stderr, "\t\t\t\tAllocate prec incts of a band (opj_tcd_precinct_t): %d\n",l_nb_precinct_size); */ \ 884 l_band->precincts_data_size = 0;
848 memset(l_band->precincts,0,l_nb_precinct _size); \ 885 return OPJ_FALSE;
849 l_band->precincts_data_size = l_nb_preci nct_size; \ 886 }
850 } \ 887 l_band->precincts = new_precincts;
851 else if (l_band->precincts_data_size < l_nb_prec inct_size) { \ 888 /*fprintf(stderr, "\t\t\t\tReallocate pr ecincts of a band (opj_tcd_precinct_t): from %d to %d\n",l_band->precincts_data_ size, l_nb_precinct_size);*/
852 \ 889 memset(((OPJ_BYTE *) l_band->precincts) + l_band->precincts_data_size,0,l_nb_precinct_size - l_band->precincts_data_size );
853 opj_tcd_precinct_t * new_precincts = (op j_tcd_precinct_t *) opj_realloc(l_band->precincts,/*3 * */ l_nb_precinct_size); \ 890 l_band->precincts_data_size = l_nb_preci nct_size;
854 if (! new_precincts) { \ 891 }
855 /* opj_event_msg(p_manager, EVT_ ERROR, "Not enough memory to handle band precints\n"); */ \ 892
856 fprintf(stderr, "Not enough memo ry to handle band precints\n"); \ 893 l_current_precinct = l_band->precincts;
857 opj_free(l_band->precincts); \ 894 for (precno = 0; precno < l_nb_precincts; ++prec no) {
858 l_band->precincts = NULL; \ 895 OPJ_INT32 tlcblkxstart, tlcblkystart, br cblkxend, brcblkyend;
859 l_band->precincts_data_size = 0; \ 896 OPJ_INT32 cbgxstart = tlcbgxstart + (OPJ _INT32)(precno % l_res->pw) * (1 << cbgwidthexpn);
860 return OPJ_FALSE; \ 897 OPJ_INT32 cbgystart = tlcbgystart + (OPJ _INT32)(precno / l_res->pw) * (1 << cbgheightexpn);
861 } \ 898 OPJ_INT32 cbgxend = cbgxstart + (1 << cb gwidthexpn);
862 l_band->precincts = new_precincts; \ 899 OPJ_INT32 cbgyend = cbgystart + (1 << cb gheightexpn);
863 /*fprintf(stderr, "\t\t\t\tReallocate pr ecincts of a band (opj_tcd_precinct_t): from %d to %d\n",l_band->precincts_data_ size, l_nb_precinct_size);*/ \ 900 /*fprintf(stderr, "\t precno=%d; bandno= %d, resno=%d; compno=%d\n", precno, bandno , resno, compno);*/
864 memset(((OPJ_BYTE *) l_band->precincts) + l_band->precincts_data_size,0,l_nb_precinct_size - l_band->precincts_data_size ); \ 901 /*fprintf(stderr, "\t tlcbgxstart(=%d) + (precno(=%d) percent res->pw(=%d)) * (1 << cbgwidthexpn(=%d)) \n",tlcbgxstart,p recno,l_res->pw,cbgwidthexpn);*/
865 l_band->precincts_data_size = l_nb_preci nct_size; \ 902
866 } \ 903 /* precinct size (global) */
867 \ 904 /*fprintf(stderr, "\t cbgxstart=%d, l_ba nd->x0 = %d \n",cbgxstart, l_band->x0);*/
868 l_current_precinct = l_band->precincts; \ 905
869 for (precno = 0; precno < l_nb_precincts; ++ precno) { \ 906 l_current_precinct->x0 = opj_int_max(cbg xstart, l_band->x0);
870 OPJ_INT32 tlcblkxstart, tlcblkystart, br cblkxend, brcblkyend; \ 907 l_current_precinct->y0 = opj_int_max(cbg ystart, l_band->y0);
871 OPJ_INT32 cbgxstart = tlcbgxstart + (OPJ _INT32)(precno % l_res->pw) * (1 << cbgwidthexpn); \ 908 l_current_precinct->x1 = opj_int_min(cbg xend, l_band->x1);
872 OPJ_INT32 cbgystart = tlcbgystart + (OPJ _INT32)(precno / l_res->pw) * (1 << cbgheightexpn); \ 909 l_current_precinct->y1 = opj_int_min(cbg yend, l_band->y1);
873 OPJ_INT32 cbgxend = cbgxstart + (1 << cb gwidthexpn); \ 910 /*fprintf(stderr, "\t prc_x0=%d; prc_y0= %d, prc_x1=%d; prc_y1=%d\n",l_current_precinct->x0, l_current_precinct->y0 ,l_cu rrent_precinct->x1, l_current_precinct->y1);*/
874 OPJ_INT32 cbgyend = cbgystart + (1 << cb gheightexpn); \ 911
875 /*fprintf(stderr, "\t precno=%d; bandno= %d, resno=%d; compno=%d\n", precno, bandno , resno, compno);*/ \ 912 tlcblkxstart = opj_int_floordivpow2(l_cu rrent_precinct->x0, (OPJ_INT32)cblkwidthexpn) << cblkwidthexpn;
876 /*fprintf(stderr, "\t tlcbgxstart(=%d) + (precno(=%d) percent res->pw(=%d)) * (1 << cbgwidthexpn(=%d)) \n",tlcbgxstart,p recno,l_res->pw,cbgwidthexpn);*/ \ 913 /*fprintf(stderr, "\t tlcblkxstart =%d\n ",tlcblkxstart );*/
877 \ 914 tlcblkystart = opj_int_floordivpow2(l_cu rrent_precinct->y0, (OPJ_INT32)cblkheightexpn) << cblkheightexpn;
878 /* precinct size (global) */ \ 915 /*fprintf(stderr, "\t tlcblkystart =%d\n ",tlcblkystart );*/
879 /*fprintf(stderr, "\t cbgxstart=%d, l_ba nd->x0 = %d \n",cbgxstart, l_band->x0);*/ \ 916 brcblkxend = opj_int_ceildivpow2(l_curre nt_precinct->x1, (OPJ_INT32)cblkwidthexpn) << cblkwidthexpn;
880 \ 917 /*fprintf(stderr, "\t brcblkxend =%d\n", brcblkxend );*/
881 l_current_precinct->x0 = opj_int_max(cbg xstart, l_band->x0); \ 918 brcblkyend = opj_int_ceildivpow2(l_curre nt_precinct->y1, (OPJ_INT32)cblkheightexpn) << cblkheightexpn;
882 l_current_precinct->y0 = opj_int_max(cbg ystart, l_band->y0); \ 919 /*fprintf(stderr, "\t brcblkyend =%d\n", brcblkyend );*/
883 l_current_precinct->x1 = opj_int_min(cbg xend, l_band->x1); \ 920 l_current_precinct->cw = (OPJ_UINT32)((b rcblkxend - tlcblkxstart) >> cblkwidthexpn);
884 l_current_precinct->y1 = opj_int_min(cbg yend, l_band->y1); \ 921 l_current_precinct->ch = (OPJ_UINT32)((b rcblkyend - tlcblkystart) >> cblkheightexpn);
885 /*fprintf(stderr, "\t prc_x0=%d; prc_y0= %d, prc_x1=%d; prc_y1=%d\n",l_current_precinct->x0, l_current_precinct->y0 ,l_cu rrent_precinct->x1, l_current_precinct->y1);*/ \ 922
886 \ 923 l_nb_code_blocks = l_current_precinct->c w * l_current_precinct->ch;
887 tlcblkxstart = opj_int_floordivpow2(l_cu rrent_precinct->x0, (OPJ_INT32)cblkwidthexpn) << cblkwidthexpn; \ 924 /*fprintf(stderr, "\t\t\t\t precinct_cw = %d x recinct_ch = %d\n",l_current_precinct->cw, l_current_precinct->ch); */
888 /*fprintf(stderr, "\t tlcblkxstart =%d\n ",tlcblkxstart );*/ \ 925 l_nb_code_blocks_size = l_nb_code_blocks * (OPJ_UINT32)sizeof_block;
889 tlcblkystart = opj_int_floordivpow2(l_cu rrent_precinct->y0, (OPJ_INT32)cblkheightexpn) << cblkheightexpn; \ 926
890 /*fprintf(stderr, "\t tlcblkystart =%d\n ",tlcblkystart );*/ \ 927 if (! l_current_precinct->cblks.blocks) {
891 brcblkxend = opj_int_ceildivpow2(l_curre nt_precinct->x1, (OPJ_INT32)cblkwidthexpn) << cblkwidthexpn; \ 928 l_current_precinct->cblks.blocks = opj_malloc(l_nb_code_blocks_size);
892 /*fprintf(stderr, "\t brcblkxend =%d\n", brcblkxend );*/ \ 929 if (! l_current_precinct->cblks. blocks ) {
893 brcblkyend = opj_int_ceildivpow2(l_curre nt_precinct->y1, (OPJ_INT32)cblkheightexpn) << cblkheightexpn; \ 930 return OPJ_FALSE;
894 /*fprintf(stderr, "\t brcblkyend =%d\n", brcblkyend );*/ \ 931 }
895 l_current_precinct->cw = (OPJ_UINT32)((b rcblkxend - tlcblkxstart) >> cblkwidthexpn); \ 932 /*fprintf(stderr, "\t\t\t\tAlloc ate cblks of a precinct (opj_tcd_cblk_dec_t): %d\n",l_nb_code_blocks_size);*/
896 l_current_precinct->ch = (OPJ_UINT32)((b rcblkyend - tlcblkystart) >> cblkheightexpn); \ 933
897 \ 934 memset(l_current_precinct->cblks .blocks,0,l_nb_code_blocks_size);
898 l_nb_code_blocks = l_current_precinct->c w * l_current_precinct->ch; \ 935
899 /*fprintf(stderr, "\t\t\t\t precinct_cw = %d x recinct_ch = %d\n",l_current_precinct->cw, l_current_precinct->ch); */ \ 936 l_current_precinct->block_size = l_nb_code_blocks_size;
900 l_nb_code_blocks_size = l_nb_code_blocks * (OPJ_UINT32)sizeof(TYPE); \ 937 }
901 \ 938 else if (l_nb_code_blocks_size > l_curre nt_precinct->block_size) {
902 if (! l_current_precinct->cblks.ELEMENT) { \ 939 void *new_blocks = opj_realloc(l _current_precinct->cblks.blocks, l_nb_code_blocks_size);
903 l_current_precinct->cblks.ELEMEN T = (TYPE*) opj_malloc(l_nb_code_blocks_size); \ 940 if (! new_blocks) {
904 if (! l_current_precinct->cblks. ELEMENT ) { \ 941 opj_free(l_current_preci nct->cblks.blocks);
905 return OPJ_FALSE; \ 942 l_current_precinct->cblk s.blocks = NULL;
906 } \ 943 l_current_precinct->bloc k_size = 0;
907 /*fprintf(stderr, "\t\t\t\tAlloc ate cblks of a precinct (opj_tcd_cblk_dec_t): %d\n",l_nb_code_blocks_size);*/ \ 944 /* opj_event_msg(p_manag er, EVT_ERROR, "Not enough memory for current precinct codeblock element\n"); */
908 \ 945 fprintf(stderr, "Not eno ugh memory for current precinct codeblock element\n");
909 memset(l_current_precinct->cblks .ELEMENT,0,l_nb_code_blocks_size); \ 946 return OPJ_FALSE;
910 \ 947 }
911 l_current_precinct->block_size = l_nb_code_blocks_size; \ 948 l_current_precinct->cblks.blocks = new_blocks;
912 } \ 949 /*fprintf(stderr, "\t\t\t\tReall ocate cblks of a precinct (opj_tcd_cblk_dec_t): from %d to %d\n",l_current_preci nct->block_size, l_nb_code_blocks_size); */
913 else if (l_nb_code_blocks_size > l_curre nt_precinct->block_size) { \ 950
914 TYPE *new_ELEMENT = (TYPE*) opj_ realloc(l_current_precinct->cblks.ELEMENT, l_nb_code_blocks_size); \ 951 memset(((OPJ_BYTE *) l_current_p recinct->cblks.blocks) + l_current_precinct->block_size
915 if (! new_ELEMENT) { \ 952 ,0
916 opj_free(l_current_preci nct->cblks.ELEMENT); \ 953 ,l_nb_c ode_blocks_size - l_current_precinct->block_size);
917 l_current_precinct->cblk s.ELEMENT = NULL; \ 954
918 l_current_precinct->bloc k_size = 0; \ 955 l_current_precinct->block_size = l_nb_code_blocks_size;
919 /* opj_event_msg(p_manag er, EVT_ERROR, "Not enough memory for current precinct codeblock element\n"); */ \ 956 }
920 fprintf(stderr, "Not eno ugh memory for current precinct codeblock element\n"); \ 957
921 return OPJ_FALSE; \ 958 if (! l_current_precinct->incltree) {
922 } \ 959 l_current_precinct->incltree = o pj_tgt_create(l_current_precinct->cw,
923 l_current_precinct->cblks.ELEMEN T = new_ELEMENT; \ 960 l_curren t_precinct->ch);
924 /*fprintf(stderr, "\t\t\t\tReall ocate cblks of a precinct (opj_tcd_cblk_dec_t): from %d to %d\n",l_current_preci nct->block_size, l_nb_code_blocks_size); */\ 961 }
925 \ 962 else{
926 memset(((OPJ_BYTE *) l_current_p recinct->cblks.ELEMENT) + l_current_precinct->block_size \ 963 l_current_precinct->incltree = o pj_tgt_init(l_current_precinct->incltree,
927 ,0 \ 964 l_current_precin ct->cw,
928 ,l_nb_code_block s_size - l_current_precinct->block_size); \ 965 l_current_precin ct->ch);
929 \ 966 }
930 l_current_precinct->block_size = l_nb_code_blocks_size; \ 967
931 } \ 968 if (! l_current_precinct->incltree) {
932 \ 969 fprintf(stderr, "WARNING: No inc ltree created.\n");
933 if (! l_current_precinct->incltree) { \ 970 /*return OPJ_FALSE;*/
934 l_current_precinct->incltree = o pj_tgt_create(l_current_precinct->cw, \ 971 }
935 l_current_precin ct->ch); \ 972
936 } \ 973 if (! l_current_precinct->imsbtree) {
937 else{ \ 974 l_current_precinct->imsbtree = o pj_tgt_create(
938 l_current_precinct->incltree = o pj_tgt_init(l_current_precinct->incltree, \ 975 l_curren t_precinct->cw,
939 l_current_precin ct->cw, \ 976 l_curren t_precinct->ch);
940 l_current_precin ct->ch); \ 977 }
941 } \ 978 else {
942 \ 979 l_current_precinct->imsbtree = o pj_tgt_init(
943 if (! l_current_precinct->incltree) { \ 980 l_current_precin ct->imsbtree,
944 fprintf(stderr, "WARNING: No inc ltree created.\n"); \ 981 l_current_precin ct->cw,
945 /*return OPJ_FALSE;*/ \ 982 l_current_precin ct->ch);
946 } \ 983 }
947 \ 984
948 if (! l_current_precinct->imsbtree) { \ 985 if (! l_current_precinct->imsbtree) {
949 l_current_precinct->imsbtree = o pj_tgt_create( \ 986 fprintf(stderr, "WARNING: No ims btree created.\n");
950 l_current_precin ct->cw, \ 987 /*return OPJ_FALSE;*/
951 l_current_precin ct->ch); \ 988 }
952 } \ 989
953 else { \ 990 for (cblkno = 0; cblkno < l_nb_code_bloc ks; ++cblkno) {
954 l_current_precinct->imsbtree = o pj_tgt_init( \ 991 OPJ_INT32 cblkxstart = tlcblkxst art + (OPJ_INT32)(cblkno % l_current_precinct->cw) * (1 << cblkwidthexpn);
955 l_current_precin ct->imsbtree, \ 992 OPJ_INT32 cblkystart = tlcblkyst art + (OPJ_INT32)(cblkno / l_current_precinct->cw) * (1 << cblkheightexpn);
956 l_current_precin ct->cw, \ 993 OPJ_INT32 cblkxend = cblkxstart + (1 << cblkwidthexpn);
957 l_current_precin ct->ch); \ 994 OPJ_INT32 cblkyend = cblkystart + (1 << cblkheightexpn);
958 } \ 995
959 \ 996 if (isEncoder) {
960 if (! l_current_precinct->imsbtree) { \ 997 opj_tcd_cblk_enc_t* l_co de_block = l_current_precinct->cblks.enc + cblkno;
961 fprintf(stderr, "WARNING: No ims btree created.\n"); \ 998
962 /*return OPJ_FALSE;*/ \ 999 if (! opj_tcd_code_block _enc_allocate(l_code_block)) {
963 } \ 1000 return OPJ_FALSE ;
964 \ 1001 }
965 l_code_block = l_current_precinct->cblks .ELEMENT; \ 1002 /* code-block size (glob al) */
966 \ 1003 l_code_block->x0 = opj_i nt_max(cblkxstart, l_current_precinct->x0);
967 for (cblkno = 0; cblkno < l_nb_code_bloc ks; ++cblkno) { \ 1004 l_code_block->y0 = opj_i nt_max(cblkystart, l_current_precinct->y0);
968 OPJ_INT32 cblkxstart = tlcblkxst art + (OPJ_INT32)(cblkno % l_current_precinct->cw) * (1 << cblkwidthexpn); \ 1005 l_code_block->x1 = opj_i nt_min(cblkxend, l_current_precinct->x1);
969 OPJ_INT32 cblkystart = tlcblkyst art + (OPJ_INT32)(cblkno / l_current_precinct->cw) * (1 << cblkheightexpn); \ 1006 l_code_block->y1 = opj_i nt_min(cblkyend, l_current_precinct->y1);
970 OPJ_INT32 cblkxend = cblkxstart + (1 << cblkwidthexpn); \ 1007 } else {
971 OPJ_INT32 cblkyend = cblkystart + (1 << cblkheightexpn); \ 1008 opj_tcd_cblk_dec_t* l_co de_block = l_current_precinct->cblks.dec + cblkno;
972 \ 1009
973 if (! FUNCTION_ELEMENT(l_code_bl ock)) { \ 1010 if (! opj_tcd_code_block _dec_allocate(l_code_block)) {
974 return OPJ_FALSE; \ 1011 return OPJ_FALSE ;
975 } \ 1012 }
976 /* code-block size (global) */ \ 1013 /* code-block size (glob al) */
977 l_code_block->x0 = opj_int_max(c blkxstart, l_current_precinct->x0); \ 1014 l_code_block->x0 = opj_i nt_max(cblkxstart, l_current_precinct->x0);
978 l_code_block->y0 = opj_int_max(c blkystart, l_current_precinct->y0); \ 1015 l_code_block->y0 = opj_i nt_max(cblkystart, l_current_precinct->y0);
979 l_code_block->x1 = opj_int_min(c blkxend, l_current_precinct->x1); \ 1016 l_code_block->x1 = opj_i nt_min(cblkxend, l_current_precinct->x1);
980 l_code_block->y1 = opj_int_min(c blkyend, l_current_precinct->y1); \ 1017 l_code_block->y1 = opj_i nt_min(cblkyend, l_current_precinct->y1);
981 ++l_code_block; \ 1018 }
982 } \ 1019 }
983 ++l_current_precinct; \ 1020 ++l_current_precinct;
984 } /* precno */ \ 1021 } /* precno */
985 ++l_band; \ 1022 ++l_band;
986 ++l_step_size; \ 1023 ++l_step_size;
987 } /* bandno */ \ 1024 } /* bandno */
988 ++l_res; \ 1025 ++l_res;
989 --l_level_no; \ 1026 --l_level_no;
990 } /* resno */ \ 1027 } /* resno */
991 ++l_tccp; \ 1028 ++l_tccp;
992 ++l_tilec; \ 1029 ++l_tilec;
993 ++l_image_comp; \ 1030 ++l_image_comp;
994 } /* compno */ \ 1031 } /* compno */
995 return OPJ_TRUE; \ 1032 return OPJ_TRUE;
996 } \ 1033 }
997 1034
998 1035 OPJ_BOOL opj_tcd_init_encode_tile (opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no)
999 OPJ_MACRO_TCD_ALLOCATE(opj_tcd_init_encode_tile, opj_tcd_cblk_enc_t, 1.f, enc, o pj_tcd_code_block_enc_allocate) 1036 {
1000 OPJ_MACRO_TCD_ALLOCATE(opj_tcd_init_decode_tile, opj_tcd_cblk_dec_t, 0.5f, dec, opj_tcd_code_block_dec_allocate) 1037 return opj_tcd_init_tile(p_tcd, p_tile_no, OPJ_TRUE, 1.0F, sizeof(opj_tc d_cblk_enc_t));
1001 1038 }
1002 #undef OPJ_MACRO_TCD_ALLOCATE 1039
1040 OPJ_BOOL opj_tcd_init_decode_tile (opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no)
1041 {
1042 return opj_tcd_init_tile(p_tcd, p_tile_no, OPJ_FALSE, 0.5F, sizeof(opj_t cd_cblk_dec_t));
1043 }
1003 1044
1004 /** 1045 /**
1005 * Allocates memory for an encoding code block. 1046 * Allocates memory for an encoding code block.
1006 */ 1047 */
1007 OPJ_BOOL opj_tcd_code_block_enc_allocate (opj_tcd_cblk_enc_t * p_code_block) 1048 OPJ_BOOL opj_tcd_code_block_enc_allocate (opj_tcd_cblk_enc_t * p_code_block)
1008 { 1049 {
1009 if (! p_code_block->data) { 1050 if (! p_code_block->data) {
1010 1051
1011 p_code_block->data = (OPJ_BYTE*) opj_malloc(OPJ_J2K_DEFAULT_CBLK _DATA_SIZE*2); /*why +1 ?*/ 1052 p_code_block->data = (OPJ_BYTE*) opj_malloc(OPJ_J2K_DEFAULT_CBLK _DATA_SIZE*2); /*why +1 ?*/
1012 if(! p_code_block->data) { 1053 if(! p_code_block->data) {
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1450 } 1491 }
1451 ++l_band; 1492 ++l_band;
1452 } /* for (resno */ 1493 } /* for (resno */
1453 ++l_res; 1494 ++l_res;
1454 } 1495 }
1455 1496
1456 opj_free(l_tile_comp->resolutions); 1497 opj_free(l_tile_comp->resolutions);
1457 l_tile_comp->resolutions = 00; 1498 l_tile_comp->resolutions = 00;
1458 } 1499 }
1459 1500
1460 if (l_tile_comp->data) { 1501 if (l_tile_comp->ownsData && l_tile_comp->data) {
1461 opj_free(l_tile_comp->data); 1502 opj_free(l_tile_comp->data);
1462 l_tile_comp->data = 00; 1503 l_tile_comp->data = 00;
1504 l_tile_comp->ownsData = 0;
1505 l_tile_comp->data_size = 0;
1506 l_tile_comp->data_size_needed = 0;
1463 } 1507 }
1464 ++l_tile_comp; 1508 ++l_tile_comp;
1465 } 1509 }
1466 1510
1467 opj_free(l_tile->comps); 1511 opj_free(l_tile->comps);
1468 l_tile->comps = 00; 1512 l_tile->comps = 00;
1469 opj_free(p_tcd->tcd_image->tiles); 1513 opj_free(p_tcd->tcd_image->tiles);
1470 p_tcd->tcd_image->tiles = 00; 1514 p_tcd->tcd_image->tiles = 00;
1471 } 1515 }
1472 1516
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1505 1549
1506 OPJ_BOOL opj_tcd_t1_decode ( opj_tcd_t *p_tcd ) 1550 OPJ_BOOL opj_tcd_t1_decode ( opj_tcd_t *p_tcd )
1507 { 1551 {
1508 OPJ_UINT32 compno; 1552 OPJ_UINT32 compno;
1509 opj_t1_t * l_t1; 1553 opj_t1_t * l_t1;
1510 opj_tcd_tile_t * l_tile = p_tcd->tcd_image->tiles; 1554 opj_tcd_tile_t * l_tile = p_tcd->tcd_image->tiles;
1511 opj_tcd_tilecomp_t* l_tile_comp = l_tile->comps; 1555 opj_tcd_tilecomp_t* l_tile_comp = l_tile->comps;
1512 opj_tccp_t * l_tccp = p_tcd->tcp->tccps; 1556 opj_tccp_t * l_tccp = p_tcd->tcp->tccps;
1513 1557
1514 1558
1515 l_t1 = opj_t1_create(); 1559 l_t1 = opj_t1_create(OPJ_FALSE);
1516 if (l_t1 == 00) { 1560 if (l_t1 == 00) {
1517 return OPJ_FALSE; 1561 return OPJ_FALSE;
1518 } 1562 }
1519 1563
1520 for (compno = 0; compno < l_tile->numcomps; ++compno) { 1564 for (compno = 0; compno < l_tile->numcomps; ++compno) {
1521 /* The +3 is headroom required by the vectorized DWT */ 1565 /* The +3 is headroom required by the vectorized DWT */
1522 if (OPJ_FALSE == opj_t1_decode_cblks(l_t1, l_tile_comp, l_tccp)) { 1566 if (OPJ_FALSE == opj_t1_decode_cblks(l_t1, l_tile_comp, l_tccp)) {
1523 opj_t1_destroy(l_t1); 1567 opj_t1_destroy(l_t1);
1524 return OPJ_FALSE; 1568 return OPJ_FALSE;
1525 } 1569 }
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
1940 1984
1941 return OPJ_TRUE; 1985 return OPJ_TRUE;
1942 } 1986 }
1943 1987
1944 OPJ_BOOL opj_tcd_t1_encode ( opj_tcd_t *p_tcd ) 1988 OPJ_BOOL opj_tcd_t1_encode ( opj_tcd_t *p_tcd )
1945 { 1989 {
1946 opj_t1_t * l_t1; 1990 opj_t1_t * l_t1;
1947 const OPJ_FLOAT64 * l_mct_norms; 1991 const OPJ_FLOAT64 * l_mct_norms;
1948 opj_tcp_t * l_tcp = p_tcd->tcp; 1992 opj_tcp_t * l_tcp = p_tcd->tcp;
1949 1993
1950 l_t1 = opj_t1_create(); 1994 l_t1 = opj_t1_create(OPJ_TRUE);
1951 if (l_t1 == 00) { 1995 if (l_t1 == 00) {
1952 return OPJ_FALSE; 1996 return OPJ_FALSE;
1953 } 1997 }
1954 1998
1955 if (l_tcp->mct == 1) { 1999 if (l_tcp->mct == 1) {
1956 /* irreversible encoding */ 2000 /* irreversible encoding */
1957 if (l_tcp->tccps->qmfbid == 0) { 2001 if (l_tcp->tccps->qmfbid == 0) {
1958 l_mct_norms = opj_mct_get_mct_norms_real(); 2002 l_mct_norms = opj_mct_get_mct_norms_real();
1959 } 2003 }
1960 else { 2004 else {
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
2123 } 2167 }
2124 break; 2168 break;
2125 } 2169 }
2126 2170
2127 ++l_img_comp; 2171 ++l_img_comp;
2128 ++l_tilec; 2172 ++l_tilec;
2129 } 2173 }
2130 2174
2131 return OPJ_TRUE; 2175 return OPJ_TRUE;
2132 } 2176 }
OLDNEW
« no previous file with comments | « core/src/fxcodec/fx_libopenjpeg/libopenjpeg20/tcd.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698