2 * Copyright (c) 2005, Hervé Drolon, FreeImage Team
\r
3 * All rights reserved.
\r
5 * Redistribution and use in source and binary forms, with or without
\r
6 * modification, are permitted provided that the following conditions
\r
8 * 1. Redistributions of source code must retain the above copyright
\r
9 * notice, this list of conditions and the following disclaimer.
\r
10 * 2. Redistributions in binary form must reproduce the above copyright
\r
11 * notice, this list of conditions and the following disclaimer in the
\r
12 * documentation and/or other materials provided with the distribution.
\r
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
\r
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
\r
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
\r
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
\r
18 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
\r
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
\r
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
\r
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
\r
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
\r
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
\r
24 * POSSIBILITY OF SUCH DAMAGE.
\r
27 #include "opj_includes.h"
\r
29 const char * opj_version() {
\r
30 return OPENJPEG_VERSION;
\r
33 opj_dinfo_t* opj_create_decompress(OPJ_CODEC_FORMAT format) {
\r
34 opj_dinfo_t *dinfo = (opj_dinfo_t*)opj_malloc(sizeof(opj_dinfo_t));
\r
35 if(!dinfo) return NULL;
\r
36 dinfo->is_decompressor = true;
\r
40 /* get a J2K decoder handle */
\r
41 dinfo->j2k_handle = (void*)j2k_create_decompress((opj_common_ptr)dinfo);
\r
42 if(!dinfo->j2k_handle) {
\r
48 /* get a JP2 decoder handle */
\r
49 dinfo->jp2_handle = (void*)jp2_create_decompress((opj_common_ptr)dinfo);
\r
50 if(!dinfo->jp2_handle) {
\r
60 dinfo->codec_format = format;
\r
65 void opj_destroy_decompress(opj_dinfo_t *dinfo) {
\r
67 /* destroy the codec */
\r
68 switch(dinfo->codec_format) {
\r
71 j2k_destroy_decompress((opj_j2k_t*)dinfo->j2k_handle);
\r
74 jp2_destroy_decompress((opj_jp2_t*)dinfo->jp2_handle);
\r
77 /* destroy the decompressor */
\r
82 void opj_set_default_decoder_parameters(opj_dparameters_t *parameters) {
\r
84 memset(parameters, 0, sizeof(opj_dparameters_t));
\r
85 /* default decoding parameters */
\r
86 parameters->cp_layer = 0;
\r
87 parameters->cp_reduce = 0;
\r
89 parameters->decod_format = -1;
\r
90 parameters->cod_format = -1;
\r
94 void opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters) {
\r
95 if(dinfo && parameters) {
\r
96 switch(dinfo->codec_format) {
\r
99 j2k_setup_decoder((opj_j2k_t*)dinfo->j2k_handle, parameters);
\r
102 jp2_setup_decoder((opj_jp2_t*)dinfo->jp2_handle, parameters);
\r
108 opj_image_t* opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio) {
\r
110 switch(dinfo->codec_format) {
\r
112 return j2k_decode((opj_j2k_t*)dinfo->j2k_handle, cio);
\r
114 return j2k_decode_jpt_stream((opj_j2k_t*)dinfo->j2k_handle, cio);
\r
116 return jp2_decode((opj_jp2_t*)dinfo->jp2_handle, cio);
\r
123 opj_cinfo_t* opj_create_compress(OPJ_CODEC_FORMAT format) {
\r
124 opj_cinfo_t *cinfo = (opj_cinfo_t*)opj_malloc(sizeof(opj_cinfo_t));
\r
125 if(!cinfo) return NULL;
\r
126 cinfo->is_decompressor = false;
\r
129 /* get a J2K coder handle */
\r
130 cinfo->j2k_handle = (void*)j2k_create_compress((opj_common_ptr)cinfo);
\r
131 if(!cinfo->j2k_handle) {
\r
137 /* get a JP2 coder handle */
\r
138 cinfo->jp2_handle = (void*)jp2_create_compress((opj_common_ptr)cinfo);
\r
139 if(!cinfo->jp2_handle) {
\r
149 cinfo->codec_format = format;
\r
154 void opj_destroy_compress(opj_cinfo_t *cinfo) {
\r
156 /* destroy the codec */
\r
157 switch(cinfo->codec_format) {
\r
159 j2k_destroy_decompress((opj_j2k_t*)cinfo->j2k_handle);
\r
162 jp2_destroy_decompress((opj_jp2_t*)cinfo->jp2_handle);
\r
165 /* destroy the decompressor */
\r
170 void opj_set_default_encoder_parameters(opj_cparameters_t *parameters) {
\r
172 memset(parameters, 0, sizeof(opj_cparameters_t));
\r
173 /* default coding parameters */
\r
174 parameters->numresolution = 6;
\r
175 parameters->cblockw_init = 64;
\r
176 parameters->cblockh_init = 64;
\r
177 parameters->prog_order = LRCP;
\r
178 parameters->roi_compno = -1; /* no ROI */
\r
179 parameters->subsampling_dx = 1;
\r
180 parameters->subsampling_dy = 1;
\r
182 parameters->decod_format = -1;
\r
183 parameters->cod_format = -1;
\r
187 void opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_image_t *image) {
\r
188 if(cinfo && parameters && image) {
\r
189 switch(cinfo->codec_format) {
\r
191 j2k_setup_encoder((opj_j2k_t*)cinfo->j2k_handle, parameters, image);
\r
194 jp2_setup_encoder((opj_jp2_t*)cinfo->jp2_handle, parameters, image);
\r
200 bool opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index) {
\r
201 if(cinfo && cio && image) {
\r
202 switch(cinfo->codec_format) {
\r
204 return j2k_encode((opj_j2k_t*)cinfo->j2k_handle, cio, image, index);
\r
206 return jp2_encode((opj_jp2_t*)cinfo->jp2_handle, cio, image, index);
\r