opj_read_bytes(p_header_data, &l_tcp->mct, 1); /* SGcod (C) */
++p_header_data;
+ if (l_tcp->mct > 1) {
+ opj_event_msg(p_manager, EVT_ERROR,
+ "Invalid multiple component transformation\n");
+ return OPJ_FALSE;
+ }
+
p_header_size -= 5;
for (i = 0; i < l_image->numcomps; ++i) {
l_tcp->tccps[i].csty = l_tcp->csty & J2K_CCP_CSTY_PRT;
OPJ_FLOAT32 * l_rates = 0;
OPJ_FLOAT32 l_sot_remove;
OPJ_UINT32 l_bits_empty, l_size_pixel;
- OPJ_UINT32 l_tile_size = 0;
+ OPJ_UINT64 l_tile_size = 0;
OPJ_UINT32 l_last_res;
OPJ_FLOAT32(* l_tp_stride_func)(opj_tcp_t *) = 00;
l_rates = l_tcp->rates;
/* Modification of the RATE >> */
- if (*l_rates > 0.0f) {
- *l_rates = (((OPJ_FLOAT32)(l_size_pixel * (OPJ_UINT32)(l_x1 - l_x0) *
- (OPJ_UINT32)(l_y1 - l_y0)))
- /
- ((*l_rates) * (OPJ_FLOAT32)l_bits_empty)
- )
- -
- l_offset;
- }
-
- ++l_rates;
-
- for (k = 1; k < l_tcp->numlayers; ++k) {
+ for (k = 0; k < l_tcp->numlayers; ++k) {
if (*l_rates > 0.0f) {
- *l_rates = (((OPJ_FLOAT32)(l_size_pixel * (OPJ_UINT32)(l_x1 - l_x0) *
- (OPJ_UINT32)(l_y1 - l_y0)))
- /
- ((*l_rates) * (OPJ_FLOAT32)l_bits_empty)
- )
+ *l_rates = (OPJ_FLOAT32)(((OPJ_FLOAT64)l_size_pixel * (OPJ_UINT32)(
+ l_x1 - l_x0) *
+ (OPJ_UINT32)(l_y1 - l_y0))
+ / ((*l_rates) * (OPJ_FLOAT32)l_bits_empty))
-
l_offset;
}
l_tile_size = 0;
for (i = 0; i < l_image->numcomps; ++i) {
- l_tile_size += (opj_uint_ceildiv(l_cp->tdx, l_img_comp->dx)
- *
- opj_uint_ceildiv(l_cp->tdy, l_img_comp->dy)
- *
- l_img_comp->prec
- );
+ l_tile_size += (OPJ_UINT64)opj_uint_ceildiv(l_cp->tdx, l_img_comp->dx)
+ *
+ opj_uint_ceildiv(l_cp->tdy, l_img_comp->dy)
+ *
+ l_img_comp->prec;
++l_img_comp;
}
/* bin/test_tile_encoder 1 256 256 32 32 8 0 reversible_with_precinct.j2k 4 4 3 0 0 1 16 16 */
/* TODO revise this to take into account the overhead linked to the */
/* number of packets and number of code blocks in packets */
- l_tile_size = (OPJ_UINT32)(l_tile_size * 1.4 / 8);
+ l_tile_size = (OPJ_UINT64)((double)l_tile_size * 1.4 / 8);
/* Arbitrary amount to make the following work: */
/* bin/test_tile_encoder 1 256 256 17 16 8 0 reversible_no_precinct.j2k 4 4 3 0 0 1 */
l_tile_size += opj_j2k_get_specific_header_sizes(p_j2k);
- p_j2k->m_specific_param.m_encoder.m_encoded_tile_size = l_tile_size;
+ if (l_tile_size > UINT_MAX) {
+ l_tile_size = UINT_MAX;
+ }
+
+ p_j2k->m_specific_param.m_encoder.m_encoded_tile_size = (OPJ_UINT32)l_tile_size;
p_j2k->m_specific_param.m_encoder.m_encoded_tile_data =
(OPJ_BYTE *) opj_malloc(p_j2k->m_specific_param.m_encoder.m_encoded_tile_size);
if (p_j2k->m_specific_param.m_encoder.m_encoded_tile_data == 00) {
+ opj_event_msg(p_manager, EVT_ERROR,
+ "Not enough memory to allocate m_encoded_tile_data. %u MB required\n",
+ (OPJ_UINT32)(l_tile_size / 1024 / 1024));
return OPJ_FALSE;
}
/*Allocate and initialize some elements of codestrem index*/
if (!opj_j2k_allocate_tile_element_cstr_index(p_j2k)) {
+ opj_image_destroy(*p_image);
+ *p_image = NULL;
return OPJ_FALSE;
}
return OPJ_FALSE;
}
- opj_read_bytes(l_current_ptr, &l_tccp->numresolutions,
- 1); /* SPcox (D) */
- ++l_tccp->numresolutions; /* tccp->numresolutions = read() + 1 */
+ /* SPcod (D) / SPcoc (A) */
+ opj_read_bytes(l_current_ptr, &l_tccp->numresolutions, 1);
+ ++l_tccp->numresolutions; /* tccp->numresolutions = read() + 1 */
if (l_tccp->numresolutions > OPJ_J2K_MAXRLVLS) {
opj_event_msg(p_manager, EVT_ERROR,
"Invalid value for numresolutions : %d, max value is set in openjpeg.h at %d\n",
return OPJ_FALSE;
}
- opj_read_bytes(l_current_ptr, &l_tccp->cblkw, 1); /* SPcoc (E) */
+ /* SPcod (E) / SPcoc (B) */
+ opj_read_bytes(l_current_ptr, &l_tccp->cblkw, 1);
++l_current_ptr;
l_tccp->cblkw += 2;
- opj_read_bytes(l_current_ptr, &l_tccp->cblkh, 1); /* SPcoc (F) */
+ /* SPcod (F) / SPcoc (C) */
+ opj_read_bytes(l_current_ptr, &l_tccp->cblkh, 1);
++l_current_ptr;
l_tccp->cblkh += 2;
return OPJ_FALSE;
}
-
- opj_read_bytes(l_current_ptr, &l_tccp->cblksty, 1); /* SPcoc (G) */
+ /* SPcod (G) / SPcoc (D) */
+ opj_read_bytes(l_current_ptr, &l_tccp->cblksty, 1);
++l_current_ptr;
if (l_tccp->cblksty & 0xC0U) { /* 2 msb are reserved, assume we can't read */
opj_event_msg(p_manager, EVT_ERROR,
return OPJ_FALSE;
}
- opj_read_bytes(l_current_ptr, &l_tccp->qmfbid, 1); /* SPcoc (H) */
+ /* SPcod (H) / SPcoc (E) */
+ opj_read_bytes(l_current_ptr, &l_tccp->qmfbid, 1);
++l_current_ptr;
+ if (l_tccp->qmfbid > 1) {
+ opj_event_msg(p_manager, EVT_ERROR,
+ "Error reading SPCod SPCoc element, Invalid transformation found\n");
+ return OPJ_FALSE;
+ }
+
*p_header_size = *p_header_size - 5;
/* use custom precinct size ? */
return OPJ_FALSE;
}
+ /* SPcod (I_i) / SPcoc (F_i) */
for (i = 0; i < l_tccp->numresolutions; ++i) {
- opj_read_bytes(l_current_ptr, &l_tmp, 1); /* SPcoc (I_i) */
+ opj_read_bytes(l_current_ptr, &l_tmp, 1);
++l_current_ptr;
/* Precinct exponent 0 is only allowed for lowest resolution level (Table A.21) */
if ((i != 0) && (((l_tmp & 0xf) == 0) || ((l_tmp >> 4) == 0))) {