OpenJPEG library interface modified to retain compatibility with version 1.2. Sorry...
authorFrancois-Olivier Devaux <fodevaux@users.noreply.github.com>
Mon, 17 Sep 2007 15:11:20 +0000 (15:11 +0000)
committerFrancois-Olivier Devaux <fodevaux@users.noreply.github.com>
Mon, 17 Sep 2007 15:11:20 +0000 (15:11 +0000)
ChangeLog
codec/image_to_j2k.c
codec/j2k_to_image.c
libopenjpeg/openjpeg.c
libopenjpeg/openjpeg.h
mj2/meta_out.c
mj2/mj2_to_frames.c

index 20acfaa939bd1a94c03b6f83ceeb93c5163109bc..5e7a33315353fc921a199db982aca94d1ffbe9e3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,7 @@ What's New for OpenJPEG
 
 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.
index 40ec2af03a97290f3d7ec2c8117742788993d0d7..d3027a813f0c03adc51bbaa902c53c2f8ea6ca65 100644 (file)
@@ -1919,7 +1919,10 @@ int main(int argc, char **argv) {
                                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");
@@ -1950,8 +1953,8 @@ int main(int argc, char **argv) {
 
                                /* 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;
@@ -1971,7 +1974,10 @@ int main(int argc, char **argv) {
                                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");
@@ -2001,7 +2007,8 @@ int main(int argc, char **argv) {
 
                                /* 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 */
index 98eae955b50371e12b5168a0f9224f4e93a93d8e..f265894e6fe8bd04cd6b8b8eb48c92dc65cd170d 100644 (file)
@@ -834,8 +834,6 @@ int main(int argc, char **argv) {
                fread(src, 1, file_length, fsrc);
                fclose(fsrc);
 
-
-
                /* decode the code-stream */
                /* ---------------------- */
 
@@ -857,7 +855,10 @@ int main(int argc, char **argv) {
                        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);
@@ -896,7 +897,10 @@ int main(int argc, char **argv) {
                        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);
@@ -935,7 +939,10 @@ int main(int argc, char **argv) {
                        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);
@@ -1029,7 +1036,8 @@ int main(int argc, char **argv) {
                        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);
 
index 95653d06c52f8d07c37e66c374eacf0b1887c18e..356d2ca9e6a841266dca2168ff796612e8628e87 100644 (file)
@@ -147,7 +147,11 @@ void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *param
        }
 }
 
-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:
@@ -161,7 +165,6 @@ opj_image_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio, opj_cod
                                break;
                }
        }
-
        return NULL;
 }
 
@@ -287,7 +290,15 @@ void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *param
        }
 }
 
-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:
index 20ff7cf728144d8fefd353e3e393b48c29df4a21..b58d39f92e4f91c10feddff8a5165a84b2ba8df3 100644 (file)
@@ -817,13 +817,21 @@ Decoding parameters are returned in j2k->cp.
 */
 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
@@ -869,10 +877,19 @@ Encode an image into a JPEG-2000 codestream
 @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
index b6c99e13e0c2ae82a28dfac63e9bd37f54077d2f..c77ec20a6485cefcf2683f4de4e8e084e933b2c8 100644 (file)
@@ -945,7 +945,7 @@ int xml_out_frame(FILE* file, FILE* xmlout, mj2_sample_t *sample, unsigned int s
        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);
index 6eae57f098c55c4851c077de2148ca6753abd5d3..bf4dfe6b10cf2f5b97bb3fef23a0b6be59a06cb5 100644 (file)
@@ -160,7 +160,7 @@ int main(int argc, char *argv[]) {
                /* 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))