#include <stdlib.h>
#include "openjpeg.h"
static void test_colorspace(const char* pszDirectory)
{
char szFile[2048];
opj_image_t* image = NULL;
opj_stream_t *l_stream = NULL;
opj_codec_t* l_codec = NULL;
opj_dparameters_t parameters;
snprintf(szFile, sizeof(szFile), "%s/input/conformance/file1.jp2",
pszDirectory);
l_stream = opj_stream_create_default_file_stream(szFile, 1);
if (!l_stream) {
fprintf(stderr, "ERROR -> failed to create the stream from the file %s\n",
szFile);
exit(1);
}
l_codec = opj_create_decompress(OPJ_CODEC_JP2);
opj_set_default_decoder_parameters(¶meters);
if (!opj_setup_decoder(l_codec, ¶meters)) {
fprintf(stderr, "ERROR -> opj_decompress: failed to setup the decoder\n");
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
exit(1);
}
if (! opj_read_header(l_stream, l_codec, &image)) {
fprintf(stderr, "ERROR -> opj_decompress: failed to read the header\n");
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
opj_image_destroy(image);
exit(1);
}
if (image->color_space != OPJ_CLRSPC_SRGB) {
fprintf(stderr, "ERROR -> image->color_space (=%d) != OPJ_CLRSPC_SRGB\n",
image->color_space);
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
opj_image_destroy(image);
exit(1);
}
opj_destroy_codec(l_codec);
opj_stream_destroy(l_stream);
opj_image_destroy(image);
}
static void test_iccprofile(const char* pszDirectory)
{
char szFile[2048];
opj_image_t* image = NULL;
opj_stream_t *l_stream = NULL;
opj_codec_t* l_codec = NULL;
opj_dparameters_t parameters;
snprintf(szFile, sizeof(szFile), "%s/input/nonregression/relax.jp2",
pszDirectory);
l_stream = opj_stream_create_default_file_stream(szFile, 1);
if (!l_stream) {
fprintf(stderr, "ERROR -> failed to create the stream from the file %s\n",
szFile);
exit(1);
}
l_codec = opj_create_decompress(OPJ_CODEC_JP2);
opj_set_default_decoder_parameters(¶meters);
if (!opj_setup_decoder(l_codec, ¶meters)) {
fprintf(stderr, "ERROR -> opj_decompress: failed to setup the decoder\n");
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
exit(1);
}
if (! opj_read_header(l_stream, l_codec, &image)) {
fprintf(stderr, "ERROR -> opj_decompress: failed to read the header\n");
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
opj_image_destroy(image);
exit(1);
}
if (image->icc_profile_len != 278) {
fprintf(stderr, "ERROR -> image->icc_profile_len (=%d) != 278\n",
image->icc_profile_len);
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
opj_image_destroy(image);
exit(1);
}
opj_destroy_codec(l_codec);
opj_stream_destroy(l_stream);
opj_image_destroy(image);
}
int main(int argc, char* argv[])
{
if (argc != 2) {
fprintf(stderr, "usage: testjp2 /path/to/opj_data_root\n");
exit(1);
}
test_colorspace(argv[1]);
test_iccprofile(argv[1]);
return 0;
}