GIRAFFE Pipeline Reference Manual

giimagestack.c

00001 /* $Id: giimagestack.c,v 1.4 2009/05/29 12:33:03 rpalsa Exp $
00002  *
00003  * This file is part of the GIRAFFE Pipeline
00004  * Copyright (C) 2002-2006 European Southern Observatory
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 /*
00022  * $Author: rpalsa $
00023  * $Date: 2009/05/29 12:33:03 $
00024  * $Revision: 1.4 $
00025  * $Name: giraffe-2_10 $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #  include <config.h>
00030 #endif
00031 
00032 #include <cxmemory.h>
00033 
00034 #include "giimagestack.h"
00035 
00036 
00057 GiImageStack*
00058 giraffe_imagestack_new(cxint size)
00059 {
00060 
00061     GiImageStack *istack = NULL;
00062 
00063     istack = cx_malloc(sizeof(GiImageStack));
00064 
00065     istack->nimages = size;
00066     istack->images  = cx_calloc(size, sizeof(cpl_image *));
00067 
00068     return istack;
00069 
00070 }
00071 
00072 
00090 cxint
00091 giraffe_imagestack_resize(GiImageStack *istack, cxint size)
00092 {
00093 
00094     cxint i;
00095 
00096     cpl_image **tmp = NULL;
00097 
00098 
00099     if (istack == NULL) {
00100         return 1;
00101     }
00102 
00103     if (istack->nimages == size) {
00104         return 0;
00105     }
00106 
00107     tmp = cx_calloc(size, sizeof(cpl_image *));
00108 
00109     if (size > istack->nimages) {
00110         /* grow array */
00111         for (i = 0; i < istack->nimages; ++i) {
00112             tmp[i] = istack->images[i];
00113         }
00114 
00115         for (i = istack->nimages; i < size; ++i) {
00116             tmp[i] = NULL;
00117         }
00118     }
00119     else {
00120         /* shrink array */
00121         for (i = 0; i < size; ++i) {
00122             tmp[i] = istack->images[i];
00123         }
00124 
00125         for (i = size; i < istack->nimages; ++i) {
00126             cpl_image_delete(istack->images[i]);
00127         }
00128     }
00129 
00130     cx_free(istack->images);
00131 
00132     istack->images = tmp;
00133 
00134     return 0;
00135 
00136 }
00137 
00138 
00148 void
00149 giraffe_imagestack_delete(GiImageStack *istack)
00150 {
00151 
00152     cxint i;
00153 
00154     if (istack == NULL) {
00155         return;
00156     }
00157 
00158     if (istack->images != NULL) {
00159         for (i = 0; i < istack->nimages; ++i) {
00160             cpl_image_delete(istack->images[i]);
00161         }
00162 
00163         cx_free(istack->images);
00164     }
00165 
00166     istack->images = NULL;
00167     istack->nimages = 0;
00168 
00169     return;
00170 
00171 }
00172 
00173 
00196 cxint
00197 giraffe_imagestack_set(GiImageStack *istack, cxint position, cpl_image *src)
00198 {
00199     if (istack == NULL) {
00200         return 1;
00201     }
00202 
00203     if (istack->images == NULL) {
00204         return 1;
00205     }
00206 
00207     if ((position < 0) || (position > istack->nimages)) {
00208         return 2;
00209     }
00210 
00211     istack->images[position] = src;
00212 
00213     return 0;
00214 
00215 }
00216 
00217 
00232 cpl_image *
00233 giraffe_imagestack_get(GiImageStack *istack, cxint position)
00234 {
00235 
00236     if (istack == NULL) {
00237         return NULL;
00238     }
00239 
00240     if (istack->images == NULL) {
00241         return NULL;
00242     }
00243 
00244     if ((position < 0) || (position > istack->nimages)) {
00245         return NULL;
00246     }
00247 
00248     return istack->images[position];
00249 
00250 }
00251 
00252 
00266 cxint
00267 giraffe_imagestack_size(GiImageStack *istack)
00268 {
00269 
00270     if (istack == NULL) {
00271         return 0;
00272     }
00273 
00274     return istack->nimages;
00275 
00276 }

This file is part of the GIRAFFE Pipeline Reference Manual 2.10.
Documentation copyright © 2002-2006 European Southern Observatory.
Generated on Thu Mar 7 14:11:02 2013 by doxygen 1.4.7 written by Dimitri van Heesch, © 1997-2004