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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 { | 211 { |
212 OPJ_BYTE *l_current_data = p_dest; | 212 OPJ_BYTE *l_current_data = p_dest; |
213 OPJ_UINT32 l_nb_bytes = 0; | 213 OPJ_UINT32 l_nb_bytes = 0; |
214 OPJ_UINT32 compno; | 214 OPJ_UINT32 compno; |
215 OPJ_UINT32 poc; | 215 OPJ_UINT32 poc; |
216 opj_pi_iterator_t *l_pi = 00; | 216 opj_pi_iterator_t *l_pi = 00; |
217 opj_pi_iterator_t *l_current_pi = 00; | 217 opj_pi_iterator_t *l_current_pi = 00; |
218 opj_image_t *l_image = p_t2->image; | 218 opj_image_t *l_image = p_t2->image; |
219 opj_cp_t *l_cp = p_t2->cp; | 219 opj_cp_t *l_cp = p_t2->cp; |
220 opj_tcp_t *l_tcp = &l_cp->tcps[p_tile_no]; | 220 opj_tcp_t *l_tcp = &l_cp->tcps[p_tile_no]; |
221 OPJ_UINT32 pocno = l_cp->m_specific_param.m_enc.m_cinema == OPJ_CINEMA4K
_24? 2: 1; | 221 OPJ_UINT32 pocno = (l_cp->rsiz == OPJ_PROFILE_CINEMA_4K)? 2: 1; |
222 OPJ_UINT32 l_max_comp = l_cp->m_specific_param.m_enc.m_max_comp_size > 0
? l_image->numcomps : 1; | 222 OPJ_UINT32 l_max_comp = l_cp->m_specific_param.m_enc.m_max_comp_size > 0
? l_image->numcomps : 1; |
223 OPJ_UINT32 l_nb_pocs = l_tcp->numpocs + 1; | 223 OPJ_UINT32 l_nb_pocs = l_tcp->numpocs + 1; |
224 | 224 |
225 l_pi = opj_pi_initialise_encode(l_image, l_cp, p_tile_no, p_t2_mode); | 225 l_pi = opj_pi_initialise_encode(l_image, l_cp, p_tile_no, p_t2_mode); |
226 if (!l_pi) { | 226 if (!l_pi) { |
227 return OPJ_FALSE; | 227 return OPJ_FALSE; |
228 } | 228 } |
229 | 229 |
230 * p_data_written = 0; | 230 * p_data_written = 0; |
231 | 231 |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 /** | 470 /** |
471 * Creates a Tier 2 handle | 471 * Creates a Tier 2 handle |
472 * | 472 * |
473 * @param p_image Source or destination image | 473 * @param p_image Source or destination image |
474 * @param p_cp Image coding parameters. | 474 * @param p_cp Image coding parameters. |
475 * @return a new T2 handle if successful, NULL otherwise. | 475 * @return a new T2 handle if successful, NULL otherwise. |
476 */ | 476 */ |
477 opj_t2_t* opj_t2_create(opj_image_t *p_image, opj_cp_t *p_cp) | 477 opj_t2_t* opj_t2_create(opj_image_t *p_image, opj_cp_t *p_cp) |
478 { | 478 { |
479 /* create the t2 structure */ | 479 /* create the t2 structure */ |
480 opj_t2_t *l_t2 = (opj_t2_t*)opj_malloc(sizeof(opj_t2_t)); | 480 opj_t2_t *l_t2 = (opj_t2_t*)opj_calloc(1,sizeof(opj_t2_t)); |
481 if (!l_t2) { | 481 if (!l_t2) { |
482 return NULL; | 482 return NULL; |
483 } | 483 } |
484 memset(l_t2,0,sizeof(opj_t2_t)); | |
485 | 484 |
486 l_t2->image = p_image; | 485 l_t2->image = p_image; |
487 l_t2->cp = p_cp; | 486 l_t2->cp = p_cp; |
488 | 487 |
489 return l_t2; | 488 return l_t2; |
490 } | 489 } |
491 | 490 |
492 void opj_t2_destroy(opj_t2_t *t2) { | 491 void opj_t2_destroy(opj_t2_t *t2) { |
493 if(t2) { | 492 if(t2) { |
494 opj_free(t2); | 493 opj_free(t2); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 cblk = &prc->cblks.enc[cblkno]; | 591 cblk = &prc->cblks.enc[cblkno]; |
593 | 592 |
594 cblk->numpasses = 0; | 593 cblk->numpasses = 0; |
595 opj_tgt_setvalue(prc->imsbtree, cblkno, band->nu
mbps - (OPJ_INT32)cblk->numbps); | 594 opj_tgt_setvalue(prc->imsbtree, cblkno, band->nu
mbps - (OPJ_INT32)cblk->numbps); |
596 } | 595 } |
597 ++band; | 596 ++band; |
598 } | 597 } |
599 } | 598 } |
600 | 599 |
601 bio = opj_bio_create(); | 600 bio = opj_bio_create(); |
| 601 if (!bio) { |
| 602 /* FIXME event manager error callback */ |
| 603 return OPJ_FALSE; |
| 604 } |
602 opj_bio_init_enc(bio, c, length); | 605 opj_bio_init_enc(bio, c, length); |
603 opj_bio_write(bio, 1, 1); /* Empty header bit */ | 606 opj_bio_write(bio, 1, 1); /* Empty header bit */ |
604 | 607 |
605 /* Writing Packet header */ | 608 /* Writing Packet header */ |
606 band = res->bands; | 609 band = res->bands; |
607 for (bandno = 0; bandno < res->numbands; ++bandno) { | 610 for (bandno = 0; bandno < res->numbands; ++bandno) { |
608 opj_tcd_precinct_t *prc = &band->precincts[precno]; | 611 opj_tcd_precinct_t *prc = &band->precincts[precno]; |
609 | 612 |
610 l_nb_blocks = prc->cw * prc->ch; | 613 l_nb_blocks = prc->cw * prc->ch; |
611 cblk = prc->cblks.enc; | 614 cblk = prc->cblks.enc; |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
856 | 859 |
857 ++l_band; | 860 ++l_band; |
858 } | 861 } |
859 } | 862 } |
860 | 863 |
861 /* SOP markers */ | 864 /* SOP markers */ |
862 | 865 |
863 if (p_tcp->csty & J2K_CP_CSTY_SOP) { | 866 if (p_tcp->csty & J2K_CP_CSTY_SOP) { |
864 if (p_max_length < 6) { | 867 if (p_max_length < 6) { |
865 /* TODO opj_event_msg(p_t2->cinfo->event_mgr, EVT_WARNIN
G, "Not enough space for expected SOP marker\n"); */ | 868 /* TODO opj_event_msg(p_t2->cinfo->event_mgr, EVT_WARNIN
G, "Not enough space for expected SOP marker\n"); */ |
866 printf("Not enough space for expected SOP marker\n"); | 869 fprintf(stderr, "Not enough space for expected SOP marke
r\n"); |
867 } else if ((*l_current_data) != 0xff || (*(l_current_data + 1) !
= 0x91)) { | 870 } else if ((*l_current_data) != 0xff || (*(l_current_data + 1) !
= 0x91)) { |
868 /* TODO opj_event_msg(p_t2->cinfo->event_mgr, EVT_WARNIN
G, "Expected SOP marker\n"); */ | 871 /* TODO opj_event_msg(p_t2->cinfo->event_mgr, EVT_WARNIN
G, "Expected SOP marker\n"); */ |
869 printf("Expected SOP marker\n"); | 872 fprintf(stderr, "Warning: expected SOP marker\n"); |
870 fprintf(stderr, "Error : expected SOP marker\n"); | |
871 } else { | 873 } else { |
872 l_current_data += 6; | 874 l_current_data += 6; |
873 } | 875 } |
874 | 876 |
875 /** TODO : check the Nsop value */ | 877 /** TODO : check the Nsop value */ |
876 } | 878 } |
877 | 879 |
878 /* | 880 /* |
879 When the marker PPT/PPM is used the packet header are store in PPT/PPM m
arker | 881 When the marker PPT/PPM is used the packet header are store in PPT/PPM m
arker |
880 This part deal with this caracteristic | 882 This part deal with this caracteristic |
(...skipping 29 matching lines...) Expand all Loading... |
910 l_present = opj_bio_read(l_bio, 1); | 912 l_present = opj_bio_read(l_bio, 1); |
911 JAS_FPRINTF(stderr, "present=%d \n", l_present ); | 913 JAS_FPRINTF(stderr, "present=%d \n", l_present ); |
912 if (!l_present) { | 914 if (!l_present) { |
913 /* TODO MSD: no test to control the output of this function*/ | 915 /* TODO MSD: no test to control the output of this function*/ |
914 opj_bio_inalign(l_bio); | 916 opj_bio_inalign(l_bio); |
915 l_header_data += opj_bio_numbytes(l_bio); | 917 l_header_data += opj_bio_numbytes(l_bio); |
916 opj_bio_destroy(l_bio); | 918 opj_bio_destroy(l_bio); |
917 | 919 |
918 /* EPH markers */ | 920 /* EPH markers */ |
919 if (p_tcp->csty & J2K_CP_CSTY_EPH) { | 921 if (p_tcp->csty & J2K_CP_CSTY_EPH) { |
920 if (p_max_length < 2) { | 922 if ((*l_modified_length_ptr - (OPJ_UINT32)(l_header_data
- *l_header_data_start)) < 2U) { |
921 fprintf(stderr, "Not enough space for expected E
PH marker\n"); | 923 fprintf(stderr, "Not enough space for expected E
PH marker\n"); |
922 } else if ((*l_header_data) != 0xff || (*(l_header_data
+ 1) != 0x92)) { | 924 } else if ((*l_header_data) != 0xff || (*(l_header_data
+ 1) != 0x92)) { |
923 fprintf(stderr, "Error : expected EPH marker\n")
; | 925 fprintf(stderr, "Error : expected EPH marker\n")
; |
924 } else { | 926 } else { |
925 l_header_data += 2; | 927 l_header_data += 2; |
926 } | 928 } |
927 } | 929 } |
928 | 930 |
929 l_header_length = (OPJ_UINT32)(l_header_data - *l_header_data_st
art); | 931 l_header_length = (OPJ_UINT32)(l_header_data - *l_header_data_st
art); |
930 *l_modified_length_ptr -= l_header_length; | 932 *l_modified_length_ptr -= l_header_length; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1038 if (!opj_bio_inalign(l_bio)) { | 1040 if (!opj_bio_inalign(l_bio)) { |
1039 opj_bio_destroy(l_bio); | 1041 opj_bio_destroy(l_bio); |
1040 return OPJ_FALSE; | 1042 return OPJ_FALSE; |
1041 } | 1043 } |
1042 | 1044 |
1043 l_header_data += opj_bio_numbytes(l_bio); | 1045 l_header_data += opj_bio_numbytes(l_bio); |
1044 opj_bio_destroy(l_bio); | 1046 opj_bio_destroy(l_bio); |
1045 | 1047 |
1046 /* EPH markers */ | 1048 /* EPH markers */ |
1047 if (p_tcp->csty & J2K_CP_CSTY_EPH) { | 1049 if (p_tcp->csty & J2K_CP_CSTY_EPH) { |
1048 if (p_max_length < 2) { | 1050 if ((*l_modified_length_ptr - (OPJ_UINT32)(l_header_data - *l_he
ader_data_start)) < 2U) { |
1049 fprintf(stderr, "Not enough space for expected EPH marke
r\n"); | 1051 fprintf(stderr, "Not enough space for expected EPH marke
r\n"); |
1050 } else if ((*l_header_data) != 0xff || (*(l_header_data + 1) !=
0x92)) { | 1052 } else if ((*l_header_data) != 0xff || (*(l_header_data + 1) !=
0x92)) { |
1051 /* TODO opj_event_msg(t2->cinfo->event_mgr, EVT_ERROR, "
Expected EPH marker\n"); */ | 1053 /* TODO opj_event_msg(t2->cinfo->event_mgr, EVT_ERROR, "
Expected EPH marker\n"); */ |
1052 fprintf(stderr, "Error : expected EPH marker\n"); | 1054 fprintf(stderr, "Error : expected EPH marker\n"); |
1053 } else { | 1055 } else { |
1054 l_header_data += 2; | 1056 l_header_data += 2; |
1055 } | 1057 } |
1056 } | 1058 } |
1057 | 1059 |
1058 l_header_length = (OPJ_UINT32)(l_header_data - *l_header_data_start); | 1060 l_header_length = (OPJ_UINT32)(l_header_data - *l_header_data_start); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1122 else { | 1124 else { |
1123 l_seg = &l_cblk->segs[l_cblk->numsegs - 1]; | 1125 l_seg = &l_cblk->segs[l_cblk->numsegs - 1]; |
1124 | 1126 |
1125 if (l_seg->numpasses == l_seg->maxpasses) { | 1127 if (l_seg->numpasses == l_seg->maxpasses) { |
1126 ++l_seg; | 1128 ++l_seg; |
1127 ++l_cblk->numsegs; | 1129 ++l_cblk->numsegs; |
1128 } | 1130 } |
1129 } | 1131 } |
1130 | 1132 |
1131 do { | 1133 do { |
1132 if (l_current_data + l_seg->newlen > p_src_data
+ p_max_length) { | 1134 /* Check possible overflow (on l_current_data on
ly, assumes input args already checked) then size */ |
| 1135 if (((OPJ_SIZE_T)(l_current_data + l_seg->newlen
) < (OPJ_SIZE_T)l_current_data) || (l_current_data + l_seg->newlen > p_src_data
+ p_max_length)) { |
1133 fprintf(stderr, "read: segment too long
(%d) with max (%d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n", | 1136 fprintf(stderr, "read: segment too long
(%d) with max (%d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n", |
1134 l_seg->newlen, p_max_length, cbl
kno, p_pi->precno, bandno, p_pi->resno, p_pi->compno); | 1137 l_seg->newlen, p_max_length, cbl
kno, p_pi->precno, bandno, p_pi->resno, p_pi->compno); |
1135 return OPJ_FALSE; | 1138 return OPJ_FALSE; |
1136 } | 1139 } |
1137 | 1140 |
1138 #ifdef USE_JPWL | 1141 #ifdef USE_JPWL |
1139 /* we need here a j2k handle to verify if making a check
to | 1142 /* we need here a j2k handle to verify if making a check
to |
1140 the validity of cblocks parameters is selected from user
(-W) */ | 1143 the validity of cblocks parameters is selected from user
(-W) */ |
1141 | 1144 |
1142 /* let's check that we are not exceeding */ | 1145 /* let's check that we are not exceeding */ |
1143 if ((l_cblk->len + l_seg->newlen) > 8192) { | 1146 if ((l_cblk->len + l_seg->newlen) > 8192) { |
1144 opj_event_msg(p_t2->cinfo, EVT_WARNING, | 1147 opj_event_msg(p_t2->cinfo, EVT_WARNING, |
1145 "JPWL: segment too long (%d) for
codeblock %d (p=%d, b=%d, r=%d, c=%d)\n", | 1148 "JPWL: segment too long (%d) for
codeblock %d (p=%d, b=%d, r=%d, c=%d)\n", |
1146 l_seg->newlen, cblkno, p_pi->pre
cno, bandno, p_pi->resno, p_pi->compno); | 1149 l_seg->newlen, cblkno, p_pi->pre
cno, bandno, p_pi->resno, p_pi->compno); |
1147 if (!JPWL_ASSUME) { | 1150 if (!JPWL_ASSUME) { |
1148 opj_event_msg(p_t2->cinfo, EVT_E
RROR, "JPWL: giving up\n"); | 1151 opj_event_msg(p_t2->cinfo, EVT_E
RROR, "JPWL: giving up\n"); |
1149 return OPJ_FALSE; | 1152 return OPJ_FALSE; |
1150 } | 1153 } |
1151 l_seg->newlen = 8192 - l_cblk->len; | 1154 l_seg->newlen = 8192 - l_cblk->len; |
1152 opj_event_msg(p_t2->cinfo, EVT_WARNING,
" - truncating segment to %d\n", l_seg->newlen); | 1155 opj_event_msg(p_t2->cinfo, EVT_WARNING,
" - truncating segment to %d\n", l_seg->newlen); |
1153 break; | 1156 break; |
1154 }; | 1157 }; |
1155 | 1158 |
1156 #endif /* USE_JPWL */ | 1159 #endif /* USE_JPWL */ |
| 1160 /* Check possible overflow on size */ |
| 1161 if ((l_cblk->data_current_size + l_seg->newlen)
< l_cblk->data_current_size) { |
| 1162 fprintf(stderr, "read: segment too long
(%d) with current size (%d > %d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n", |
| 1163 l_seg->newlen, l_cblk->data_curr
ent_size, 0xFFFFFFFF - l_seg->newlen, cblkno, p_pi->precno, bandno, p_pi->resno,
p_pi->compno); |
| 1164 return OPJ_FALSE; |
| 1165 } |
1157 /* Check if the cblk->data have allocated enough
memory */ | 1166 /* Check if the cblk->data have allocated enough
memory */ |
1158 if ((l_cblk->data_current_size + l_seg->newlen)
> l_cblk->data_max_size) { | 1167 if ((l_cblk->data_current_size + l_seg->newlen)
> l_cblk->data_max_size) { |
1159 OPJ_BYTE* new_cblk_data = (OPJ_BYTE*) opj_re
alloc(l_cblk->data, l_cblk->data_current_size + l_seg->newlen); | 1168 OPJ_BYTE* new_cblk_data = (OPJ_BYTE*) opj_re
alloc(l_cblk->data, l_cblk->data_current_size + l_seg->newlen); |
1160 if(! new_cblk_data) { | 1169 if(! new_cblk_data) { |
1161 opj_free(l_cblk->data); | 1170 opj_free(l_cblk->data); |
| 1171 l_cblk->data = NULL; |
1162 l_cblk->data_max_size = 0; | 1172 l_cblk->data_max_size = 0; |
1163 /* opj_event_msg(p_manager, EVT_ERROR, "
Not enough memory to realloc code block cata!\n"); */ | 1173 /* opj_event_msg(p_manager, EVT_ERROR, "
Not enough memory to realloc code block cata!\n"); */ |
1164 return OPJ_FALSE; | 1174 return OPJ_FALSE; |
1165 } | 1175 } |
1166 l_cblk->data_max_size = l_cblk->data_current
_size + l_seg->newlen; | 1176 l_cblk->data_max_size = l_cblk->data_current
_size + l_seg->newlen; |
1167 l_cblk->data = new_cblk_data; | 1177 l_cblk->data = new_cblk_data; |
1168 } | 1178 } |
1169 | 1179 |
1170 memcpy(l_cblk->data + l_cblk->data_current_size,
l_current_data, l_seg->newlen); | 1180 memcpy(l_cblk->data + l_cblk->data_current_size,
l_current_data, l_seg->newlen); |
1171 | 1181 |
(...skipping 18 matching lines...) Expand all Loading... |
1190 | 1200 |
1191 l_cblk->real_num_segs = l_cblk->numsegs; | 1201 l_cblk->real_num_segs = l_cblk->numsegs; |
1192 ++l_cblk; | 1202 ++l_cblk; |
1193 } /* next code_block */ | 1203 } /* next code_block */ |
1194 | 1204 |
1195 ++l_band; | 1205 ++l_band; |
1196 } | 1206 } |
1197 | 1207 |
1198 *(p_data_read) = (OPJ_UINT32)(l_current_data - p_src_data); | 1208 *(p_data_read) = (OPJ_UINT32)(l_current_data - p_src_data); |
1199 | 1209 |
| 1210 |
1200 return OPJ_TRUE; | 1211 return OPJ_TRUE; |
1201 } | 1212 } |
1202 | 1213 |
1203 OPJ_BOOL opj_t2_skip_packet_data( opj_t2_t* p_t2, | 1214 OPJ_BOOL opj_t2_skip_packet_data( opj_t2_t* p_t2, |
1204 opj_tcd_tile_t *p_tile, | 1215 opj_tcd_tile_t *p_tile, |
1205 opj_pi_iterator_t *p_pi, | 1216 opj_pi_iterator_t *p_pi, |
1206 OPJ_UINT32 * p_data_read, | 1217 OPJ_UINT32 * p_data_read, |
1207 OPJ_UINT32 p_max_length, | 1218 OPJ_UINT32 p_max_length, |
1208 opj_packet_info_t *pack_info) | 1219 opj_packet_info_t *pack_info) |
1209 { | 1220 { |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1335 seg->maxpasses = 10; | 1346 seg->maxpasses = 10; |
1336 } else { | 1347 } else { |
1337 seg->maxpasses = (((seg - 1)->maxpasses == 1) || ((seg -
1)->maxpasses == 10)) ? 2 : 1; | 1348 seg->maxpasses = (((seg - 1)->maxpasses == 1) || ((seg -
1)->maxpasses == 10)) ? 2 : 1; |
1338 } | 1349 } |
1339 } else { | 1350 } else { |
1340 seg->maxpasses = 109; | 1351 seg->maxpasses = 109; |
1341 } | 1352 } |
1342 | 1353 |
1343 return OPJ_TRUE; | 1354 return OPJ_TRUE; |
1344 } | 1355 } |
OLD | NEW |