renamed "openjpeg3d" in "openjp3d" (final step)
[openjpeg.git] / libopenjp3d / 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 #define JP3D_VERSION "1.3.0"\r
34 /* ---------------------------------------------------------------------- */\r
35 #ifdef _WIN32\r
36 #ifndef OPJ_STATIC\r
37 BOOL APIENTRY\r
38 DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {\r
39         switch (ul_reason_for_call) {\r
40                 case DLL_PROCESS_ATTACH :\r
41                         break;\r
42                 case DLL_PROCESS_DETACH :\r
43                         break;\r
44                 case DLL_THREAD_ATTACH :\r
45                 case DLL_THREAD_DETACH :\r
46                         break;\r
47     }\r
48 \r
49     return TRUE;\r
50 }\r
51 #endif /* OPJ_STATIC */\r
52 #endif /* _WIN32 */\r
53 \r
54 /* ---------------------------------------------------------------------- */\r
55 \r
56 const char* OPJ_CALLCONV opj_version() {\r
57     return JP3D_VERSION;\r
58 }\r
59 opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format) {\r
60         opj_dinfo_t *dinfo = (opj_dinfo_t*)opj_malloc(sizeof(opj_dinfo_t));\r
61         if(!dinfo) return NULL;\r
62         dinfo->is_decompressor = true;\r
63         switch(format) {\r
64                 case CODEC_J3D:\r
65                 case CODEC_J2K:\r
66                         /* get a J3D decoder handle */\r
67                         dinfo->j3d_handle = (void*)j3d_create_decompress((opj_common_ptr)dinfo);\r
68                         if(!dinfo->j3d_handle) {\r
69                                 opj_free(dinfo);\r
70                                 return NULL;\r
71                         }\r
72                         break;\r
73                 default:\r
74                         opj_free(dinfo);\r
75                         return NULL;\r
76         }\r
77 \r
78         dinfo->codec_format = format;\r
79 \r
80         return dinfo;\r
81 }\r
82 \r
83 void OPJ_CALLCONV opj_destroy_decompress(opj_dinfo_t *dinfo) {\r
84         if(dinfo) {\r
85                 /* destroy the codec */\r
86                 if(dinfo->codec_format != CODEC_UNKNOWN) {\r
87                         j3d_destroy_decompress((opj_j3d_t*)dinfo->j3d_handle);\r
88                 }\r
89                 /* destroy the decompressor */\r
90                 opj_free(dinfo);\r
91         }\r
92 }\r
93 \r
94 void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters) {\r
95         if(parameters) {\r
96                 memset(parameters, 0, sizeof(opj_dparameters_t));\r
97                 /* default decoding parameters */\r
98                 parameters->cp_layer = 0;\r
99                 parameters->cp_reduce[0] = 0;\r
100                 parameters->cp_reduce[1] = 0;\r
101                 parameters->cp_reduce[2] = 0;\r
102                 parameters->bigendian = 0;\r
103 \r
104                 parameters->decod_format = -1;\r
105                 parameters->cod_format = -1;\r
106         }\r
107 }\r
108 \r
109 void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters) {\r
110         if(dinfo && parameters) {\r
111                 if (dinfo->codec_format != CODEC_UNKNOWN) {\r
112                         j3d_setup_decoder((opj_j3d_t*)dinfo->j3d_handle, parameters);\r
113                 }\r
114         }\r
115 }\r
116 \r
117 opj_volume_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio) {\r
118         if(dinfo && cio) {\r
119                 if (dinfo->codec_format != CODEC_UNKNOWN) {\r
120                         return j3d_decode((opj_j3d_t*)dinfo->j3d_handle, cio);\r
121                 }\r
122         }\r
123 \r
124         return NULL;\r
125 }\r
126 \r
127 opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format) {\r
128         opj_cinfo_t *cinfo = (opj_cinfo_t*)opj_malloc(sizeof(opj_cinfo_t));\r
129         if(!cinfo) return NULL;\r
130         cinfo->is_decompressor = false;\r
131         switch(format) {\r
132                 case CODEC_J3D:\r
133                 case CODEC_J2K:\r
134                         /* get a J3D coder handle */\r
135                         cinfo->j3d_handle = (void*)j3d_create_compress((opj_common_ptr)cinfo);\r
136                         if(!cinfo->j3d_handle) {\r
137                                 opj_free(cinfo);\r
138                                 return NULL;\r
139                         }\r
140                         break;\r
141                 default:\r
142                         opj_free(cinfo);\r
143                         return NULL;\r
144         }\r
145 \r
146         cinfo->codec_format = format;\r
147 \r
148         return cinfo;\r
149 }\r
150 \r
151 void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo) {\r
152         if(cinfo) {\r
153                 /* destroy the codec */\r
154                 if (cinfo->codec_format != CODEC_UNKNOWN) {\r
155                                 j3d_destroy_compress((opj_j3d_t*)cinfo->j3d_handle);\r
156                 }\r
157                 /* destroy the decompressor */\r
158                 opj_free(cinfo);\r
159         }\r
160 }\r
161 \r
162 void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters) {\r
163         if(parameters) {\r
164                 memset(parameters, 0, sizeof(opj_cparameters_t));\r
165                 /* default coding parameters */\r
166                 parameters->numresolution[0] = 3;\r
167                 parameters->numresolution[1] = 3;\r
168                 parameters->numresolution[2] = 1;\r
169                 parameters->cblock_init[0] = 64;\r
170                 parameters->cblock_init[1] = 64;\r
171                 parameters->cblock_init[2] = 64;\r
172                 parameters->prog_order = LRCP;\r
173                 parameters->roi_compno = -1;            /* no ROI */\r
174                 parameters->atk_wt[0] = 1;                              /* 5-3 WT */\r
175                 parameters->atk_wt[1] = 1;                              /* 5-3 WT */\r
176                 parameters->atk_wt[2] = 1;                              /* 5-3 WT */\r
177                 parameters->irreversible = 0;\r
178                 parameters->subsampling_dx = 1;\r
179                 parameters->subsampling_dy = 1;\r
180                 parameters->subsampling_dz = 1;\r
181 \r
182                 parameters->decod_format = -1;\r
183                 parameters->cod_format = -1;\r
184                 parameters->encoding_format = ENCOD_2EB;\r
185                 parameters->transform_format = TRF_2D_DWT;\r
186         }\r
187 }\r
188 \r
189 void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_volume_t *volume) {\r
190         if(cinfo && parameters && volume) {\r
191                 if (cinfo->codec_format != CODEC_UNKNOWN) {\r
192                         j3d_setup_encoder((opj_j3d_t*)cinfo->j3d_handle, parameters, volume);\r
193                 }\r
194         }\r
195 }\r
196 \r
197 bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_volume_t *volume, char *index) {\r
198         if(cinfo && cio && volume) {\r
199                 if (cinfo->codec_format != CODEC_UNKNOWN) {\r
200                         return j3d_encode((opj_j3d_t*)cinfo->j3d_handle, cio, volume, index);\r
201                 }\r
202         }\r
203 \r
204         return false;\r
205 }\r
206 \r
207 \r