openjp3d: Convert ISO-8859 to UTF-8
[openjpeg.git] / src / lib / openjp3d / openjp3d.c
1 /*
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.
6  *
7  * Copyright (c) 2005, Herve Drolon, FreeImage Team
8  * Copyright (c) 2006, Mónica Díez García, Image Processing Laboratory, University of Valladolid, Spain
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #ifdef _WIN32
34 #include <windows.h>
35 #endif /* _WIN32 */
36
37 #include "opj_includes.h"
38 #include "openjp3d.h"
39 #define JP3D_VERSION "1.3.0"
40 /* ---------------------------------------------------------------------- */
41 #ifdef _WIN32
42 #ifndef OPJ_STATIC
43 BOOL APIENTRY
44 DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
45 {
46     switch (ul_reason_for_call) {
47     case DLL_PROCESS_ATTACH :
48         break;
49     case DLL_PROCESS_DETACH :
50         break;
51     case DLL_THREAD_ATTACH :
52     case DLL_THREAD_DETACH :
53         break;
54     }
55
56     return TRUE;
57 }
58 #endif /* OPJ_STATIC */
59 #endif /* _WIN32 */
60
61 /* ---------------------------------------------------------------------- */
62
63 const char* OPJ_CALLCONV opj_version()
64 {
65     return JP3D_VERSION;
66 }
67 opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format)
68 {
69     opj_dinfo_t *dinfo = (opj_dinfo_t*)opj_malloc(sizeof(opj_dinfo_t));
70     if (!dinfo) {
71         return NULL;
72     }
73     dinfo->is_decompressor = true;
74     switch (format) {
75     case CODEC_J3D:
76     case CODEC_J2K:
77         /* get a J3D decoder handle */
78         dinfo->j3d_handle = (void*)j3d_create_decompress((opj_common_ptr)dinfo);
79         if (!dinfo->j3d_handle) {
80             opj_free(dinfo);
81             return NULL;
82         }
83         break;
84     default:
85         opj_free(dinfo);
86         return NULL;
87     }
88
89     dinfo->codec_format = format;
90
91     return dinfo;
92 }
93
94 void OPJ_CALLCONV opj_destroy_decompress(opj_dinfo_t *dinfo)
95 {
96     if (dinfo) {
97         /* destroy the codec */
98         if (dinfo->codec_format != CODEC_UNKNOWN) {
99             j3d_destroy_decompress((opj_j3d_t*)dinfo->j3d_handle);
100         }
101         /* destroy the decompressor */
102         opj_free(dinfo);
103     }
104 }
105
106 void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t
107         *parameters)
108 {
109     if (parameters) {
110         memset(parameters, 0, sizeof(opj_dparameters_t));
111         /* default decoding parameters */
112         parameters->cp_layer = 0;
113         parameters->cp_reduce[0] = 0;
114         parameters->cp_reduce[1] = 0;
115         parameters->cp_reduce[2] = 0;
116         parameters->bigendian = 0;
117
118         parameters->decod_format = -1;
119         parameters->cod_format = -1;
120     }
121 }
122
123 void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo,
124                                     opj_dparameters_t *parameters)
125 {
126     if (dinfo && parameters) {
127         if (dinfo->codec_format != CODEC_UNKNOWN) {
128             j3d_setup_decoder((opj_j3d_t*)dinfo->j3d_handle, parameters);
129         }
130     }
131 }
132
133 opj_volume_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio)
134 {
135     if (dinfo && cio) {
136         if (dinfo->codec_format != CODEC_UNKNOWN) {
137             return j3d_decode((opj_j3d_t*)dinfo->j3d_handle, cio);
138         }
139     }
140
141     return NULL;
142 }
143
144 opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format)
145 {
146     opj_cinfo_t *cinfo = (opj_cinfo_t*)opj_malloc(sizeof(opj_cinfo_t));
147     if (!cinfo) {
148         return NULL;
149     }
150     cinfo->is_decompressor = false;
151     switch (format) {
152     case CODEC_J3D:
153     case CODEC_J2K:
154         /* get a J3D coder handle */
155         cinfo->j3d_handle = (void*)j3d_create_compress((opj_common_ptr)cinfo);
156         if (!cinfo->j3d_handle) {
157             opj_free(cinfo);
158             return NULL;
159         }
160         break;
161     default:
162         opj_free(cinfo);
163         return NULL;
164     }
165
166     cinfo->codec_format = format;
167
168     return cinfo;
169 }
170
171 void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo)
172 {
173     if (cinfo) {
174         /* destroy the codec */
175         if (cinfo->codec_format != CODEC_UNKNOWN) {
176             j3d_destroy_compress((opj_j3d_t*)cinfo->j3d_handle);
177         }
178         /* destroy the decompressor */
179         opj_free(cinfo);
180     }
181 }
182
183 void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t
184         *parameters)
185 {
186     if (parameters) {
187         memset(parameters, 0, sizeof(opj_cparameters_t));
188         /* default coding parameters */
189         parameters->numresolution[0] = 3;
190         parameters->numresolution[1] = 3;
191         parameters->numresolution[2] = 1;
192         parameters->cblock_init[0] = 64;
193         parameters->cblock_init[1] = 64;
194         parameters->cblock_init[2] = 64;
195         parameters->prog_order = LRCP;
196         parameters->roi_compno = -1;        /* no ROI */
197         parameters->atk_wt[0] = 1;              /* 5-3 WT */
198         parameters->atk_wt[1] = 1;              /* 5-3 WT */
199         parameters->atk_wt[2] = 1;              /* 5-3 WT */
200         parameters->irreversible = 0;
201         parameters->subsampling_dx = 1;
202         parameters->subsampling_dy = 1;
203         parameters->subsampling_dz = 1;
204
205         parameters->decod_format = -1;
206         parameters->cod_format = -1;
207         parameters->encoding_format = ENCOD_2EB;
208         parameters->transform_format = TRF_2D_DWT;
209     }
210 }
211
212 void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo,
213                                     opj_cparameters_t *parameters, opj_volume_t *volume)
214 {
215     if (cinfo && parameters && volume) {
216         if (cinfo->codec_format != CODEC_UNKNOWN) {
217             j3d_setup_encoder((opj_j3d_t*)cinfo->j3d_handle, parameters, volume);
218         }
219     }
220 }
221
222 bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio,
223                              opj_volume_t *volume, char *index)
224 {
225     if (cinfo && cio && volume) {
226         if (cinfo->codec_format != CODEC_UNKNOWN) {
227             return j3d_encode((opj_j3d_t*)cinfo->j3d_handle, cio, volume, index);
228         }
229     }
230
231     return false;
232 }
233
234