2 * The copyright in this software is being made available under the 2-clauses
3 * BSD License, included below. This software may be subject to other third
4 * party and contributor rights, including patent rights, and no such rights
5 * are granted under this license.
7 * Copyright (c) 2005, Herve Drolon, FreeImage Team
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
36 #include "opj_config_private.h"
37 #include "opj_includes.h"
39 /* ---------------------------------------------------------------------- */
43 DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
45 OPJ_ARG_NOT_USED(lpReserved);
46 OPJ_ARG_NOT_USED(hModule);
48 switch (ul_reason_for_call) {
49 case DLL_PROCESS_ATTACH :
51 case DLL_PROCESS_DETACH :
53 case DLL_THREAD_ATTACH :
54 case DLL_THREAD_DETACH :
60 #endif /* OPJ_STATIC */
63 /* ---------------------------------------------------------------------- */
66 const char* OPJ_CALLCONV opj_version(void) {
67 return OPJ_PACKAGE_VERSION;
70 opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format) {
71 opj_dinfo_t *dinfo = (opj_dinfo_t*)opj_calloc(1, sizeof(opj_dinfo_t));
72 if(!dinfo) return NULL;
73 dinfo->is_decompressor = OPJ_TRUE;
77 /* get a J2K decoder handle */
78 dinfo->j2k_handle = (void*)j2k_create_decompress((opj_common_ptr)dinfo);
79 if(!dinfo->j2k_handle) {
85 /* get a JP2 decoder handle */
86 dinfo->jp2_handle = (void*)jp2_create_decompress((opj_common_ptr)dinfo);
87 if(!dinfo->jp2_handle) {
98 dinfo->codec_format = format;
103 void OPJ_CALLCONV opj_destroy_decompress(opj_dinfo_t *dinfo) {
105 /* destroy the codec */
106 switch(dinfo->codec_format) {
109 j2k_destroy_decompress((opj_j2k_t*)dinfo->j2k_handle);
112 jp2_destroy_decompress((opj_jp2_t*)dinfo->jp2_handle);
118 /* destroy the decompressor */
123 void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters) {
125 memset(parameters, 0, sizeof(opj_dparameters_t));
126 /* default decoding parameters */
127 parameters->cp_layer = 0;
128 parameters->cp_reduce = 0;
129 parameters->cp_limit_decoding = NO_LIMITATION;
131 parameters->decod_format = -1;
132 parameters->cod_format = -1;
133 parameters->flags = 0;
136 parameters->jpwl_correct = OPJ_FALSE;
137 parameters->jpwl_exp_comps = JPWL_EXPECTED_COMPONENTS;
138 parameters->jpwl_max_tiles = JPWL_MAXIMUM_TILES;
139 #endif /* USE_JPWL */
144 void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters) {
145 if(dinfo && parameters) {
146 switch(dinfo->codec_format) {
149 j2k_setup_decoder((opj_j2k_t*)dinfo->j2k_handle, parameters);
152 jp2_setup_decoder((opj_jp2_t*)dinfo->jp2_handle, parameters);
161 opj_image_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio) {
162 return opj_decode_with_info(dinfo, cio, NULL);
165 opj_image_t* OPJ_CALLCONV opj_decode_with_info(opj_dinfo_t *dinfo, opj_cio_t *cio, opj_codestream_info_t *cstr_info) {
167 switch(dinfo->codec_format) {
169 return j2k_decode((opj_j2k_t*)dinfo->j2k_handle, cio, cstr_info);
171 return j2k_decode_jpt_stream((opj_j2k_t*)dinfo->j2k_handle, cio, cstr_info);
173 return opj_jp2_decode((opj_jp2_t*)dinfo->jp2_handle, cio, cstr_info);
182 opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format) {
183 opj_cinfo_t *cinfo = (opj_cinfo_t*)opj_calloc(1, sizeof(opj_cinfo_t));
184 if(!cinfo) return NULL;
185 cinfo->is_decompressor = OPJ_FALSE;
188 /* get a J2K coder handle */
189 cinfo->j2k_handle = (void*)j2k_create_compress((opj_common_ptr)cinfo);
190 if(!cinfo->j2k_handle) {
196 /* get a JP2 coder handle */
197 cinfo->jp2_handle = (void*)jp2_create_compress((opj_common_ptr)cinfo);
198 if(!cinfo->jp2_handle) {
210 cinfo->codec_format = format;
215 void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo) {
217 /* destroy the codec */
218 switch(cinfo->codec_format) {
220 j2k_destroy_compress((opj_j2k_t*)cinfo->j2k_handle);
223 jp2_destroy_compress((opj_jp2_t*)cinfo->jp2_handle);
230 /* destroy the decompressor */
235 void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters) {
237 memset(parameters, 0, sizeof(opj_cparameters_t));
238 /* default coding parameters */
239 parameters->cp_cinema = OFF;
240 parameters->max_comp_size = 0;
241 parameters->numresolution = 6;
242 parameters->cp_rsiz = STD_RSIZ;
243 parameters->cblockw_init = 64;
244 parameters->cblockh_init = 64;
245 parameters->prog_order = LRCP;
246 parameters->roi_compno = -1; /* no ROI */
247 parameters->subsampling_dx = 1;
248 parameters->subsampling_dy = 1;
249 parameters->tp_on = 0;
250 parameters->decod_format = -1;
251 parameters->cod_format = -1;
252 parameters->tcp_rates[0] = 0;
253 parameters->tcp_numlayers = 0;
254 parameters->cp_disto_alloc = 0;
255 parameters->cp_fixed_alloc = 0;
256 parameters->cp_fixed_quality = 0;
259 parameters->jpwl_epc_on = OPJ_FALSE;
260 parameters->jpwl_hprot_MH = -1; /* -1 means unassigned */
263 for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) {
264 parameters->jpwl_hprot_TPH_tileno[i] = -1; /* unassigned */
265 parameters->jpwl_hprot_TPH[i] = 0; /* absent */
270 for (i = 0; i < JPWL_MAX_NO_PACKSPECS; i++) {
271 parameters->jpwl_pprot_tileno[i] = -1; /* unassigned */
272 parameters->jpwl_pprot_packno[i] = -1; /* unassigned */
273 parameters->jpwl_pprot[i] = 0; /* absent */
276 parameters->jpwl_sens_size = 0; /* 0 means no ESD */
277 parameters->jpwl_sens_addr = 0; /* 0 means auto */
278 parameters->jpwl_sens_range = 0; /* 0 means packet */
279 parameters->jpwl_sens_MH = -1; /* -1 means unassigned */
282 for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) {
283 parameters->jpwl_sens_TPH_tileno[i] = -1; /* unassigned */
284 parameters->jpwl_sens_TPH[i] = -1; /* absent */
287 #endif /* USE_JPWL */
292 void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_image_t *image) {
293 if(cinfo && parameters && image) {
294 switch(cinfo->codec_format) {
296 j2k_setup_encoder((opj_j2k_t*)cinfo->j2k_handle, parameters, image);
299 jp2_setup_encoder((opj_jp2_t*)cinfo->jp2_handle, parameters, image);
309 opj_bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index) {
311 opj_event_msg((opj_common_ptr)cinfo, EVT_WARNING, "Set index to NULL when calling the opj_encode function.\n"
312 "To extract the index, use the opj_encode_with_info() function.\n"
313 "No index will be generated during this encoding\n");
314 return opj_encode_with_info(cinfo, cio, image, NULL);
317 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) {
318 if(cinfo && cio && image) {
319 switch(cinfo->codec_format) {
321 return j2k_encode((opj_j2k_t*)cinfo->j2k_handle, cio, image, cstr_info);
323 return opj_jp2_encode((opj_jp2_t*)cinfo->jp2_handle, cio, image, cstr_info);
333 void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info) {
336 for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
337 opj_tile_info_t *tile_info = &cstr_info->tile[tileno];
338 opj_free(tile_info->thresh);
339 opj_free(tile_info->packet);
340 opj_free(tile_info->tp);
341 opj_free(tile_info->marker);
343 opj_free(cstr_info->tile);
344 opj_free(cstr_info->marker);
345 opj_free(cstr_info->numdecompos);