GIRAFFE Pipeline Reference Manual

giimagestack.c

00001 /* $Id: giimagestack.c,v 1.3 2006/03/10 15:56:10 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: 2006/03/10 15:56:10 $
00024  * $Revision: 1.3 $
00025  * $Name: giraffe-2_5_1 $
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 
00195 cxint
00196 giraffe_imagestack_set(GiImageStack *istack, cxint position, cpl_image *src)
00197 {
00198     if (istack == NULL) {
00199         return 1;
00200     }
00201 
00202     if (istack->images == NULL) {
00203         return 1;
00204     }
00205 
00206     if ((position < 0) || (position > istack->nimages)) {
00207         return 2;
00208     }
00209 
00210     istack->images[position] = src;
00211 
00212     return 0;
00213 
00214 }
00215 
00216 
00231 cpl_image *
00232 giraffe_imagestack_get(GiImageStack *istack, cxint position)
00233 {
00234 
00235     if (istack == NULL) {
00236         return NULL;
00237     }
00238 
00239     if (istack->images == NULL) {
00240         return NULL;
00241     }
00242 
00243     if ((position < 0) || (position > istack->nimages)) {
00244         return NULL;
00245     }
00246 
00247     return istack->images[position];
00248 
00249 }
00250 
00251 
00265 cxint
00266 giraffe_imagestack_size(GiImageStack *istack)
00267 {
00268 
00269     if (istack == NULL) {
00270         return 0;
00271     }
00272 
00273     return istack->nimages;
00274 
00275 }

This file is part of the GIRAFFE Pipeline Reference Manual 2.5.1.
Documentation copyright © 2002-2006 European Southern Observatory.
Generated on Tue Mar 18 10:47:42 2008 by doxygen 1.4.6 written by Dimitri van Heesch, © 1997-2004