OLD | NEW |
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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 * Allocates memory for a decoding code block. | 113 * Allocates memory for a decoding code block. |
114 */ | 114 */ |
115 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); |
116 | 116 |
117 /** | 117 /** |
118 * Deallocates the decoding data of the given precinct. | 118 * Deallocates the decoding data of the given precinct. |
119 */ | 119 */ |
120 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); |
121 | 121 |
122 /** | 122 /** |
123 * Allocates memory for an encoding code block. | 123 * Allocates memory for an encoding code block (but not data). |
124 */ | 124 */ |
125 static OPJ_BOOL opj_tcd_code_block_enc_allocate (opj_tcd_cblk_enc_t * p_code_blo
ck); | 125 static OPJ_BOOL opj_tcd_code_block_enc_allocate (opj_tcd_cblk_enc_t * p_code_blo
ck); |
126 | 126 |
127 /** | 127 /** |
| 128 * Allocates data for an encoding code block |
| 129 */ |
| 130 static OPJ_BOOL opj_tcd_code_block_enc_allocate_data (opj_tcd_cblk_enc_t * p_cod
e_block); |
| 131 |
| 132 /** |
128 * Deallocates the encoding data of the given precinct. | 133 * Deallocates the encoding data of the given precinct. |
129 */ | 134 */ |
130 static void opj_tcd_code_block_enc_deallocate (opj_tcd_precinct_t * p_precinct); | 135 static void opj_tcd_code_block_enc_deallocate (opj_tcd_precinct_t * p_precinct); |
131 | 136 |
132 | 137 |
133 /** | 138 /** |
134 Free the memory allocated for encoding | 139 Free the memory allocated for encoding |
135 @param tcd TCD handle | 140 @param tcd TCD handle |
136 */ | 141 */ |
137 static void opj_tcd_free_tile(opj_tcd_t *tcd); | 142 static void opj_tcd_free_tile(opj_tcd_t *tcd); |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 opj_tcd_resolution_t *l_res = 00; | 668 opj_tcd_resolution_t *l_res = 00; |
664 opj_tcd_band_t *l_band = 00; | 669 opj_tcd_band_t *l_band = 00; |
665 opj_stepsize_t * l_step_size = 00; | 670 opj_stepsize_t * l_step_size = 00; |
666 opj_tcd_precinct_t *l_current_precinct = 00; | 671 opj_tcd_precinct_t *l_current_precinct = 00; |
667 opj_image_t *l_image = 00; | 672 opj_image_t *l_image = 00; |
668 OPJ_UINT32 p,q; | 673 OPJ_UINT32 p,q; |
669 OPJ_UINT32 l_level_no; | 674 OPJ_UINT32 l_level_no; |
670 OPJ_UINT32 l_pdx, l_pdy; | 675 OPJ_UINT32 l_pdx, l_pdy; |
671 OPJ_UINT32 l_gain; | 676 OPJ_UINT32 l_gain; |
672 OPJ_INT32 l_x0b, l_y0b; | 677 OPJ_INT32 l_x0b, l_y0b; |
| 678 OPJ_UINT32 l_tx0, l_ty0; |
673 /* extent of precincts , top left, bottom right**/ | 679 /* extent of precincts , top left, bottom right**/ |
674 OPJ_INT32 l_tl_prc_x_start, l_tl_prc_y_start, l_br_prc_x_end, l_br_prc_y
_end; | 680 OPJ_INT32 l_tl_prc_x_start, l_tl_prc_y_start, l_br_prc_x_end, l_br_prc_y
_end; |
675 /* number of precinct for a resolution */ | 681 /* number of precinct for a resolution */ |
676 OPJ_UINT32 l_nb_precincts; | 682 OPJ_UINT32 l_nb_precincts; |
677 /* room needed to store l_nb_precinct precinct for a resolution */ | 683 /* room needed to store l_nb_precinct precinct for a resolution */ |
678 OPJ_UINT32 l_nb_precinct_size; | 684 OPJ_UINT32 l_nb_precinct_size; |
679 /* number of code blocks for a precinct*/ | 685 /* number of code blocks for a precinct*/ |
680 OPJ_UINT32 l_nb_code_blocks; | 686 OPJ_UINT32 l_nb_code_blocks; |
681 /* room needed to store l_nb_code_blocks code blocks for a precinct*/ | 687 /* room needed to store l_nb_code_blocks code blocks for a precinct*/ |
682 OPJ_UINT32 l_nb_code_blocks_size; | 688 OPJ_UINT32 l_nb_code_blocks_size; |
683 /* size of data for a tile */ | 689 /* size of data for a tile */ |
684 OPJ_UINT32 l_data_size; | 690 OPJ_UINT32 l_data_size; |
685 | 691 » |
686 l_cp = p_tcd->cp; | 692 l_cp = p_tcd->cp; |
687 l_tcp = &(l_cp->tcps[p_tile_no]); | 693 l_tcp = &(l_cp->tcps[p_tile_no]); |
688 l_tile = p_tcd->tcd_image->tiles; | 694 l_tile = p_tcd->tcd_image->tiles; |
689 l_tccp = l_tcp->tccps; | 695 l_tccp = l_tcp->tccps; |
690 l_tilec = l_tile->comps; | 696 l_tilec = l_tile->comps; |
691 l_image = p_tcd->image; | 697 l_image = p_tcd->image; |
692 l_image_comp = p_tcd->image->comps; | 698 l_image_comp = p_tcd->image->comps; |
693 | 699 » |
694 p = p_tile_no % l_cp->tw; /* tile coordinates */ | 700 p = p_tile_no % l_cp->tw; /* tile coordinates */ |
695 q = p_tile_no / l_cp->tw; | 701 q = p_tile_no / l_cp->tw; |
696 /*fprintf(stderr, "Tile coordinate = %d,%d\n", p, q);*/ | 702 /*fprintf(stderr, "Tile coordinate = %d,%d\n", p, q);*/ |
| 703 |
| 704 /* 4 borders of the tile rescale on the image if necessary */ |
| 705 l_tx0 = l_cp->tx0 + p * l_cp->tdx; /* can't be greater than l_image->x1
so won't overflow */ |
| 706 l_tile->x0 = (OPJ_INT32)opj_uint_max(l_tx0, l_image->x0); |
| 707 l_tile->x1 = (OPJ_INT32)opj_uint_min(opj_uint_adds(l_tx0, l_cp->tdx), l_
image->x1); |
| 708 l_ty0 = l_cp->ty0 + q * l_cp->tdy; /* can't be greater than l_image->y1
so won't overflow */ |
| 709 l_tile->y0 = (OPJ_INT32)opj_uint_max(l_ty0, l_image->y0); |
| 710 l_tile->y1 = (OPJ_INT32)opj_uint_min(opj_uint_adds(l_ty0, l_cp->tdy), l_
image->y1); |
697 | 711 |
698 /* 4 borders of the tile rescale on the image if necessary */ | |
699 l_tile->x0 = opj_int_max((OPJ_INT32)(l_cp->tx0 + p * l_cp->tdx), (OPJ_IN
T32)l_image->x0); | |
700 l_tile->y0 = opj_int_max((OPJ_INT32)(l_cp->ty0 + q * l_cp->tdy), (OPJ_IN
T32)l_image->y0); | |
701 l_tile->x1 = opj_int_min((OPJ_INT32)(l_cp->tx0 + (p + 1) * l_cp->tdx), (
OPJ_INT32)l_image->x1); | |
702 l_tile->y1 = opj_int_min((OPJ_INT32)(l_cp->ty0 + (q + 1) * l_cp->tdy), (
OPJ_INT32)l_image->y1); | |
703 /* testcase 1888.pdf.asan.35.988 */ | 712 /* testcase 1888.pdf.asan.35.988 */ |
704 if (l_tccp->numresolutions == 0) { | 713 if (l_tccp->numresolutions == 0) { |
705 fprintf(stderr, "tiles require at least one resolution\n"); | 714 fprintf(stderr, "tiles require at least one resolution\n"); |
706 return OPJ_FALSE; | 715 return OPJ_FALSE; |
707 } | 716 } |
708 /*fprintf(stderr, "Tile border = %d,%d,%d,%d\n", l_tile->x0, l_tile->y0,
l_tile->x1,l_tile->y1);*/ | 717 /*fprintf(stderr, "Tile border = %d,%d,%d,%d\n", l_tile->x0, l_tile->y0,
l_tile->x1,l_tile->y1);*/ |
709 | 718 » |
710 /*tile->numcomps = image->numcomps; */ | 719 /*tile->numcomps = image->numcomps; */ |
711 for (compno = 0; compno < l_tile->numcomps; ++compno) { | 720 for (compno = 0; compno < l_tile->numcomps; ++compno) { |
712 /*fprintf(stderr, "compno = %d/%d\n", compno, l_tile->numcomps);
*/ | 721 /*fprintf(stderr, "compno = %d/%d\n", compno, l_tile->numcomps);
*/ |
713 l_image_comp->resno_decoded = 0; | 722 l_image_comp->resno_decoded = 0; |
714 /* border of each l_tile component (global) */ | 723 /* border of each l_tile component (global) */ |
715 l_tilec->x0 = opj_int_ceildiv(l_tile->x0, (OPJ_INT32)l_image_com
p->dx); | 724 l_tilec->x0 = opj_int_ceildiv(l_tile->x0, (OPJ_INT32)l_image_com
p->dx); |
716 l_tilec->y0 = opj_int_ceildiv(l_tile->y0, (OPJ_INT32)l_image_com
p->dy); | 725 l_tilec->y0 = opj_int_ceildiv(l_tile->y0, (OPJ_INT32)l_image_com
p->dy); |
717 l_tilec->x1 = opj_int_ceildiv(l_tile->x1, (OPJ_INT32)l_image_com
p->dx); | 726 l_tilec->x1 = opj_int_ceildiv(l_tile->x1, (OPJ_INT32)l_image_com
p->dx); |
718 l_tilec->y1 = opj_int_ceildiv(l_tile->y1, (OPJ_INT32)l_image_com
p->dy); | 727 l_tilec->y1 = opj_int_ceildiv(l_tile->y1, (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);*/ | 728 /*fprintf(stderr, "\tTile compo border = %d,%d,%d,%d\n", l_tilec
->x0, l_tilec->y0,l_tilec->x1,l_tilec->y1);*/ |
720 | 729 » » |
721 /* compute l_data_size with overflow check */ | 730 /* compute l_data_size with overflow check */ |
722 l_data_size = (OPJ_UINT32)(l_tilec->x1 - l_tilec->x0); | 731 l_data_size = (OPJ_UINT32)(l_tilec->x1 - l_tilec->x0); |
723 if ((((OPJ_UINT32)-1) / l_data_size) < (OPJ_UINT32)(l_tilec->y1
- l_tilec->y0)) { | 732 if ((((OPJ_UINT32)-1) / l_data_size) < (OPJ_UINT32)(l_tilec->y1
- l_tilec->y0)) { |
724 /* TODO event */ | 733 /* TODO event */ |
725 return OPJ_FALSE; | 734 return OPJ_FALSE; |
726 } | 735 } |
727 l_data_size = l_data_size * (OPJ_UINT32)(l_tilec->y1 - l_tilec->
y0); | 736 l_data_size = l_data_size * (OPJ_UINT32)(l_tilec->y1 - l_tilec->
y0); |
728 | 737 » » |
729 if ((((OPJ_UINT32)-1) / (OPJ_UINT32)sizeof(OPJ_UINT32)) < l_data
_size) { | 738 if ((((OPJ_UINT32)-1) / (OPJ_UINT32)sizeof(OPJ_UINT32)) < l_data
_size) { |
730 /* TODO event */ | 739 /* TODO event */ |
731 return OPJ_FALSE; | 740 return OPJ_FALSE; |
732 } | 741 } |
733 l_data_size = l_data_size * (OPJ_UINT32)sizeof(OPJ_UINT32); | 742 l_data_size = l_data_size * (OPJ_UINT32)sizeof(OPJ_UINT32); |
734 l_tilec->numresolutions = l_tccp->numresolutions; | 743 l_tilec->numresolutions = l_tccp->numresolutions; |
735 if (l_tccp->numresolutions < l_cp->m_specific_param.m_dec.m_redu
ce) { | 744 if (l_tccp->numresolutions < l_cp->m_specific_param.m_dec.m_redu
ce) { |
736 l_tilec->minimum_num_resolutions = 1; | 745 l_tilec->minimum_num_resolutions = 1; |
737 } | 746 } |
738 else { | 747 else { |
739 l_tilec->minimum_num_resolutions = l_tccp->numresolution
s - l_cp->m_specific_param.m_dec.m_reduce; | 748 l_tilec->minimum_num_resolutions = l_tccp->numresolution
s - l_cp->m_specific_param.m_dec.m_reduce; |
740 } | 749 } |
741 | 750 » » |
742 l_tilec->data_size_needed = l_data_size; | 751 l_tilec->data_size_needed = l_data_size; |
743 if (p_tcd->m_is_decoder && !opj_alloc_tile_component_data(l_tile
c)) { | 752 if (p_tcd->m_is_decoder && !opj_alloc_tile_component_data(l_tile
c)) { |
744 return OPJ_FALSE; | 753 return OPJ_FALSE; |
745 } | 754 } |
746 | 755 » » |
747 l_data_size = l_tilec->numresolutions * (OPJ_UINT32)sizeof(opj_t
cd_resolution_t); | 756 l_data_size = l_tilec->numresolutions * (OPJ_UINT32)sizeof(opj_t
cd_resolution_t); |
748 | 757 » » |
749 if (l_tilec->resolutions == 00) { | 758 if (l_tilec->resolutions == 00) { |
750 l_tilec->resolutions = (opj_tcd_resolution_t *) opj_mall
oc(l_data_size); | 759 l_tilec->resolutions = (opj_tcd_resolution_t *) opj_mall
oc(l_data_size); |
751 if (! l_tilec->resolutions ) { | 760 if (! l_tilec->resolutions ) { |
752 return OPJ_FALSE; | 761 return OPJ_FALSE; |
753 } | 762 } |
754 /*fprintf(stderr, "\tAllocate resolutions of tilec (opj_
tcd_resolution_t): %d\n",l_data_size);*/ | 763 /*fprintf(stderr, "\tAllocate resolutions of tilec (opj_
tcd_resolution_t): %d\n",l_data_size);*/ |
755 l_tilec->resolutions_size = l_data_size; | 764 l_tilec->resolutions_size = l_data_size; |
756 memset(l_tilec->resolutions,0,l_data_size); | 765 memset(l_tilec->resolutions,0,l_data_size); |
757 } | 766 } |
758 else if (l_data_size > l_tilec->resolutions_size) { | 767 else if (l_data_size > l_tilec->resolutions_size) { |
759 opj_tcd_resolution_t* new_resolutions = (opj_tcd_resolut
ion_t *) opj_realloc(l_tilec->resolutions, l_data_size); | 768 opj_tcd_resolution_t* new_resolutions = (opj_tcd_resolut
ion_t *) opj_realloc(l_tilec->resolutions, l_data_size); |
760 if (! new_resolutions) { | 769 if (! new_resolutions) { |
761 /* opj_event_msg(p_manager, EVT_ERROR, "Not enou
gh memory to tile resolutions\n");
*/ | 770 /* opj_event_msg(p_manager, EVT_ERROR, "Not enou
gh memory to tile resolutions\n");
*/ |
762 fprintf(stderr, "Not enough memory to tile resol
utions\n"); | 771 fprintf(stderr, "Not enough memory to tile resol
utions\n"); |
763 opj_free(l_tilec->resolutions); | 772 opj_free(l_tilec->resolutions); |
764 l_tilec->resolutions = NULL; | 773 l_tilec->resolutions = NULL; |
765 l_tilec->resolutions_size = 0; | 774 l_tilec->resolutions_size = 0; |
766 return OPJ_FALSE; | 775 return OPJ_FALSE; |
767 } | 776 } |
768 l_tilec->resolutions = new_resolutions; | 777 l_tilec->resolutions = new_resolutions; |
769 /*fprintf(stderr, "\tReallocate data of tilec (int): fro
m %d to %d x OPJ_UINT32\n", l_tilec->resolutions_size, l_data_size);*/ | 778 /*fprintf(stderr, "\tReallocate data of tilec (int): fro
m %d to %d x OPJ_UINT32\n", l_tilec->resolutions_size, l_data_size);*/ |
770 memset(((OPJ_BYTE*) l_tilec->resolutions)+l_tilec->resol
utions_size,0,l_data_size - l_tilec->resolutions_size); | 779 memset(((OPJ_BYTE*) l_tilec->resolutions)+l_tilec->resol
utions_size,0,l_data_size - l_tilec->resolutions_size); |
771 l_tilec->resolutions_size = l_data_size; | 780 l_tilec->resolutions_size = l_data_size; |
772 } | 781 } |
773 | 782 » » |
774 l_level_no = l_tilec->numresolutions - 1; | 783 l_level_no = l_tilec->numresolutions - 1; |
775 l_res = l_tilec->resolutions; | 784 l_res = l_tilec->resolutions; |
776 l_step_size = l_tccp->stepsizes; | 785 l_step_size = l_tccp->stepsizes; |
777 if (l_tccp->qmfbid == 0) { | 786 if (l_tccp->qmfbid == 0) { |
778 l_gain_ptr = &opj_dwt_getgain_real; | 787 l_gain_ptr = &opj_dwt_getgain_real; |
779 } | 788 } |
780 else { | 789 else { |
781 l_gain_ptr = &opj_dwt_getgain; | 790 l_gain_ptr = &opj_dwt_getgain; |
782 } | 791 } |
783 /*fprintf(stderr, "\tlevel_no=%d\n",l_level_no);*/ | 792 /*fprintf(stderr, "\tlevel_no=%d\n",l_level_no);*/ |
784 | 793 » » |
785 for (resno = 0; resno < l_tilec->numresolutions; ++resno) { | 794 for (resno = 0; resno < l_tilec->numresolutions; ++resno) { |
786 /*fprintf(stderr, "\t\tresno = %d/%d\n", resno, l_tilec-
>numresolutions);*/ | 795 /*fprintf(stderr, "\t\tresno = %d/%d\n", resno, l_tilec-
>numresolutions);*/ |
787 OPJ_INT32 tlcbgxstart, tlcbgystart /*, brcbgxend, brcbgy
end*/; | 796 OPJ_INT32 tlcbgxstart, tlcbgystart /*, brcbgxend, brcbgy
end*/; |
788 OPJ_UINT32 cbgwidthexpn, cbgheightexpn; | 797 OPJ_UINT32 cbgwidthexpn, cbgheightexpn; |
789 OPJ_UINT32 cblkwidthexpn, cblkheightexpn; | 798 OPJ_UINT32 cblkwidthexpn, cblkheightexpn; |
790 | 799 » » » |
791 /* border for each resolution level (global) */ | 800 /* border for each resolution level (global) */ |
792 l_res->x0 = opj_int_ceildivpow2(l_tilec->x0, (OPJ_INT32)
l_level_no); | 801 l_res->x0 = opj_int_ceildivpow2(l_tilec->x0, (OPJ_INT32)
l_level_no); |
793 l_res->y0 = opj_int_ceildivpow2(l_tilec->y0, (OPJ_INT32)
l_level_no); | 802 l_res->y0 = opj_int_ceildivpow2(l_tilec->y0, (OPJ_INT32)
l_level_no); |
794 l_res->x1 = opj_int_ceildivpow2(l_tilec->x1, (OPJ_INT32)
l_level_no); | 803 l_res->x1 = opj_int_ceildivpow2(l_tilec->x1, (OPJ_INT32)
l_level_no); |
795 l_res->y1 = opj_int_ceildivpow2(l_tilec->y1, (OPJ_INT32)
l_level_no); | 804 l_res->y1 = opj_int_ceildivpow2(l_tilec->y1, (OPJ_INT32)
l_level_no); |
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);*/ | 805 /*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);*/ |
797 /* p. 35, table A-23, ISO/IEC FDIS154444-1 : 2000 (18 au
gust 2000) */ | 806 /* p. 35, table A-23, ISO/IEC FDIS154444-1 : 2000 (18 au
gust 2000) */ |
798 l_pdx = l_tccp->prcw[resno]; | 807 l_pdx = l_tccp->prcw[resno]; |
799 l_pdy = l_tccp->prch[resno]; | 808 l_pdy = l_tccp->prch[resno]; |
800 /*fprintf(stderr, "\t\t\tpdx=%d, pdy=%d\n", l_pdx, l_pdy
);*/ | 809 /*fprintf(stderr, "\t\t\tpdx=%d, pdy=%d\n", l_pdx, l_pdy
);*/ |
801 /* p. 64, B.6, ISO/IEC FDIS15444-1 : 2000 (18 august 200
0) */ | 810 /* p. 64, B.6, ISO/IEC FDIS15444-1 : 2000 (18 august 200
0) */ |
802 l_tl_prc_x_start = opj_int_floordivpow2(l_res->x0, (OPJ_
INT32)l_pdx) << l_pdx; | 811 l_tl_prc_x_start = opj_int_floordivpow2(l_res->x0, (OPJ_
INT32)l_pdx) << l_pdx; |
803 l_tl_prc_y_start = opj_int_floordivpow2(l_res->y0, (OPJ_
INT32)l_pdy) << l_pdy; | 812 l_tl_prc_y_start = opj_int_floordivpow2(l_res->y0, (OPJ_
INT32)l_pdy) << l_pdy; |
804 l_br_prc_x_end = opj_int_ceildivpow2(l_res->x1, (OPJ_INT
32)l_pdx) << l_pdx; | 813 l_br_prc_x_end = opj_int_ceildivpow2(l_res->x1, (OPJ_INT
32)l_pdx) << l_pdx; |
805 l_br_prc_y_end = opj_int_ceildivpow2(l_res->y1, (OPJ_INT
32)l_pdy) << l_pdy; | 814 l_br_prc_y_end = opj_int_ceildivpow2(l_res->y1, (OPJ_INT
32)l_pdy) << l_pdy; |
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 );*/ | 815 /*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 );*/ |
807 | 816 » » » |
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); | 817 l_res->pw = (l_res->x0 == l_res->x1) ? 0 : (OPJ_UINT32)(
(l_br_prc_x_end - l_tl_prc_x_start) >> l_pdx); |
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); | 818 l_res->ph = (l_res->y0 == l_res->y1) ? 0 : (OPJ_UINT32)(
(l_br_prc_y_end - l_tl_prc_y_start) >> l_pdy); |
810 /*fprintf(stderr, "\t\t\tres_pw=%d, res_ph=%d\n", l_res-
>pw, l_res->ph );*/ | 819 /*fprintf(stderr, "\t\t\tres_pw=%d, res_ph=%d\n", l_res-
>pw, l_res->ph );*/ |
811 | 820 » » » |
812 l_nb_precincts = l_res->pw * l_res->ph; | 821 l_nb_precincts = l_res->pw * l_res->ph; |
813 l_nb_precinct_size = l_nb_precincts * (OPJ_UINT32)sizeof
(opj_tcd_precinct_t); | 822 l_nb_precinct_size = l_nb_precincts * (OPJ_UINT32)sizeof
(opj_tcd_precinct_t); |
814 if (resno == 0) { | 823 if (resno == 0) { |
815 tlcbgxstart = l_tl_prc_x_start; | 824 tlcbgxstart = l_tl_prc_x_start; |
816 tlcbgystart = l_tl_prc_y_start; | 825 tlcbgystart = l_tl_prc_y_start; |
817 /*brcbgxend = l_br_prc_x_end;*/ | 826 /*brcbgxend = l_br_prc_x_end;*/ |
818 /* brcbgyend = l_br_prc_y_end;*/ | 827 /* brcbgyend = l_br_prc_y_end;*/ |
819 cbgwidthexpn = l_pdx; | 828 cbgwidthexpn = l_pdx; |
820 cbgheightexpn = l_pdy; | 829 cbgheightexpn = l_pdy; |
821 l_res->numbands = 1; | 830 l_res->numbands = 1; |
822 } | 831 } |
823 else { | 832 else { |
824 tlcbgxstart = opj_int_ceildivpow2(l_tl_prc_x_sta
rt, 1); | 833 tlcbgxstart = opj_int_ceildivpow2(l_tl_prc_x_sta
rt, 1); |
825 tlcbgystart = opj_int_ceildivpow2(l_tl_prc_y_sta
rt, 1); | 834 tlcbgystart = opj_int_ceildivpow2(l_tl_prc_y_sta
rt, 1); |
826 /*brcbgxend = opj_int_ceildivpow2(l_br_prc_x_end
, 1);*/ | 835 /*brcbgxend = opj_int_ceildivpow2(l_br_prc_x_end
, 1);*/ |
827 /*brcbgyend = opj_int_ceildivpow2(l_br_prc_y_end
, 1);*/ | 836 /*brcbgyend = opj_int_ceildivpow2(l_br_prc_y_end
, 1);*/ |
828 cbgwidthexpn = l_pdx - 1; | 837 cbgwidthexpn = l_pdx - 1; |
829 cbgheightexpn = l_pdy - 1; | 838 cbgheightexpn = l_pdy - 1; |
830 l_res->numbands = 3; | 839 l_res->numbands = 3; |
831 } | 840 } |
832 | 841 » » » |
833 cblkwidthexpn = opj_uint_min(l_tccp->cblkw, cbgwidthexpn
); | 842 cblkwidthexpn = opj_uint_min(l_tccp->cblkw, cbgwidthexpn
); |
834 cblkheightexpn = opj_uint_min(l_tccp->cblkh, cbgheightex
pn); | 843 cblkheightexpn = opj_uint_min(l_tccp->cblkh, cbgheightex
pn); |
835 l_band = l_res->bands; | 844 l_band = l_res->bands; |
836 | 845 » » » |
837 for (bandno = 0; bandno < l_res->numbands; ++bandno) { | 846 for (bandno = 0; bandno < l_res->numbands; ++bandno) { |
838 OPJ_INT32 numbps; | 847 OPJ_INT32 numbps; |
839 /*fprintf(stderr, "\t\t\tband_no=%d/%d\n", bandn
o, l_res->numbands );*/ | 848 /*fprintf(stderr, "\t\t\tband_no=%d/%d\n", bandn
o, l_res->numbands );*/ |
840 | 849 » » » » |
841 if (resno == 0) { | 850 if (resno == 0) { |
842 l_band->bandno = 0 ; | 851 l_band->bandno = 0 ; |
843 l_band->x0 = opj_int_ceildivpow2(l_tilec
->x0, (OPJ_INT32)l_level_no); | 852 l_band->x0 = opj_int_ceildivpow2(l_tilec
->x0, (OPJ_INT32)l_level_no); |
844 l_band->y0 = opj_int_ceildivpow2(l_tilec
->y0, (OPJ_INT32)l_level_no); | 853 l_band->y0 = opj_int_ceildivpow2(l_tilec
->y0, (OPJ_INT32)l_level_no); |
845 l_band->x1 = opj_int_ceildivpow2(l_tilec
->x1, (OPJ_INT32)l_level_no); | 854 l_band->x1 = opj_int_ceildivpow2(l_tilec
->x1, (OPJ_INT32)l_level_no); |
846 l_band->y1 = opj_int_ceildivpow2(l_tilec
->y1, (OPJ_INT32)l_level_no); | 855 l_band->y1 = opj_int_ceildivpow2(l_tilec
->y1, (OPJ_INT32)l_level_no); |
847 } | 856 } |
848 else { | 857 else { |
849 l_band->bandno = bandno + 1; | 858 l_band->bandno = bandno + 1; |
850 /* x0b = 1 if bandno = 1 or 3 */ | 859 /* x0b = 1 if bandno = 1 or 3 */ |
851 l_x0b = l_band->bandno&1; | 860 l_x0b = l_band->bandno&1; |
852 /* y0b = 1 if bandno = 2 or 3 */ | 861 /* y0b = 1 if bandno = 2 or 3 */ |
853 l_y0b = (OPJ_INT32)((l_band->bandno)>>1)
; | 862 l_y0b = (OPJ_INT32)((l_band->bandno)>>1)
; |
854 /* l_band border (global) */ | 863 /* l_band border (global) */ |
855 l_band->x0 = opj_int_ceildivpow2(l_tilec
->x0 - (1 << l_level_no) * l_x0b, (OPJ_INT32)(l_level_no + 1)); | 864 l_band->x0 = opj_int_ceildivpow2(l_tilec
->x0 - (1 << l_level_no) * l_x0b, (OPJ_INT32)(l_level_no + 1)); |
856 l_band->y0 = opj_int_ceildivpow2(l_tilec
->y0 - (1 << l_level_no) * l_y0b, (OPJ_INT32)(l_level_no + 1)); | 865 l_band->y0 = opj_int_ceildivpow2(l_tilec
->y0 - (1 << l_level_no) * l_y0b, (OPJ_INT32)(l_level_no + 1)); |
857 l_band->x1 = opj_int_ceildivpow2(l_tilec
->x1 - (1 << l_level_no) * l_x0b, (OPJ_INT32)(l_level_no + 1)); | 866 l_band->x1 = opj_int_ceildivpow2(l_tilec
->x1 - (1 << l_level_no) * l_x0b, (OPJ_INT32)(l_level_no + 1)); |
858 l_band->y1 = opj_int_ceildivpow2(l_tilec
->y1 - (1 << l_level_no) * l_y0b, (OPJ_INT32)(l_level_no + 1)); | 867 l_band->y1 = opj_int_ceildivpow2(l_tilec
->y1 - (1 << l_level_no) * l_y0b, (OPJ_INT32)(l_level_no + 1)); |
859 } | 868 } |
860 | 869 » » » » |
861 /** avoid an if with storing function pointer */ | 870 /** avoid an if with storing function pointer */ |
862 l_gain = (*l_gain_ptr) (l_band->bandno); | 871 l_gain = (*l_gain_ptr) (l_band->bandno); |
863 numbps = (OPJ_INT32)(l_image_comp->prec + l_gain
); | 872 numbps = (OPJ_INT32)(l_image_comp->prec + l_gain
); |
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; | 873 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; |
865 l_band->numbps = l_step_size->expn + (OPJ_INT32)
l_tccp->numgbits - 1; /* WHY -1 ? */ | 874 l_band->numbps = l_step_size->expn + (OPJ_INT32)
l_tccp->numgbits - 1; /* WHY -1 ? */ |
866 | 875 » » » » |
867 if (! l_band->precincts) { | 876 if (! l_band->precincts) { |
868 l_band->precincts = (opj_tcd_precinct_t
*) opj_malloc( /*3 * */ l_nb_precinct_size); | 877 l_band->precincts = (opj_tcd_precinct_t
*) opj_malloc( /*3 * */ l_nb_precinct_size); |
869 if (! l_band->precincts) { | 878 if (! l_band->precincts) { |
870 return OPJ_FALSE; | 879 return OPJ_FALSE; |
871 } | 880 } |
872 /*fprintf(stderr, "\t\t\t\tAllocate prec
incts of a band (opj_tcd_precinct_t): %d\n",l_nb_precinct_size); */ | 881 /*fprintf(stderr, "\t\t\t\tAllocate prec
incts of a band (opj_tcd_precinct_t): %d\n",l_nb_precinct_size); */ |
873 memset(l_band->precincts,0,l_nb_precinct
_size); | 882 memset(l_band->precincts,0,l_nb_precinct
_size); |
874 l_band->precincts_data_size = l_nb_preci
nct_size; | 883 l_band->precincts_data_size = l_nb_preci
nct_size; |
875 } | 884 } |
876 else if (l_band->precincts_data_size < l_nb_prec
inct_size) { | 885 else if (l_band->precincts_data_size < l_nb_prec
inct_size) { |
877 | 886 » » » » » |
878 opj_tcd_precinct_t * new_precincts = (op
j_tcd_precinct_t *) opj_realloc(l_band->precincts,/*3 * */ l_nb_precinct_size); | 887 opj_tcd_precinct_t * new_precincts = (op
j_tcd_precinct_t *) opj_realloc(l_band->precincts,/*3 * */ l_nb_precinct_size); |
879 if (! new_precincts) { | 888 if (! new_precincts) { |
880 /* opj_event_msg(p_manager, EVT_
ERROR, "Not enough memory to handle band precints\n");
*/ | 889 /* opj_event_msg(p_manager, EVT_
ERROR, "Not enough memory to handle band precints\n");
*/ |
881 fprintf(stderr, "Not enough memo
ry to handle band precints\n"); | 890 fprintf(stderr, "Not enough memo
ry to handle band precints\n"); |
882 opj_free(l_band->precincts); | 891 opj_free(l_band->precincts); |
883 l_band->precincts = NULL; | 892 l_band->precincts = NULL; |
884 l_band->precincts_data_size = 0; | 893 l_band->precincts_data_size = 0; |
885 return OPJ_FALSE; | 894 return OPJ_FALSE; |
886 } | 895 } |
887 l_band->precincts = new_precincts; | 896 l_band->precincts = new_precincts; |
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);*/ | 897 /*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);*/ |
889 memset(((OPJ_BYTE *) l_band->precincts)
+ l_band->precincts_data_size,0,l_nb_precinct_size - l_band->precincts_data_size
); | 898 memset(((OPJ_BYTE *) l_band->precincts)
+ l_band->precincts_data_size,0,l_nb_precinct_size - l_band->precincts_data_size
); |
890 l_band->precincts_data_size = l_nb_preci
nct_size; | 899 l_band->precincts_data_size = l_nb_preci
nct_size; |
891 } | 900 } |
892 | 901 » » » » |
893 l_current_precinct = l_band->precincts; | 902 l_current_precinct = l_band->precincts; |
894 for (precno = 0; precno < l_nb_precincts; ++prec
no) { | 903 for (precno = 0; precno < l_nb_precincts; ++prec
no) { |
895 OPJ_INT32 tlcblkxstart, tlcblkystart, br
cblkxend, brcblkyend; | 904 OPJ_INT32 tlcblkxstart, tlcblkystart, br
cblkxend, brcblkyend; |
896 OPJ_INT32 cbgxstart = tlcbgxstart + (OPJ
_INT32)(precno % l_res->pw) * (1 << cbgwidthexpn); | 905 OPJ_INT32 cbgxstart = tlcbgxstart + (OPJ
_INT32)(precno % l_res->pw) * (1 << cbgwidthexpn); |
897 OPJ_INT32 cbgystart = tlcbgystart + (OPJ
_INT32)(precno / l_res->pw) * (1 << cbgheightexpn); | 906 OPJ_INT32 cbgystart = tlcbgystart + (OPJ
_INT32)(precno / l_res->pw) * (1 << cbgheightexpn); |
898 OPJ_INT32 cbgxend = cbgxstart + (1 << cb
gwidthexpn); | 907 OPJ_INT32 cbgxend = cbgxstart + (1 << cb
gwidthexpn); |
899 OPJ_INT32 cbgyend = cbgystart + (1 << cb
gheightexpn); | 908 OPJ_INT32 cbgyend = cbgystart + (1 << cb
gheightexpn); |
900 /*fprintf(stderr, "\t precno=%d; bandno=
%d, resno=%d; compno=%d\n", precno, bandno , resno, compno);*/ | 909 /*fprintf(stderr, "\t precno=%d; bandno=
%d, resno=%d; compno=%d\n", precno, bandno , resno, compno);*/ |
901 /*fprintf(stderr, "\t tlcbgxstart(=%d) +
(precno(=%d) percent res->pw(=%d)) * (1 << cbgwidthexpn(=%d)) \n",tlcbgxstart,p
recno,l_res->pw,cbgwidthexpn);*/ | 910 /*fprintf(stderr, "\t tlcbgxstart(=%d) +
(precno(=%d) percent res->pw(=%d)) * (1 << cbgwidthexpn(=%d)) \n",tlcbgxstart,p
recno,l_res->pw,cbgwidthexpn);*/ |
902 | 911 » » » » » |
903 /* precinct size (global) */ | 912 /* precinct size (global) */ |
904 /*fprintf(stderr, "\t cbgxstart=%d, l_ba
nd->x0 = %d \n",cbgxstart, l_band->x0);*/ | 913 /*fprintf(stderr, "\t cbgxstart=%d, l_ba
nd->x0 = %d \n",cbgxstart, l_band->x0);*/ |
905 | 914 » » » » » |
906 l_current_precinct->x0 = opj_int_max(cbg
xstart, l_band->x0); | 915 l_current_precinct->x0 = opj_int_max(cbg
xstart, l_band->x0); |
907 l_current_precinct->y0 = opj_int_max(cbg
ystart, l_band->y0); | 916 l_current_precinct->y0 = opj_int_max(cbg
ystart, l_band->y0); |
908 l_current_precinct->x1 = opj_int_min(cbg
xend, l_band->x1); | 917 l_current_precinct->x1 = opj_int_min(cbg
xend, l_band->x1); |
909 l_current_precinct->y1 = opj_int_min(cbg
yend, l_band->y1); | 918 l_current_precinct->y1 = opj_int_min(cbg
yend, l_band->y1); |
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);*/ | 919 /*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);*/ |
911 | 920 » » » » » |
912 tlcblkxstart = opj_int_floordivpow2(l_cu
rrent_precinct->x0, (OPJ_INT32)cblkwidthexpn) << cblkwidthexpn; | 921 tlcblkxstart = opj_int_floordivpow2(l_cu
rrent_precinct->x0, (OPJ_INT32)cblkwidthexpn) << cblkwidthexpn; |
913 /*fprintf(stderr, "\t tlcblkxstart =%d\n
",tlcblkxstart );*/ | 922 /*fprintf(stderr, "\t tlcblkxstart =%d\n
",tlcblkxstart );*/ |
914 tlcblkystart = opj_int_floordivpow2(l_cu
rrent_precinct->y0, (OPJ_INT32)cblkheightexpn) << cblkheightexpn; | 923 tlcblkystart = opj_int_floordivpow2(l_cu
rrent_precinct->y0, (OPJ_INT32)cblkheightexpn) << cblkheightexpn; |
915 /*fprintf(stderr, "\t tlcblkystart =%d\n
",tlcblkystart );*/ | 924 /*fprintf(stderr, "\t tlcblkystart =%d\n
",tlcblkystart );*/ |
916 brcblkxend = opj_int_ceildivpow2(l_curre
nt_precinct->x1, (OPJ_INT32)cblkwidthexpn) << cblkwidthexpn; | 925 brcblkxend = opj_int_ceildivpow2(l_curre
nt_precinct->x1, (OPJ_INT32)cblkwidthexpn) << cblkwidthexpn; |
917 /*fprintf(stderr, "\t brcblkxend =%d\n",
brcblkxend );*/ | 926 /*fprintf(stderr, "\t brcblkxend =%d\n",
brcblkxend );*/ |
918 brcblkyend = opj_int_ceildivpow2(l_curre
nt_precinct->y1, (OPJ_INT32)cblkheightexpn) << cblkheightexpn; | 927 brcblkyend = opj_int_ceildivpow2(l_curre
nt_precinct->y1, (OPJ_INT32)cblkheightexpn) << cblkheightexpn; |
919 /*fprintf(stderr, "\t brcblkyend =%d\n",
brcblkyend );*/ | 928 /*fprintf(stderr, "\t brcblkyend =%d\n",
brcblkyend );*/ |
920 l_current_precinct->cw = (OPJ_UINT32)((b
rcblkxend - tlcblkxstart) >> cblkwidthexpn); | 929 l_current_precinct->cw = (OPJ_UINT32)((b
rcblkxend - tlcblkxstart) >> cblkwidthexpn); |
921 l_current_precinct->ch = (OPJ_UINT32)((b
rcblkyend - tlcblkystart) >> cblkheightexpn); | 930 l_current_precinct->ch = (OPJ_UINT32)((b
rcblkyend - tlcblkystart) >> cblkheightexpn); |
922 | 931 » » » » » |
923 l_nb_code_blocks = l_current_precinct->c
w * l_current_precinct->ch; | 932 l_nb_code_blocks = l_current_precinct->c
w * l_current_precinct->ch; |
924 /*fprintf(stderr, "\t\t\t\t precinct_cw
= %d x recinct_ch = %d\n",l_current_precinct->cw, l_current_precinct->ch);
*/ | 933 /*fprintf(stderr, "\t\t\t\t precinct_cw
= %d x recinct_ch = %d\n",l_current_precinct->cw, l_current_precinct->ch);
*/ |
925 l_nb_code_blocks_size = l_nb_code_blocks
* (OPJ_UINT32)sizeof_block; | 934 l_nb_code_blocks_size = l_nb_code_blocks
* (OPJ_UINT32)sizeof_block; |
926 | 935 » » » » » |
927 if (! l_current_precinct->cblks.blocks)
{ | 936 if (! l_current_precinct->cblks.blocks)
{ |
928 l_current_precinct->cblks.blocks
= opj_malloc(l_nb_code_blocks_size); | 937 l_current_precinct->cblks.blocks
= opj_malloc(l_nb_code_blocks_size); |
929 if (! l_current_precinct->cblks.
blocks ) { | 938 if (! l_current_precinct->cblks.
blocks ) { |
930 return OPJ_FALSE; | 939 return OPJ_FALSE; |
931 } | 940 } |
932 /*fprintf(stderr, "\t\t\t\tAlloc
ate cblks of a precinct (opj_tcd_cblk_dec_t): %d\n",l_nb_code_blocks_size);*/ | 941 /*fprintf(stderr, "\t\t\t\tAlloc
ate cblks of a precinct (opj_tcd_cblk_dec_t): %d\n",l_nb_code_blocks_size);*/ |
933 | 942 » » » » » » |
934 memset(l_current_precinct->cblks
.blocks,0,l_nb_code_blocks_size); | 943 memset(l_current_precinct->cblks
.blocks,0,l_nb_code_blocks_size); |
935 | 944 » » » » » » |
936 l_current_precinct->block_size =
l_nb_code_blocks_size; | 945 l_current_precinct->block_size =
l_nb_code_blocks_size; |
937 } | 946 } |
938 else if (l_nb_code_blocks_size > l_curre
nt_precinct->block_size) { | 947 else if (l_nb_code_blocks_size > l_curre
nt_precinct->block_size) { |
939 void *new_blocks = opj_realloc(l
_current_precinct->cblks.blocks, l_nb_code_blocks_size); | 948 void *new_blocks = opj_realloc(l
_current_precinct->cblks.blocks, l_nb_code_blocks_size); |
940 if (! new_blocks) { | 949 if (! new_blocks) { |
941 opj_free(l_current_preci
nct->cblks.blocks); | 950 opj_free(l_current_preci
nct->cblks.blocks); |
942 l_current_precinct->cblk
s.blocks = NULL; | 951 l_current_precinct->cblk
s.blocks = NULL; |
943 l_current_precinct->bloc
k_size = 0; | 952 l_current_precinct->bloc
k_size = 0; |
944 /* opj_event_msg(p_manag
er, EVT_ERROR, "Not enough memory for current precinct codeblock element\n");
*/ | 953 /* opj_event_msg(p_manag
er, EVT_ERROR, "Not enough memory for current precinct codeblock element\n");
*/ |
945 fprintf(stderr, "Not eno
ugh memory for current precinct codeblock element\n"); | 954 fprintf(stderr, "Not eno
ugh memory for current precinct codeblock element\n"); |
946 return OPJ_FALSE; | 955 return OPJ_FALSE; |
947 } | 956 } |
948 l_current_precinct->cblks.blocks
= new_blocks; | 957 l_current_precinct->cblks.blocks
= new_blocks; |
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); */ | 958 /*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); */ |
950 | 959 » » » » » » |
951 memset(((OPJ_BYTE *) l_current_p
recinct->cblks.blocks) + l_current_precinct->block_size | 960 memset(((OPJ_BYTE *) l_current_p
recinct->cblks.blocks) + l_current_precinct->block_size |
952 ,0 | 961 ,0 |
953 ,l_nb_c
ode_blocks_size - l_current_precinct->block_size); | 962 ,l_nb_c
ode_blocks_size - l_current_precinct->block_size); |
954 | 963 » » » » » » |
955 l_current_precinct->block_size =
l_nb_code_blocks_size; | 964 l_current_precinct->block_size =
l_nb_code_blocks_size; |
956 } | 965 } |
957 | 966 » » » » » |
958 if (! l_current_precinct->incltree) { | 967 if (! l_current_precinct->incltree) { |
959 l_current_precinct->incltree = o
pj_tgt_create(l_current_precinct->cw, | 968 l_current_precinct->incltree = o
pj_tgt_create(l_current_precinct->cw, |
960
l_curren
t_precinct->ch); | 969
l_curren
t_precinct->ch); |
961 } | 970 } |
962 else{ | 971 else{ |
963 l_current_precinct->incltree = o
pj_tgt_init(l_current_precinct->incltree, | 972 l_current_precinct->incltree = o
pj_tgt_init(l_current_precinct->incltree, |
964
l_current_precin
ct->cw, | 973
l_current_precin
ct->cw, |
965
l_current_precin
ct->ch); | 974
l_current_precin
ct->ch); |
966 } | 975 } |
967 | 976 |
(...skipping 17 matching lines...) Expand all Loading... |
985 if (! l_current_precinct->imsbtree) { | 994 if (! l_current_precinct->imsbtree) { |
986 fprintf(stderr, "WARNING: No ims
btree created.\n"); | 995 fprintf(stderr, "WARNING: No ims
btree created.\n"); |
987 /*return OPJ_FALSE;*/ | 996 /*return OPJ_FALSE;*/ |
988 } | 997 } |
989 | 998 |
990 for (cblkno = 0; cblkno < l_nb_code_bloc
ks; ++cblkno) { | 999 for (cblkno = 0; cblkno < l_nb_code_bloc
ks; ++cblkno) { |
991 OPJ_INT32 cblkxstart = tlcblkxst
art + (OPJ_INT32)(cblkno % l_current_precinct->cw) * (1 << cblkwidthexpn); | 1000 OPJ_INT32 cblkxstart = tlcblkxst
art + (OPJ_INT32)(cblkno % l_current_precinct->cw) * (1 << cblkwidthexpn); |
992 OPJ_INT32 cblkystart = tlcblkyst
art + (OPJ_INT32)(cblkno / l_current_precinct->cw) * (1 << cblkheightexpn); | 1001 OPJ_INT32 cblkystart = tlcblkyst
art + (OPJ_INT32)(cblkno / l_current_precinct->cw) * (1 << cblkheightexpn); |
993 OPJ_INT32 cblkxend = cblkxstart
+ (1 << cblkwidthexpn); | 1002 OPJ_INT32 cblkxend = cblkxstart
+ (1 << cblkwidthexpn); |
994 OPJ_INT32 cblkyend = cblkystart
+ (1 << cblkheightexpn); | 1003 OPJ_INT32 cblkyend = cblkystart
+ (1 << cblkheightexpn); |
995 | 1004 » » » » » » |
996 if (isEncoder) { | 1005 if (isEncoder) { |
997 opj_tcd_cblk_enc_t* l_co
de_block = l_current_precinct->cblks.enc + cblkno; | 1006 opj_tcd_cblk_enc_t* l_co
de_block = l_current_precinct->cblks.enc + cblkno; |
998 | 1007 » » » » » » » |
999 if (! opj_tcd_code_block
_enc_allocate(l_code_block)) { | 1008 if (! opj_tcd_code_block
_enc_allocate(l_code_block)) { |
1000 return OPJ_FALSE
; | 1009 return OPJ_FALSE
; |
1001 } | 1010 } |
1002 /* code-block size (glob
al) */ | 1011 /* code-block size (glob
al) */ |
1003 l_code_block->x0 = opj_i
nt_max(cblkxstart, l_current_precinct->x0); | 1012 l_code_block->x0 = opj_i
nt_max(cblkxstart, l_current_precinct->x0); |
1004 l_code_block->y0 = opj_i
nt_max(cblkystart, l_current_precinct->y0); | 1013 l_code_block->y0 = opj_i
nt_max(cblkystart, l_current_precinct->y0); |
1005 l_code_block->x1 = opj_i
nt_min(cblkxend, l_current_precinct->x1); | 1014 l_code_block->x1 = opj_i
nt_min(cblkxend, l_current_precinct->x1); |
1006 l_code_block->y1 = opj_i
nt_min(cblkyend, l_current_precinct->y1); | 1015 l_code_block->y1 = opj_i
nt_min(cblkyend, l_current_precinct->y1); |
| 1016 |
| 1017 if (! opj_tcd_code_block
_enc_allocate_data(l_code_block)) { |
| 1018 return OPJ_FALSE
; |
| 1019 } |
1007 } else { | 1020 } else { |
1008 opj_tcd_cblk_dec_t* l_co
de_block = l_current_precinct->cblks.dec + cblkno; | 1021 opj_tcd_cblk_dec_t* l_co
de_block = l_current_precinct->cblks.dec + cblkno; |
1009 | 1022 » » » » » » » |
1010 if (! opj_tcd_code_block
_dec_allocate(l_code_block)) { | 1023 if (! opj_tcd_code_block
_dec_allocate(l_code_block)) { |
1011 return OPJ_FALSE
; | 1024 return OPJ_FALSE
; |
1012 } | 1025 } |
1013 /* code-block size (glob
al) */ | 1026 /* code-block size (glob
al) */ |
1014 l_code_block->x0 = opj_i
nt_max(cblkxstart, l_current_precinct->x0); | 1027 l_code_block->x0 = opj_i
nt_max(cblkxstart, l_current_precinct->x0); |
1015 l_code_block->y0 = opj_i
nt_max(cblkystart, l_current_precinct->y0); | 1028 l_code_block->y0 = opj_i
nt_max(cblkystart, l_current_precinct->y0); |
1016 l_code_block->x1 = opj_i
nt_min(cblkxend, l_current_precinct->x1); | 1029 l_code_block->x1 = opj_i
nt_min(cblkxend, l_current_precinct->x1); |
1017 l_code_block->y1 = opj_i
nt_min(cblkyend, l_current_precinct->y1); | 1030 l_code_block->y1 = opj_i
nt_min(cblkyend, l_current_precinct->y1); |
1018 } | 1031 } |
1019 } | 1032 } |
(...skipping 16 matching lines...) Expand all Loading... |
1036 { | 1049 { |
1037 return opj_tcd_init_tile(p_tcd, p_tile_no, OPJ_TRUE, 1.0F, sizeof(opj_tc
d_cblk_enc_t)); | 1050 return opj_tcd_init_tile(p_tcd, p_tile_no, OPJ_TRUE, 1.0F, sizeof(opj_tc
d_cblk_enc_t)); |
1038 } | 1051 } |
1039 | 1052 |
1040 OPJ_BOOL opj_tcd_init_decode_tile (opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no) | 1053 OPJ_BOOL opj_tcd_init_decode_tile (opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no) |
1041 { | 1054 { |
1042 return opj_tcd_init_tile(p_tcd, p_tile_no, OPJ_FALSE, 0.5F, sizeof(opj_t
cd_cblk_dec_t)); | 1055 return opj_tcd_init_tile(p_tcd, p_tile_no, OPJ_FALSE, 0.5F, sizeof(opj_t
cd_cblk_dec_t)); |
1043 } | 1056 } |
1044 | 1057 |
1045 /** | 1058 /** |
1046 * Allocates memory for an encoding code block. | 1059 * Allocates memory for an encoding code block (but not data memory). |
1047 */ | 1060 */ |
1048 OPJ_BOOL opj_tcd_code_block_enc_allocate (opj_tcd_cblk_enc_t * p_code_block) | 1061 static OPJ_BOOL opj_tcd_code_block_enc_allocate (opj_tcd_cblk_enc_t * p_code_blo
ck) |
1049 { | 1062 { |
1050 if (! p_code_block->data) { | 1063 » if (! p_code_block->layers) { |
| 1064 » » /* no memset since data */ |
| 1065 » » p_code_block->layers = (opj_tcd_layer_t*) opj_calloc(100, sizeof
(opj_tcd_layer_t)); |
| 1066 » » if (! p_code_block->layers) { |
| 1067 » » » return OPJ_FALSE; |
| 1068 » » } |
| 1069 » } |
| 1070 » if (! p_code_block->passes) { |
| 1071 » » p_code_block->passes = (opj_tcd_pass_t*) opj_calloc(100, sizeof(
opj_tcd_pass_t)); |
| 1072 » » if (! p_code_block->passes) { |
| 1073 » » » return OPJ_FALSE; |
| 1074 » » } |
| 1075 » } |
| 1076 » return OPJ_TRUE; |
| 1077 } |
1051 | 1078 |
1052 p_code_block->data = (OPJ_BYTE*) opj_malloc(OPJ_J2K_DEFAULT_CBLK
_DATA_SIZE*2); /*why +1 ?*/ | 1079 /** |
1053 if(! p_code_block->data) { | 1080 * Allocates data memory for an encoding code block. |
1054 return OPJ_FALSE; | 1081 */ |
1055 } | 1082 static OPJ_BOOL opj_tcd_code_block_enc_allocate_data (opj_tcd_cblk_enc_t * p_cod
e_block) |
1056 | 1083 { |
1057 p_code_block->data[0] = 0; | 1084 » OPJ_UINT32 l_data_size; |
1058 p_code_block->data+=1; | 1085 » |
1059 | 1086 » l_data_size = (OPJ_UINT32)((p_code_block->x1 - p_code_block->x0) * (p_co
de_block->y1 - p_code_block->y0) * (OPJ_INT32)sizeof(OPJ_UINT32)); |
1060 /* no memset since data */ | 1087 » |
1061 p_code_block->layers = (opj_tcd_layer_t*) opj_calloc(100, sizeof
(opj_tcd_layer_t)); | 1088 » if (l_data_size > p_code_block->data_size) { |
1062 if (! p_code_block->layers) { | 1089 » » if (p_code_block->data) { |
1063 return OPJ_FALSE; | 1090 » » » opj_free(p_code_block->data - 1); /* again, why -1 */ |
1064 } | 1091 » » } |
1065 | 1092 » » p_code_block->data = (OPJ_BYTE*) opj_malloc(l_data_size); |
1066 p_code_block->passes = (opj_tcd_pass_t*) opj_calloc(100, sizeof(
opj_tcd_pass_t)); | 1093 » » if(! p_code_block->data) { |
1067 if (! p_code_block->passes) { | 1094 » » » p_code_block->data_size = 0U; |
1068 return OPJ_FALSE; | 1095 » » » return OPJ_FALSE; |
1069 } | 1096 » » } |
1070 } | 1097 » » p_code_block->data_size = l_data_size; |
1071 | 1098 » » |
1072 return OPJ_TRUE; | 1099 » » p_code_block->data[0] = 0; |
| 1100 » » p_code_block->data+=1; /*why +1 ?*/ |
| 1101 » } |
| 1102 » return OPJ_TRUE; |
1073 } | 1103 } |
1074 | 1104 |
1075 /** | 1105 /** |
1076 * Allocates memory for a decoding code block. | 1106 * Allocates memory for a decoding code block. |
1077 */ | 1107 */ |
1078 OPJ_BOOL opj_tcd_code_block_dec_allocate (opj_tcd_cblk_dec_t * p_code_block) | 1108 static OPJ_BOOL opj_tcd_code_block_dec_allocate (opj_tcd_cblk_dec_t * p_code_blo
ck) |
1079 { | 1109 { |
1080 if (! p_code_block->data) { | 1110 if (! p_code_block->data) { |
1081 | 1111 |
1082 p_code_block->data = (OPJ_BYTE*) opj_malloc(OPJ_J2K_DEFAULT_CBLK
_DATA_SIZE); | 1112 p_code_block->data = (OPJ_BYTE*) opj_malloc(OPJ_J2K_DEFAULT_CBLK
_DATA_SIZE); |
1083 if (! p_code_block->data) { | 1113 if (! p_code_block->data) { |
1084 return OPJ_FALSE; | 1114 return OPJ_FALSE; |
1085 } | 1115 } |
1086 p_code_block->data_max_size = OPJ_J2K_DEFAULT_CBLK_DATA_SIZE; | 1116 p_code_block->data_max_size = OPJ_J2K_DEFAULT_CBLK_DATA_SIZE; |
1087 /*fprintf(stderr, "Allocate 8192 elements of code_block->data\n"
);*/ | 1117 /*fprintf(stderr, "Allocate 8192 elements of code_block->data\n"
);*/ |
1088 | 1118 |
(...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1982 ++l_tccp; | 2012 ++l_tccp; |
1983 } | 2013 } |
1984 | 2014 |
1985 return OPJ_TRUE; | 2015 return OPJ_TRUE; |
1986 } | 2016 } |
1987 | 2017 |
1988 OPJ_BOOL opj_tcd_t1_encode ( opj_tcd_t *p_tcd ) | 2018 OPJ_BOOL opj_tcd_t1_encode ( opj_tcd_t *p_tcd ) |
1989 { | 2019 { |
1990 opj_t1_t * l_t1; | 2020 opj_t1_t * l_t1; |
1991 const OPJ_FLOAT64 * l_mct_norms; | 2021 const OPJ_FLOAT64 * l_mct_norms; |
| 2022 OPJ_UINT32 l_mct_numcomps = 0U; |
1992 opj_tcp_t * l_tcp = p_tcd->tcp; | 2023 opj_tcp_t * l_tcp = p_tcd->tcp; |
1993 | 2024 |
1994 l_t1 = opj_t1_create(OPJ_TRUE); | 2025 l_t1 = opj_t1_create(OPJ_TRUE); |
1995 if (l_t1 == 00) { | 2026 if (l_t1 == 00) { |
1996 return OPJ_FALSE; | 2027 return OPJ_FALSE; |
1997 } | 2028 } |
1998 | 2029 |
1999 if (l_tcp->mct == 1) { | 2030 if (l_tcp->mct == 1) { |
| 2031 l_mct_numcomps = 3U; |
2000 /* irreversible encoding */ | 2032 /* irreversible encoding */ |
2001 if (l_tcp->tccps->qmfbid == 0) { | 2033 if (l_tcp->tccps->qmfbid == 0) { |
2002 l_mct_norms = opj_mct_get_mct_norms_real(); | 2034 l_mct_norms = opj_mct_get_mct_norms_real(); |
2003 } | 2035 } |
2004 else { | 2036 else { |
2005 l_mct_norms = opj_mct_get_mct_norms(); | 2037 l_mct_norms = opj_mct_get_mct_norms(); |
2006 } | 2038 } |
2007 } | 2039 } |
2008 else { | 2040 else { |
| 2041 l_mct_numcomps = p_tcd->image->numcomps; |
2009 l_mct_norms = (const OPJ_FLOAT64 *) (l_tcp->mct_norms); | 2042 l_mct_norms = (const OPJ_FLOAT64 *) (l_tcp->mct_norms); |
2010 } | 2043 } |
2011 | 2044 |
2012 if (! opj_t1_encode_cblks(l_t1, p_tcd->tcd_image->tiles , l_tcp, l_mct_n
orms)) { | 2045 if (! opj_t1_encode_cblks(l_t1, p_tcd->tcd_image->tiles , l_tcp, l_mct_n
orms, l_mct_numcomps)) { |
2013 opj_t1_destroy(l_t1); | 2046 opj_t1_destroy(l_t1); |
2014 return OPJ_FALSE; | 2047 return OPJ_FALSE; |
2015 } | 2048 } |
2016 | 2049 |
2017 opj_t1_destroy(l_t1); | 2050 opj_t1_destroy(l_t1); |
2018 | 2051 |
2019 return OPJ_TRUE; | 2052 return OPJ_TRUE; |
2020 } | 2053 } |
2021 | 2054 |
2022 OPJ_BOOL opj_tcd_t2_encode (opj_tcd_t *p_tcd, | 2055 OPJ_BOOL opj_tcd_t2_encode (opj_tcd_t *p_tcd, |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2167 } | 2200 } |
2168 break; | 2201 break; |
2169 } | 2202 } |
2170 | 2203 |
2171 ++l_img_comp; | 2204 ++l_img_comp; |
2172 ++l_tilec; | 2205 ++l_tilec; |
2173 } | 2206 } |
2174 | 2207 |
2175 return OPJ_TRUE; | 2208 return OPJ_TRUE; |
2176 } | 2209 } |
OLD | NEW |