aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/openjpeg-libsl/libopenjpeg/openjpeg.c
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/openjpeg-libsl/libopenjpeg/openjpeg.c')
-rw-r--r--libraries/openjpeg-libsl/libopenjpeg/openjpeg.c307
1 files changed, 307 insertions, 0 deletions
diff --git a/libraries/openjpeg-libsl/libopenjpeg/openjpeg.c b/libraries/openjpeg-libsl/libopenjpeg/openjpeg.c
new file mode 100644
index 0000000..6f12ff0
--- /dev/null
+++ b/libraries/openjpeg-libsl/libopenjpeg/openjpeg.c
@@ -0,0 +1,307 @@
1/*
2 * Copyright (c) 2005, Hervé Drolon, FreeImage Team
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
27#ifdef WIN32
28#include <windows.h>
29#endif /* WIN32 */
30
31#include "opj_includes.h"
32
33/* ---------------------------------------------------------------------- */
34#ifdef WIN32
35#ifndef OPJ_STATIC
36BOOL APIENTRY
37DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
38 switch (ul_reason_for_call) {
39 case DLL_PROCESS_ATTACH :
40 break;
41 case DLL_PROCESS_DETACH :
42 break;
43 case DLL_THREAD_ATTACH :
44 case DLL_THREAD_DETACH :
45 break;
46 }
47
48 return TRUE;
49}
50#endif /* OPJ_STATIC */
51#endif /* WIN32 */
52
53/* ---------------------------------------------------------------------- */
54
55
56const char* OPJ_CALLCONV opj_version() {
57 return OPENJPEG_VERSION;
58}
59
60opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format) {
61 opj_dinfo_t *dinfo = (opj_dinfo_t*)opj_malloc(sizeof(opj_dinfo_t));
62 if(!dinfo) return NULL;
63 dinfo->is_decompressor = true;
64 switch(format) {
65 case CODEC_J2K:
66 case CODEC_JPT:
67 /* get a J2K decoder handle */
68 dinfo->j2k_handle = (void*)j2k_create_decompress((opj_common_ptr)dinfo);
69 if(!dinfo->j2k_handle) {
70 opj_free(dinfo);
71 return NULL;
72 }
73 break;
74 case CODEC_JP2:
75 /* get a JP2 decoder handle */
76 dinfo->jp2_handle = (void*)jp2_create_decompress((opj_common_ptr)dinfo);
77 if(!dinfo->jp2_handle) {
78 opj_free(dinfo);
79 return NULL;
80 }
81 break;
82 case CODEC_UNKNOWN:
83 default:
84 opj_free(dinfo);
85 return NULL;
86 }
87
88 dinfo->codec_format = format;
89
90 return dinfo;
91}
92
93void OPJ_CALLCONV opj_destroy_decompress(opj_dinfo_t *dinfo) {
94 if(dinfo) {
95 /* destroy the codec */
96 switch(dinfo->codec_format) {
97 case CODEC_J2K:
98 case CODEC_JPT:
99 j2k_destroy_decompress((opj_j2k_t*)dinfo->j2k_handle);
100 break;
101 case CODEC_JP2:
102 jp2_destroy_decompress((opj_jp2_t*)dinfo->jp2_handle);
103 break;
104 case CODEC_UNKNOWN:
105 default:
106 break;
107 }
108 /* destroy the decompressor */
109 opj_free(dinfo);
110 }
111}
112
113void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters) {
114 if(parameters) {
115 memset(parameters, 0, sizeof(opj_dparameters_t));
116 /* default decoding parameters */
117 parameters->cp_layer = 0;
118 parameters->cp_reduce = 0;
119 parameters->cp_limit_decoding = NO_LIMITATION;
120
121 parameters->decod_format = -1;
122 parameters->cod_format = -1;
123/* UniPG>> */
124#ifdef USE_JPWL
125 parameters->jpwl_correct = false;
126 parameters->jpwl_exp_comps = JPWL_EXPECTED_COMPONENTS;
127 parameters->jpwl_max_tiles = JPWL_MAXIMUM_TILES;
128#endif /* USE_JPWL */
129/* <<UniPG */
130 }
131}
132
133void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters) {
134 if(dinfo && parameters) {
135 switch(dinfo->codec_format) {
136 case CODEC_J2K:
137 case CODEC_JPT:
138 j2k_setup_decoder((opj_j2k_t*)dinfo->j2k_handle, parameters);
139 break;
140 case CODEC_JP2:
141 jp2_setup_decoder((opj_jp2_t*)dinfo->jp2_handle, parameters);
142 break;
143 case CODEC_UNKNOWN:
144 default:
145 break;
146 }
147 }
148}
149
150opj_image_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio) {
151 if(dinfo && cio) {
152 switch(dinfo->codec_format) {
153 case CODEC_J2K:
154 return j2k_decode((opj_j2k_t*)dinfo->j2k_handle, cio);
155 case CODEC_JPT:
156 return j2k_decode_jpt_stream((opj_j2k_t*)dinfo->j2k_handle, cio);
157 case CODEC_JP2:
158 return jp2_decode((opj_jp2_t*)dinfo->jp2_handle, cio);
159 case CODEC_UNKNOWN:
160 default:
161 break;
162 }
163 }
164
165 return NULL;
166}
167
168opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format) {
169 opj_cinfo_t *cinfo = (opj_cinfo_t*)opj_malloc(sizeof(opj_cinfo_t));
170 if(!cinfo) return NULL;
171 cinfo->is_decompressor = false;
172 switch(format) {
173 case CODEC_J2K:
174 /* get a J2K coder handle */
175 cinfo->j2k_handle = (void*)j2k_create_compress((opj_common_ptr)cinfo);
176 if(!cinfo->j2k_handle) {
177 opj_free(cinfo);
178 return NULL;
179 }
180 break;
181 case CODEC_JP2:
182 /* get a JP2 coder handle */
183 cinfo->jp2_handle = (void*)jp2_create_compress((opj_common_ptr)cinfo);
184 if(!cinfo->jp2_handle) {
185 opj_free(cinfo);
186 return NULL;
187 }
188 break;
189 case CODEC_JPT:
190 case CODEC_UNKNOWN:
191 default:
192 opj_free(cinfo);
193 return NULL;
194 }
195
196 cinfo->codec_format = format;
197
198 return cinfo;
199}
200
201void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo) {
202 if(cinfo) {
203 /* destroy the codec */
204 switch(cinfo->codec_format) {
205 case CODEC_J2K:
206 j2k_destroy_decompress((opj_j2k_t*)cinfo->j2k_handle);
207 break;
208 case CODEC_JP2:
209 jp2_destroy_decompress((opj_jp2_t*)cinfo->jp2_handle);
210 break;
211 case CODEC_JPT:
212 case CODEC_UNKNOWN:
213 default:
214 break;
215 }
216 /* destroy the decompressor */
217 opj_free(cinfo);
218 }
219}
220
221void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters) {
222 if(parameters) {
223 memset(parameters, 0, sizeof(opj_cparameters_t));
224 /* default coding parameters */
225 parameters->cp_cinema = OFF;
226 parameters->max_comp_size = 0;
227 parameters->numresolution = 6;
228 parameters->cp_rsiz = STD_RSIZ;
229 parameters->cblockw_init = 64;
230 parameters->cblockh_init = 64;
231 parameters->prog_order = LRCP;
232 parameters->roi_compno = -1; /* no ROI */
233 parameters->subsampling_dx = 1;
234 parameters->subsampling_dy = 1;
235 parameters->tp_on = 0;
236 parameters->decod_format = -1;
237 parameters->cod_format = -1;
238/* UniPG>> */
239#ifdef USE_JPWL
240 parameters->jpwl_epc_on = false;
241 parameters->jpwl_hprot_MH = -1; /* -1 means unassigned */
242 {
243 int i;
244 for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) {
245 parameters->jpwl_hprot_TPH_tileno[i] = -1; /* unassigned */
246 parameters->jpwl_hprot_TPH[i] = 0; /* absent */
247 }
248 };
249 {
250 int i;
251 for (i = 0; i < JPWL_MAX_NO_PACKSPECS; i++) {
252 parameters->jpwl_pprot_tileno[i] = -1; /* unassigned */
253 parameters->jpwl_pprot_packno[i] = -1; /* unassigned */
254 parameters->jpwl_pprot[i] = 0; /* absent */
255 }
256 };
257 parameters->jpwl_sens_size = 0; /* 0 means no ESD */
258 parameters->jpwl_sens_addr = 0; /* 0 means auto */
259 parameters->jpwl_sens_range = 0; /* 0 means packet */
260 parameters->jpwl_sens_MH = -1; /* -1 means unassigned */
261 {
262 int i;
263 for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) {
264 parameters->jpwl_sens_TPH_tileno[i] = -1; /* unassigned */
265 parameters->jpwl_sens_TPH[i] = -1; /* absent */
266 }
267 };
268#endif /* USE_JPWL */
269/* <<UniPG */
270 }
271}
272
273void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_image_t *image) {
274 if(cinfo && parameters && image) {
275 switch(cinfo->codec_format) {
276 case CODEC_J2K:
277 j2k_setup_encoder((opj_j2k_t*)cinfo->j2k_handle, parameters, image);
278 break;
279 case CODEC_JP2:
280 jp2_setup_encoder((opj_jp2_t*)cinfo->jp2_handle, parameters, image);
281 break;
282 case CODEC_JPT:
283 case CODEC_UNKNOWN:
284 default:
285 break;
286 }
287 }
288}
289
290bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index) {
291 if(cinfo && cio && image) {
292 switch(cinfo->codec_format) {
293 case CODEC_J2K:
294 return j2k_encode((opj_j2k_t*)cinfo->j2k_handle, cio, image, index);
295 case CODEC_JP2:
296 return jp2_encode((opj_jp2_t*)cinfo->jp2_handle, cio, image, index);
297 case CODEC_JPT:
298 case CODEC_UNKNOWN:
299 default:
300 break;
301 }
302 }
303
304 return false;
305}
306
307