1ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov/*
2ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov * The copyright in this software is being made available under the 2-clauses
3ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov * BSD License, included below. This software may be subject to other third
4ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov * party and contributor rights, including patent rights, and no such rights
5ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov * are granted under this license.
6ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov *
7ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov * Copyright (c) 2005, Herve Drolon, FreeImage Team
8ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov * All rights reserved.
9ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov *
10ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov * Redistribution and use in source and binary forms, with or without
11ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov * modification, are permitted provided that the following conditions
12ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov * are met:
13ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov * 1. Redistributions of source code must retain the above copyright
14ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov *    notice, this list of conditions and the following disclaimer.
15ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov * 2. Redistributions in binary form must reproduce the above copyright
16ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov *    notice, this list of conditions and the following disclaimer in the
17ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov *    documentation and/or other materials provided with the distribution.
18ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov *
19ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
20ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov * POSSIBILITY OF SUCH DAMAGE.
30ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov */
31ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
32ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include "opj_includes.h"
33ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
34ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovopj_image_t* opj_image_create0(void) {
35ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	opj_image_t *image = (opj_image_t*)opj_calloc(1, sizeof(opj_image_t));
36ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	return image;
37ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
38ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
39ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovopj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc) {
40ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	OPJ_UINT32 compno;
41ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	opj_image_t *image = NULL;
42ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
43ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	image = (opj_image_t*) opj_calloc(1, sizeof(opj_image_t));
44ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	if(image) {
45ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		image->color_space = clrspc;
46ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		image->numcomps = numcmpts;
47ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		/* allocate memory for the per-component information */
48ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		image->comps = (opj_image_comp_t*)opj_calloc(1,image->numcomps * sizeof(opj_image_comp_t));
49ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		if(!image->comps) {
50ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			fprintf(stderr,"Unable to allocate memory for image.\n");
51ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			opj_image_destroy(image);
52ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			return NULL;
53ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		}
54ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		/* create the individual image components */
55ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		for(compno = 0; compno < numcmpts; compno++) {
56ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			opj_image_comp_t *comp = &image->comps[compno];
57ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			comp->dx = cmptparms[compno].dx;
58ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			comp->dy = cmptparms[compno].dy;
59ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			comp->w = cmptparms[compno].w;
60ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			comp->h = cmptparms[compno].h;
61ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			comp->x0 = cmptparms[compno].x0;
62ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			comp->y0 = cmptparms[compno].y0;
63ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			comp->prec = cmptparms[compno].prec;
64ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			comp->bpp = cmptparms[compno].bpp;
65ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			comp->sgnd = cmptparms[compno].sgnd;
66ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			comp->data = (OPJ_INT32*) opj_calloc(comp->w * comp->h, sizeof(OPJ_INT32));
67ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			if(!comp->data) {
68ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov				fprintf(stderr,"Unable to allocate memory for image.\n");
69ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov				opj_image_destroy(image);
70ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov				return NULL;
71ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			}
72ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		}
73ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	}
74ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
75ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	return image;
76ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
77ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
78ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid OPJ_CALLCONV opj_image_destroy(opj_image_t *image) {
79ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	if(image) {
80ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		if(image->comps) {
81ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			OPJ_UINT32 compno;
82ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
83ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			/* image components */
84ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			for(compno = 0; compno < image->numcomps; compno++) {
85ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov				opj_image_comp_t *image_comp = &(image->comps[compno]);
86ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov				if(image_comp->data) {
87ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov					opj_free(image_comp->data);
88ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov				}
89ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			}
90ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			opj_free(image->comps);
91ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		}
92ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
93ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		if(image->icc_profile_buf) {
94ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			opj_free(image->icc_profile_buf);
95ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		}
96ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
97ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		opj_free(image);
98ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	}
99ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
100ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
101ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov/**
102ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov * Updates the components characteristics of the image from the coding parameters.
103ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov *
104ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov * @param p_image_header	the image header to update.
105ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov * @param p_cp				the coding parameters from which to update the image.
106ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov */
107ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid opj_image_comp_header_update(opj_image_t * p_image_header, const struct opj_cp * p_cp)
108ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
109ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	OPJ_UINT32 i, l_width, l_height;
110ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	OPJ_INT32 l_x0, l_y0, l_x1, l_y1;
111ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	OPJ_INT32 l_comp_x0, l_comp_y0, l_comp_x1, l_comp_y1;
112ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	opj_image_comp_t* l_img_comp = NULL;
113ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
114ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	l_x0 = opj_int_max((OPJ_INT32)p_cp->tx0 , (OPJ_INT32)p_image_header->x0);
115ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	l_y0 = opj_int_max((OPJ_INT32)p_cp->ty0 , (OPJ_INT32)p_image_header->y0);
116ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	l_x1 = opj_int_min((OPJ_INT32)(p_cp->tx0 + p_cp->tw * p_cp->tdx), (OPJ_INT32)p_image_header->x1);
117ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	l_y1 = opj_int_min((OPJ_INT32)(p_cp->ty0 + p_cp->th * p_cp->tdy), (OPJ_INT32)p_image_header->y1);
118ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
119ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	l_img_comp = p_image_header->comps;
120ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	for	(i = 0; i < p_image_header->numcomps; ++i) {
121ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		l_comp_x0 = opj_int_ceildiv(l_x0, (OPJ_INT32)l_img_comp->dx);
122ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		l_comp_y0 = opj_int_ceildiv(l_y0, (OPJ_INT32)l_img_comp->dy);
123ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		l_comp_x1 = opj_int_ceildiv(l_x1, (OPJ_INT32)l_img_comp->dx);
124ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		l_comp_y1 = opj_int_ceildiv(l_y1, (OPJ_INT32)l_img_comp->dy);
125ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		l_width = (OPJ_UINT32)opj_int_ceildivpow2(l_comp_x1 - l_comp_x0, (OPJ_INT32)l_img_comp->factor);
126ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		l_height = (OPJ_UINT32)opj_int_ceildivpow2(l_comp_y1 - l_comp_y0, (OPJ_INT32)l_img_comp->factor);
127ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		l_img_comp->w = l_width;
128ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		l_img_comp->h = l_height;
129ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		l_img_comp->x0 = (OPJ_UINT32)l_comp_x0/*l_x0*/;
130ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		l_img_comp->y0 = (OPJ_UINT32)l_comp_y0/*l_y0*/;
131ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		++l_img_comp;
132ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	}
133ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
134ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
135ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
136ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov/**
137ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov * Copy only header of image and its component header (no data are copied)
138ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov * if dest image have data, they will be freed
139ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov *
140ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov * @param	p_image_src		the src image
141ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov * @param	p_image_dest	the dest image
142ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov *
143ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov */
144ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid opj_copy_image_header(const opj_image_t* p_image_src, opj_image_t* p_image_dest)
145ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
146ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	OPJ_UINT32 compno;
147ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
148ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	/* preconditions */
149ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	assert(p_image_src != 00);
150ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	assert(p_image_dest != 00);
151ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
152ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	p_image_dest->x0 = p_image_src->x0;
153ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	p_image_dest->y0 = p_image_src->y0;
154ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	p_image_dest->x1 = p_image_src->x1;
155ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	p_image_dest->y1 = p_image_src->y1;
156ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
157ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	if (p_image_dest->comps){
158ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		for(compno = 0; compno < p_image_dest->numcomps; compno++) {
159ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			opj_image_comp_t *image_comp = &(p_image_dest->comps[compno]);
160ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			if(image_comp->data) {
161ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov				opj_free(image_comp->data);
162ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			}
163ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		}
164ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		opj_free(p_image_dest->comps);
165ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		p_image_dest->comps = NULL;
166ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	}
167ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
168ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	p_image_dest->numcomps = p_image_src->numcomps;
169ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
170ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	p_image_dest->comps = (opj_image_comp_t*) opj_malloc(p_image_dest->numcomps * sizeof(opj_image_comp_t));
171ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	if (!p_image_dest->comps){
172ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		p_image_dest->comps = NULL;
173ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		p_image_dest->numcomps = 0;
174ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		return;
175ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	}
176ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
177ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	for (compno=0; compno < p_image_dest->numcomps; compno++){
178ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		memcpy( &(p_image_dest->comps[compno]),
179ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov				&(p_image_src->comps[compno]),
180ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov				sizeof(opj_image_comp_t));
181ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		p_image_dest->comps[compno].data = NULL;
182ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	}
183ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
184ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	p_image_dest->color_space = p_image_src->color_space;
185ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	p_image_dest->icc_profile_len = p_image_src->icc_profile_len;
186ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
187ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	if (p_image_dest->icc_profile_len) {
188ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		p_image_dest->icc_profile_buf = (OPJ_BYTE*)opj_malloc(p_image_dest->icc_profile_len);
189ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		if (!p_image_dest->icc_profile_buf){
190ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			p_image_dest->icc_profile_buf = NULL;
191ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			p_image_dest->icc_profile_len = 0;
192ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			return;
193ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		}
194ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		memcpy( p_image_dest->icc_profile_buf,
195ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov				p_image_src->icc_profile_buf,
196ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov				p_image_src->icc_profile_len);
197ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		}
198ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		else
199ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			p_image_dest->icc_profile_buf = NULL;
200ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
201ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	return;
202ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
203ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
204ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovopj_image_t* OPJ_CALLCONV opj_image_tile_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc) {
205ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	OPJ_UINT32 compno;
206ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	opj_image_t *image = 00;
207ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
208e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov	image = (opj_image_t*) opj_calloc(1,sizeof(opj_image_t));
209ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	if (image)
210ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	{
211ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
212ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		image->color_space = clrspc;
213ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		image->numcomps = numcmpts;
214ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
215ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		/* allocate memory for the per-component information */
216e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov		image->comps = (opj_image_comp_t*)opj_calloc(image->numcomps, sizeof(opj_image_comp_t));
217ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		if (!image->comps) {
218ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			opj_image_destroy(image);
219ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			return 00;
220ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		}
221ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
222ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		/* create the individual image components */
223ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		for(compno = 0; compno < numcmpts; compno++) {
224ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			opj_image_comp_t *comp = &image->comps[compno];
225ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			comp->dx = cmptparms[compno].dx;
226ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			comp->dy = cmptparms[compno].dy;
227ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			comp->w = cmptparms[compno].w;
228ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			comp->h = cmptparms[compno].h;
229ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			comp->x0 = cmptparms[compno].x0;
230ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			comp->y0 = cmptparms[compno].y0;
231ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			comp->prec = cmptparms[compno].prec;
232ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			comp->sgnd = cmptparms[compno].sgnd;
233ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov			comp->data = 0;
234ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov		}
235ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	}
236ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
237ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov	return image;
238ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
239