2 * Copyright (c) 2023, Even Rouault
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
18 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 * POSSIBILITY OF SUCH DAMAGE.
31 static void test_colorspace(const char* pszDirectory)
34 opj_image_t* image = NULL;
35 opj_stream_t *l_stream = NULL; /* Stream */
36 opj_codec_t* l_codec = NULL; /* Handle to a decompressor */
37 opj_dparameters_t parameters; /* decompression parameters */
39 snprintf(szFile, sizeof(szFile), "%s/input/conformance/file1.jp2",
41 l_stream = opj_stream_create_default_file_stream(szFile, 1);
43 fprintf(stderr, "ERROR -> failed to create the stream from the file %s\n",
47 l_codec = opj_create_decompress(OPJ_CODEC_JP2);
49 /* Setup the decoder */
50 opj_set_default_decoder_parameters(¶meters);
51 if (!opj_setup_decoder(l_codec, ¶meters)) {
52 fprintf(stderr, "ERROR -> opj_decompress: failed to setup the decoder\n");
53 opj_stream_destroy(l_stream);
54 opj_destroy_codec(l_codec);
58 /* Read the main header of the codestream and if necessary the JP2 boxes*/
59 if (! opj_read_header(l_stream, l_codec, &image)) {
60 fprintf(stderr, "ERROR -> opj_decompress: failed to read the header\n");
61 opj_stream_destroy(l_stream);
62 opj_destroy_codec(l_codec);
63 opj_image_destroy(image);
67 /* Check that color_space is set after opj_read_header() */
68 if (image->color_space != OPJ_CLRSPC_SRGB) {
69 fprintf(stderr, "ERROR -> image->color_space (=%d) != OPJ_CLRSPC_SRGB\n",
71 opj_stream_destroy(l_stream);
72 opj_destroy_codec(l_codec);
73 opj_image_destroy(image);
77 opj_destroy_codec(l_codec);
78 opj_stream_destroy(l_stream);
79 opj_image_destroy(image);
82 static void test_iccprofile(const char* pszDirectory)
85 opj_image_t* image = NULL;
86 opj_stream_t *l_stream = NULL; /* Stream */
87 opj_codec_t* l_codec = NULL; /* Handle to a decompressor */
88 opj_dparameters_t parameters; /* decompression parameters */
90 snprintf(szFile, sizeof(szFile), "%s/input/nonregression/relax.jp2",
92 l_stream = opj_stream_create_default_file_stream(szFile, 1);
94 fprintf(stderr, "ERROR -> failed to create the stream from the file %s\n",
98 l_codec = opj_create_decompress(OPJ_CODEC_JP2);
100 /* Setup the decoder */
101 opj_set_default_decoder_parameters(¶meters);
102 if (!opj_setup_decoder(l_codec, ¶meters)) {
103 fprintf(stderr, "ERROR -> opj_decompress: failed to setup the decoder\n");
104 opj_stream_destroy(l_stream);
105 opj_destroy_codec(l_codec);
109 /* Read the main header of the codestream and if necessary the JP2 boxes*/
110 if (! opj_read_header(l_stream, l_codec, &image)) {
111 fprintf(stderr, "ERROR -> opj_decompress: failed to read the header\n");
112 opj_stream_destroy(l_stream);
113 opj_destroy_codec(l_codec);
114 opj_image_destroy(image);
118 /* Check that icc_profile_len is set after opj_read_header() */
119 if (image->icc_profile_len != 278) {
120 fprintf(stderr, "ERROR -> image->icc_profile_len (=%d) != 278\n",
121 image->icc_profile_len);
122 opj_stream_destroy(l_stream);
123 opj_destroy_codec(l_codec);
124 opj_image_destroy(image);
128 opj_destroy_codec(l_codec);
129 opj_stream_destroy(l_stream);
130 opj_image_destroy(image);
133 int main(int argc, char* argv[])
136 fprintf(stderr, "usage: testjp2 /path/to/opj_data_root\n");
140 test_colorspace(argv[1]);
141 test_iccprofile(argv[1]);