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....

This commit is contained in:
Francois-Olivier Devaux 2007-09-17 15:11:20 +00:00
parent 569bbb0077
commit 55c4c14352
7 changed files with 63 additions and 19 deletions

View File

@ -7,6 +7,7 @@ What's New for OpenJPEG
September 17, 2007 September 17, 2007
* [FOD] Fixed issues with cstr_info when codestream has components with different number of resolutions. * [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 September 12, 2007
* [FOD] Patch from Callum Lerwick. * [FOD] Patch from Callum Lerwick.

View File

@ -1919,7 +1919,10 @@ int main(int argc, char **argv) {
cio = opj_cio_open((opj_common_ptr)cinfo, NULL, 0); cio = opj_cio_open((opj_common_ptr)cinfo, NULL, 0);
/* encode the image */ /* 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) { if (!bSuccess) {
opj_cio_close(cio); opj_cio_close(cio);
fprintf(stderr, "failed to encode image\n"); fprintf(stderr, "failed to encode image\n");
@ -1950,8 +1953,8 @@ int main(int argc, char **argv) {
/* free remaining compression structures */ /* free remaining compression structures */
opj_destroy_compress(cinfo); opj_destroy_compress(cinfo);
if (*indexfilename)
opj_destroy_cstr_info(&cstr_info); opj_destroy_cstr_info(&cstr_info);
} else { /* JP2 format output */ } else { /* JP2 format output */
int codestream_length; int codestream_length;
opj_cio_t *cio = NULL; 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); cio = opj_cio_open((opj_common_ptr)cinfo, NULL, 0);
/* encode the image */ /* 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) { if (!bSuccess) {
opj_cio_close(cio); opj_cio_close(cio);
fprintf(stderr, "failed to encode image\n"); fprintf(stderr, "failed to encode image\n");
@ -2001,6 +2007,7 @@ int main(int argc, char **argv) {
/* free remaining compression structures */ /* free remaining compression structures */
opj_destroy_compress(cinfo); opj_destroy_compress(cinfo);
if (*indexfilename)
opj_destroy_cstr_info(&cstr_info); opj_destroy_cstr_info(&cstr_info);
} }

View File

@ -834,8 +834,6 @@ int main(int argc, char **argv) {
fread(src, 1, file_length, fsrc); fread(src, 1, file_length, fsrc);
fclose(fsrc); fclose(fsrc);
/* decode the code-stream */ /* 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); cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length);
/* decode the stream and fill the image structure */ /* 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) { if(!image) {
fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n"); fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
opj_destroy_decompress(dinfo); 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); cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length);
/* decode the stream and fill the image structure */ /* 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) { if(!image) {
fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n"); fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
opj_destroy_decompress(dinfo); 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); cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length);
/* decode the stream and fill the image structure */ /* 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) { if(!image) {
fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n"); fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
opj_destroy_decompress(dinfo); opj_destroy_decompress(dinfo);
@ -1029,6 +1036,7 @@ int main(int argc, char **argv) {
opj_destroy_decompress(dinfo); opj_destroy_decompress(dinfo);
} }
/* free codestream information structure */ /* free codestream information structure */
if (*indexfilename)
opj_destroy_cstr_info(&cstr_info); opj_destroy_cstr_info(&cstr_info);
/* free image data structure */ /* free image data structure */
opj_image_destroy(image); opj_image_destroy(image);

View 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) { if(dinfo && cio) {
switch(dinfo->codec_format) { switch(dinfo->codec_format) {
case CODEC_J2K: 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; break;
} }
} }
return NULL; 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) { if(cinfo && cio && image) {
switch(cinfo->codec_format) { switch(cinfo->codec_format) {
case CODEC_J2K: case CODEC_J2K:

View File

@ -820,10 +820,18 @@ OPJ_API void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_
Decode an image from a JPEG-2000 codestream Decode an image from a JPEG-2000 codestream
@param dinfo decompressor handle @param dinfo decompressor handle
@param cio Input buffer stream @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 @param cstr_info Codestream information structure if needed afterwards, NULL otherwise
@return Returns a decoded image if successful, returns 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 Creates a J2K/JP2 compression structure
@param format Coder to select @param format Coder to select
@ -869,10 +877,19 @@ Encode an image into a JPEG-2000 codestream
@param cinfo compressor handle @param cinfo compressor handle
@param cio Output buffer stream @param cio Output buffer stream
@param image Image to encode @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 @param cstr_info Codestream information structure if needed afterwards, NULL otherwise
@return Returns true if successful, returns false 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 Destroy Codestream information after compression or decompression
@param cstr_info Codestream information structure @param cstr_info Codestream information structure

View 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); cio = opj_cio_open((opj_common_ptr)dinfo, frame_codestream, sample->sample_size-8);
/* Decode J2K to image: */ /* 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) { if (!img) {
fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n"); fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
opj_destroy_decompress(dinfo); opj_destroy_decompress(dinfo);

View File

@ -160,7 +160,7 @@ int main(int argc, char *argv[]) {
/* open a byte stream */ /* open a byte stream */
cio = opj_cio_open((opj_common_ptr)dinfo, frame_codestream, sample->sample_size-8); 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) 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)) && (img->comps[0].dx == img->comps[2].dx / 2 ) && (img->comps[0].dx == 1))