2011-04-14 20:37:47 +02:00
|
|
|
/*
|
2011-05-09 20:11:40 +02:00
|
|
|
* $Id: faixbox_manager.c 53 2011-05-09 16:55:39Z kaori $
|
2011-04-14 20:37:47 +02:00
|
|
|
*
|
|
|
|
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
|
|
|
* Copyright (c) 2002-2011, Professor Benoit Macq
|
|
|
|
* Copyright (c) 2010-2011, Kaori Hagihara
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "faixbox_manager.h"
|
2012-03-19 12:18:24 +01:00
|
|
|
#include "opj_inttypes.h"
|
2011-04-14 20:37:47 +02:00
|
|
|
|
|
|
|
#ifdef SERVER
|
|
|
|
#include "fcgi_stdio.h"
|
|
|
|
#define logstream FCGI_stdout
|
|
|
|
#else
|
|
|
|
#define FCGI_stdout stdout
|
|
|
|
#define FCGI_stderr stderr
|
|
|
|
#define logstream stderr
|
2012-03-02 12:09:16 +01:00
|
|
|
#endif /*SERVER*/
|
2011-04-14 20:37:47 +02:00
|
|
|
|
|
|
|
faixbox_param_t * gene_faixbox( box_param_t *box)
|
|
|
|
{
|
|
|
|
faixbox_param_t *faix;
|
|
|
|
size_t numOfelem;
|
|
|
|
long pos = 0;
|
|
|
|
|
|
|
|
faix = ( faixbox_param_t *)malloc( sizeof(faixbox_param_t));
|
|
|
|
|
|
|
|
faix->version = fetch_DBox1byte( box, (pos+=1)-1);
|
|
|
|
|
2012-03-02 12:09:16 +01:00
|
|
|
if( 3< faix->version){
|
2011-04-14 20:37:47 +02:00
|
|
|
fprintf( FCGI_stderr, "Error: version %d in faix box is reserved for ISO use.\n", faix->version);
|
|
|
|
free(faix);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( faix->version%2){
|
|
|
|
subfaixbox8_param_t *subfaixbox;
|
2012-03-02 12:09:16 +01:00
|
|
|
size_t i;
|
2011-04-14 20:37:47 +02:00
|
|
|
|
|
|
|
faix->subfaixbox.byte8_params = (subfaixbox8_param_t *)malloc( sizeof(subfaixbox8_param_t));
|
|
|
|
|
|
|
|
subfaixbox = faix->subfaixbox.byte8_params;
|
|
|
|
subfaixbox->nmax = fetch_DBox8bytebigendian( box, (pos+=8)-8);
|
|
|
|
subfaixbox->m = fetch_DBox8bytebigendian( box, (pos+=8)-8);
|
|
|
|
|
|
|
|
numOfelem = subfaixbox->nmax*subfaixbox->m;
|
|
|
|
|
|
|
|
subfaixbox->elem = ( faixelem8_param_t *)malloc( numOfelem*sizeof(faixelem8_param_t));
|
|
|
|
|
|
|
|
if( faix->version == 3)
|
|
|
|
subfaixbox->aux = ( Byte4_t *)malloc( numOfelem*sizeof(Byte4_t));
|
|
|
|
|
2011-05-09 20:11:40 +02:00
|
|
|
for( i=0; i<numOfelem; i++){
|
2011-04-14 20:37:47 +02:00
|
|
|
subfaixbox->elem[i].off = fetch_DBox8bytebigendian( box, (pos+=8)-8);
|
|
|
|
subfaixbox->elem[i].len = fetch_DBox8bytebigendian( box, (pos+=8)-8);
|
|
|
|
if( faix->version == 3)
|
|
|
|
subfaixbox->aux[i] = fetch_DBox4bytebigendian( box, (pos+=4)-4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
subfaixbox4_param_t *subfaixbox;
|
2012-03-02 12:09:16 +01:00
|
|
|
size_t i;
|
2011-04-14 20:37:47 +02:00
|
|
|
|
|
|
|
faix->subfaixbox.byte4_params = (subfaixbox4_param_t *)malloc( sizeof(subfaixbox4_param_t));
|
|
|
|
|
|
|
|
subfaixbox = faix->subfaixbox.byte4_params;
|
|
|
|
subfaixbox->nmax = fetch_DBox4bytebigendian( box, (pos+=4)-4);
|
|
|
|
subfaixbox->m = fetch_DBox4bytebigendian( box, (pos+=4)-4);
|
|
|
|
|
|
|
|
numOfelem = subfaixbox->nmax*subfaixbox->m;
|
|
|
|
|
|
|
|
subfaixbox->elem = ( faixelem4_param_t *)malloc( numOfelem*sizeof(faixelem4_param_t));
|
|
|
|
|
|
|
|
if( faix->version == 2)
|
|
|
|
subfaixbox->aux = ( Byte4_t *)malloc( numOfelem*sizeof(Byte4_t));
|
|
|
|
|
2011-05-09 20:11:40 +02:00
|
|
|
for( i=0; i<numOfelem; i++){
|
2011-04-14 20:37:47 +02:00
|
|
|
subfaixbox->elem[i].off = fetch_DBox4bytebigendian( box, (pos+=4)-4);
|
|
|
|
subfaixbox->elem[i].len = fetch_DBox4bytebigendian( box, (pos+=4)-4);
|
|
|
|
if( faix->version == 2)
|
|
|
|
subfaixbox->aux[i] = fetch_DBox4bytebigendian( box, (pos+=4)-4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return faix;
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_faixbox( faixbox_param_t *faix)
|
|
|
|
{
|
2011-05-09 20:11:40 +02:00
|
|
|
Byte8_t i, j;
|
|
|
|
|
2011-04-14 20:37:47 +02:00
|
|
|
fprintf( logstream, "faix box info\n");
|
|
|
|
fprintf( logstream, "\tversion: %d\n", faix->version);
|
|
|
|
|
2012-03-19 12:18:24 +01:00
|
|
|
fprintf( logstream, "\t nmax: %#" PRIx64 " = %" PRId64 "\n", get_nmax( faix), get_nmax( faix));
|
|
|
|
fprintf( logstream, "\t m: %#" PRIx64 " = %" PRId64 "\n", get_m( faix), get_m( faix));
|
2011-04-14 20:37:47 +02:00
|
|
|
|
2011-05-09 20:11:40 +02:00
|
|
|
for( i=0; i<get_m( faix); i++){
|
|
|
|
for( j=0; j<get_nmax( faix); j++){
|
2012-03-19 12:18:24 +01:00
|
|
|
fprintf( logstream, "\t off = %#" PRIx64 ", len = %#" PRIx64 "", get_elemOff( faix, j, i), get_elemLen( faix, j, i));
|
2011-04-14 20:37:47 +02:00
|
|
|
if( 2 <= faix->version)
|
|
|
|
fprintf( logstream, ", aux = %#x", get_elemAux( faix, j, i));
|
|
|
|
fprintf( logstream, "\n");
|
|
|
|
}
|
|
|
|
fprintf( logstream, "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void delete_faixbox( faixbox_param_t **faix)
|
|
|
|
{
|
|
|
|
if((*faix)->version%2){
|
|
|
|
free((*faix)->subfaixbox.byte8_params->elem);
|
|
|
|
if( (*faix)->version == 3)
|
|
|
|
free((*faix)->subfaixbox.byte8_params->aux);
|
|
|
|
free((*faix)->subfaixbox.byte8_params);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
free((*faix)->subfaixbox.byte4_params->elem);
|
|
|
|
if( (*faix)->version == 2)
|
|
|
|
free((*faix)->subfaixbox.byte4_params->aux);
|
|
|
|
free((*faix)->subfaixbox.byte4_params);
|
|
|
|
}
|
|
|
|
free( *faix);
|
|
|
|
}
|
|
|
|
|
|
|
|
Byte8_t get_nmax( faixbox_param_t *faix)
|
|
|
|
{
|
|
|
|
if( faix->version%2)
|
|
|
|
return faix->subfaixbox.byte8_params->nmax;
|
|
|
|
else
|
|
|
|
return (Byte8_t)faix->subfaixbox.byte4_params->nmax;
|
|
|
|
}
|
|
|
|
|
|
|
|
Byte8_t get_m( faixbox_param_t *faix)
|
|
|
|
{
|
|
|
|
if( faix->version%2)
|
|
|
|
return faix->subfaixbox.byte8_params->m;
|
|
|
|
else
|
|
|
|
return (Byte8_t)faix->subfaixbox.byte4_params->m;
|
|
|
|
}
|
|
|
|
|
|
|
|
Byte8_t get_elemOff( faixbox_param_t *faix, Byte8_t elem_id, Byte8_t row_id)
|
|
|
|
{
|
|
|
|
Byte8_t nmax = get_nmax( faix);
|
|
|
|
if( faix->version%2)
|
|
|
|
return faix->subfaixbox.byte8_params->elem[ row_id*nmax+elem_id].off;
|
|
|
|
else
|
|
|
|
return (Byte8_t)faix->subfaixbox.byte4_params->elem[ row_id*nmax+elem_id].off;
|
|
|
|
}
|
|
|
|
|
|
|
|
Byte8_t get_elemLen( faixbox_param_t *faix, Byte8_t elem_id, Byte8_t row_id)
|
|
|
|
{
|
|
|
|
Byte8_t nmax = get_nmax( faix);
|
|
|
|
if( faix->version%2)
|
|
|
|
return faix->subfaixbox.byte8_params->elem[ row_id*nmax+elem_id].len;
|
|
|
|
else
|
|
|
|
return (Byte8_t)faix->subfaixbox.byte4_params->elem[ row_id*nmax+elem_id].len;
|
|
|
|
}
|
|
|
|
|
|
|
|
Byte4_t get_elemAux( faixbox_param_t *faix, Byte8_t elem_id, Byte8_t row_id)
|
|
|
|
{
|
2012-03-02 12:09:16 +01:00
|
|
|
Byte8_t nmax;
|
2011-04-14 20:37:47 +02:00
|
|
|
if( faix->version <2)
|
|
|
|
return -1;
|
|
|
|
|
2012-03-02 12:09:16 +01:00
|
|
|
nmax = get_nmax( faix);
|
2011-04-14 20:37:47 +02:00
|
|
|
if( faix->version%2)
|
|
|
|
return faix->subfaixbox.byte8_params->aux[ row_id*nmax+elem_id];
|
|
|
|
else
|
|
|
|
return faix->subfaixbox.byte4_params->aux[ row_id*nmax+elem_id];
|
|
|
|
}
|