2 * Copyright (c) 2005, Herve Drolon, FreeImage Team
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 #include "opj_config.h"
32 #include "opj_includes.h"
34 /* ---------------------------------------------------------------------- */
38 DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
40 OPJ_ARG_NOT_USED(lpReserved);
41 OPJ_ARG_NOT_USED(hModule);
43 switch (ul_reason_for_call) {
44 case DLL_PROCESS_ATTACH :
46 case DLL_PROCESS_DETACH :
48 case DLL_THREAD_ATTACH :
49 case DLL_THREAD_DETACH :
55 #endif /* OPJ_STATIC */
58 /* ---------------------------------------------------------------------- */
61 const char* OPJ_CALLCONV opj_version(void) {
62 return PACKAGE_VERSION;
65 opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format) {
66 opj_dinfo_t *dinfo = (opj_dinfo_t*)opj_calloc(1, sizeof(opj_dinfo_t));
67 if(!dinfo) return NULL;
68 dinfo->is_decompressor = OPJ_TRUE;
72 /* get a J2K decoder handle */
73 dinfo->j2k_handle = (void*)j2k_create_decompress((opj_common_ptr)dinfo);
74 if(!dinfo->j2k_handle) {
80 /* get a JP2 decoder handle */
81 dinfo->jp2_handle = (void*)jp2_create_decompress((opj_common_ptr)dinfo);
82 if(!dinfo->jp2_handle) {
93 dinfo->codec_format = format;
98 void OPJ_CALLCONV opj_destroy_decompress(opj_dinfo_t *dinfo) {
100 /* destroy the codec */
101 switch(dinfo->codec_format) {
104 j2k_destroy_decompress((opj_j2k_t*)dinfo->j2k_handle);
107 jp2_destroy_decompress((opj_jp2_t*)dinfo->jp2_handle);
113 /* destroy the decompressor */
118 void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters) {
120 memset(parameters, 0, sizeof(opj_dparameters_t));
121 /* default decoding parameters */
122 parameters->cp_layer = 0;
123 parameters->cp_reduce = 0;
124 parameters->cp_limit_decoding = NO_LIMITATION;
126 parameters->decod_format = -1;
127 parameters->cod_format = -1;
128 parameters->flags = 0;
131 parameters->jpwl_correct = OPJ_FALSE;
132 parameters->jpwl_exp_comps = JPWL_EXPECTED_COMPONENTS;
133 parameters->jpwl_max_tiles = JPWL_MAXIMUM_TILES;
134 #endif /* USE_JPWL */
139 void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters) {
140 if(dinfo && parameters) {
141 switch(dinfo->codec_format) {
144 j2k_setup_decoder((opj_j2k_t*)dinfo->j2k_handle, parameters);
147 jp2_setup_decoder((opj_jp2_t*)dinfo->jp2_handle, parameters);
156 opj_image_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio) {
157 return opj_decode_with_info(dinfo, cio, NULL);
160 opj_image_t* OPJ_CALLCONV opj_decode_with_info(opj_dinfo_t *dinfo, opj_cio_t *cio, opj_codestream_info_t *cstr_info) {
162 switch(dinfo->codec_format) {
164 return j2k_decode((opj_j2k_t*)dinfo->j2k_handle, cio, cstr_info);
166 return j2k_decode_jpt_stream((opj_j2k_t*)dinfo->j2k_handle, cio, cstr_info);
168 return opj_jp2_decode((opj_jp2_t*)dinfo->jp2_handle, cio, cstr_info);
177 opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format) {
178 opj_cinfo_t *cinfo = (opj_cinfo_t*)opj_calloc(1, sizeof(opj_cinfo_t));
179 if(!cinfo) return NULL;
180 cinfo->is_decompressor = OPJ_FALSE;
183 /* get a J2K coder handle */
184 cinfo->j2k_handle = (void*)j2k_create_compress((opj_common_ptr)cinfo);
185 if(!cinfo->j2k_handle) {
191 /* get a JP2 coder handle */
192 cinfo->jp2_handle = (void*)jp2_create_compress((opj_common_ptr)cinfo);
193 if(!cinfo->jp2_handle) {
205 cinfo->codec_format = format;
210 void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo) {
212 /* destroy the codec */
213 switch(cinfo->codec_format) {
215 j2k_destroy_compress((opj_j2k_t*)cinfo->j2k_handle);
218 jp2_destroy_compress((opj_jp2_t*)cinfo->jp2_handle);
225 /* destroy the decompressor */
230 void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters) {
232 memset(parameters, 0, sizeof(opj_cparameters_t));
233 /* default coding parameters */
234 parameters->cp_cinema = OFF;
235 parameters->max_comp_size = 0;
236 parameters->numresolution = 6;
237 parameters->cp_rsiz = STD_RSIZ;
238 parameters->cblockw_init = 64;
239 parameters->cblockh_init = 64;
240 parameters->prog_order = LRCP;
241 parameters->roi_compno = -1; /* no ROI */
242 parameters->subsampling_dx = 1;
243 parameters->subsampling_dy = 1;
244 parameters->tp_on = 0;
245 parameters->decod_format = -1;
246 parameters->cod_format = -1;
247 parameters->tcp_rates[0] = 0;
248 parameters->tcp_numlayers = 0;
249 parameters->cp_disto_alloc = 0;
250 parameters->cp_fixed_alloc = 0;
251 parameters->cp_fixed_quality = 0;
252 parameters->jpip_on = OPJ_FALSE;
255 parameters->jpwl_epc_on = OPJ_FALSE;
256 parameters->jpwl_hprot_MH = -1; /* -1 means unassigned */
259 for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) {
260 parameters->jpwl_hprot_TPH_tileno[i] = -1; /* unassigned */
261 parameters->jpwl_hprot_TPH[i] = 0; /* absent */
266 for (i = 0; i < JPWL_MAX_NO_PACKSPECS; i++) {
267 parameters->jpwl_pprot_tileno[i] = -1; /* unassigned */
268 parameters->jpwl_pprot_packno[i] = -1; /* unassigned */
269 parameters->jpwl_pprot[i] = 0; /* absent */
272 parameters->jpwl_sens_size = 0; /* 0 means no ESD */
273 parameters->jpwl_sens_addr = 0; /* 0 means auto */
274 parameters->jpwl_sens_range = 0; /* 0 means packet */
275 parameters->jpwl_sens_MH = -1; /* -1 means unassigned */
278 for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) {
279 parameters->jpwl_sens_TPH_tileno[i] = -1; /* unassigned */
280 parameters->jpwl_sens_TPH[i] = -1; /* absent */
283 #endif /* USE_JPWL */
288 void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_image_t *image) {
289 if(cinfo && parameters && image) {
290 switch(cinfo->codec_format) {
292 j2k_setup_encoder((opj_j2k_t*)cinfo->j2k_handle, parameters, image);
295 jp2_setup_encoder((opj_jp2_t*)cinfo->jp2_handle, parameters, image);
305 opj_bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index) {
307 opj_event_msg((opj_common_ptr)cinfo, EVT_WARNING, "Set index to NULL when calling the opj_encode function.\n"
308 "To extract the index, use the opj_encode_with_info() function.\n"
309 "No index will be generated during this encoding\n");
310 return opj_encode_with_info(cinfo, cio, image, NULL);
313 opj_bool OPJ_CALLCONV opj_encode_with_info(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info) {
314 if(cinfo && cio && image) {
315 switch(cinfo->codec_format) {
317 return j2k_encode((opj_j2k_t*)cinfo->j2k_handle, cio, image, cstr_info);
319 return opj_jp2_encode((opj_jp2_t*)cinfo->jp2_handle, cio, image, cstr_info);
329 void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info) {
332 for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
333 opj_tile_info_t *tile_info = &cstr_info->tile[tileno];
334 opj_free(tile_info->thresh);
335 opj_free(tile_info->packet);
336 opj_free(tile_info->tp);
337 opj_free(tile_info->marker);
339 opj_free(cstr_info->tile);
340 opj_free(cstr_info->marker);
341 opj_free(cstr_info->numdecompos);