Alien-FreeImage

 view release on metacpan or  search on metacpan

src/Source/LibOpenJPEG/t2.c  view on Meta::CPAN

                                    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;
                                        ++l_cblk->numsegs;
                                }
                        }

                        do {
                                if (l_current_data + l_seg->newlen > p_src_data + p_max_length) {
                                        fprintf(stderr, "read: segment too long (%d) with max (%d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n",
                                                l_seg->newlen, p_max_length, cblkno, p_pi->precno, bandno, p_pi->resno, p_pi->compno);
                                        return OPJ_FALSE;
                                }

#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 ((l_cblk->len + l_seg->newlen) > 8192) {
                                        opj_event_msg(p_t2->cinfo, EVT_WARNING,
                                                "JPWL: segment too long (%d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n",
                                                l_seg->newlen, cblkno, p_pi->precno, bandno, p_pi->resno, p_pi->compno);
                                        if (!JPWL_ASSUME) {
                                                opj_event_msg(p_t2->cinfo, EVT_ERROR, "JPWL: giving up\n");
                                                return OPJ_FALSE;
                                        }
                                        l_seg->newlen = 8192 - l_cblk->len;
                                        opj_event_msg(p_t2->cinfo, EVT_WARNING, "      - truncating segment to %d\n", l_seg->newlen);
                                        break;
                                };

#endif /* USE_JPWL */
                                /* 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->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->data_current_size;
                                }

                                l_current_data += l_seg->newlen;
                                l_seg->numpasses += l_seg->numnewpasses;
                                l_cblk->numnewpasses -= l_seg->numnewpasses;

                                l_seg->real_num_passes = l_seg->numpasses;
                                l_cblk->data_current_size += l_seg->newlen;
                                l_seg->len += l_seg->newlen;

                                if (l_cblk->numnewpasses > 0) {
                                        ++l_seg;
                                        ++l_cblk->numsegs;
                                }
                        } while (l_cblk->numnewpasses > 0);

                        l_cblk->real_num_segs = l_cblk->numsegs;
                        ++l_cblk;
                } /* next code_block */

                ++l_band;
        }

        *(p_data_read) = (OPJ_UINT32)(l_current_data - p_src_data);

src/Source/LibOpenJPEG/t2.c  view on Meta::CPAN

                                    opj_tcd_tile_t *p_tile,
                                    opj_pi_iterator_t *p_pi,
                                    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_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);

        *p_data_read = 0;
        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;
                                        ++l_cblk->numsegs;
                                }
                        }

                        do {
                                if (* p_data_read + l_seg->newlen > p_max_length) {
                                        fprintf(stderr, "skip: segment too long (%d) with max (%d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n",
                                                l_seg->newlen, p_max_length, cblkno, p_pi->precno, bandno, p_pi->resno, p_pi->compno);
                                        return OPJ_FALSE;
                                }

#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 ((l_cblk->len + l_seg->newlen) > 8192) {
                                        opj_event_msg(p_t2->cinfo, EVT_WARNING,
                                                "JPWL: segment too long (%d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n",
                                                l_seg->newlen, cblkno, p_pi->precno, bandno, p_pi->resno, p_pi->compno);
                                        if (!JPWL_ASSUME) {
                                                opj_event_msg(p_t2->cinfo, EVT_ERROR, "JPWL: giving up\n");
                                                return -999;
                                        }
                                        l_seg->newlen = 8192 - l_cblk->len;
                                        opj_event_msg(p_t2->cinfo, EVT_WARNING, "      - truncating segment to %d\n", l_seg->newlen);
                                        break;
                                };

#endif /* USE_JPWL */
                                        JAS_FPRINTF(stderr, "p_data_read (%d) newlen (%d) \n", *p_data_read, l_seg->newlen );
                                *(p_data_read) += l_seg->newlen;

                                l_seg->numpasses += l_seg->numnewpasses;
                                l_cblk->numnewpasses -= l_seg->numnewpasses;
                                if (l_cblk->numnewpasses > 0)
                                {
                                        ++l_seg;
                                        ++l_cblk->numsegs;
                                }
                        } while (l_cblk->numnewpasses > 0);

                        ++l_cblk;
                }

                ++l_band;
        }

        return OPJ_TRUE;
}


OPJ_BOOL opj_t2_init_seg(   opj_tcd_cblk_dec_t* cblk,
                            OPJ_UINT32 index, 
                            OPJ_UINT32 cblksty, 
                            OPJ_UINT32 first)
{
        opj_tcd_seg_t* seg = 00;
        OPJ_UINT32 l_nb_segs = index + 1;

        if (l_nb_segs > cblk->m_current_max_segs) {
                opj_tcd_seg_t* new_segs;
                cblk->m_current_max_segs += OPJ_J2K_DEFAULT_NB_SEGS;

                new_segs = (opj_tcd_seg_t*) opj_realloc(cblk->segs, cblk->m_current_max_segs * sizeof(opj_tcd_seg_t));
                if(! new_segs) {
                        opj_free(cblk->segs);
                        cblk->segs = NULL;
                        cblk->m_current_max_segs = 0;
                        /* opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to initialize segment %d\n", l_nb_segs); */
                        return OPJ_FALSE;
                }
                cblk->segs = new_segs;



( run in 0.536 second using v1.01-cache-2.11-cpan-119454b85a5 )