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.
7 * Copyright (c) 2005, Herve Drolon, FreeImage Team
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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.
32 #include "opj_includes.h"
36 opj_volume_t* OPJ_CALLCONV opj_volume_create(int numcmpts,
37 opj_volume_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc)
40 opj_volume_t *volume = NULL;
42 volume = (opj_volume_t*)opj_malloc(sizeof(opj_volume_t));
44 volume->color_space = clrspc;
45 volume->numcomps = numcmpts;
46 /* allocate memory for the per-component information */
47 volume->comps = (opj_volume_comp_t*)opj_malloc(volume->numcomps * sizeof(
50 opj_volume_destroy(volume);
53 /* create the individual volume components */
54 for (compno = 0; compno < numcmpts; compno++) {
55 opj_volume_comp_t *comp = &volume->comps[compno];
56 comp->dx = cmptparms[compno].dx;
57 comp->dy = cmptparms[compno].dy;
58 comp->dz = cmptparms[compno].dz;
59 comp->w = cmptparms[compno].w;
60 comp->h = cmptparms[compno].h;
61 comp->l = cmptparms[compno].l;
62 comp->x0 = cmptparms[compno].x0;
63 comp->y0 = cmptparms[compno].y0;
64 comp->z0 = cmptparms[compno].z0;
65 comp->prec = cmptparms[compno].prec;
66 comp->bpp = cmptparms[compno].bpp;
67 comp->sgnd = cmptparms[compno].sgnd;
68 comp->bigendian = cmptparms[compno].bigendian;
69 comp->dcoffset = cmptparms[compno].dcoffset;
70 comp->data = (int*)opj_malloc(comp->w * comp->h * comp->l * sizeof(int));
72 fprintf(stdout, "Unable to malloc comp->data (%d x %d x %d x bytes)", comp->w,
74 opj_volume_destroy(volume);
77 /*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);*/
84 void OPJ_CALLCONV opj_volume_destroy(opj_volume_t *volume)
89 /* volume components */
90 for (i = 0; i < volume->numcomps; i++) {
91 opj_volume_comp_t *volume_comp = &volume->comps[i];
92 if (volume_comp->data) {
93 opj_free(volume_comp->data);
96 opj_free(volume->comps);