#define J2K_CCP_QNTSTY_SIQNT 1
#define J2K_CCP_QNTSTY_SEQNT 2
+#define OPJ_J2K_DEFAULT_CBLK_DATA_SIZE 8192
+
/* ----------------------------------------------------------------------- */
#define J2K_MS_SOC 0xff4f /**< SOC marker value */
opj_codestream_info_t *cstr_info)
{
OPJ_UINT32 bandno, cblkno;
- OPJ_BYTE *c = dest;
+ OPJ_BYTE* c = dest;
OPJ_UINT32 l_nb_bytes;
- OPJ_UINT32 compno = pi->compno; /* component value */
- OPJ_UINT32 resno = pi->resno; /* resolution level value */
- OPJ_UINT32 precno = pi->precno; /* precinct value */
- OPJ_UINT32 layno = pi->layno; /* quality layer value */
+ OPJ_UINT32 compno = pi->compno; /* component value */
+ OPJ_UINT32 resno = pi->resno; /* resolution level value */
+ OPJ_UINT32 precno = pi->precno; /* precinct value */
+ OPJ_UINT32 layno = pi->layno; /* quality layer value */
OPJ_UINT32 l_nb_blocks;
opj_tcd_band_t *band = 00;
opj_tcd_cblk_enc_t* cblk = 00;
if (!l_cblk->numsegs) {
l_seg = l_cblk->segs;
++l_cblk->numsegs;
- l_cblk->len = 0;
+ l_cblk->data_current_size = 0;
}
else {
l_seg = &l_cblk->segs[l_cblk->numsegs - 1];
};
#endif /* USE_JPWL */
-
- if ((l_cblk->len + l_seg->newlen) > 8192) {
+ /* Check if the cblk->data have allocated enough memory */
+ if ((l_cblk->data_current_size + l_seg->newlen) > l_cblk->data_max_size) {
+ OPJ_BYTE* new_cblk_data = (OPJ_BYTE*) opj_realloc(l_cblk->data, l_cblk->data_current_size + l_seg->newlen);
+ if(! new_cblk_data) {
+ opj_free(l_cblk->data);
+ l_cblk->data_max_size = 0;
+ /* opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to realloc code block cata!\n"); */
return OPJ_FALSE;
+ }
+ l_cblk->data_max_size = l_cblk->data_current_size + l_seg->newlen;
+ l_cblk->data = new_cblk_data;
}
- memcpy(l_cblk->data + l_cblk->len, l_current_data, l_seg->newlen);
+ memcpy(l_cblk->data + l_cblk->data_current_size, l_current_data, l_seg->newlen);
if (l_seg->numpasses == 0) {
l_seg->data = &l_cblk->data;
- l_seg->dataindex = l_cblk->len;
+ l_seg->dataindex = l_cblk->data_current_size;
}
l_current_data += l_seg->newlen;
l_cblk->numnewpasses -= l_seg->numnewpasses;
l_seg->real_num_passes = l_seg->numpasses;
- l_cblk->len += l_seg->newlen;
+ l_cblk->data_current_size += l_seg->newlen;
l_seg->len += l_seg->newlen;
if (l_cblk->numnewpasses > 0) {
l_cblk->real_num_segs = l_cblk->numsegs;
++l_cblk;
- }
+ } /* next code_block */
++l_band;
}
if (!l_cblk->numsegs) {
l_seg = l_cblk->segs;
++l_cblk->numsegs;
- l_cblk->len = 0;
+ l_cblk->data_current_size = 0;
}
else {
l_seg = &l_cblk->segs[l_cblk->numsegs - 1];
{
if (! p_code_block->data) {
- p_code_block->data = (OPJ_BYTE*) opj_malloc(8192+1);
+ p_code_block->data = (OPJ_BYTE*) opj_malloc(OPJ_J2K_DEFAULT_CBLK_DATA_SIZE); //why +1 ?
if(! p_code_block->data) {
return OPJ_FALSE;
}
if (! p_code_block->data) {
- p_code_block->data = (OPJ_BYTE*) opj_malloc(8192);
+ p_code_block->data = (OPJ_BYTE*) opj_malloc(OPJ_J2K_DEFAULT_CBLK_DATA_SIZE);
if (! p_code_block->data) {
return OPJ_FALSE;
}
+ p_code_block->data_max_size = OPJ_J2K_DEFAULT_CBLK_DATA_SIZE;
/*fprintf(stderr, "Allocate 8192 elements of code_block->data\n");*/
l_seg_size = OPJ_J2K_DEFAULT_NB_SEGS * sizeof(opj_tcd_seg_t);
/*--------------TIER2------------------*/
/* FIXME _ProfStart(PGROUP_T2); */
l_data_read = 0;
- if
- (! opj_tcd_t2_decode(p_tcd, p_src, &l_data_read, p_max_length, p_cstr_index))
+ if (! opj_tcd_t2_decode(p_tcd, p_src, &l_data_read, p_max_length, p_cstr_index))
{
return OPJ_FALSE;
}
for (cblkno = 0; cblkno < l_nb_code_blocks; ++cblkno) {
if (l_code_block->data) {
- opj_free(l_code_block->data-1);
+ opj_free(l_code_block->data);
l_code_block->data = 00;
}
typedef struct opj_tcd_cblk_dec {
OPJ_BYTE * data; /* Data */
opj_tcd_seg_t* segs; /* segments information */
- OPJ_INT32 x0, y0, x1, y1; /* dimension of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */
+ OPJ_INT32 x0, y0, x1, y1; /* position of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */
OPJ_UINT32 numbps;
OPJ_UINT32 numlenbits;
- OPJ_UINT32 len; /* length */
+ OPJ_UINT32 data_max_size; /* Size of allocated data buffer */
+ OPJ_UINT32 data_current_size; /* Size of used data buffer */
OPJ_UINT32 numnewpasses; /* number of pass added to the code-blocks */
OPJ_UINT32 numsegs; /* number of segments */
OPJ_UINT32 real_num_segs;
opj_compress -i @INPUT_NR_PATH@/Cevennes1.bmp -o @TEMP_PATH@/Cevennes1.j2k -r 10
opj_compress -i @INPUT_NR_PATH@/Cevennes2.ppm -o @TEMP_PATH@/Cevennes2.jp2 -r 50
opj_compress -i @INPUT_NR_PATH@/Rome.bmp -o @TEMP_PATH@/Rome.jp2 -q 30,35,50 -p LRCP -n 3
+# related to issue 5
+opj_compress -i @INPUT_NR_PATH@/random.tif -o @TEMP_PATH@/random.tif.j2k
+# related to issue 62
+opj_compress -i @INPUT_NR_PATH@/tmp.raw -o @TEMP_PATH@/tmp.raw.j2k -F 512,512,1,16,u
opj_compress -i @INPUT_NR_PATH@/X_4_2K_24_185_CBR_WB_000.tif -o @TEMP_PATH@/X_4_2K_24_185_CBR_WB_000.j2k -cinema2K 24
opj_compress -i @INPUT_NR_PATH@/X_5_2K_24_235_CBR_STEM24_000.tif -o @TEMP_PATH@/X_5_2K_24_235_CBR_STEM24_000.j2k -cinema2K 24
opj_compress -i @INPUT_NR_PATH@/X_6_2K_24_FULL_CBR_CIRCLE_000.tif -o @TEMP_PATH@/X_6_2K_24_FULL_CBR_CIRCLE_000.j2k -cinema2K 24