Debian Codegraph @

tests/unit/testempty1.c

raw
1 /*
2 * Copyright (c) 2012, Mathieu Malaterre
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
13 *
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.
25 */
26 #include <assert.h>
27 #include <string.h>
28 #include <stdio.h>
29
30 #include "opj_config.h"
31 #include "openjpeg.h"
32
33 #define J2K_CFMT 0
34
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);
38
39 void error_callback(const char *msg, void *v)
40 {
41 (void)msg;
42 (void)v;
43 puts(msg);
44 }
45 void warning_callback(const char *msg, void *v)
46 {
47 (void)msg;
48 (void)v;
49 puts(msg);
50 }
51 void info_callback(const char *msg, void *v)
52 {
53 (void)msg;
54 (void)v;
55 puts(msg);
56 }
57
58 int main(int argc, char *argv[])
59 {
60 const char * v = opj_version();
61
62 const OPJ_COLOR_SPACE color_space = OPJ_CLRSPC_GRAY;
63 unsigned int numcomps = 1;
64 unsigned int i;
65 unsigned int image_width = 256;
66 unsigned int image_height = 256;
67
68 opj_cparameters_t parameters;
69
70 unsigned int subsampling_dx = 0;
71 unsigned int subsampling_dy = 0;
72
73 opj_image_cmptparm_t cmptparm;
74 opj_image_t *image;
75 opj_codec_t* l_codec = 00;
76 OPJ_BOOL bSuccess;
77 opj_stream_t *l_stream = 00;
78 (void)argc;
79 (void)argv;
80
81 opj_set_default_encoder_parameters(&parameters);
82 parameters.cod_format = J2K_CFMT;
83 puts(v);
84 cmptparm.prec = 8;
85 cmptparm.sgnd = 0;
86 cmptparm.dx = subsampling_dx;
87 cmptparm.dy = subsampling_dy;
88 cmptparm.w = image_width;
89 cmptparm.h = image_height;
90
91 image = opj_image_create(numcomps, &cmptparm, color_space);
92 assert(image);
93
94 for (i = 0; i < image_width * image_height; i++) {
95 unsigned int compno;
96 for (compno = 0; compno < numcomps; compno++) {
97 image->comps[compno].data[i] = 0;
98 }
99 }
100
101 /* catch events using our callbacks and give a local context */
102 opj_set_info_handler(l_codec, info_callback, 00);
103 opj_set_warning_handler(l_codec, warning_callback, 00);
104 opj_set_error_handler(l_codec, error_callback, 00);
105
106 l_codec = opj_create_compress(OPJ_CODEC_J2K);
107 opj_set_info_handler(l_codec, info_callback, 00);
108 opj_set_warning_handler(l_codec, warning_callback, 00);
109 opj_set_error_handler(l_codec, error_callback, 00);
110
111 opj_setup_encoder(l_codec, &parameters, image);
112
113 l_stream = opj_stream_create_default_file_stream("testempty1.j2k", OPJ_FALSE);
114 assert(l_stream);
115 bSuccess = opj_start_compress(l_codec, image, l_stream);
116 if (!bSuccess) {
117 opj_stream_destroy(l_stream);
118 opj_destroy_codec(l_codec);
119 opj_image_destroy(image);
120 return 0;
121 }
122
123 assert(bSuccess);
124 bSuccess = opj_encode(l_codec, l_stream);
125 assert(bSuccess);
126 bSuccess = opj_end_compress(l_codec, l_stream);
127 assert(bSuccess);
128
129 opj_stream_destroy(l_stream);
130
131 opj_destroy_codec(l_codec);
132 opj_image_destroy(image);
133
134 puts("end");
135 return 0;
136 }