2 * Copyright (c) 2012, Mathieu Malaterre
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.
30 #include "opj_config.h"
35 void error_callback(const char *msg, void *v);
36 void warning_callback(const char *msg, void *v);
37 void info_callback(const char *msg, void *v);
39 void error_callback(const char *msg, void *v) {
44 void warning_callback(const char *msg, void *v) {
49 void info_callback(const char *msg, void *v) {
55 int main(int argc, char *argv[])
57 const char * v = opj_version();
59 const OPJ_COLOR_SPACE color_space = OPJ_CLRSPC_GRAY;
62 int image_width = 256;
63 int image_height = 256;
65 opj_cparameters_t parameters;
67 int subsampling_dx = 0;
68 int subsampling_dy = 0;
70 opj_image_cmptparm_t cmptparm;
72 opj_codec_t* l_codec = 00;
75 opj_stream_t *l_stream = 00;
79 opj_set_default_encoder_parameters(¶meters);
80 parameters.cod_format = J2K_CFMT;
85 cmptparm.dx = subsampling_dx;
86 cmptparm.dy = subsampling_dy;
87 cmptparm.w = image_width;
88 cmptparm.h = image_height;
90 image = opj_image_create(numcomps, &cmptparm, color_space);
93 for (i = 0; i < image_width * image_height; i++)
96 for(compno = 0; compno < numcomps; compno++)
98 image->comps[compno].data[i] = 0;
102 /* catch events using our callbacks and give a local context */
\r
103 opj_set_info_handler(l_codec, info_callback,00);
\r
104 opj_set_warning_handler(l_codec, warning_callback,00);
\r
105 opj_set_error_handler(l_codec, error_callback,00);
107 l_codec = opj_create_compress(OPJ_CODEC_J2K);
108 opj_set_info_handler(l_codec, info_callback,00);
109 opj_set_warning_handler(l_codec, warning_callback,00);
110 opj_set_error_handler(l_codec, error_callback,00);
112 opj_setup_encoder(l_codec, ¶meters, image);
114 strcpy(parameters.outfile, "testempty1.j2k");
115 f = fopen(parameters.outfile, "wb");
118 l_stream = opj_stream_create_default_file_stream(f,OPJ_FALSE);
120 bSuccess = opj_start_compress(l_codec,image,l_stream);
123 bSuccess = opj_encode(l_codec, l_stream);
125 bSuccess = opj_end_compress(l_codec, l_stream);
128 opj_stream_destroy(l_stream);
131 opj_destroy_codec(l_codec);
132 opj_image_destroy(image);