GIRAFFE Pipeline Reference Manual

giimagestack.c
1 /* $Id$
2  *
3  * This file is part of the GIRAFFE Pipeline
4  * Copyright (C) 2002-2006 European Southern Observatory
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /*
22  * $Author$
23  * $Date$
24  * $Revision$
25  * $Name$
26  */
27 
28 #ifdef HAVE_CONFIG_H
29 # include <config.h>
30 #endif
31 
32 #include <cxmemory.h>
33 
34 #include "giimagestack.h"
35 
36 
59 {
60 
61  GiImageStack *istack = NULL;
62 
63  istack = cx_malloc(sizeof(GiImageStack));
64 
65  istack->nimages = size;
66  istack->images = cx_calloc(size, sizeof(cpl_image *));
67 
68  return istack;
69 
70 }
71 
72 
90 cxint
92 {
93 
94  cxint i;
95 
96  cpl_image **tmp = NULL;
97 
98 
99  if (istack == NULL) {
100  return 1;
101  }
102 
103  if (istack->nimages == size) {
104  return 0;
105  }
106 
107  tmp = cx_calloc(size, sizeof(cpl_image *));
108 
109  if (size > istack->nimages) {
110  /* grow array */
111  for (i = 0; i < istack->nimages; ++i) {
112  tmp[i] = istack->images[i];
113  }
114 
115  for (i = istack->nimages; i < size; ++i) {
116  tmp[i] = NULL;
117  }
118  }
119  else {
120  /* shrink array */
121  for (i = 0; i < size; ++i) {
122  tmp[i] = istack->images[i];
123  }
124 
125  for (i = size; i < istack->nimages; ++i) {
126  cpl_image_delete(istack->images[i]);
127  }
128  }
129 
130  cx_free(istack->images);
131 
132  istack->images = tmp;
133 
134  return 0;
135 
136 }
137 
138 
148 void
150 {
151 
152  cxint i;
153 
154  if (istack == NULL) {
155  return;
156  }
157 
158  if (istack->images != NULL) {
159  for (i = 0; i < istack->nimages; ++i) {
160  cpl_image_delete(istack->images[i]);
161  }
162 
163  cx_free(istack->images);
164  }
165 
166  istack->images = NULL;
167  istack->nimages = 0;
168 
169  return;
170 
171 }
172 
173 
196 cxint
197 giraffe_imagestack_set(GiImageStack *istack, cxint position, cpl_image *src)
198 {
199  if (istack == NULL) {
200  return 1;
201  }
202 
203  if (istack->images == NULL) {
204  return 1;
205  }
206 
207  if ((position < 0) || (position > istack->nimages)) {
208  return 2;
209  }
210 
211  istack->images[position] = src;
212 
213  return 0;
214 
215 }
216 
217 
232 cpl_image *
233 giraffe_imagestack_get(GiImageStack *istack, cxint position)
234 {
235 
236  if (istack == NULL) {
237  return NULL;
238  }
239 
240  if (istack->images == NULL) {
241  return NULL;
242  }
243 
244  if ((position < 0) || (position > istack->nimages)) {
245  return NULL;
246  }
247 
248  return istack->images[position];
249 
250 }
251 
252 
266 cxint
268 {
269 
270  if (istack == NULL) {
271  return 0;
272  }
273 
274  return istack->nimages;
275 
276 }
cpl_image ** images
Definition: giimagestack.h:53
GiImageStack * giraffe_imagestack_new(cxint size)
Create a new GiImageStack.
Definition: giimagestack.c:58
cxint giraffe_imagestack_resize(GiImageStack *istack, cxint size)
Non destructive resize of an GiImageStack.
Definition: giimagestack.c:91
cxint giraffe_imagestack_size(GiImageStack *istack)
Returns current size of an GiImageStack.
Definition: giimagestack.c:267
void giraffe_imagestack_delete(GiImageStack *istack)
Destroys an GiImageStack.
Definition: giimagestack.c:149
cpl_image * giraffe_imagestack_get(GiImageStack *istack, cxint position)
Retrieve a cpl_image reference stored in a GiImageStack.
Definition: giimagestack.c:233
cxint giraffe_imagestack_set(GiImageStack *istack, cxint position, cpl_image *src)
Stores a reference to a cpl_image in a GiImageStack.
Definition: giimagestack.c:197
Structure to handle an array/stack of cpl_images.
Definition: giimagestack.h:50

This file is part of the GIRAFFE Pipeline Reference Manual 2.14.
Documentation copyright © 2002-2006 European Southern Observatory.
Generated on Wed Mar 11 2015 13:19:41 by doxygen 1.8.9.1 written by Dimitri van Heesch, © 1997-2004