Esempio n. 1
0
SIZmarker_param_t get_SIZmkrdata_from_j2kstream( Byte_t *SIZstream)
{
  SIZmarker_param_t SIZ ={0};
  int i;

  if( *SIZstream++ != 0xff || *SIZstream++ != 0x51){
    fprintf( FCGI_stderr, "Error, SIZ marker not found in the reconstructed j2kstream\n");
    return SIZ;
  }

  SIZ.Lsiz   = big2( SIZstream);
  SIZ.Rsiz   = big2( SIZstream+2);
  SIZ.Xsiz   = big4( SIZstream+4);
  SIZ.Ysiz   = big4( SIZstream+8);
  SIZ.XOsiz  = big4( SIZstream+12);
  SIZ.YOsiz  = big4( SIZstream+16);
  SIZ.XTsiz  = big4( SIZstream+20);
  SIZ.YTsiz  = big4( SIZstream+24);
  SIZ.XTOsiz = big4( SIZstream+28);
  SIZ.YTOsiz = big4( SIZstream+32);
  SIZ.Csiz   = big2( SIZstream+36);

  SIZ.XTnum  = ( SIZ.Xsiz-SIZ.XTOsiz+SIZ.XTsiz-1)/SIZ.XTsiz;
  SIZ.YTnum  = ( SIZ.Ysiz-SIZ.YTOsiz+SIZ.YTsiz-1)/SIZ.YTsiz;

  for( i=0; i<(int)SIZ.Csiz; i++){
    SIZ.Ssiz[i]  = *(SIZstream+(38+i*3));
    SIZ.XRsiz[i] = *(SIZstream+(39+i*3));
    SIZ.YRsiz[i] = *(SIZstream+(40+i*3));
  }

  return SIZ;
}
Esempio n. 2
0
box_param_t * gene_boxbyOffinStream( Byte_t *stream, OPJ_OFF_T offset)
{
  Byte8_t boxlen;
  Byte_t headlen;
  char *boxtype;
  box_param_t *box;

  /* read LBox and TBox*/
  headlen = 8;
  boxlen = (Byte8_t)big4( stream);
  boxtype = (char *)( stream+4);  

  /* box type constraint*/
  if( !isalpha(boxtype[0]) || !isalpha(boxtype[1]) ||
      (!isalnum(boxtype[2])&&!isspace(boxtype[2])) ||
      (!isalpha(boxtype[3])&&!isspace(boxtype[3]))){
    return NULL;
  }
  
  if( boxlen == 1){
    headlen = 16;
    boxlen = big8( stream+8); /* read XLBox*/
  }
  box = (box_param_t *)malloc( sizeof( box_param_t));
  box->fd = -1;
  box->offset = offset;
  box->headlen = headlen;
  box->length = boxlen;
  strncpy( box->type, boxtype, 4);
  box->next = NULL;

  return box;
}
Esempio n. 3
0
box_param_t * gene_boxbyType( int fd, Byte8_t offset, Byte8_t length, char TBox[])
{
  Byte8_t pos;
  Byte_t *data;
  Byte8_t boxlen, headlen;
  char *boxtype;
  box_param_t *foundbox;

  
  if( length==0){ /* set the max length*/
    if( (length = get_filesize( fd) - offset) <= 0)
      return NULL;
  }

  pos = offset;
  while( pos < offset+length-7){ /* LBox+TBox-1=7*/
    
    /* read LBox and TBox*/
    if((data = fetch_bytes( fd, pos, 8))){
      headlen = 8;
      boxlen = (Byte8_t)big4(data);
      boxtype = (char *)(data+4);

      if( boxlen == 1){
	Byte_t *data2;
	headlen = 16;
	/* read XLBox*/
	if((data2 = fetch_bytes( fd, pos+8, 8))){
	  boxlen = big8(data2);
	  free(data2);
	}
	else{
	  fprintf( FCGI_stderr, "Error: error in gene_boxbyType( %d, %lld, %lld, %s)\n", fd, offset, length, TBox);
	  return NULL;
	}
      }
      if( strncmp ( boxtype, TBox, 4) == 0){
	foundbox = (box_param_t *)malloc( sizeof( box_param_t));
	foundbox->fd = fd;
	foundbox->offset = pos;
	foundbox->headlen = headlen;
	foundbox->length = boxlen;
	strncpy( foundbox->type, TBox, 4);
	foundbox->next = NULL;
	free( data);
	return foundbox;
      }
      free( data);
    }
    else{
      fprintf( FCGI_stderr, "Error: error in gene_boxbyType( %d, %lld, %lld, %s)\n", fd, offset, length, TBox);
      return NULL;
    }
    pos+= boxlen;
  }
  fprintf( FCGI_stderr, "Error: Box %s not found\n", TBox);

  return NULL;
}
Esempio n. 4
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;
}
void test_big_num()
{
	BigNum<unsigned int> big1("56"); //567
	BigNum<unsigned int> big2("4932");

	//big1 += big2;
	BigNum<unsigned int> big3 = big2*big1;
	BigNum<unsigned int> big4("56");
	printf("equal=%d\n",big1==big4);
	printf("equal=%d\n",big1==big3);
	int gh = 0;
}
Esempio n. 6
0
box_param_t * gene_boxbyOffset( int fd, OPJ_OFF_T offset)
{
  Byte_t *data;
  Byte8_t boxlen;
  Byte_t headlen;
  char *boxtype;
  box_param_t *box;

  /* read LBox and TBox*/
  if(!(data = fetch_bytes( fd, offset, 8))){
    fprintf( FCGI_stderr, "Error: error in gene_boxbyOffset( %d, %" PRId64 ")\n", fd, offset);
    return NULL;
  }
  
  headlen = 8;
  boxlen = (Byte8_t)big4(data);
  boxtype = (char *)(data+4);  

  /* box type constraint*/
  if( !isalpha(boxtype[0]) || !isalpha(boxtype[1]) ||
      (!isalnum(boxtype[2])&&!isspace(boxtype[2])) ||
      (!isalpha(boxtype[3])&&!isspace(boxtype[3]))){
    free( data);
    return NULL;
  }
  
  if( boxlen == 1){
    Byte_t *data2;
    headlen = 16;
    /* read XLBox*/
    if((data2 = fetch_bytes( fd, offset+8, 8))){
      boxlen = big8(data2);
      free(data2);
    }
    else{
      fprintf( FCGI_stderr, "Error: error in gene_boxbyOffset( %d, %" PRId64 ")\n", fd, offset);
      free( data);
      return NULL;
    }
  }
  box = (box_param_t *)malloc( sizeof( box_param_t));
  box->fd = fd;
  box->offset = offset;
  box->headlen = headlen;
  box->length = boxlen;
  strncpy( box->type, boxtype, 4);
  box->next = NULL;
  free( data);
  return box;
}
Esempio n. 7
0
Byte4_t fetch_4bytebigendian( int fd, OPJ_OFF_T offset)
{
  Byte_t *data;
  Byte4_t code;

  if(!(data = fetch_bytes( fd, offset, 4))){
    fprintf( FCGI_stderr, "Error: error in fetch_4bytebigendian( %d, %ld)\n", fd, offset);
    return 0;
  }
  code = big4(data);
  free( data);

  return code;
}
Esempio n. 8
0
box_param_t * gene_boxbyTypeinStream( Byte_t *stream, Byte8_t offset, Byte8_t length, char TBox[])
{
  Byte8_t pos;
  Byte_t *data;
  Byte8_t boxlen, headlen;
  char *boxtype;
  box_param_t *foundbox;

  
  if( length<=0){ // set the max length
    fprintf( FCGI_stderr, "func gene_boxbyTypeinStream(), max length must be more than 0\n");
    return NULL;
  }
  
  pos = offset;
  while( pos < offset+length-7){ // LBox+TBox-1=7
    
    // read LBox and TBox
    data = stream + pos;
    headlen = 8;
    boxlen = (Byte8_t)big4(data);
    boxtype = (char *)(data+4);
   
    if( boxlen == 1){
      // read XLBox
      headlen = 16;
      boxlen = big8( data+8);
    }

    if( strncmp ( boxtype, TBox, 4) == 0){
      foundbox = (box_param_t *)malloc( sizeof( box_param_t));
      foundbox->fd = -1;
      foundbox->offset = pos;
      foundbox->headlen = headlen;
      foundbox->length = boxlen;
      strncpy( foundbox->type, TBox, 4);
      foundbox->next = NULL;
      return foundbox;
    }
    pos+= boxlen;
  }
  fprintf( FCGI_stderr, "Error: Box %s not found\n", TBox);
  
  return NULL;
}
Esempio n. 9
0
box_param_t * gene_boxbyTypeinStream( Byte_t *stream, OPJ_OFF_T offset, OPJ_SIZE_T length, const char TBox[])
{
  OPJ_OFF_T pos;
  Byte_t *data;
  Byte8_t boxlen;
  Byte_t headlen;
  char *boxtype;
  box_param_t *foundbox;

  pos = offset;
  assert( pos >= 0 );
  assert( (OPJ_OFF_T)length >= 0 );
  while( pos < offset+(OPJ_OFF_T)(length)-7){ /* LBox+TBox-1=7*/
    
    /* read LBox and TBox*/
    data = stream + pos;
    headlen = 8;
    boxlen = (Byte8_t)big4(data);
    boxtype = (char *)(data+4);
   
    if( boxlen == 1){
      /* read XLBox*/
      headlen = 16;
      boxlen = big8( data+8);
    }

    if( strncmp ( boxtype, TBox, 4) == 0){
      foundbox = (box_param_t *)malloc( sizeof( box_param_t));
      foundbox->fd = -1;
      foundbox->offset = pos;
      foundbox->headlen = headlen;
      foundbox->length = boxlen;
      strncpy( foundbox->type, TBox, 4);
      foundbox->next = NULL;
      return foundbox;
    }
    assert( ((Byte8_t)pos+boxlen)>=(Byte8_t)pos);
    pos+= (OPJ_OFF_T)boxlen;
  }
  fprintf( FCGI_stderr, "Error: Box %s not found\n", TBox);
  
  return NULL;
}
Esempio n. 10
0
box_param_t * gene_boxbyType( int fd, OPJ_OFF_T offset, OPJ_SIZE_T length, const char TBox[])
{
  OPJ_OFF_T pos;
  Byte_t *data;
  Byte8_t boxlen;
  Byte_t headlen;
  char *boxtype;
  box_param_t *foundbox;

  
  if( length==0){ /* set the max length*/
    if( get_filesize( fd) <= offset )
      return NULL;
    assert( get_filesize( fd) > offset );
    assert( offset >= 0 );
    length = (OPJ_SIZE_T)(get_filesize( fd) - offset);
  }

  pos = offset;
  assert( pos >= 0 );
  assert( (OPJ_OFF_T)length >= 0 );
  while( pos < offset+(OPJ_OFF_T)length-7){ /* LBox+TBox-1=7*/
    
    /* read LBox and TBox*/
    if((data = fetch_bytes( fd, pos, 8))){
      headlen = 8;
      boxlen = (Byte8_t)big4(data);
      boxtype = (char *)(data+4);

      if( boxlen == 1){
	Byte_t *data2;
	headlen = 16;
	/* read XLBox*/
	if((data2 = fetch_bytes( fd, pos+8, 8))){
	  boxlen = big8(data2);
	  free(data2);
	}
	else{
	  fprintf( FCGI_stderr, "Error: error in gene_boxbyType( %d, %" PRId64 ", %" PRId64 ", %s)\n", fd, offset, length, TBox);
	  return NULL;
	}
      }
      if( strncmp ( boxtype, TBox, 4) == 0){
	foundbox = (box_param_t *)malloc( sizeof( box_param_t));
	foundbox->fd = fd;
	foundbox->offset = pos;
	foundbox->headlen = headlen;
	foundbox->length = boxlen;
	strncpy( foundbox->type, TBox, 4);
	foundbox->next = NULL;
	free( data);
	return foundbox;
      }
      free( data);
    }
    else{
      fprintf( FCGI_stderr, "Error: error in gene_boxbyType( %d, %" PRId64 ", %" PRId64 ", %s)\n", fd, offset, length, TBox);
      return NULL;
    }
    assert( ((Byte8_t)pos+boxlen)>=(Byte8_t)pos);
    pos+= (OPJ_OFF_T)boxlen;
  }
  fprintf( FCGI_stderr, "Error: Box %s not found\n", TBox);

  return NULL;
}
Esempio n. 11
0
Byte8_t big8( Byte_t *buf)
{
  return (((Byte8_t) big4 (buf)) << 32)
        + ((Byte8_t) big4 (buf + 4));
}
Esempio n. 12
0
box_param_t * gene_boxbyType( int fd, Byte8_t offset, Byte8_t length, char TBox[])
{
  Byte8_t pos;
  Byte_t *data;
  Byte8_t boxlen, headlen;
  char *boxtype;
  box_param_t *foundbox;

  
  if( length==0){ // set the max length
    struct stat sb;
    if( fstat( fd, &sb) == -1){
      fprintf( FCGI_stdout, "Reason: Target broken (fstat error)\r\n");
      return NULL;
    }
    length = (Byte8_t)sb.st_size - offset;
  }

  pos = offset;
  while( pos < offset+length-7){ // LBox+TBox-1=7
    
    // read LBox and TBox
    if((data = fetch_bytes( fd, pos, 8))){
      headlen = 8;
      boxlen = (Byte8_t)big4(data);
      boxtype = (char *)(data+4);

      if( boxlen == 1){
	Byte_t *data2;
	headlen = 16;
	// read XLBox
	if((data2 = fetch_bytes( fd, pos+8, 8))){
	  boxlen = big8(data2);
	  free(data2);
	}
	else{
	  fprintf( FCGI_stderr, "Error: error in gene_boxbyType( %d, %lld, %lld, %s)\n", fd, offset, length, TBox);
	  return NULL;
	}
      }
      if( strncmp ( boxtype, TBox, 4) == 0){
	foundbox = (box_param_t *)malloc( sizeof( box_param_t));
	foundbox->fd = fd;
	foundbox->offset = pos;
	foundbox->headlen = headlen;
	foundbox->length = boxlen;
	strncpy( foundbox->type, TBox, 4);
	foundbox->next = NULL;
	free( data);
	return foundbox;
      }
      free( data);
    }
    else{
      fprintf( FCGI_stderr, "Error: error in gene_boxbyType( %d, %lld, %lld, %s)\n", fd, offset, length, TBox);
      return NULL;
    }
    pos+= boxlen;
  }
  fprintf( FCGI_stderr, "Error: Box %s not found\n", TBox);

  return NULL;
}