September 17, 2007
* [FOD] Fixed issues with cstr_info when codestream has components with different number of resolutions.
+! [FOD] OpenJPEG library interface modified to retain compatibility with version 1.2
September 12, 2007
* [FOD] Patch from Callum Lerwick.
cio = opj_cio_open((opj_common_ptr)cinfo, NULL, 0);
/* encode the image */
- bSuccess = opj_encode(cinfo, cio, image, &cstr_info);
+ if (*indexfilename) // If need to extract codestream information
+ bSuccess = opj_encode_with_info(cinfo, cio, image, &cstr_info);
+ else
+ bSuccess = opj_encode(cinfo, cio, image, NULL);
if (!bSuccess) {
opj_cio_close(cio);
fprintf(stderr, "failed to encode image\n");
/* free remaining compression structures */
opj_destroy_compress(cinfo);
- opj_destroy_cstr_info(&cstr_info);
-
+ if (*indexfilename)
+ opj_destroy_cstr_info(&cstr_info);
} else { /* JP2 format output */
int codestream_length;
opj_cio_t *cio = NULL;
cio = opj_cio_open((opj_common_ptr)cinfo, NULL, 0);
/* encode the image */
- bSuccess = opj_encode(cinfo, cio, image, &cstr_info);
+ if (*indexfilename) // If need to extract codestream information
+ bSuccess = opj_encode_with_info(cinfo, cio, image, &cstr_info);
+ else
+ bSuccess = opj_encode(cinfo, cio, image, NULL);
if (!bSuccess) {
opj_cio_close(cio);
fprintf(stderr, "failed to encode image\n");
/* free remaining compression structures */
opj_destroy_compress(cinfo);
- opj_destroy_cstr_info(&cstr_info);
+ if (*indexfilename)
+ opj_destroy_cstr_info(&cstr_info);
}
/* free image data */
fread(src, 1, file_length, fsrc);
fclose(fsrc);
-
-
/* decode the code-stream */
/* ---------------------- */
cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length);
/* decode the stream and fill the image structure */
- image = opj_decode(dinfo, cio, &cstr_info);
+ if (*indexfilename) // If need to extract codestream information
+ image = opj_decode_with_info(dinfo, cio, &cstr_info);
+ else
+ image = opj_decode(dinfo, cio);
if(!image) {
fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
opj_destroy_decompress(dinfo);
cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length);
/* decode the stream and fill the image structure */
- image = opj_decode(dinfo, cio, &cstr_info);
+ if (*indexfilename) // If need to extract codestream information
+ image = opj_decode_with_info(dinfo, cio, &cstr_info);
+ else
+ image = opj_decode(dinfo, cio);
if(!image) {
fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
opj_destroy_decompress(dinfo);
cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length);
/* decode the stream and fill the image structure */
- image = opj_decode(dinfo, cio, &cstr_info);
+ if (*indexfilename) // If need to extract codestream information
+ image = opj_decode_with_info(dinfo, cio, &cstr_info);
+ else
+ image = opj_decode(dinfo, cio);
if(!image) {
fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
opj_destroy_decompress(dinfo);
opj_destroy_decompress(dinfo);
}
/* free codestream information structure */
- opj_destroy_cstr_info(&cstr_info);
+ if (*indexfilename)
+ opj_destroy_cstr_info(&cstr_info);
/* free image data structure */
opj_image_destroy(image);
}
}
-opj_image_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio, opj_codestream_info_t *cstr_info) {
+opj_image_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio) {
+ return opj_decode_with_info(dinfo, cio, NULL);
+}
+
+opj_image_t* OPJ_CALLCONV opj_decode_with_info(opj_dinfo_t *dinfo, opj_cio_t *cio, opj_codestream_info_t *cstr_info) {
if(dinfo && cio) {
switch(dinfo->codec_format) {
case CODEC_J2K:
break;
}
}
-
return NULL;
}
}
}
-bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info) {
+bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index) {
+ if (index != NULL)
+ opj_event_msg((opj_common_ptr)cinfo, EVT_WARNING, "Set index to NULL when calling the opj_encode function.\n"
+ "To extract the index, use the opj_encode_with_info() function.\n"
+ "No index will be generated during this encoding\n");
+ return opj_encode_with_info(cinfo, cio, image, NULL);
+}
+
+bool OPJ_CALLCONV opj_encode_with_info(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info) {
if(cinfo && cio && image) {
switch(cinfo->codec_format) {
case CODEC_J2K:
*/
OPJ_API void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters);
/**
-Decode an image from a JPEG-2000 codestream
+Decode an image from a JPEG-2000 codestream
+@param dinfo decompressor handle
+@param cio Input buffer stream
+@return Returns a decoded image if successful, returns NULL otherwise
+*/
+OPJ_API opj_image_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio);
+
+/**
+Decode an image from a JPEG-2000 codestream and extract the codestream information
@param dinfo decompressor handle
@param cio Input buffer stream
@param cstr_info Codestream information structure if needed afterwards, NULL otherwise
@return Returns a decoded image if successful, returns NULL otherwise
*/
-OPJ_API opj_image_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio, opj_codestream_info_t *cstr_info);
+OPJ_API opj_image_t* OPJ_CALLCONV opj_decode_with_info(opj_dinfo_t *dinfo, opj_cio_t *cio, opj_codestream_info_t *cstr_info);
/**
Creates a J2K/JP2 compression structure
@param format Coder to select
@param cinfo compressor handle
@param cio Output buffer stream
@param image Image to encode
+@param index Depreacted -> Set to NULL. To extract index, used opj_encode_wci()
+@return Returns true if successful, returns false otherwise
+*/
+OPJ_API bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index);
+/**
+Encode an image into a JPEG-2000 codestream and extract the codestream information
+@param cinfo compressor handle
+@param cio Output buffer stream
+@param image Image to encode
@param cstr_info Codestream information structure if needed afterwards, NULL otherwise
@return Returns true if successful, returns false otherwise
*/
-OPJ_API bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info);
+OPJ_API bool OPJ_CALLCONV opj_encode_with_info(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info);
/**
Destroy Codestream information after compression or decompression
@param cstr_info Codestream information structure
cio = opj_cio_open((opj_common_ptr)dinfo, frame_codestream, sample->sample_size-8);
/* Decode J2K to image: */
- img = opj_decode(dinfo, cio, NULL); /* We don't need cstr_info -> set to NULL */
+ img = opj_decode(dinfo, cio);
if (!img) {
fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
opj_destroy_decompress(dinfo);
/* open a byte stream */
cio = opj_cio_open((opj_common_ptr)dinfo, frame_codestream, sample->sample_size-8);
- img = opj_decode(dinfo, cio, NULL); // Decode J2K to image. We will not use the cstr_info afterwards -> set to NULL
+ img = opj_decode(dinfo, cio); // Decode J2K to image
if (((img->numcomps == 3) && (img->comps[0].dx == img->comps[1].dx / 2)
&& (img->comps[0].dx == img->comps[2].dx / 2 ) && (img->comps[0].dx == 1))