summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancois-Olivier Devaux <fodevaux@users.noreply.github.com>2007-09-17 15:11:20 +0000
committerFrancois-Olivier Devaux <fodevaux@users.noreply.github.com>2007-09-17 15:11:20 +0000
commit55c4c14352519b84ad79abcb2f8527e1c25b9e54 (patch)
treeeb3efc84b540eccc43ca1ef19d8ca11ef0370942
parent569bbb00776f08211f7184ea4ea94571b652adae (diff)
OpenJPEG library interface modified to retain compatibility with version 1.2. Sorry if some of you already adapted their code to the previous interface, but we want to avoid a ABI break....
-rw-r--r--ChangeLog1
-rw-r--r--codec/image_to_j2k.c17
-rw-r--r--codec/j2k_to_image.c20
-rw-r--r--libopenjpeg/openjpeg.c17
-rw-r--r--libopenjpeg/openjpeg.h23
-rw-r--r--mj2/meta_out.c2
-rw-r--r--mj2/mj2_to_frames.c2
7 files changed, 63 insertions, 19 deletions
diff --git a/ChangeLog b/ChangeLog
index 20acfaa9..5e7a3331 100644
--- 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.
diff --git a/codec/image_to_j2k.c b/codec/image_to_j2k.c
index 40ec2af0..d3027a81 100644
--- a/codec/image_to_j2k.c
+++ b/codec/image_to_j2k.c
@@ -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 */
diff --git a/codec/j2k_to_image.c b/codec/j2k_to_image.c
index 98eae955..f265894e 100644
--- a/codec/j2k_to_image.c
+++ b/codec/j2k_to_image.c
@@ -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);
diff --git a/libopenjpeg/openjpeg.c b/libopenjpeg/openjpeg.c
index 95653d06..356d2ca9 100644
--- a/libopenjpeg/openjpeg.c
+++ b/libopenjpeg/openjpeg.c
@@ -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:
diff --git a/libopenjpeg/openjpeg.h b/libopenjpeg/openjpeg.h
index 20ff7cf7..b58d39f9 100644
--- a/libopenjpeg/openjpeg.h
+++ b/libopenjpeg/openjpeg.h
@@ -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
diff --git a/mj2/meta_out.c b/mj2/meta_out.c
index b6c99e13..c77ec20a 100644
--- a/mj2/meta_out.c
+++ b/mj2/meta_out.c
@@ -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);
diff --git a/mj2/mj2_to_frames.c b/mj2/mj2_to_frames.c
index 6eae57f0..bf4dfe6b 100644
--- a/mj2/mj2_to_frames.c
+++ b/mj2/mj2_to_frames.c
@@ -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))