예제 #1
0
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*/
  boxheader_param_t *bh;     /**< box headers*/
  faixbox_param_t *faix;     /**< faix*/
  OPJ_OFF_T inbox_offset;
  int comp_idx;

  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 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");
    opj_free( ppix_box);
    return OPJ_FALSE;
  }

  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;

  opj_free( manf_box);

  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 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 OPJ_FALSE;
    }

    faix = gene_faixbox( faix_box);
    jp2idx->precpacket[comp_idx] = faix;

    inbox_offset = faix_box->offset + (OPJ_OFF_T)faix_box->length;
    opj_free( faix_box);
  }

  delete_manfbox( &manf);

  return OPJ_TRUE;
}
예제 #2
0
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;
  boxheader_param_t *ptr;
  mhixbox_param_t *mhix;
  Byte8_t pos;
  OPJ_OFF_T mhixseqoff;
  Byte2_t tile_no;

  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 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");
    opj_free( thix_box);
    return OPJ_FALSE;
  }

  manf = gene_manfbox( manf_box);
  ptr = manf->first;
  mhixseqoff = manf_box->offset+(OPJ_OFF_T)manf_box->length;
  pos = 0;
  tile_no = 0;
  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);
      opj_free( manf_box);
      opj_free( thix_box);
      return OPJ_FALSE;
    }
    mhix = gene_mhixbox( mhix_box);

    pos += mhix_box->length;
    ptr = ptr->next;

    opj_free( mhix_box);
    jp2idx->tileheader[tile_no++] = mhix;
  }

  delete_manfbox( &manf);
  opj_free( manf_box);
  opj_free( thix_box);

  return OPJ_TRUE;
}
예제 #3
0
metadatalist_param_t * const_metadatalist( int fd)
{
  metadatalist_param_t *metadatalist;
  metadata_param_t *metabin;
  boxlist_param_t *toplev_boxlist;
  box_param_t *box, *next;
  placeholderlist_param_t *phldlist;
  placeholder_param_t *phld;
  Byte8_t idx;
  Byte8_t filesize;

  if(!(filesize = (Byte8_t)get_filesize( fd)))
    return NULL;
  
  if( !(toplev_boxlist = get_boxstructure( fd, 0, filesize))){
    fprintf( FCGI_stderr, "Error: Not correctl JP2 format\n");
    return NULL;
  }
  
  phldlist = gene_placeholderlist();
  metadatalist = gene_metadatalist();

  box = toplev_boxlist->first;
  idx = 0;
  while( box){
    next = box->next;
    if( strncmp( box->type, "jP  ",4)!=0 && strncmp( box->type, "ftyp",4)!=0 && strncmp( box->type, "jp2h",4)!=0){
      boxlist_param_t *boxlist = NULL;
      boxcontents_param_t *boxcontents = NULL;

      phld = gene_placeholder( box, ++idx);
      insert_placeholder_into_list( phld, phldlist);

      boxlist = get_boxstructure( box->fd, get_DBoxoff( box), get_DBoxlen(box));
      if( !boxlist)
	boxcontents = gene_boxcontents( get_DBoxoff( box), get_DBoxlen(box));
      
      delete_box_in_list( &box, toplev_boxlist);
      metabin = gene_metadata( idx, boxlist, NULL, boxcontents);
      insert_metadata_into_list( metabin, metadatalist);
    }
    box = next;
  }

  metabin = gene_metadata( 0, toplev_boxlist, phldlist, NULL);
  insert_metadata_into_list( metabin, metadatalist);

  return metadatalist;
}
예제 #4
0
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 *sizmkidx;
  markeridx_param_t *codmkidx;

  if( !(mhix_box = gene_boxbyType( cidx_box->fd, get_DBoxoff( cidx_box), get_DBoxlen( cidx_box), "mhix")))
    return OPJ_FALSE;

  jp2idx->mhead_length = fetch_DBox8bytebigendian( mhix_box, 0);

  mhix = gene_mhixbox( mhix_box);
  opj_free( mhix_box);

  sizmkidx = search_markeridx( 0xff51, mhix);
  set_SIZmkrdata( sizmkidx, codestream, &(jp2idx->SIZ));

  codmkidx = search_markeridx( 0xff52, mhix);
  set_CODmkrdata( codmkidx, codestream, &(jp2idx->COD));

  delete_mhixbox( &mhix);

  return OPJ_TRUE;
}
예제 #5
0
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 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");
    opj_free( box);
    return OPJ_FALSE;
  }

  /* CONT: Container Type*/
  /* If 0, the entire codestream appears as a contiguous range of*/
  /* bytes within its file or resource.*/
  if(( cont = fetch_DBox2bytebigendian( box, 2))){
    fprintf( FCGI_stderr, "Error: Can't cope with fragmented codestreams yet\n");
    opj_free( box);
    return OPJ_FALSE;
  }

  jp2idx->offset = (OPJ_OFF_T)fetch_DBox8bytebigendian( box, 4);
  jp2idx->length = fetch_DBox8bytebigendian( box, 12);

  opj_free( box);

  return OPJ_TRUE;
}
예제 #6
0
ihdrbox_param_t * gene_ihdrbox( metadatalist_param_t *metadatalist, Byte_t *jpipstream)
{
  ihdrbox_param_t *ihdrbox;
  metadata_param_t *meta;
  box_param_t *jp2h, *ihdr;
  int bpc_val;
  
  jp2h = NULL;
  meta = metadatalist->first;
  while( meta){
    if( meta->boxlist){
      jp2h = search_box( "jp2h", meta->boxlist);
      if( jp2h)
	break;
    }
    meta = meta->next;
  }
  if( !jp2h){
    fprintf( stderr, "jp2h box not found\n");
    return NULL;
  }
  
  ihdr = gene_boxbyTypeinStream( jpipstream, get_DBoxoff( jp2h), get_DBoxlen( jp2h), "ihdr");

  if( !ihdr){
    fprintf( stderr, "ihdr box not found\n");
    return NULL;
  }
  
  ihdrbox = (ihdrbox_param_t *)malloc( sizeof(ihdrbox_param_t));
  
  ihdrbox->height = big4( jpipstream+get_DBoxoff(ihdr));
  ihdrbox->width  = big4( jpipstream+get_DBoxoff(ihdr)+4);
  ihdrbox->nc     = big2( jpipstream+get_DBoxoff(ihdr)+8);
  bpc_val = *(jpipstream+get_DBoxoff(ihdr)+10)+1;
  assert( bpc_val >= 0 && bpc_val <= 255 );
  ihdrbox->bpc    = (Byte_t)bpc_val;

  free( ihdr);

  return ihdrbox;
}
예제 #7
0
box_param_t * gene_childboxbyType( box_param_t *superbox, OPJ_OFF_T offset, const char TBox[])
{
  OPJ_SIZE_T DBOXlen = get_DBoxlen(superbox);
  assert( offset >= 0 );
  if( DBOXlen < (OPJ_SIZE_T)offset )
    {
    fprintf( FCGI_stderr, "Error: Impossible happen %lu < %ld\n", DBOXlen, offset);
    return NULL;
    }
  return gene_boxbyType( superbox->fd, get_DBoxoff( superbox)+offset, DBOXlen-(OPJ_SIZE_T)offset, TBox);
}
예제 #8
0
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 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 OPJ_FALSE;
  }

  jp2idx->tilepart = gene_faixbox( faix_box);

  opj_free( tpix_box);
  opj_free( faix_box);

  return OPJ_TRUE;
}
예제 #9
0
OPJ_BOOL set_cidxdata( box_param_t *cidx_box, index_param_t *jp2idx)
{
  box_param_t *manf_box;
  manfbox_param_t *manf;
  codestream_param_t codestream;

  set_cptrdata( cidx_box, jp2idx);

  codestream = set_codestream( cidx_box->fd, jp2idx->offset, jp2idx->length);

  manf_box = gene_boxbyType( cidx_box->fd, get_DBoxoff( cidx_box), get_DBoxlen( cidx_box), "manf");
  manf = gene_manfbox( manf_box);

  if( !search_boxheader( "mhix", manf)){
    fprintf( FCGI_stderr, "Error: mhix box not present in manfbox\n");
    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");
    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");
    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");
    opj_free(jp2idx);
    return OPJ_FALSE;
  }
  set_ppixdata( cidx_box, jp2idx);

  delete_manfbox( &manf);
  opj_free( manf_box);

  return OPJ_TRUE;
}
예제 #10
0
Byte8_t fetch_DBox8bytebigendian( box_param_t *box, OPJ_OFF_T offset)
{
  return fetch_8bytebigendian( box->fd, get_DBoxoff( box)+offset);
}
예제 #11
0
box_param_t * gene_childboxbyType( box_param_t *superbox, Byte8_t offset, char TBox[])
{
  return gene_boxbyType( superbox->fd, get_DBoxoff( superbox)+offset, get_DBoxlen( superbox)-offset, TBox);
}
예제 #12
0
Byte_t * fetch_DBoxbytes( box_param_t *box, OPJ_OFF_T offset, OPJ_SIZE_T size)
{
  return fetch_bytes( box->fd, get_DBoxoff( box)+offset, size);
}
예제 #13
0
box_param_t * gene_childboxbyOffset( box_param_t *superbox, OPJ_OFF_T offset)
{
  return gene_boxbyOffset( superbox->fd, get_DBoxoff( superbox)+offset);
}
예제 #14
0
Byte4_t fetch_DBox4bytebigendian( box_param_t *box, long offset)
{
  return fetch_4bytebigendian( box->fd, get_DBoxoff( box)+offset);
}
예제 #15
0
Byte_t * fetch_DBoxbytes( box_param_t *box, long offset, int size)
{
  return fetch_bytes( box->fd, get_DBoxoff( box)+offset, size);
}
예제 #16
0
Byte_t fetch_DBox1byte( box_param_t *box, OPJ_OFF_T offset)
{
  return fetch_1byte( box->fd, get_DBoxoff( box)+offset);
}
예제 #17
0
box_param_t * gene_childboxbyOffset( box_param_t *superbox, Byte8_t offset)
{
  return gene_boxbyOffset( superbox->fd, get_DBoxoff( superbox)+offset);
}