Beispiel #1
0
static opj_bool jp2_read_colr(opj_jp2_t *jp2, opj_cio_t *cio,
	opj_jp2_box_t *box, opj_jp2_color_t *color) 
{
	int skip_len;
    opj_common_ptr cinfo;

/* Part 1, I.5.3.3 : 'A conforming JP2 reader shall ignore all Colour
 * Specification boxes after the first.' 
*/
	if(color->jp2_has_colr) return OPJ_FALSE;

	cinfo = jp2->cinfo;

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

	if (jp2->meth == 1) 
   {
	jp2->enumcs = cio_read(cio, 4);	/* EnumCS */
   } 
	else
	if (jp2->meth == 2) 
   {
/* 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() */
Beispiel #2
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;
}