{PCRL, "PCRL"},
{RLCP, "RLCP"},
{RPCL, "RPCL"},
- {-1, ""}
+ {(OPJ_PROG_ORDER)-1, ""}
};
char *j2k_convert_progression_order(OPJ_PROG_ORDER prg_order){
return po->str_prog;
}
-static void j2k_check_poc_val(opj_cparameters_t *parameters, int numcomps, int numlayers){
- int* packet_array;
- int index, resno, compno, layno, i;
- int step_c = 1;
- int step_r = numcomps * step_c;
- int step_l = parameters->numresolution * step_r;
- bool loss = false;
- packet_array = (int*) opj_calloc(step_l * numlayers, sizeof(int));
-
- for (i = 0; i < parameters->numpocs ; i++) {
- int layno0 = 0;
- if(i > 0)
- layno0 = (parameters->POC[i].layno1 > parameters->POC[i-1].layno1 )? parameters->POC[i-1].layno1 : 0;
- for (resno = parameters->POC[i].resno0 ; resno < parameters->POC[i].resno1 ; resno++) {
- for (compno = parameters->POC[i].compno0 ; compno < parameters->POC[i].compno1 ; compno++) {
- for (layno = layno0; layno < parameters->POC[i].layno1 ; layno++) {
- index = step_r * resno + step_c * compno + step_l * layno;
- packet_array[index]= 1;
- }
- }
- }
- }
- for (resno = 0; resno < parameters->numresolution; resno++) {
- for (compno = 0; compno < numcomps; compno++) {
- for (layno = 0; layno < numlayers ; layno++) {
- index = step_r * resno + step_c * compno + step_l * layno;
- if(!( packet_array[index]== 1)){
- loss = true;
- }
- }
- }
- }
- if(loss)
- fprintf(stdout,"Missing packets possible loss of data\n");
- opj_free(packet_array);
-}
-
void j2k_dump_image(FILE *fd, opj_image_t * img) {
int compno;
fprintf(fd, "image {\n");
fprintf(fd, " comp %d {\n", compno);
fprintf(fd, " dx=%d, dy=%d\n", comp->dx, comp->dy);
fprintf(fd, " prec=%d\n", comp->prec);
+ //fprintf(fd, " bpp=%d\n", comp->bpp);
fprintf(fd, " sgnd=%d\n", comp->sgnd);
fprintf(fd, " }\n");
}
cp->tx0 = cio_read(cio, 4); /* XT0siz */
cp->ty0 = cio_read(cio, 4); /* YT0siz */
+ if ((image->x0<0)||(image->x1<0)||(image->y0<0)||(image->y1<0)) {
+ opj_event_msg(j2k->cinfo, EVT_ERROR,
+ "%s: invalid image size (x0:%d, x1:%d, y0:%d, y1:%d)\n",
+ image->x0,image->x1,image->y0,image->y1);
+ return;
+ }
+
image->numcomps = cio_read(cio, 2); /* Csiz */
#ifdef USE_JPWL
tccp->numresolutions = cio_read(cio, 1) + 1; /* SPcox (D) */
- /* check the reduce value */
- cp->reduce = int_min((tccp->numresolutions)-1, cp->reduce);
+ // If user wants to remove more resolutions than the codestream contains, return error
+ if (cp->reduce >= tccp->numresolutions) {
+ opj_event_msg(j2k->cinfo, EVT_ERROR, "Error decoding component %d.\nThe number of resolutions to remove is higher than the number "
+ "of resolutions of this component\nModify the cp_reduce parameter.\n\n", compno);
+ j2k->state |= J2K_STATE_ERR;
+ }
+
tccp->cblkw = cio_read(cio, 1) + 2; /* SPcox (E) */
tccp->cblkh = cio_read(cio, 1) + 2; /* SPcox (F) */
tccp->cblksty = cio_read(cio, 1); /* SPcox (G) */
tcp = &cp->tcps[j2k->curtileno];
for (layno = 0; layno < tcp->numlayers; layno++) {
- tcp->rates[layno] -= tcp->rates[layno] ? (j2k->sod_start / (cp->th * cp->tw)) : 0;
+ if (tcp->rates[layno]>(j2k->sod_start / (cp->th * cp->tw))) {
+ tcp->rates[layno]-=(j2k->sod_start / (cp->th * cp->tw));
+ } else if (tcp->rates[layno]) {
+ tcp->rates[layno]=1;
+ }
}
if(j2k->cur_tp_num == 0){
tcd->tcd_image->tiles->packno = 0;
truncate = 1; /* Case of a truncate codestream */
}
- data = (unsigned char *) opj_malloc((j2k->tile_len[curtileno] + len) * sizeof(unsigned char));
-
- for (i = 0; i < j2k->tile_len[curtileno]; i++) {
- data[i] = j2k->tile_data[curtileno][i];
- }
+ data = j2k->tile_data[curtileno];
+ data = (unsigned char*) opj_realloc(data, (j2k->tile_len[curtileno] + len) * sizeof(unsigned char));
data_ptr = data + j2k->tile_len[curtileno];
for (i = 0; i < len; i++) {
}
j2k->tile_len[curtileno] += len;
- opj_free(j2k->tile_data[curtileno]);
j2k->tile_data[curtileno] = data;
if (!truncate) {
static void j2k_read_eoc(opj_j2k_t *j2k) {
int i, tileno;
+ bool success;
/* if packets should be decoded */
if (j2k->cp->limit_decoding != DECODE_ALL_BUT_PACKETS) {
for (i = 0; i < j2k->cp->tileno_size; i++) {
tcd_malloc_decode_tile(tcd, j2k->image, j2k->cp, i, j2k->cstr_info);
tileno = j2k->cp->tileno[i];
- tcd_decode_tile(tcd, j2k->tile_data[tileno], j2k->tile_len[tileno], tileno, j2k->cstr_info);
+ success = tcd_decode_tile(tcd, j2k->tile_data[tileno], j2k->tile_len[tileno], tileno, j2k->cstr_info);
opj_free(j2k->tile_data[tileno]);
j2k->tile_data[tileno] = NULL;
tcd_free_decode_tile(tcd, i);
+ if (success == false) {
+ j2k->state |= J2K_STATE_ERR;
+ break;
+ }
}
tcd_free_decode(tcd);
tcd_destroy(tcd);
j2k->tile_data[tileno] = NULL;
}
}
- j2k->state = J2K_STATE_MT;
+ if (j2k->state & J2K_STATE_ERR)
+ j2k->state = J2K_STATE_MT + J2K_STATE_ERR;
+ else
+ j2k->state = J2K_STATE_MT;
}
typedef struct opj_dec_mstabent {
if (e->handler) {
(*e->handler)(j2k);
}
+ if (j2k->state & J2K_STATE_ERR)
+ return NULL;
+
if (j2k->state == J2K_STATE_MT) {
break;
}
if (parameters->numpocs) {
/* initialisation of POC */
tcp->POC = 1;
- j2k_check_poc_val(parameters, image->numcomps, tcp->numlayers);
for (i = 0; i < parameters->numpocs; i++) {
if((tileno == parameters->POC[i].tile - 1) || (parameters->POC[i].tile == -1)) {
opj_poc_t *tcp_poc = &tcp->pocs[numpocs_tile];
+