예제 #1
0
void j2k_write_coc(int compno) {
    j2k_tcp_t *tcp;
    int lenp, len;
    //fprintf(stderr, "%.8x: COC\n", cio_tell());
    cio_write(J2K_MS_COC, 2);
    lenp=cio_tell();
    cio_skip(2);
    tcp=&j2k_cp->tcps[j2k_curtileno];
    cio_write(compno, j2k_img->numcomps<=256?1:2);
    cio_write(tcp->tccps[compno].csty, 1);
    j2k_write_cox(compno);
    len=cio_tell()-lenp;
    cio_seek(lenp);
    cio_write(len, 2);
    cio_seek(lenp+len);
}
예제 #2
0
static void read_siz_marker(FILE *file, opj_image_t *image)
{
  int len,i;
  char buf, buf2[2];
  unsigned char *siz_buffer;
	opj_cio_t *cio;
  
  fseek(file, 0, SEEK_SET);
  do {
    fread(&buf,1,1, file);
    if (buf==(char)0xff)
      fread(&buf,1,1, file);
  }
  while (!(buf==(char)0x51));
  
  fread(buf2,2,1,file);		/* Lsiz                */
  len = ((buf2[0])<<8) + buf2[1];
  
  siz_buffer = (unsigned char*) malloc(len * sizeof(unsigned char));
  fread(siz_buffer,len, 1, file);
	cio = opj_cio_open(NULL, siz_buffer, len);
  
  cio_read(cio, 2);			/* Rsiz (capabilities) */
  image->x1 = cio_read(cio, 4);	/* Xsiz                */
  image->y1 = cio_read(cio, 4);	/* Ysiz                */
  image->x0 = cio_read(cio, 4);	/* X0siz               */
  image->y0 = cio_read(cio, 4);	/* Y0siz               */
  cio_skip(cio, 16);			/* XTsiz, YTsiz, XT0siz, YT0siz        */
  
  image->numcomps = cio_read(cio,2);	/* Csiz                */
  image->comps =
    (opj_image_comp_t *) malloc(image->numcomps * sizeof(opj_image_comp_t));
	
  for (i = 0; i < image->numcomps; i++) {
    int tmp;
    tmp = cio_read(cio,1);		/* Ssiz_i          */
    image->comps[i].prec = (tmp & 0x7f) + 1;
    image->comps[i].sgnd = tmp >> 7;
    image->comps[i].dx = cio_read(cio,1);	/* XRsiz_i         */
    image->comps[i].dy = cio_read(cio,1);	/* YRsiz_i         */
    image->comps[i].resno_decoded = 0;	/* number of resolution decoded */
    image->comps[i].factor = 0;	/* reducing factor by component */
  }
  fseek(file, 0, SEEK_SET);
	opj_cio_close(cio);
  free(siz_buffer);
}
예제 #3
0
void j2k_read_com() {
    int len;
    info_tile_t *tile;
    info_marker_t *tmp;

    len = cio_read(2);

    /* <INDEX> [MHIX BOX] */
    if (j2k_state == J2K_STATE_MH)
      {
	if (!img.marker_mul.num_COM) 
	  img.marker_mul.COM = (info_marker_t*)malloc(img.marker_mul.CzCOM * sizeof(info_marker_t));
	if (img.marker_mul.num_COM >= img.marker_mul.CzCOM)
	  {
	    tmp = (info_marker_t*)malloc(2 * img.marker_mul.CzCOM * sizeof(info_marker_t));
	    memcpy(tmp,img.marker_mul.COM,img.marker_mul.CzCOM);
	    img.marker_mul.CzCOM *= 2;
	    free(img.marker_mul.COM);
	    img.marker_mul.COM = tmp;
	  }

	img.marker_mul.COM[img.marker_mul.num_COM].type = J2K_MS_COM;
	img.marker_mul.COM[img.marker_mul.num_COM].start_pos = cio_tell()-2;
	img.marker_mul.COM[img.marker_mul.num_COM].len = len;
	img.marker_mul.num_COM++;
      } else
	{
	  tile = &img.tile[j2k_curtileno];
	  if (!tile->marker_mul.num_COM)
	    tile->marker_mul.COM = (info_marker_t*)calloc(START_NB, sizeof(info_marker_t));
	  if (tile->marker_mul.num_COM >= tile->marker_mul.CzCOM)
	    {
	      tmp = (info_marker_t*)malloc(2 * tile->marker_mul.CzCOM * sizeof(info_marker_t));
	      memcpy(tmp,tile->marker_mul.COM,tile->marker_mul.CzCOM);
	      tile->marker_mul.CzCOM *= 2;
	      free(tile->marker_mul.COM);
	      tile->marker_mul.COM = tmp;
	    }
	  tile->marker_mul.COM[tile->marker_mul.num_COM].type = J2K_MS_COM;
	  tile->marker_mul.COM[tile->marker_mul.num_COM].start_pos = cio_tell()-2;
	  tile->marker_mul.COM[tile->marker_mul.num_COM].len = len;
	  tile->marker_mul.num_COM++;
	}
    /* </INDEX> [MHIX BOX] */

    cio_skip(len - 2);
}
예제 #4
0
파일: jp2.c 프로젝트: 151706061/fo-dicom
static int write_fidx( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_cio_t *cio)
{  
  int len, lenp;
  
  lenp = cio_tell( cio);
  cio_skip( cio, 4);              /* L [at the end] */
  cio_write( cio, JPIP_FIDX, 4);  /* IPTR           */
  
  write_prxy( offset_jp2c, length_jp2c, offset_idx, length_idx, cio);

  len = cio_tell( cio)-lenp;
  cio_seek( cio, lenp);
  cio_write( cio, len, 4);        /* L              */
  cio_seek( cio, lenp+len);  

  return len;
}
예제 #5
0
static void ns_jp2_write_xml(opj_cio_t *cio, unsigned char * xml) {
    unsigned int i;
    opj_jp2_box_t box;
	size_t len;

    box.init_pos = cio_tell(cio);
    cio_skip(cio, 4);
    cio_write(cio, JP2_XML, 4); /* box type is 'xml ' */
	len = strlen((const char *)xml);
    for (i = 0; i < len; i++) {
       cio_write(cio, xml[i], 1);
    }
    box.length = cio_tell(cio) - box.init_pos;
    cio_seek(cio, box.init_pos);
    cio_write(cio, box.length, 4);  
    cio_seek(cio, box.init_pos + box.length);
}
예제 #6
0
static void jp2_write_bpcc(opj_jp2_t *jp2, opj_cio_t *cio) {
	unsigned int i;
	opj_jp2_box_t box;

	box.init_pos = cio_tell(cio);
	cio_skip(cio, 4);
	cio_write(cio, JP2_BPCC, 4);	/* BPCC */

	for (i = 0; i < jp2->numcomps; i++) {
		cio_write(cio, jp2->comps[i].bpcc, 1);
	}

	box.length = cio_tell(cio) - box.init_pos;
	cio_seek(cio, box.init_pos);
	cio_write(cio, box.length, 4);	/* L */
	cio_seek(cio, box.init_pos + box.length);
}
예제 #7
0
파일: jp2.c 프로젝트: 151706061/Gdcm
void jp2_write_bpcc(jp2_struct_t * jp2_struct)
{
  unsigned int i;
  jp2_box_t box;

  box.init_pos = cio_tell();
  cio_skip(4);
  cio_write(JP2_BPCC, 4);	// BPCC

  for (i = 0; i < jp2_struct->numcomps; i++)
    cio_write(jp2_struct->comps[i].bpcc, 1);

  box.length = cio_tell() - box.init_pos;
  cio_seek(box.init_pos);
  cio_write(box.length, 4);	/*    L       */
  cio_seek(box.init_pos + box.length);
}
예제 #8
0
void j2k_write_coc(int compno)
{
  j2k_tcp_t *tcp;
  int lenp, len;

  cio_write(J2K_MS_COC, 2);	/* COC */
  lenp = cio_tell();
  cio_skip(2);
  tcp = &j2k_cp->tcps[j2k_curtileno];
  cio_write(compno, j2k_img->numcomps <= 256 ? 1 : 2);	/* Ccoc */
  cio_write(tcp->tccps[compno].csty, 1);	/* Scoc */
  j2k_write_cox(compno);
  len = cio_tell() - lenp;
  cio_seek(lenp);
  cio_write(len, 2);		/* Lcoc */
  cio_seek(lenp + len);
}
예제 #9
0
파일: jp2.c 프로젝트: 151706061/fo-dicom
opj_bool opj_jp2_encode(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info) {

	int pos_iptr, pos_cidx, pos_jp2c, len_jp2c, len_cidx, end_pos, pos_fidx, len_fidx;
	pos_jp2c = pos_iptr = -1; /* remove a warning */

	/* JP2 encoding */

	/* JPEG 2000 Signature box */
	jp2_write_jp(cio);
	/* File Type box */
	jp2_write_ftyp(jp2, cio);
	/* JP2 Header box */
	jp2_write_jp2h(jp2, cio);

	if( jp2->jpip_on){
	  pos_iptr = cio_tell( cio);
	  cio_skip( cio, 24); /* IPTR further ! */
	  
	  pos_jp2c = cio_tell( cio);
	}

	/* J2K encoding */
	if(!(len_jp2c = jp2_write_jp2c( jp2, cio, image, cstr_info))){
	    opj_event_msg(jp2->cinfo, EVT_ERROR, "Failed to encode image\n");
	    return OPJ_FALSE;
	}

	if( jp2->jpip_on){
	  pos_cidx = cio_tell( cio);
	  
	  len_cidx = write_cidx( pos_jp2c+8, cio, image, *cstr_info, len_jp2c-8);
	  
	  pos_fidx = cio_tell( cio);
	  len_fidx = write_fidx( pos_jp2c, len_jp2c, pos_cidx, len_cidx, cio);
	  
	  end_pos = cio_tell( cio);
	  
	  cio_seek( cio, pos_iptr);
	  write_iptr( pos_fidx, len_fidx, cio);
	  
	  cio_seek( cio, end_pos);
	}

	return OPJ_TRUE;
}
예제 #10
0
void j2k_write_com(void) {
    unsigned int i;
    int lenp, len;
    char str[256];
    sprintf(str, "Creator: J2000 codec");
    //fprintf(stderr, "%.8x: COM\n", cio_tell());
    cio_write(J2K_MS_COM, 2);
    lenp=cio_tell();
    cio_skip(2);
    cio_write(0, 2);
    for (i=0; i<strlen(str); i++) {
        cio_write(str[i], 1);
    }
    len=cio_tell()-lenp;
    cio_seek(lenp);
    cio_write(len, 2);
    cio_seek(lenp+len);
}
예제 #11
0
void j2k_write_cod(void) {
    j2k_tcp_t *tcp;
    int lenp, len;
    //fprintf(stderr, "%.8x: COD\n", cio_tell());
    cio_write(J2K_MS_COD, 2);
    lenp=cio_tell();
    cio_skip(2);
    tcp=&j2k_cp->tcps[j2k_curtileno];
    cio_write(tcp->csty, 1);
    cio_write(tcp->prg, 1);
    cio_write(tcp->numlayers, 2);
    cio_write(tcp->mct, 1);
    j2k_write_cox(0);
    len=cio_tell()-lenp;
    cio_seek(lenp);
    cio_write(len, 2);
    cio_seek(lenp+len);
}
예제 #12
0
파일: jp2.c 프로젝트: 151706061/Gdcm
int jp2_write_jp2c(j2k_image_t * img, j2k_cp_t * cp, char *jp2_buffer,
		   char *index)
{
  int len;
  jp2_box_t box;

  box.init_pos = cio_tell();
  cio_skip(4);
  cio_write(JP2_JP2C, 4);	// JP2C

  len = j2k_encode(img, cp, jp2_buffer, cp->tdx * cp->tdy * cp->th * cp->tw * 2, index);

  box.length = cio_tell() - box.init_pos;
  cio_seek(box.init_pos);
  cio_write(box.length, 4);	/*    L       */
  cio_seek(box.init_pos + box.length);
  return box.length;
}
예제 #13
0
파일: jp2.c 프로젝트: kevinpig/MyRepository
static bool jp2_read_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, unsigned int *j2k_codestream_length, unsigned int *j2k_codestream_offset) {
	opj_jp2_box_t box;

	opj_common_ptr cinfo = jp2->cinfo;

	jp2_read_boxhdr(cinfo, cio, &box);
	do {
		if(JP2_JP2C != box.type) {
			cio_skip(cio, box.length - 8);
			jp2_read_boxhdr(cinfo, cio, &box);
		}
	} while(JP2_JP2C != box.type);

	*j2k_codestream_offset = cio_tell(cio);
	*j2k_codestream_length = box.length - 8;

	return true;
}
예제 #14
0
파일: jp2.c 프로젝트: Hao-HUST/NBIS
static void jp2_write_resc(opj_jp2_t *jp2, opj_cio_t *cio) {
	opj_jp2_box_t box;
	
	box.init_pos = cio_tell(cio);
	cio_skip(cio, 4);
	cio_write(cio, JP2_RESC, 4);	/* RES */
	
	cio_write(cio, 0x99CA, 2);
	cio_write(cio, 0x0001, 2);
	cio_write(cio, 0x99CA, 2);
	cio_write(cio, 0x0001, 2);
	cio_write(cio, 0x00, 1);
	cio_write(cio, 0x00, 1);
	
	box.length = cio_tell(cio) - box.init_pos;
	cio_seek(cio, box.init_pos);
	cio_write(cio, box.length, 4);	/* L */
	cio_seek(cio, box.init_pos + box.length);
}
예제 #15
0
파일: jp2.c 프로젝트: 151706061/Gdcm
/*
* Write the JP2H box
*
* JP2 Header box
*
*/
void jp2_write_jp2h(jp2_struct_t * jp2_struct)
{
  jp2_box_t box;

  box.init_pos = cio_tell();
  cio_skip(4);;
  cio_write(JP2_JP2H, 4);	/* JP2H */

  jp2_write_ihdr(jp2_struct);

  if (jp2_struct->bpc == 255)
    jp2_write_bpcc(jp2_struct);
  jp2_write_colr(jp2_struct);

  box.length = cio_tell() - box.init_pos;
  cio_seek(box.init_pos);
  cio_write(box.length, 4);	/*    L       */
  cio_seek(box.init_pos + box.length);
}
예제 #16
0
void jp2_write_jp2h(opj_jp2_t *jp2, opj_cio_t *cio) {
	opj_jp2_box_t box;

	box.init_pos = cio_tell(cio);
	cio_skip(cio, 4);
	cio_write(cio, JP2_JP2H, 4);	/* JP2H */

	jp2_write_ihdr(jp2, cio);

	if (jp2->bpc == 255) {
		jp2_write_bpcc(jp2, cio);
	}
	jp2_write_colr(jp2, cio);

	box.length = cio_tell(cio) - box.init_pos;
	cio_seek(cio, box.init_pos);
	cio_write(cio, box.length, 4);	/* L */
	cio_seek(cio, box.init_pos + box.length);
}
예제 #17
0
void write_manf(int second, int v, opj_jp2_box_t *box, opj_cio_t *cio)
{
  int len, lenp, i;
  
  lenp = cio_tell( cio); 
  cio_skip( cio, 4);                         /* L [at the end]                    */
  cio_write( cio, JPIP_MANF,4);              /* T                                 */

  if (second){                          /* Write only during the second pass */
    for( i=0; i<v; i++){
      cio_write( cio, box[i].length, 4);  /* Box length                     */ 
      cio_write( cio, box[i].type, 4); /* Box type                       */
    }
  }

  len = cio_tell( cio) - lenp;
  cio_seek( cio, lenp);
  cio_write( cio, len, 4);                   /* L                                 */
  cio_seek( cio, lenp+len);
}
예제 #18
0
static void jp2_write_ftyp(opj_jp2_t *jp2, opj_cio_t *cio) {
	unsigned int i;
	opj_jp2_box_t box;

	box.init_pos = cio_tell(cio);
	cio_skip(cio, 4);
	cio_write(cio, JP2_FTYP, 4);		/* FTYP */

	cio_write(cio, jp2->brand, 4);		/* BR */
	cio_write(cio, jp2->minversion, 4);	/* MinV */

	for (i = 0; i < jp2->numcl; i++) {
		cio_write(cio, jp2->cl[i], 4);	/* CL */
	}

	box.length = cio_tell(cio) - box.init_pos;
	cio_seek(cio, box.init_pos);
	cio_write(cio, box.length, 4);	/* L */
	cio_seek(cio, box.init_pos + box.length);
}
예제 #19
0
void j2k_write_com()
{
  unsigned int i;
  int lenp, len;
  char str[256];
  sprintf(str, "%s", j2k_cp->comment);

  cio_write(J2K_MS_COM, 2);
  lenp = cio_tell();
  cio_skip(2);
  cio_write(0, 2);
  for (i = 0; i < strlen(str); i++) {
    cio_write(str[i], 1);
  }
  len = cio_tell() - lenp;
  cio_seek(lenp);
  cio_write(len, 2);
  cio_seek(lenp + len);

}
예제 #20
0
파일: jp2.c 프로젝트: 151706061/Gdcm
/*
* Write the FTYP box
*
* File type box
*
*/
void jp2_write_ftyp(jp2_struct_t * jp2_struct)
{
  unsigned int i;
  jp2_box_t box;

  box.init_pos = cio_tell();
  cio_skip(4);
  cio_write(JP2_FTYP, 4);	/* FTYP       */

  cio_write(jp2_struct->brand, 4);	/* BR         */
  cio_write(jp2_struct->minversion, 4);	/* MinV       */

  for (i = 0; i < jp2_struct->numcl; i++)
    cio_write(jp2_struct->cl[i], 4);	/* CL           */

  box.length = cio_tell() - box.init_pos;
  cio_seek(box.init_pos);
  cio_write(box.length, 4);	/*    L       */
  cio_seek(box.init_pos + box.length);
}
예제 #21
0
static void jp2_write_url(opj_cio_t *cio, char *Idx_file) {
	unsigned int i;
	opj_jp2_box_t box;

	box.init_pos = cio_tell(cio);
	cio_skip(cio, 4);
	cio_write(cio, JP2_URL, 4);	/* DBTL */
	cio_write(cio, 0, 1);		/* VERS */
	cio_write(cio, 0, 3);		/* FLAG */

	if(Idx_file) {
		for (i = 0; i < strlen(Idx_file); i++) {
			cio_write(cio, Idx_file[i], 1);
		}
	}

	box.length = cio_tell(cio) - box.init_pos;
	cio_seek(cio, box.init_pos);
	cio_write(cio, box.length, 4);	/* L */
	cio_seek(cio, box.init_pos + box.length);
}
예제 #22
0
static opj_bool jp2_read_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, unsigned int *j2k_codestream_length, unsigned int *j2k_codestream_offset) {
	opj_jp2_box_t box;

	opj_common_ptr cinfo = jp2->cinfo;

  if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) {
    opj_event_msg(cinfo, EVT_ERROR, "Failed to read boxhdr\n");
    return OPJ_FALSE;
  }
	do {
		if(JP2_JP2C != box.type) {
			cio_skip(cio, box.length - 8);
			if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) return OPJ_FALSE;
		}
	} while(JP2_JP2C != box.type);

	*j2k_codestream_offset = cio_tell(cio);
	*j2k_codestream_length = box.length - 8;

	return OPJ_TRUE;
}
예제 #23
0
static void jp2_write_colr(opj_jp2_t *jp2, opj_cio_t *cio) {
	opj_jp2_box_t box;

	box.init_pos = cio_tell(cio);
	cio_skip(cio, 4);
	cio_write(cio, JP2_COLR, 4);		/* COLR */

	cio_write(cio, jp2->meth, 1);		/* METH */
	cio_write(cio, jp2->precedence, 1);	/* PRECEDENCE */
	cio_write(cio, jp2->approx, 1);		/* APPROX */

	if(jp2->meth == 2)
	 jp2->enumcs = 0;

	cio_write(cio, jp2->enumcs, 4);	/* EnumCS */

	box.length = cio_tell(cio) - box.init_pos;
	cio_seek(cio, box.init_pos);
	cio_write(cio, box.length, 4);	/* L */
	cio_seek(cio, box.init_pos + box.length);
}
예제 #24
0
static void jp2_write_ihdr(opj_jp2_t *jp2, opj_cio_t *cio) {
	opj_jp2_box_t box;

	box.init_pos = cio_tell(cio);
	cio_skip(cio, 4);
	cio_write(cio, JP2_IHDR, 4);		/* IHDR */

	cio_write(cio, jp2->h, 4);			/* HEIGHT */
	cio_write(cio, jp2->w, 4);			/* WIDTH */
	cio_write(cio, jp2->numcomps, 2);	/* NC */

	cio_write(cio, jp2->bpc, 1);		/* BPC */

	cio_write(cio, jp2->C, 1);			/* C : Always 7 */
	cio_write(cio, jp2->UnkC, 1);		/* UnkC, colorspace unknown */
	cio_write(cio, jp2->IPR, 1);		/* IPR, no intellectual property */

	box.length = cio_tell(cio) - box.init_pos;
	cio_seek(cio, box.init_pos);
	cio_write(cio, box.length, 4);	/* L */
	cio_seek(cio, box.init_pos + box.length);
}
예제 #25
0
파일: jp2.c 프로젝트: 151706061/Gdcm
void jp2_write_colr(jp2_struct_t * jp2_struct)
{
  jp2_box_t box;

  box.init_pos = cio_tell();
  cio_skip(4);
  cio_write(JP2_COLR, 4);	// COLR

  cio_write(jp2_struct->meth, 1);	// METH
  cio_write(jp2_struct->precedence, 1);	// PRECEDENCE
  cio_write(jp2_struct->approx, 1);	// APPROX

  if (jp2_struct->meth == 1)
    cio_write(jp2_struct->enumcs, 4);	// EnumCS
  else
    cio_write(0, 1);		// PROFILE (??)

  box.length = cio_tell() - box.init_pos;
  cio_seek(box.init_pos);
  cio_write(box.length, 4);	/*    L       */
  cio_seek(box.init_pos + box.length);
}
예제 #26
0
void j2k_write_cod()
{
  j2k_tcp_t *tcp;
  int lenp, len;

  cio_write(J2K_MS_COD, 2);	/* COD */

  lenp = cio_tell();
  cio_skip(2);

  tcp = &j2k_cp->tcps[j2k_curtileno];
  cio_write(tcp->csty, 1);	/* Scod */
  cio_write(tcp->prg, 1);	/* SGcod (A) */
  cio_write(tcp->numlayers, 2);	/* SGcod (B) */
  cio_write(tcp->mct, 1);	/* SGcod (C) */

  j2k_write_cox(0);
  len = cio_tell() - lenp;
  cio_seek(lenp);
  cio_write(len, 2);		/* Lcod */
  cio_seek(lenp + len);
}
예제 #27
0
/* skip PROFILE */
	skip_len = box->init_pos + box->length - cio_tell(cio);
	if (skip_len < 0) 
  {
	opj_event_msg(cinfo, EVT_ERROR, "Error with COLR box size\n");
	return OPJ_FALSE;
  }
	if(skip_len > 0)
  {
	unsigned char *start;

	start = cio_getbp(cio);
	color->icc_profile_buf = (unsigned char*)opj_malloc(skip_len);
	color->icc_profile_len = skip_len;

	cio_skip(cio, box->init_pos + box->length - cio_tell(cio));

	memcpy(color->icc_profile_buf, start, skip_len);
  }
   }

	if (cio_tell(cio) - box->init_pos != box->length) 
   {
	opj_event_msg(cinfo, EVT_ERROR, "Error with COLR Box\n");
	return OPJ_FALSE;
   }
	color->jp2_has_colr = 1;

	return OPJ_TRUE;
}/* jp2_read_colr() */


//from openjpeg mailing list https://groups.google.com/forum/#!msg/openjpeg/7RZRPmzdE_M/eQGojBtOAawJ
#define JP2_XML 0x786D6C20 /*0x75756964*/
static opj_bool jp2_read_xml(opj_jp2_t *jp2, opj_cio_t *cio,
    opj_jp2_box_t *box,unsigned char ** xmp)
{
    int len;
    opj_common_ptr cinfo;

    cinfo = jp2->cinfo;

    len = box->init_pos + box->length - cio_tell(cio);
    if (len < 0)
   {
    opj_event_msg(cinfo, EVT_ERROR, "Error with XML box size\n");
    return OPJ_FALSE;
   }
    if(len > 0)
   {
    unsigned char *start;

    start = cio_getbp(cio);
    *xmp = (unsigned char*)opj_malloc(len+1);

    cio_skip(cio, box->init_pos + box->length - cio_tell(cio));
    memcpy(*xmp, start, len);
	(*xmp)[len] = 0;
   }
    else
   {
    (*xmp) = (unsigned char*)opj_malloc(1);
    (*xmp)[0] = 0;
   }
    if (cio_tell(cio) - box->init_pos != box->length)
   {
    opj_event_msg(cinfo, EVT_ERROR, "Error with XML Box\n");
    opj_free(*xmp);
    return OPJ_FALSE;
   }
   return OPJ_TRUE;
}
예제 #28
0
파일: jp2.c 프로젝트: 151706061/Gdcm
void jp2_write_ihdr(jp2_struct_t * jp2_struct)
{
  jp2_box_t box;

  box.init_pos = cio_tell();
  cio_skip(4);
  cio_write(JP2_IHDR, 4);	// IHDR

  cio_write(jp2_struct->h, 4);	// HEIGHT
  cio_write(jp2_struct->w, 4);	// WIDTH
  cio_write(jp2_struct->numcomps, 2);	// NC

  cio_write(jp2_struct->bpc, 1);	// BPC  

  cio_write(jp2_struct->C, 1);	// C : Always 7
  cio_write(jp2_struct->UnkC, 1);	// UnkC, colorspace unknow
  cio_write(jp2_struct->IPR, 1);	// IPR, no intellectual property

  box.length = cio_tell() - box.init_pos;
  cio_seek(box.init_pos);
  cio_write(box.length, 4);	/*    L       */
  cio_seek(box.init_pos + box.length);
}
예제 #29
0
파일: jp2.c 프로젝트: 151706061/fo-dicom
static void write_prxy( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_cio_t *cio)
{
  int len, lenp;

  lenp = cio_tell( cio);
  cio_skip( cio, 4);              /* L [at the end] */
  cio_write( cio, JPIP_PRXY, 4);  /* IPTR           */
  
  cio_write( cio, offset_jp2c, 8); /* OOFF           */
  cio_write( cio, length_jp2c, 4); /* OBH part 1     */
  cio_write( cio, JP2_JP2C, 4);        /* OBH part 2     */
  
  cio_write( cio, 1,1);           /* NI             */

  cio_write( cio, offset_idx, 8);  /* IOFF           */
  cio_write( cio, length_idx, 4);  /* IBH part 1     */
  cio_write( cio, JPIP_CIDX, 4);   /* IBH part 2     */

  len = cio_tell( cio)-lenp;
  cio_seek( cio, lenp);
  cio_write( cio, len, 4);        /* L              */
  cio_seek( cio, lenp+len);
}
예제 #30
0
파일: jp2.c 프로젝트: 151706061/Gdcm
void jp2_write_url(char *Idx_file)
{
  unsigned int i;
  char str[256];
  jp2_box_t box;

  sprintf(str, "%s", Idx_file);


  box.init_pos = cio_tell();
  cio_skip(4);
  cio_write(JP2_URL, 4);	// DBTL
  cio_write(0, 1);		// VERS
  cio_write(0, 3);		// FLAG

  for (i = 0; i < strlen(str); i++) {
    cio_write(str[i], 1);
  }

  box.length = cio_tell() - box.init_pos;
  cio_seek(box.init_pos);
  cio_write(box.length, 4);	/*    L       */
  cio_seek(box.init_pos + box.length);
}