Alien-FreeImage
view release on metacpan or search on metacpan
src/Source/LibOpenJPEG/t2.c view on Meta::CPAN
for (passno = cblk->numpasses; passno < l_nb_passes; ++passno) {
++nump;
len += pass->len;
if (pass->term || passno == (cblk->numpasses + layer->numpasses) - 1) {
increment = (OPJ_UINT32)opj_int_max((OPJ_INT32)increment, opj_int_floorlog2((OPJ_INT32)len) + 1
- ((OPJ_INT32)cblk->numlenbits + opj_int_floorlog2((OPJ_INT32)nump)));
len = 0;
nump = 0;
}
++pass;
}
opj_t2_putcommacode(bio, (OPJ_INT32)increment);
/* computation of the new Length indicator */
cblk->numlenbits += increment;
pass = cblk->passes + cblk->numpasses;
/* insertion of the codeword segment length */
for (passno = cblk->numpasses; passno < l_nb_passes; ++passno) {
nump++;
len += pass->len;
if (pass->term || passno == (cblk->numpasses + layer->numpasses) - 1) {
opj_bio_write(bio, (OPJ_UINT32)len, cblk->numlenbits + (OPJ_UINT32)opj_int_floorlog2((OPJ_INT32)nump));
len = 0;
nump = 0;
}
++pass;
}
++cblk;
}
++band;
}
if (!opj_bio_flush(bio)) {
opj_bio_destroy(bio);
return OPJ_FALSE; /* modified to eliminate longjmp !! */
}
l_nb_bytes = (OPJ_UINT32)opj_bio_numbytes(bio);
c += l_nb_bytes;
length -= l_nb_bytes;
opj_bio_destroy(bio);
/* <EPH 0xff92> */
if (tcp->csty & J2K_CP_CSTY_EPH) {
c[0] = 255;
c[1] = 146;
c += 2;
length -= 2;
}
/* </EPH> */
/* << INDEX */
/* End of packet header position. Currently only represents the distance to start of packet
Will be updated later by incrementing with packet start value*/
if(cstr_info && cstr_info->index_write) {
opj_packet_info_t *info_PK = &cstr_info->tile[tileno].packet[cstr_info->packno];
info_PK->end_ph_pos = (OPJ_INT32)(c - dest);
}
/* INDEX >> */
/* Writing the packet body */
band = res->bands;
for (bandno = 0; bandno < res->numbands; bandno++) {
opj_tcd_precinct_t *prc = &band->precincts[precno];
l_nb_blocks = prc->cw * prc->ch;
cblk = prc->cblks.enc;
for (cblkno = 0; cblkno < l_nb_blocks; ++cblkno) {
opj_tcd_layer_t *layer = &cblk->layers[layno];
if (!layer->numpasses) {
++cblk;
continue;
}
if (layer->len > length) {
return OPJ_FALSE;
}
memcpy(c, layer->data, layer->len);
cblk->numpasses += layer->numpasses;
c += layer->len;
length -= layer->len;
/* << INDEX */
if(cstr_info && cstr_info->index_write) {
opj_packet_info_t *info_PK = &cstr_info->tile[tileno].packet[cstr_info->packno];
info_PK->disto += layer->disto;
if (cstr_info->D_max < info_PK->disto) {
cstr_info->D_max = info_PK->disto;
}
}
++cblk;
/* INDEX >> */
}
++band;
}
assert( c >= dest );
* p_data_written += (OPJ_UINT32)(c - dest);
return OPJ_TRUE;
}
static OPJ_BOOL opj_t2_skip_packet( opj_t2_t* p_t2,
opj_tcd_tile_t *p_tile,
opj_tcp_t *p_tcp,
opj_pi_iterator_t *p_pi,
OPJ_BYTE *p_src,
OPJ_UINT32 * p_data_read,
OPJ_UINT32 p_max_length,
opj_packet_info_t *p_pack_info)
src/Source/LibOpenJPEG/t2.c view on Meta::CPAN
/** TODO : check the Nsop value */
}
/*
When the marker PPT/PPM is used the packet header are store in PPT/PPM marker
This part deal with this caracteristic
step 1: Read packet header in the saved structure
step 2: Return to codestream for decoding
*/
l_bio = opj_bio_create();
if (! l_bio) {
return OPJ_FALSE;
}
if (l_cp->ppm == 1) { /* PPM */
l_header_data_start = &l_cp->ppm_data;
l_header_data = *l_header_data_start;
l_modified_length_ptr = &(l_cp->ppm_len);
}
else if (p_tcp->ppt == 1) { /* PPT */
l_header_data_start = &(p_tcp->ppt_data);
l_header_data = *l_header_data_start;
l_modified_length_ptr = &(p_tcp->ppt_len);
}
else { /* Normal Case */
l_header_data_start = &(l_current_data);
l_header_data = *l_header_data_start;
l_remaining_length = (OPJ_UINT32)(p_src_data+p_max_length-l_header_data);
l_modified_length_ptr = &(l_remaining_length);
}
opj_bio_init_dec(l_bio, l_header_data,*l_modified_length_ptr);
l_present = opj_bio_read(l_bio, 1);
JAS_FPRINTF(stderr, "present=%d \n", l_present );
if (!l_present) {
/* TODO MSD: no test to control the output of this function*/
opj_bio_inalign(l_bio);
l_header_data += opj_bio_numbytes(l_bio);
opj_bio_destroy(l_bio);
/* EPH markers */
if (p_tcp->csty & J2K_CP_CSTY_EPH) {
if (p_max_length < 2) {
fprintf(stderr, "Not enough space for expected EPH marker\n");
} else if ((*l_header_data) != 0xff || (*(l_header_data + 1) != 0x92)) {
fprintf(stderr, "Error : expected EPH marker\n");
} else {
l_header_data += 2;
}
}
l_header_length = (OPJ_UINT32)(l_header_data - *l_header_data_start);
*l_modified_length_ptr -= l_header_length;
*l_header_data_start += l_header_length;
/* << INDEX */
/* End of packet header position. Currently only represents the distance to start of packet
Will be updated later by incrementing with packet start value */
if (p_pack_info) {
p_pack_info->end_ph_pos = (OPJ_INT32)(l_current_data - p_src_data);
}
/* INDEX >> */
* p_is_data_present = OPJ_FALSE;
*p_data_read = (OPJ_UINT32)(l_current_data - p_src_data);
return OPJ_TRUE;
}
l_band = l_res->bands;
for (bandno = 0; bandno < l_res->numbands; ++bandno) {
opj_tcd_precinct_t *l_prc = &(l_band->precincts[p_pi->precno]);
if ((l_band->x1-l_band->x0 == 0)||(l_band->y1-l_band->y0 == 0)) {
++l_band;
continue;
}
l_nb_code_blocks = l_prc->cw * l_prc->ch;
l_cblk = l_prc->cblks.dec;
for (cblkno = 0; cblkno < l_nb_code_blocks; cblkno++) {
OPJ_UINT32 l_included,l_increment, l_segno;
OPJ_INT32 n;
/* if cblk not yet included before --> inclusion tagtree */
if (!l_cblk->numsegs) {
l_included = opj_tgt_decode(l_bio, l_prc->incltree, cblkno, (OPJ_INT32)(p_pi->layno + 1));
/* else one bit */
}
else {
l_included = opj_bio_read(l_bio, 1);
}
/* if cblk not included */
if (!l_included) {
l_cblk->numnewpasses = 0;
++l_cblk;
JAS_FPRINTF(stderr, "included=%d \n", l_included);
continue;
}
/* if cblk not yet included --> zero-bitplane tagtree */
if (!l_cblk->numsegs) {
OPJ_UINT32 i = 0;
while (!opj_tgt_decode(l_bio, l_prc->imsbtree, cblkno, (OPJ_INT32)i)) {
++i;
}
l_cblk->numbps = (OPJ_UINT32)l_band->numbps + 1 - i;
l_cblk->numlenbits = 3;
}
/* number of coding passes */
l_cblk->numnewpasses = opj_t2_getnumpasses(l_bio);
l_increment = opj_t2_getcommacode(l_bio);
/* length indicator increment */
l_cblk->numlenbits += l_increment;
src/Source/LibOpenJPEG/t2.c view on Meta::CPAN
if (l_cblk->segs[l_segno].numpasses == l_cblk->segs[l_segno].maxpasses) {
++l_segno;
if (! opj_t2_init_seg(l_cblk, l_segno, p_tcp->tccps[p_pi->compno].cblksty, 0)) {
opj_bio_destroy(l_bio);
return OPJ_FALSE;
}
}
}
n = (OPJ_INT32)l_cblk->numnewpasses;
do {
l_cblk->segs[l_segno].numnewpasses = (OPJ_UINT32)opj_int_min((OPJ_INT32)(l_cblk->segs[l_segno].maxpasses - l_cblk->segs[l_segno].numpasses), n);
l_cblk->segs[l_segno].newlen = opj_bio_read(l_bio, l_cblk->numlenbits + opj_uint_floorlog2(l_cblk->segs[l_segno].numnewpasses));
JAS_FPRINTF(stderr, "included=%d numnewpasses=%d increment=%d len=%d \n", l_included, l_cblk->segs[l_segno].numnewpasses, l_increment, l_cblk->segs[l_segno].newlen );
n -= (OPJ_INT32)l_cblk->segs[l_segno].numnewpasses;
if (n > 0) {
++l_segno;
if (! opj_t2_init_seg(l_cblk, l_segno, p_tcp->tccps[p_pi->compno].cblksty, 0)) {
opj_bio_destroy(l_bio);
return OPJ_FALSE;
}
}
} while (n > 0);
++l_cblk;
}
++l_band;
}
if (!opj_bio_inalign(l_bio)) {
opj_bio_destroy(l_bio);
return OPJ_FALSE;
}
l_header_data += opj_bio_numbytes(l_bio);
opj_bio_destroy(l_bio);
/* EPH markers */
if (p_tcp->csty & J2K_CP_CSTY_EPH) {
if (p_max_length < 2) {
fprintf(stderr, "Not enough space for expected EPH marker\n");
} else if ((*l_header_data) != 0xff || (*(l_header_data + 1) != 0x92)) {
/* TODO opj_event_msg(t2->cinfo->event_mgr, EVT_ERROR, "Expected EPH marker\n"); */
fprintf(stderr, "Error : expected EPH marker\n");
} else {
l_header_data += 2;
}
}
l_header_length = (OPJ_UINT32)(l_header_data - *l_header_data_start);
JAS_FPRINTF( stderr, "hdrlen=%d \n", l_header_length );
JAS_FPRINTF( stderr, "packet body\n");
*l_modified_length_ptr -= l_header_length;
*l_header_data_start += l_header_length;
/* << INDEX */
/* End of packet header position. Currently only represents the distance to start of packet
Will be updated later by incrementing with packet start value */
if (p_pack_info) {
p_pack_info->end_ph_pos = (OPJ_INT32)(l_current_data - p_src_data);
}
/* INDEX >> */
*p_is_data_present = OPJ_TRUE;
*p_data_read = (OPJ_UINT32)(l_current_data - p_src_data);
return OPJ_TRUE;
}
OPJ_BOOL opj_t2_read_packet_data( opj_t2_t* p_t2,
opj_tcd_tile_t *p_tile,
opj_pi_iterator_t *p_pi,
OPJ_BYTE *p_src_data,
OPJ_UINT32 * p_data_read,
OPJ_UINT32 p_max_length,
opj_packet_info_t *pack_info)
{
OPJ_UINT32 bandno, cblkno;
OPJ_UINT32 l_nb_code_blocks;
OPJ_BYTE *l_current_data = p_src_data;
opj_tcd_band_t *l_band = 00;
opj_tcd_cblk_dec_t* l_cblk = 00;
opj_tcd_resolution_t* l_res = &p_tile->comps[p_pi->compno].resolutions[p_pi->resno];
OPJ_ARG_NOT_USED(p_t2);
OPJ_ARG_NOT_USED(pack_info);
l_band = l_res->bands;
for (bandno = 0; bandno < l_res->numbands; ++bandno) {
opj_tcd_precinct_t *l_prc = &l_band->precincts[p_pi->precno];
if ((l_band->x1-l_band->x0 == 0)||(l_band->y1-l_band->y0 == 0)) {
++l_band;
continue;
}
l_nb_code_blocks = l_prc->cw * l_prc->ch;
l_cblk = l_prc->cblks.dec;
for (cblkno = 0; cblkno < l_nb_code_blocks; ++cblkno) {
opj_tcd_seg_t *l_seg = 00;
if (!l_cblk->numnewpasses) {
/* nothing to do */
++l_cblk;
continue;
}
if (!l_cblk->numsegs) {
l_seg = l_cblk->segs;
++l_cblk->numsegs;
l_cblk->data_current_size = 0;
}
else {
l_seg = &l_cblk->segs[l_cblk->numsegs - 1];
if (l_seg->numpasses == l_seg->maxpasses) {
++l_seg;
( run in 0.306 second using v1.01-cache-2.11-cpan-fa01517f264 )