[trunk] updated copyright and added copyright notice required by ISO, in each file...
[openjpeg.git] / src / lib / openjp3d / volume.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  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31
32 #include "opj_includes.h"
33 #include "volume.h"
34 #include "openjp3d.h"
35
36 opj_volume_t* OPJ_CALLCONV opj_volume_create(int numcmpts, opj_volume_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc) {
37         int compno;
38         opj_volume_t *volume = NULL;
39
40         volume = (opj_volume_t*)opj_malloc(sizeof(opj_volume_t));
41         if(volume) {
42                 volume->color_space = clrspc;
43                 volume->numcomps = numcmpts;
44                 /* allocate memory for the per-component information */
45                 volume->comps = (opj_volume_comp_t*)opj_malloc(volume->numcomps * sizeof(opj_volume_comp_t));
46                 if(!volume->comps) {
47                         opj_volume_destroy(volume);
48                         return NULL;
49                 }
50                 /* create the individual volume components */
51                 for(compno = 0; compno < numcmpts; compno++) {
52                         opj_volume_comp_t *comp = &volume->comps[compno];
53                         comp->dx = cmptparms[compno].dx;
54                         comp->dy = cmptparms[compno].dy;
55                         comp->dz = cmptparms[compno].dz;
56                         comp->w = cmptparms[compno].w;
57                         comp->h = cmptparms[compno].h;
58                         comp->l = cmptparms[compno].l;
59                         comp->x0 = cmptparms[compno].x0;
60                         comp->y0 = cmptparms[compno].y0;
61                         comp->z0 = cmptparms[compno].z0;
62                         comp->prec = cmptparms[compno].prec;
63                         comp->bpp = cmptparms[compno].bpp;
64                         comp->sgnd = cmptparms[compno].sgnd;
65                         comp->bigendian = cmptparms[compno].bigendian;
66                         comp->dcoffset = cmptparms[compno].dcoffset;
67                         comp->data = (int*)opj_malloc(comp->w * comp->h * comp->l * sizeof(int));
68                         if(!comp->data) {
69                                 fprintf(stdout,"Unable to malloc comp->data (%d x %d x %d x bytes)",comp->w,comp->h,comp->l);
70                                 opj_volume_destroy(volume);
71                                 return NULL;
72                         }
73                         /*fprintf(stdout,"%d %d %d %d %d %d %d %d %d", comp->w,comp->h, comp->l, comp->dx, comp->dy, comp->dz, comp->prec, comp->bpp, comp->sgnd);*/
74                 }
75         }
76
77         return volume;
78 }
79
80 void OPJ_CALLCONV opj_volume_destroy(opj_volume_t *volume) {
81         int i;
82         if(volume) {
83                 if(volume->comps) {
84                         /* volume components */
85                         for(i = 0; i < volume->numcomps; i++) {
86                                 opj_volume_comp_t *volume_comp = &volume->comps[i];
87                                 if(volume_comp->data) {
88                                         opj_free(volume_comp->data);
89                                 }
90                         }
91                         opj_free(volume->comps);
92                 }
93                 opj_free(volume);
94         }
95 }
96