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