2 * Copyright (c) 2005, Herv� 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_includes.h"
33 /* ---------------------------------------------------------------------- */
37 DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
38 switch (ul_reason_for_call) {
39 case DLL_PROCESS_ATTACH :
41 case DLL_PROCESS_DETACH :
43 case DLL_THREAD_ATTACH :
44 case DLL_THREAD_DETACH :
50 #endif /* OPJ_STATIC */
53 /* ---------------------------------------------------------------------- */
56 const char* OPJ_CALLCONV opj_version() {
57 return OPENJPEG_VERSION;
60 opj_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;
67 /* get a J2K decoder handle */
68 dinfo->j2k_handle = (void*)j2k_create_decompress((opj_common_ptr)dinfo);
69 if(!dinfo->j2k_handle) {
75 /* get a JP2 decoder handle */
76 dinfo->jp2_handle = (void*)jp2_create_decompress((opj_common_ptr)dinfo);
77 if(!dinfo->jp2_handle) {
88 dinfo->codec_format = format;
93 void OPJ_CALLCONV opj_destroy_decompress(opj_dinfo_t *dinfo) {
95 /* destroy the codec */
96 switch(dinfo->codec_format) {
99 j2k_destroy_decompress((opj_j2k_t*)dinfo->j2k_handle);
102 jp2_destroy_decompress((opj_jp2_t*)dinfo->jp2_handle);
108 /* destroy the decompressor */
113 void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *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;
121 parameters->decod_format = -1;
122 parameters->cod_format = -1;
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 */
133 void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters) {
134 if(dinfo && parameters) {
135 switch(dinfo->codec_format) {
138 j2k_setup_decoder((opj_j2k_t*)dinfo->j2k_handle, parameters);
141 jp2_setup_decoder((opj_jp2_t*)dinfo->jp2_handle, parameters);
150 opj_image_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio) {
152 switch(dinfo->codec_format) {
154 return j2k_decode((opj_j2k_t*)dinfo->j2k_handle, cio);
156 return j2k_decode_jpt_stream((opj_j2k_t*)dinfo->j2k_handle, cio);
158 return jp2_decode((opj_jp2_t*)dinfo->jp2_handle, cio);
168 opj_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;
174 /* get a J2K coder handle */
175 cinfo->j2k_handle = (void*)j2k_create_compress((opj_common_ptr)cinfo);
176 if(!cinfo->j2k_handle) {
182 /* get a JP2 coder handle */
183 cinfo->jp2_handle = (void*)jp2_create_compress((opj_common_ptr)cinfo);
184 if(!cinfo->jp2_handle) {
196 cinfo->codec_format = format;
201 void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo) {
203 /* destroy the codec */
204 switch(cinfo->codec_format) {
206 j2k_destroy_decompress((opj_j2k_t*)cinfo->j2k_handle);
209 jp2_destroy_decompress((opj_jp2_t*)cinfo->jp2_handle);
216 /* destroy the decompressor */
221 void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters) {
223 memset(parameters, 0, sizeof(opj_cparameters_t));
224 /* default coding parameters */
225 parameters->cp_cinema = OFF;
226 parameters->numresolution = 6;
227 parameters->cp_rsiz = STD_RSIZ;
228 parameters->cblockw_init = 64;
229 parameters->cblockh_init = 64;
230 parameters->prog_order = LRCP;
231 parameters->roi_compno = -1; /* no ROI */
232 parameters->subsampling_dx = 1;
233 parameters->subsampling_dy = 1;
235 parameters->decod_format = -1;
236 parameters->cod_format = -1;
239 parameters->jpwl_epc_on = false;
240 parameters->jpwl_hprot_MH = -1; /* -1 means unassigned */
243 for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) {
244 parameters->jpwl_hprot_TPH_tileno[i] = -1; /* unassigned */
245 parameters->jpwl_hprot_TPH[i] = 0; /* absent */
250 for (i = 0; i < JPWL_MAX_NO_PACKSPECS; i++) {
251 parameters->jpwl_pprot_tileno[i] = -1; /* unassigned */
252 parameters->jpwl_pprot_packno[i] = -1; /* unassigned */
253 parameters->jpwl_pprot[i] = 0; /* absent */
256 parameters->jpwl_sens_size = 0; /* 0 means no ESD */
257 parameters->jpwl_sens_addr = 0; /* 0 means auto */
258 parameters->jpwl_sens_range = 0; /* 0 means packet */
259 parameters->jpwl_sens_MH = -1; /* -1 means unassigned */
262 for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) {
263 parameters->jpwl_sens_TPH_tileno[i] = -1; /* unassigned */
264 parameters->jpwl_sens_TPH[i] = -1; /* absent */
267 #endif /* USE_JPWL */
272 void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_image_t *image) {
273 if(cinfo && parameters && image) {
274 switch(cinfo->codec_format) {
276 j2k_setup_encoder((opj_j2k_t*)cinfo->j2k_handle, parameters, image);
279 jp2_setup_encoder((opj_jp2_t*)cinfo->jp2_handle, parameters, image);
289 bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index) {
290 if(cinfo && cio && image) {
291 switch(cinfo->codec_format) {
293 return j2k_encode((opj_j2k_t*)cinfo->j2k_handle, cio, image, index);
295 return jp2_encode((opj_jp2_t*)cinfo->jp2_handle, cio, image, index);