GIRAFFE Pipeline Reference Manual

giimagestack.c
1/*
2 * This file is part of the GIRAFFE Pipeline
3 * Copyright (C) 2002-2019 European Southern Observatory
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#ifdef HAVE_CONFIG_H
21# include <config.h>
22#endif
23
24#include <cxmemory.h>
25
26#include "giimagestack.h"
27
28
51{
52
53 GiImageStack *istack = NULL;
54
55 istack = cx_malloc(sizeof(GiImageStack));
56
57 istack->nimages = size;
58 istack->images = cx_calloc(size, sizeof(cpl_image *));
59
60 return istack;
61
62}
63
64
82cxint
84{
85
86 cxint i;
87
88 cpl_image **tmp = NULL;
89
90
91 if (istack == NULL) {
92 return 1;
93 }
94
95 if (istack->nimages == size) {
96 return 0;
97 }
98
99 tmp = cx_calloc(size, sizeof(cpl_image *));
100
101 if (size > istack->nimages) {
102 /* grow array */
103 for (i = 0; i < istack->nimages; ++i) {
104 tmp[i] = istack->images[i];
105 }
106
107 for (i = istack->nimages; i < size; ++i) {
108 tmp[i] = NULL;
109 }
110 }
111 else {
112 /* shrink array */
113 for (i = 0; i < size; ++i) {
114 tmp[i] = istack->images[i];
115 }
116
117 for (i = size; i < istack->nimages; ++i) {
118 cpl_image_delete(istack->images[i]);
119 }
120 }
121
122 cx_free(istack->images);
123
124 istack->images = tmp;
125
126 return 0;
127
128}
129
130
140void
142{
143
144 cxint i;
145
146 if (istack == NULL) {
147 return;
148 }
149
150 if (istack->images != NULL) {
151 for (i = 0; i < istack->nimages; ++i) {
152 cpl_image_delete(istack->images[i]);
153 }
154
155 cx_free(istack->images);
156 }
157
158 istack->images = NULL;
159 istack->nimages = 0;
160
161 return;
162
163}
164
165
188cxint
189giraffe_imagestack_set(GiImageStack *istack, cxint position, cpl_image *src)
190{
191 if (istack == NULL) {
192 return 1;
193 }
194
195 if (istack->images == NULL) {
196 return 1;
197 }
198
199 if ((position < 0) || (position > istack->nimages)) {
200 return 2;
201 }
202
203 istack->images[position] = src;
204
205 return 0;
206
207}
208
209
224cpl_image *
225giraffe_imagestack_get(GiImageStack *istack, cxint position)
226{
227
228 if (istack == NULL) {
229 return NULL;
230 }
231
232 if (istack->images == NULL) {
233 return NULL;
234 }
235
236 if ((position < 0) || (position > istack->nimages)) {
237 return NULL;
238 }
239
240 return istack->images[position];
241
242}
243
244
258cxint
260{
261
262 if (istack == NULL) {
263 return 0;
264 }
265
266 return istack->nimages;
267
268}
cxint giraffe_imagestack_set(GiImageStack *istack, cxint position, cpl_image *src)
Stores a reference to a cpl_image in a GiImageStack.
Definition: giimagestack.c:189
cpl_image * giraffe_imagestack_get(GiImageStack *istack, cxint position)
Retrieve a cpl_image reference stored in a GiImageStack.
Definition: giimagestack.c:225
GiImageStack * giraffe_imagestack_new(cxint size)
Create a new GiImageStack.
Definition: giimagestack.c:50
cxint giraffe_imagestack_size(GiImageStack *istack)
Returns current size of an GiImageStack.
Definition: giimagestack.c:259
cxint giraffe_imagestack_resize(GiImageStack *istack, cxint size)
Non destructive resize of an GiImageStack.
Definition: giimagestack.c:83
void giraffe_imagestack_delete(GiImageStack *istack)
Destroys an GiImageStack.
Definition: giimagestack.c:141
Structure to handle an array/stack of cpl_images.
Definition: giimagestack.h:42
cpl_image ** images
Definition: giimagestack.h:45

This file is part of the GIRAFFE Pipeline Reference Manual 2.16.14.
Documentation copyright © 2002-2006 European Southern Observatory.
Generated on Wed Jan 15 2025 22:16:53 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2004