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)
46 OPJ_ARG_NOT_USED(lpReserved);
47 OPJ_ARG_NOT_USED(hModule);
49 switch (ul_reason_for_call) {
50 case DLL_PROCESS_ATTACH :
52 case DLL_PROCESS_DETACH :
54 case DLL_THREAD_ATTACH :
55 case DLL_THREAD_DETACH :
61 #endif /* OPJ_STATIC */
64 /* ---------------------------------------------------------------------- */
67 const char* OPJ_CALLCONV opj_version(void)
69 return OPJ_PACKAGE_VERSION;
72 opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format)
74 opj_dinfo_t *dinfo = (opj_dinfo_t*)opj_calloc(1, sizeof(opj_dinfo_t));
78 dinfo->is_decompressor = OPJ_TRUE;
82 /* get a J2K decoder handle */
83 dinfo->j2k_handle = (void*)j2k_create_decompress((opj_common_ptr)dinfo);
84 if (!dinfo->j2k_handle) {
90 /* get a JP2 decoder handle */
91 dinfo->jp2_handle = (void*)jp2_create_decompress((opj_common_ptr)dinfo);
92 if (!dinfo->jp2_handle) {
103 dinfo->codec_format = format;
108 void OPJ_CALLCONV opj_destroy_decompress(opj_dinfo_t *dinfo)
111 /* destroy the codec */
112 switch (dinfo->codec_format) {
115 j2k_destroy_decompress((opj_j2k_t*)dinfo->j2k_handle);
118 jp2_destroy_decompress((opj_jp2_t*)dinfo->jp2_handle);
124 /* destroy the decompressor */
129 void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t
133 memset(parameters, 0, sizeof(opj_dparameters_t));
134 /* default decoding parameters */
135 parameters->cp_layer = 0;
136 parameters->cp_reduce = 0;
137 parameters->cp_limit_decoding = NO_LIMITATION;
139 parameters->decod_format = -1;
140 parameters->cod_format = -1;
141 parameters->flags = 0;
144 parameters->jpwl_correct = OPJ_FALSE;
145 parameters->jpwl_exp_comps = JPWL_EXPECTED_COMPONENTS;
146 parameters->jpwl_max_tiles = JPWL_MAXIMUM_TILES;
147 #endif /* USE_JPWL */
152 void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo,
153 opj_dparameters_t *parameters)
155 if (dinfo && parameters) {
156 switch (dinfo->codec_format) {
159 j2k_setup_decoder((opj_j2k_t*)dinfo->j2k_handle, parameters);
162 jp2_setup_decoder((opj_jp2_t*)dinfo->jp2_handle, parameters);
171 opj_image_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio)
173 return opj_decode_with_info(dinfo, cio, NULL);
176 opj_image_t* OPJ_CALLCONV opj_decode_with_info(opj_dinfo_t *dinfo,
177 opj_cio_t *cio, opj_codestream_info_t *cstr_info)
180 switch (dinfo->codec_format) {
182 return j2k_decode((opj_j2k_t*)dinfo->j2k_handle, cio, cstr_info);
184 return j2k_decode_jpt_stream((opj_j2k_t*)dinfo->j2k_handle, cio, cstr_info);
186 return opj_jp2_decode((opj_jp2_t*)dinfo->jp2_handle, cio, cstr_info);
195 opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format)
197 opj_cinfo_t *cinfo = (opj_cinfo_t*)opj_calloc(1, sizeof(opj_cinfo_t));
201 cinfo->is_decompressor = OPJ_FALSE;
204 /* get a J2K coder handle */
205 cinfo->j2k_handle = (void*)j2k_create_compress((opj_common_ptr)cinfo);
206 if (!cinfo->j2k_handle) {
212 /* get a JP2 coder handle */
213 cinfo->jp2_handle = (void*)jp2_create_compress((opj_common_ptr)cinfo);
214 if (!cinfo->jp2_handle) {
226 cinfo->codec_format = format;
231 void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo)
234 /* destroy the codec */
235 switch (cinfo->codec_format) {
237 j2k_destroy_compress((opj_j2k_t*)cinfo->j2k_handle);
240 jp2_destroy_compress((opj_jp2_t*)cinfo->jp2_handle);
247 /* destroy the decompressor */
252 void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t
256 memset(parameters, 0, sizeof(opj_cparameters_t));
257 /* default coding parameters */
258 parameters->cp_cinema = OFF;
259 parameters->max_comp_size = 0;
260 parameters->numresolution = 6;
261 parameters->cp_rsiz = STD_RSIZ;
262 parameters->cblockw_init = 64;
263 parameters->cblockh_init = 64;
264 parameters->prog_order = LRCP;
265 parameters->roi_compno = -1; /* no ROI */
266 parameters->subsampling_dx = 1;
267 parameters->subsampling_dy = 1;
268 parameters->tp_on = 0;
269 parameters->decod_format = -1;
270 parameters->cod_format = -1;
271 parameters->tcp_rates[0] = 0;
272 parameters->tcp_numlayers = 0;
273 parameters->cp_disto_alloc = 0;
274 parameters->cp_fixed_alloc = 0;
275 parameters->cp_fixed_quality = 0;
278 parameters->jpwl_epc_on = OPJ_FALSE;
279 parameters->jpwl_hprot_MH = -1; /* -1 means unassigned */
282 for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) {
283 parameters->jpwl_hprot_TPH_tileno[i] = -1; /* unassigned */
284 parameters->jpwl_hprot_TPH[i] = 0; /* absent */
289 for (i = 0; i < JPWL_MAX_NO_PACKSPECS; i++) {
290 parameters->jpwl_pprot_tileno[i] = -1; /* unassigned */
291 parameters->jpwl_pprot_packno[i] = -1; /* unassigned */
292 parameters->jpwl_pprot[i] = 0; /* absent */
295 parameters->jpwl_sens_size = 0; /* 0 means no ESD */
296 parameters->jpwl_sens_addr = 0; /* 0 means auto */
297 parameters->jpwl_sens_range = 0; /* 0 means packet */
298 parameters->jpwl_sens_MH = -1; /* -1 means unassigned */
301 for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) {
302 parameters->jpwl_sens_TPH_tileno[i] = -1; /* unassigned */
303 parameters->jpwl_sens_TPH[i] = -1; /* absent */
306 #endif /* USE_JPWL */
311 void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo,
312 opj_cparameters_t *parameters, opj_image_t *image)
314 if (cinfo && parameters && image) {
315 switch (cinfo->codec_format) {
317 j2k_setup_encoder((opj_j2k_t*)cinfo->j2k_handle, parameters, image);
320 jp2_setup_encoder((opj_jp2_t*)cinfo->jp2_handle, parameters, image);
330 opj_bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio,
331 opj_image_t *image, char *index)
334 opj_event_msg((opj_common_ptr)cinfo, EVT_WARNING,
335 "Set index to NULL when calling the opj_encode function.\n"
336 "To extract the index, use the opj_encode_with_info() function.\n"
337 "No index will be generated during this encoding\n");
338 return opj_encode_with_info(cinfo, cio, image, NULL);
341 opj_bool OPJ_CALLCONV opj_encode_with_info(opj_cinfo_t *cinfo, opj_cio_t *cio,
342 opj_image_t *image, opj_codestream_info_t *cstr_info)
344 if (cinfo && cio && image) {
345 switch (cinfo->codec_format) {
347 return j2k_encode((opj_j2k_t*)cinfo->j2k_handle, cio, image, cstr_info);
349 return opj_jp2_encode((opj_jp2_t*)cinfo->jp2_handle, cio, image, cstr_info);
359 void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info)
363 for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
364 opj_tile_info_t *tile_info = &cstr_info->tile[tileno];
365 opj_free(tile_info->thresh);
366 opj_free(tile_info->packet);
367 opj_free(tile_info->tp);
368 opj_free(tile_info->marker);
370 opj_free(cstr_info->tile);
371 opj_free(cstr_info->marker);
372 opj_free(cstr_info->numdecompos);
376 void* OPJ_CALLCONV opj_image_data_alloc(size_t size)
378 /* NOTE: this defers from libopenjp2 where we use opj_aligned_malloc */
379 void* ret = opj_malloc(size);
380 /* printf("opj_image_data_alloc %p\n", ret); */
384 void OPJ_CALLCONV opj_image_data_free(void* ptr)
386 /* NOTE: this defers from libopenjp2 where we use opj_aligned_free */
387 /* printf("opj_image_data_free %p\n", ptr); */