/*
- * $Id: index_manager.c 53 2011-05-09 16:55:39Z kaori $
+ * $Id$
*
- * Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
- * Copyright (c) 2002-2011, Professor Benoit Macq
+ * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
+ * Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2010-2011, Kaori Hagihara
* All rights reserved.
*
#include <math.h>
#include <string.h>
-#include "bool.h"
#include "opj_inttypes.h"
#include "index_manager.h"
#include "box_manager.h"
* @param[in] toplev_boxlist top level box list
* @return if correct (true) or wrong (false)
*/
-bool check_JP2boxidx( boxlist_param_t *toplev_boxlist);
+OPJ_BOOL check_JP2boxidx( boxlist_param_t *toplev_boxlist);
/**
* set code index parameters (parse cidx box)
* @param[out] codeidx pointer to index parameters
* @return if succeeded (true) or failed (false)
*/
-bool set_cidxdata( box_param_t *cidx_box, index_param_t *codeidx);
+OPJ_BOOL set_cidxdata( box_param_t *cidx_box, index_param_t *codeidx);
index_param_t * parse_jp2file( int fd)
{
return NULL;
}
- jp2idx = (index_param_t *)malloc( sizeof(index_param_t));
+ jp2idx = (index_param_t *)opj_malloc( sizeof(index_param_t));
if( !set_cidxdata( cidx, jp2idx)){
fprintf( FCGI_stderr, "Error: Not correctl format in cidx box\n");
- free(jp2idx);
+ opj_free(jp2idx);
delete_boxlist( &toplev_boxlist);
return NULL;
}
for( i=0; i< (int)((*index)->SIZ.XTnum*(*index)->SIZ.YTnum);i++)
delete_mhixbox( &((*index)->tileheader[i]));
- free( (*index)->tileheader);
+ opj_free( (*index)->tileheader);
for( i=0; i<(*index)->SIZ.Csiz; i++)
delete_faixbox( &((*index)->precpacket[i]));
- free( (*index)->precpacket);
+ opj_free( (*index)->precpacket);
- free(*index);
+ opj_free(*index);
}
void delete_COD( CODmarker_param_t COD)
{
- if( COD.XPsiz) free( COD.XPsiz);
- if( COD.YPsiz) free( COD.YPsiz);
+ if( COD.XPsiz) opj_free( COD.XPsiz);
+ if( COD.YPsiz) opj_free( COD.YPsiz);
}
-bool check_JP2boxidx( boxlist_param_t *toplev_boxlist)
+OPJ_BOOL check_JP2boxidx( boxlist_param_t *toplev_boxlist)
{
box_param_t *iptr, *fidx, *prxy;
box_param_t *cidx, *jp2c;
if( obh->length != jp2c->length || strncmp( obh->type, "jp2c",4)!=0)
fprintf( FCGI_stderr, "Reference jp2c header in prxy box not correct\n");
pos += obh->headlen;
- free(obh);
+ opj_free(obh);
ni = fetch_DBox1byte( prxy, pos);
if( ni != 1){
fprintf( FCGI_stderr, "Multiple indexes not supported\n");
- return false;
+ return OPJ_FALSE;
}
pos += 1;
if( ibh->length != cidx->length || strncmp( ibh->type, "cidx",4)!=0)
fprintf( FCGI_stderr, "Reference cidx header in prxy box not correct\n");
pos += ibh->headlen;
- free(ibh);
+ opj_free(ibh);
- free(prxy);
+ opj_free(prxy);
- return true;
+ return OPJ_TRUE;
}
/**
* @param[out] jp2idx pointer to index parameters
* @return if succeeded (true) or failed (false)
*/
-bool set_cptrdata( box_param_t *cidx_box, index_param_t *jp2idx);
+OPJ_BOOL set_cptrdata( box_param_t *cidx_box, index_param_t *jp2idx);
/**
* set code index parameters from mhix box for main header
* @param[out] jp2idx pointer to index parameters
* @return if succeeded (true) or failed (false)
*/
-bool set_mainmhixdata( box_param_t *cidx_box, codestream_param_t codestream, index_param_t *jp2idx);
+OPJ_BOOL set_mainmhixdata( box_param_t *cidx_box, codestream_param_t codestream, index_param_t *jp2idx);
/**
* set code index parameters from tpix box
* @param[out] jp2idx pointer to index parameters
* @return if succeeded (true) or failed (false)
*/
-bool set_tpixdata( box_param_t *cidx_box, index_param_t *jp2idx);
+OPJ_BOOL set_tpixdata( box_param_t *cidx_box, index_param_t *jp2idx);
/**
* set code index parameters from thix box
* @param[out] jp2idx pointer to index parameters
* @return if succeeded (true) or failed (false)
*/
-bool set_thixdata( box_param_t *cidx_box, index_param_t *jp2idx);
+OPJ_BOOL set_thixdata( box_param_t *cidx_box, index_param_t *jp2idx);
/**
* set code index parameters from ppix box
* @param[out] jp2idx pointer to index parameters
* @return if succeeded (true) or failed (false)
*/
-bool set_ppixdata( box_param_t *cidx_box, index_param_t *jp2idx);
+OPJ_BOOL set_ppixdata( box_param_t *cidx_box, index_param_t *jp2idx);
-bool set_cidxdata( box_param_t *cidx_box, index_param_t *jp2idx)
+OPJ_BOOL set_cidxdata( box_param_t *cidx_box, index_param_t *jp2idx)
{
box_param_t *manf_box;
manfbox_param_t *manf;
if( !search_boxheader( "mhix", manf)){
fprintf( FCGI_stderr, "Error: mhix box not present in manfbox\n");
- free(jp2idx);
- return false;
+ opj_free(jp2idx);
+ return OPJ_FALSE;
}
set_mainmhixdata( cidx_box, codestream, jp2idx);
if( !search_boxheader( "tpix", manf)){
fprintf( FCGI_stderr, "Error: tpix box not present in manfbox\n");
- free(jp2idx);
- return false;
+ opj_free(jp2idx);
+ return OPJ_FALSE;
}
set_tpixdata( cidx_box, jp2idx);
if( !search_boxheader( "thix", manf)){
fprintf( FCGI_stderr, "Error: thix box not present in manfbox\n");
- free(jp2idx);
- return false;
+ opj_free(jp2idx);
+ return OPJ_FALSE;
}
set_thixdata( cidx_box, jp2idx);
if( !search_boxheader( "ppix", manf)){
fprintf( FCGI_stderr, "Error: ppix box not present in manfbox\n");
- free(jp2idx);
- return false;
+ opj_free(jp2idx);
+ return OPJ_FALSE;
}
set_ppixdata( cidx_box, jp2idx);
delete_manfbox( &manf);
- free( manf_box);
+ opj_free( manf_box);
- return true;
+ return OPJ_TRUE;
}
-bool set_cptrdata( box_param_t *cidx_box, index_param_t *jp2idx)
+OPJ_BOOL set_cptrdata( box_param_t *cidx_box, index_param_t *jp2idx)
{
box_param_t *box; /**< cptr box*/
Byte2_t dr, cont;
if( !(box = gene_boxbyType( cidx_box->fd, get_DBoxoff( cidx_box), get_DBoxlen( cidx_box), "cptr")))
- return false;
+ return OPJ_FALSE;
/* DR: Data Reference. */
/* If 0, the codestream or its Fragment Table box exists in the current file*/
if(( dr = fetch_DBox2bytebigendian( box, 0))){
fprintf( FCGI_stderr, "Error: Codestream not present in current file\n");
- free( box);
- return false;
+ opj_free( box);
+ return OPJ_FALSE;
}
/* CONT: Container Type*/
/* bytes within its file or resource.*/
if(( cont = fetch_DBox2bytebigendian( box, 2))){
fprintf( FCGI_stderr, "Error: Can't cope with fragmented codestreams yet\n");
- free( box);
- return false;
+ opj_free( box);
+ return OPJ_FALSE;
}
jp2idx->offset = (OPJ_OFF_T)fetch_DBox8bytebigendian( box, 4);
jp2idx->length = fetch_DBox8bytebigendian( box, 12);
- free( box);
+ opj_free( box);
- return true;
+ return OPJ_TRUE;
}
* @param[out] SIZ SIZ marker parameters pointer
* @return if succeeded (true) or failed (false)
*/
-bool set_SIZmkrdata( markeridx_param_t *sizmkidx, codestream_param_t codestream, SIZmarker_param_t *SIZ);
+OPJ_BOOL set_SIZmkrdata( markeridx_param_t *sizmkidx, codestream_param_t codestream, SIZmarker_param_t *SIZ);
/**
* set code index parameters from COD marker in codestream
* @param[out] COD COD marker parameters pointer
* @return if succeeded (true) or failed (false)
*/
-bool set_CODmkrdata( markeridx_param_t *codmkidx, codestream_param_t codestream, CODmarker_param_t *COD);
+OPJ_BOOL set_CODmkrdata( markeridx_param_t *codmkidx, codestream_param_t codestream, CODmarker_param_t *COD);
-bool set_mainmhixdata( box_param_t *cidx_box, codestream_param_t codestream, index_param_t *jp2idx)
+OPJ_BOOL set_mainmhixdata( box_param_t *cidx_box, codestream_param_t codestream, index_param_t *jp2idx)
{
box_param_t *mhix_box;
mhixbox_param_t *mhix;
markeridx_param_t *codmkidx;
if( !(mhix_box = gene_boxbyType( cidx_box->fd, get_DBoxoff( cidx_box), get_DBoxlen( cidx_box), "mhix")))
- return false;
+ return OPJ_FALSE;
jp2idx->mhead_length = fetch_DBox8bytebigendian( mhix_box, 0);
mhix = gene_mhixbox( mhix_box);
- free( mhix_box);
+ opj_free( mhix_box);
sizmkidx = search_markeridx( 0xff51, mhix);
set_SIZmkrdata( sizmkidx, codestream, &(jp2idx->SIZ));
delete_mhixbox( &mhix);
- return true;
+ return OPJ_TRUE;
}
-bool set_tpixdata( box_param_t *cidx_box, index_param_t *jp2idx)
+OPJ_BOOL set_tpixdata( box_param_t *cidx_box, index_param_t *jp2idx)
{
box_param_t *tpix_box; /**< tpix box*/
box_param_t *faix_box; /**< faix box*/
if( !(tpix_box = gene_boxbyType( cidx_box->fd, get_DBoxoff( cidx_box), get_DBoxlen( cidx_box), "tpix"))){
fprintf( FCGI_stderr, "Error: tpix box not present in cidx box\n");
- return false;
+ return OPJ_FALSE;
}
if( !(faix_box = gene_boxbyType( tpix_box->fd, get_DBoxoff( tpix_box), get_DBoxlen( tpix_box), "faix"))){
fprintf( FCGI_stderr, "Error: faix box not present in tpix box\n");
- return false;
+ return OPJ_FALSE;
}
jp2idx->tilepart = gene_faixbox( faix_box);
- free( tpix_box);
- free( faix_box);
+ opj_free( tpix_box);
+ opj_free( faix_box);
- return true;
+ return OPJ_TRUE;
}
-bool set_thixdata( box_param_t *cidx_box, index_param_t *jp2idx)
+OPJ_BOOL set_thixdata( box_param_t *cidx_box, index_param_t *jp2idx)
{
box_param_t *thix_box, *manf_box, *mhix_box;
manfbox_param_t *manf;
if( !(thix_box = gene_boxbyType( cidx_box->fd, get_DBoxoff( cidx_box), get_DBoxlen( cidx_box), "thix"))){
fprintf( FCGI_stderr, "Error: thix box not present in cidx box\n");
- return false;
+ return OPJ_FALSE;
}
if( !(manf_box = gene_boxbyType( thix_box->fd, get_DBoxoff( thix_box), get_DBoxlen( thix_box), "manf"))){
fprintf( FCGI_stderr, "Error: manf box not present in thix box\n");
- free( thix_box);
- return false;
+ opj_free( thix_box);
+ return OPJ_FALSE;
}
manf = gene_manfbox( manf_box);
mhixseqoff = manf_box->offset+(OPJ_OFF_T)manf_box->length;
pos = 0;
tile_no = 0;
- jp2idx->tileheader = (mhixbox_param_t **)malloc( jp2idx->SIZ.XTnum*jp2idx->SIZ.YTnum*sizeof(mhixbox_param_t *));
+ jp2idx->tileheader = (mhixbox_param_t **)opj_malloc( jp2idx->SIZ.XTnum*jp2idx->SIZ.YTnum*sizeof(mhixbox_param_t *));
while( ptr){
if( !(mhix_box = gene_boxbyType( thix_box->fd, mhixseqoff+(OPJ_OFF_T)pos, get_DBoxlen( thix_box)-manf_box->length-pos, "mhix"))){
fprintf( FCGI_stderr, "Error: mhix box not present in thix box\n");
delete_manfbox( &manf);
- free( manf_box);
- free( thix_box);
- return false;
+ opj_free( manf_box);
+ opj_free( thix_box);
+ return OPJ_FALSE;
}
mhix = gene_mhixbox( mhix_box);
pos += mhix_box->length;
ptr = ptr->next;
- free( mhix_box);
+ opj_free( mhix_box);
jp2idx->tileheader[tile_no++] = mhix;
}
delete_manfbox( &manf);
- free( manf_box);
- free( thix_box);
+ opj_free( manf_box);
+ opj_free( thix_box);
- return true;
+ return OPJ_TRUE;
}
-bool set_ppixdata( box_param_t *cidx_box, index_param_t *jp2idx)
+OPJ_BOOL set_ppixdata( box_param_t *cidx_box, index_param_t *jp2idx)
{
box_param_t *ppix_box, *faix_box, *manf_box;
manfbox_param_t *manf; /**< manf*/
if( !(ppix_box = gene_boxbyType( cidx_box->fd, get_DBoxoff( cidx_box), get_DBoxlen( cidx_box), "ppix"))){
fprintf( FCGI_stderr, "Error: ppix box not present in cidx box\n");
- return false;
+ return OPJ_FALSE;
}
inbox_offset = get_DBoxoff( ppix_box);
if( !(manf_box = gene_boxbyType( ppix_box->fd, inbox_offset, get_DBoxlen( ppix_box), "manf"))){
fprintf( FCGI_stderr, "Error: manf box not present in ppix box\n");
- free( ppix_box);
- return false;
+ opj_free( ppix_box);
+ return OPJ_FALSE;
}
- free( ppix_box);
+ opj_free( ppix_box);
manf = gene_manfbox( manf_box);
bh = search_boxheader( "faix", manf);
inbox_offset = manf_box->offset + (OPJ_OFF_T)manf_box->length;
- free( manf_box);
+ opj_free( manf_box);
- jp2idx->precpacket = (faixbox_param_t **)malloc( jp2idx->SIZ.Csiz*sizeof(faixbox_param_t *));
+ jp2idx->precpacket = (faixbox_param_t **)opj_malloc( jp2idx->SIZ.Csiz*sizeof(faixbox_param_t *));
for( comp_idx=0; bh!=NULL; bh=bh->next, comp_idx++){
if( jp2idx->SIZ.Csiz <= comp_idx ){
fprintf( FCGI_stderr, "Error: num of faix boxes is not identical to num of components in ppix box\n");
- return false;
+ return OPJ_FALSE;
}
if( !(faix_box = gene_boxbyOffset( cidx_box->fd, inbox_offset))){
fprintf( FCGI_stderr, "Error: faix box not present in ppix box\n");
- return false;
+ return OPJ_FALSE;
}
faix = gene_faixbox( faix_box);
jp2idx->precpacket[comp_idx] = faix;
inbox_offset = faix_box->offset + (OPJ_OFF_T)faix_box->length;
- free( faix_box);
+ opj_free( faix_box);
}
delete_manfbox( &manf);
- return true;
+ return OPJ_TRUE;
}
-bool set_SIZmkrdata( markeridx_param_t *sizmkidx, codestream_param_t codestream, SIZmarker_param_t *SIZ)
+OPJ_BOOL set_SIZmkrdata( markeridx_param_t *sizmkidx, codestream_param_t codestream, SIZmarker_param_t *SIZ)
{
marker_param_t sizmkr;
int i;
if( sizmkidx->length != SIZ->Lsiz){
fprintf( FCGI_stderr, "Error: marker %#x index is not correct\n", sizmkidx->code);
- return false;
+ return OPJ_FALSE;
}
SIZ->Rsiz = fetch_marker2bytebigendian( sizmkr, 2);
SIZ->XRsiz[i] = fetch_marker1byte( sizmkr, 39+i*3);
SIZ->YRsiz[i] = fetch_marker1byte( sizmkr, 40+i*3);
}
- return true;
+ return OPJ_TRUE;
}
-bool set_CODmkrdata( markeridx_param_t *codmkidx, codestream_param_t codestream, CODmarker_param_t *COD)
+OPJ_BOOL set_CODmkrdata( markeridx_param_t *codmkidx, codestream_param_t codestream, CODmarker_param_t *COD)
{
marker_param_t codmkr;
int i;
if( codmkidx->length != COD->Lcod){
fprintf( FCGI_stderr, "Error: marker %#x index is not correct\n", codmkidx->code);
- return false;
+ return OPJ_FALSE;
}
COD->Scod = fetch_marker1byte( codmkr, 2);
COD->numOfdecomp = fetch_marker1byte( codmkr, 7);
if(COD->Scod & 0x01){
- COD->XPsiz = (Byte4_t *)malloc( (OPJ_SIZE_T)(COD->numOfdecomp+1)*sizeof(Byte4_t));
- COD->YPsiz = (Byte4_t *)malloc( (OPJ_SIZE_T)(COD->numOfdecomp+1)*sizeof(Byte4_t));
+ COD->XPsiz = (Byte4_t *)opj_malloc( (OPJ_SIZE_T)(COD->numOfdecomp+1)*sizeof(Byte4_t));
+ COD->YPsiz = (Byte4_t *)opj_malloc( (OPJ_SIZE_T)(COD->numOfdecomp+1)*sizeof(Byte4_t));
for( i=0; i<=COD->numOfdecomp; i++){
/*precinct size*/
}
}
else{
- COD->XPsiz = (Byte4_t *)malloc( sizeof(Byte4_t));
- COD->YPsiz = (Byte4_t *)malloc( sizeof(Byte4_t));
+ COD->XPsiz = (Byte4_t *)opj_malloc( sizeof(Byte4_t));
+ COD->YPsiz = (Byte4_t *)opj_malloc( sizeof(Byte4_t));
- COD->XPsiz[0] = COD->YPsiz[0] = pow(2,15);
+ COD->XPsiz[0] = COD->YPsiz[0] = 1 << 15; /* pow(2,15); */
}
- return true;
+ return OPJ_TRUE;
}
return n2;
}
-bool isJPTfeasible( index_param_t index)
+OPJ_BOOL isJPTfeasible( index_param_t index)
{
if( 1 < get_nmax( index.tilepart))
- return true;
+ return OPJ_TRUE;
else
- return false;
+ return OPJ_FALSE;
}