X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libopenjpeg%2Ft2.c;h=3e6f0e7b5e8751f0cbabd7f3f19fcc7e37b7cad8;hb=f7c9b01800446213919cac9246c9bd66eb3701ad;hp=d9336ee14054d9e2adf5459340a3b8a96e839b95;hpb=6a4572a56fe69583c68b8330c527ac346e2402fc;p=openjpeg.git diff --git a/libopenjpeg/t2.c b/libopenjpeg/t2.c index d9336ee1..3e6f0e7b 100644 --- a/libopenjpeg/t2.c +++ b/libopenjpeg/t2.c @@ -1,9 +1,10 @@ /* + * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2007, Professor Benoit Macq * Copyright (c) 2001-2003, David Janssens * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe - * Copyright (c) 2005, Hervé Drolon, FreeImage Team - * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium + * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -268,7 +269,7 @@ static int t2_encode_packet(opj_tcd_tile_t * tile, opj_tcp_t * tcp, opj_pi_itera if (!layer->numpasses) { continue; } - if (c + layer->len > dest + len) { + if (c + layer->len > dest + length) { return -999; } @@ -519,6 +520,25 @@ static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_t if (c + seg->newlen > src + len) { return -999; } + +/* UniPG>> */ +#ifdef USE_JPWL + /* we need here a j2k handle to verify if making a check to + the validity of cblocks parameters is selected from user (-W) */ + + /* let's check that we are not exceeding */ + if ((cblk->len + seg->newlen) > 8192) { + fprintf(stderr, "JPWL: segment too long (%d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n", + seg->newlen, cblkno, precno, bandno, resno, compno); + if (!JPWL_ASSUME) + exit(-1); + seg->newlen = 8192 - cblk->len; + fprintf(stderr, " - truncating segment to %d\n", seg->newlen); + break; + }; + +#endif /* USE_JPWL */ +/* <data + cblk->len, c, seg->newlen); if (seg->numpasses == 0) { @@ -542,59 +562,59 @@ static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_t /* ----------------------------------------------------------------------- */ -int t2_encode_packets(opj_t2_t* t2, int tileno, opj_tcd_tile_t *tile, int maxlayers, unsigned char *dest, int len, opj_image_info_t *image_info) { +int t2_encode_packets(opj_t2_t* t2,int tileno, opj_tcd_tile_t *tile, int maxlayers, unsigned char *dest, int len, opj_image_info_t *image_info,opj_pi_iterator_t *tcd_pi,int tpnum, int tppos,int pino, char final_encoding){ unsigned char *c = dest; int e = 0; opj_pi_iterator_t *pi = NULL; - int pino; opj_image_t *image = t2->image; opj_cp_t *cp = t2->cp; - - /* create a packet iterator */ - pi = pi_create(image, cp, tileno); + + if(final_encoding == 0){ + pi = pi_initialise_encode(image, cp, tileno,pino); + }else{ + pi = tcd_pi; + } if(!pi) { /* TODO: throw an error */ return -999; } + pi_create_encode(pi, cp,tileno,pino,tpnum,tppos,final_encoding); + if(image_info) { image_info->num = 0; } - - for (pino = 0; pino <= cp->tcps[tileno].numpocs; pino++) { - while (pi_next(&pi[pino])) { - if (pi[pino].layno < maxlayers) { - e = t2_encode_packet(tile, &cp->tcps[tileno], &pi[pino], c, dest + len - c, image_info, tileno); - if (e == -999) { - break; - } else { - c += e; - } - - /* INDEX >> */ - if(image_info && image_info->index_on) { - if(image_info->index_write) { - opj_tile_info_t *info_TL = &image_info->tile[tileno]; - opj_packet_info_t *info_PK = &info_TL->packet[image_info->num]; - if (!image_info->num) { - info_PK->start_pos = info_TL->end_header + 1; - } else { - info_PK->start_pos = info_TL->packet[image_info->num - 1].end_pos + 1; - } - info_PK->end_pos = info_PK->start_pos + e - 1; - } - image_info->num++; + while (pi_next(&pi[pino])) { + if (pi[pino].layno < maxlayers) { + e = t2_encode_packet(tile, &cp->tcps[tileno], &pi[pino], c, dest + len - c, image_info, tileno); + if (e == -999) { + break; + } else { + c += e; + } + /* INDEX >> */ + if(image_info && image_info->index_on) { + if(image_info->index_write) { + opj_tile_info_t *info_TL = &image_info->tile[tileno]; + opj_packet_info_t *info_PK = &info_TL->packet[image_info->num]; + if (!image_info->num) { + info_PK->start_pos = info_TL->end_header + 1; + } else { + info_PK->start_pos = info_TL->packet[image_info->num - 1].end_pos + 1; + } + info_PK->end_pos = info_PK->start_pos + e - 1; } - /* << INDEX */ + + image_info->num++; } + /* << INDEX */ } } - - /* don't forget to release pi */ - pi_destroy(pi, cp, tileno); - + if(final_encoding == 0){ + pi_destroy(pi, cp, tileno); + } if (e == -999) { return e; } @@ -612,7 +632,7 @@ int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj opj_cp_t *cp = t2->cp; /* create a packet iterator */ - pi = pi_create(image, cp, tileno); + pi = pi_create_decode(image, cp, tileno); if(!pi) { /* TODO: throw an error */ return -999;