/**
* Sets up the procedures to do on writing header after the codestream.
- * Developpers wanting to extend the library can add their own writing procedures.
+ * Developers wanting to extend the library can add their own writing procedures.
*/
static OPJ_BOOL opj_jp2_setup_end_header_writing(opj_jp2_t *jp2,
opj_event_mgr_t * p_manager);
/**
* Sets up the procedures to do on reading header after the codestream.
- * Developpers wanting to extend the library can add their own writing procedures.
+ * Developers wanting to extend the library can add their own writing procedures.
*/
static OPJ_BOOL opj_jp2_setup_end_header_reading(opj_jp2_t *jp2,
opj_event_mgr_t * p_manager);
/**
* Sets up the validation ,i.e. adds the procedures to launch to make sure the codec parameters
- * are valid. Developpers wanting to extend the library can add their own validation procedures.
+ * are valid. Developers wanting to extend the library can add their own validation procedures.
*/
static OPJ_BOOL opj_jp2_setup_encoding_validation(opj_jp2_t *jp2,
opj_event_mgr_t * p_manager);
/**
- * Sets up the procedures to do on writing header. Developpers wanting to extend the library can add their own writing procedures.
+ * Sets up the procedures to do on writing header. Developers wanting to extend the library can add their own writing procedures.
*/
static OPJ_BOOL opj_jp2_setup_header_writing(opj_jp2_t *jp2,
opj_event_mgr_t * p_manager);
/**
* Sets up the validation ,i.e. adds the procedures to launch to make sure the codec parameters
- * are valid. Developpers wanting to extend the library can add their own validation procedures.
+ * are valid. Developers wanting to extend the library can add their own validation procedures.
*/
static OPJ_BOOL opj_jp2_setup_decoding_validation(opj_jp2_t *jp2,
opj_event_mgr_t * p_manager);
/**
* Sets up the procedures to do on reading header.
- * Developpers wanting to extend the library can add their own writing procedures.
+ * Developers wanting to extend the library can add their own writing procedures.
*/
static OPJ_BOOL opj_jp2_setup_header_reading(opj_jp2_t *jp2,
opj_event_mgr_t * p_manager);
opj_read_bytes(p_image_header_data, &(jp2->numcomps), 2); /* NC */
p_image_header_data += 2;
+ if (jp2->h < 1 || jp2->w < 1 || jp2->numcomps < 1) {
+ opj_event_msg(p_manager, EVT_ERROR,
+ "Wrong values for: w(%d) h(%d) numcomps(%d) (ihdr)\n",
+ jp2->w, jp2->h, jp2->numcomps);
+ return OPJ_FALSE;
+ }
if ((jp2->numcomps - 1U) >=
16384U) { /* unsigned underflow is well defined: 1U <= jp2->numcomps <= 16384U */
opj_event_msg(p_manager, EVT_ERROR, "Invalid number of components (ihdr)\n");
/* Palette mapping: */
new_comps[i].data = (OPJ_INT32*)
- opj_image_data_alloc(old_comps[cmp].w * old_comps[cmp].h * sizeof(OPJ_INT32));
+ opj_image_data_alloc(sizeof(OPJ_INT32) * old_comps[cmp].w * old_comps[cmp].h);
if (!new_comps[i].data) {
while (i > 0) {
-- i;
pcol = cmap[i].pcol;
src = old_comps[cmp].data;
assert(src); /* verified above */
- max = new_comps[pcol].w * new_comps[pcol].h;
+ max = new_comps[i].w * new_comps[i].h;
/* Direct use: */
if (cmap[i].mtyp == 0) {
- assert(cmp == 0);
dst = new_comps[i].data;
assert(dst);
for (j = 0; j < max; ++j) {
}
max = image->numcomps;
- for (i = 0; i < max; ++i) {
- if (old_comps[i].data) {
- opj_image_data_free(old_comps[i].data);
+ for (j = 0; j < max; ++j) {
+ if (old_comps[j].data) {
+ opj_image_data_free(old_comps[j].data);
}
}
return OPJ_FALSE;
}
- entries = (OPJ_UINT32*) opj_malloc((size_t)nr_channels * nr_entries * sizeof(
- OPJ_UINT32));
+ entries = (OPJ_UINT32*) opj_malloc(sizeof(OPJ_UINT32) * nr_channels *
+ nr_entries);
if (!entries) {
return OPJ_FALSE;
}
"COLR BOX meth value is not a regular value (%d), "
"so we will ignore the entire Colour Specification box. \n", jp2->meth);
}
- if (jp2->color.jp2_has_colr) {
- jp2->j2k->enumcs = jp2->enumcs;
- }
+
return OPJ_TRUE;
}
-OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2,
- opj_stream_private_t *p_stream,
- opj_image_t* p_image,
- opj_event_mgr_t * p_manager)
+static OPJ_BOOL opj_jp2_apply_color_postprocessing(opj_jp2_t *jp2,
+ opj_image_t* p_image,
+ opj_event_mgr_t * p_manager)
{
- if (!p_image) {
- return OPJ_FALSE;
- }
-
- /* J2K decoding */
- if (! opj_j2k_decode(jp2->j2k, p_stream, p_image, p_manager)) {
- opj_event_msg(p_manager, EVT_ERROR,
- "Failed to decode the codestream in the JP2 file\n");
- return OPJ_FALSE;
- }
-
if (jp2->j2k->m_specific_param.m_decoder.m_numcomps_to_decode) {
/* Bypass all JP2 component transforms */
return OPJ_TRUE;
return OPJ_FALSE;
}
- /* Set Image Color Space */
- if (jp2->enumcs == 16) {
- p_image->color_space = OPJ_CLRSPC_SRGB;
- } else if (jp2->enumcs == 17) {
- p_image->color_space = OPJ_CLRSPC_GRAY;
- } else if (jp2->enumcs == 18) {
- p_image->color_space = OPJ_CLRSPC_SYCC;
- } else if (jp2->enumcs == 24) {
- p_image->color_space = OPJ_CLRSPC_EYCC;
- } else if (jp2->enumcs == 12) {
- p_image->color_space = OPJ_CLRSPC_CMYK;
- } else {
- p_image->color_space = OPJ_CLRSPC_UNKNOWN;
- }
-
if (jp2->color.jp2_pclr) {
/* Part 1, I.5.3.4: Either both or none : */
if (!jp2->color.jp2_pclr->cmap) {
return OPJ_TRUE;
}
+OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2,
+ opj_stream_private_t *p_stream,
+ opj_image_t* p_image,
+ opj_event_mgr_t * p_manager)
+{
+ if (!p_image) {
+ return OPJ_FALSE;
+ }
+
+ /* J2K decoding */
+ if (! opj_j2k_decode(jp2->j2k, p_stream, p_image, p_manager)) {
+ opj_event_msg(p_manager, EVT_ERROR,
+ "Failed to decode the codestream in the JP2 file\n");
+ return OPJ_FALSE;
+ }
+
+ return opj_jp2_apply_color_postprocessing(jp2, p_image, p_manager);
+}
+
static OPJ_BOOL opj_jp2_write_jp2h(opj_jp2_t *jp2,
opj_stream_private_t *stream,
opj_event_mgr_t * p_manager
OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG;
}
+void opj_jp2_decoder_set_strict_mode(opj_jp2_t *jp2, OPJ_BOOL strict)
+{
+ opj_j2k_decoder_set_strict_mode(jp2->j2k, strict);
+}
+
OPJ_BOOL opj_jp2_set_threads(opj_jp2_t *jp2, OPJ_UINT32 num_threads)
{
return opj_j2k_set_threads(jp2->j2k, num_threads);
opj_event_mgr_t * p_manager
)
{
+ int ret;
+
/* preconditions */
assert(jp2 != 00);
assert(p_stream != 00);
return OPJ_FALSE;
}
- return opj_j2k_read_header(p_stream,
- jp2->j2k,
- p_image,
- p_manager);
+ ret = opj_j2k_read_header(p_stream,
+ jp2->j2k,
+ p_image,
+ p_manager);
+
+ if (p_image && *p_image) {
+ /* Set Image Color Space */
+ if (jp2->enumcs == 16) {
+ (*p_image)->color_space = OPJ_CLRSPC_SRGB;
+ } else if (jp2->enumcs == 17) {
+ (*p_image)->color_space = OPJ_CLRSPC_GRAY;
+ } else if (jp2->enumcs == 18) {
+ (*p_image)->color_space = OPJ_CLRSPC_SYCC;
+ } else if (jp2->enumcs == 24) {
+ (*p_image)->color_space = OPJ_CLRSPC_EYCC;
+ } else if (jp2->enumcs == 12) {
+ (*p_image)->color_space = OPJ_CLRSPC_CMYK;
+ } else {
+ (*p_image)->color_space = OPJ_CLRSPC_UNKNOWN;
+ }
+ }
+ return ret;
}
static OPJ_BOOL opj_jp2_setup_encoding_validation(opj_jp2_t *jp2,
return OPJ_FALSE;
}
- if (p_jp2->j2k->m_specific_param.m_decoder.m_numcomps_to_decode) {
- /* Bypass all JP2 component transforms */
- return OPJ_TRUE;
- }
-
- if (!opj_jp2_check_color(p_image, &(p_jp2->color), p_manager)) {
- return OPJ_FALSE;
- }
-
- /* Set Image Color Space */
- if (p_jp2->enumcs == 16) {
- p_image->color_space = OPJ_CLRSPC_SRGB;
- } else if (p_jp2->enumcs == 17) {
- p_image->color_space = OPJ_CLRSPC_GRAY;
- } else if (p_jp2->enumcs == 18) {
- p_image->color_space = OPJ_CLRSPC_SYCC;
- } else if (p_jp2->enumcs == 24) {
- p_image->color_space = OPJ_CLRSPC_EYCC;
- } else if (p_jp2->enumcs == 12) {
- p_image->color_space = OPJ_CLRSPC_CMYK;
- } else {
- p_image->color_space = OPJ_CLRSPC_UNKNOWN;
- }
-
- if (p_jp2->color.jp2_pclr) {
- /* Part 1, I.5.3.4: Either both or none : */
- if (!p_jp2->color.jp2_pclr->cmap) {
- opj_jp2_free_pclr(&(p_jp2->color));
- } else {
- if (!opj_jp2_apply_pclr(p_image, &(p_jp2->color), p_manager)) {
- return OPJ_FALSE;
- }
- }
- }
-
- /* Apply the color space if needed */
- if (p_jp2->color.jp2_cdef) {
- opj_jp2_apply_cdef(p_image, &(p_jp2->color), p_manager);
- }
-
- if (p_jp2->color.icc_profile_buf) {
- p_image->icc_profile_buf = p_jp2->color.icc_profile_buf;
- p_image->icc_profile_len = p_jp2->color.icc_profile_len;
- p_jp2->color.icc_profile_buf = NULL;
- }
-
- return OPJ_TRUE;
+ return opj_jp2_apply_color_postprocessing(p_jp2, p_image, p_manager);
}
/* ----------------------------------------------------------------------- */
return opj_j2k_set_decoded_resolution_factor(p_jp2->j2k, res_factor, p_manager);
}
+/* ----------------------------------------------------------------------- */
+
+OPJ_BOOL opj_jp2_encoder_set_extra_options(
+ opj_jp2_t *p_jp2,
+ const char* const* p_options,
+ opj_event_mgr_t * p_manager)
+{
+ return opj_j2k_encoder_set_extra_options(p_jp2->j2k, p_options, p_manager);
+}
+
+/* ----------------------------------------------------------------------- */
+
/* JPIP specific */
#ifdef USE_JPIP