/* $Id: cpl_image_io_body.h,v 1.39 2007/05/07 14:19:49 yjung Exp $ * * This file is part of the ESO Common Pipeline Library * Copyright (C) 2001-2004 European Southern Observatory * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* Type dependent macros */ #if CPL_CLASS == CPL_CLASS_DOUBLE #define CPL_TYPE double #define CPL_TYPE_T CPL_TYPE_DOUBLE #define CPL_CFITSIO_TYPE TDOUBLE #elif CPL_CLASS == CPL_CLASS_FLOAT #define CPL_TYPE float #define CPL_TYPE_T CPL_TYPE_FLOAT #define CPL_CFITSIO_TYPE TFLOAT #elif CPL_CLASS == CPL_CLASS_INT #define CPL_TYPE int #define CPL_TYPE_T CPL_TYPE_INT #define CPL_CFITSIO_TYPE TINT #else #undef CPL_TYPE #undef CPL_TYPE_T #undef CPL_CFITSIO_TYPE #endif #if CPL_OPERATION == CPL_IMAGE_IO_ALLOC case CPL_TYPE_T: image = cpl_malloc(sizeof(cpl_image)) ; image->nx = nx ; image->ny = ny ; image->pixels = cpl_calloc(nx * ny, sizeof(CPL_TYPE)); image->type = CPL_TYPE_T ; image->bpm = NULL ; break ; #elif CPL_OPERATION == CPL_IMAGE_IO_WRAP cpl_image * im ; cpl_ensure( pixels != NULL, CPL_ERROR_NULL_INPUT, NULL) ; cpl_ensure( nx > 0, CPL_ERROR_ILLEGAL_INPUT, NULL) ; cpl_ensure( ny > 0, CPL_ERROR_ILLEGAL_INPUT, NULL) ; im = cpl_malloc(sizeof(cpl_image)) ; im->nx = nx ; im->ny = ny ; im->pixels = (void *) pixels; im->type = CPL_TYPE_T ; im->bpm = NULL ; return im ; #elif CPL_OPERATION == CPL_IMAGE_IO_GET case CPL_TYPE_T: { const CPL_TYPE * pi = (CPL_TYPE*)image->pixels; value = (double)pi[index]; break ; } #elif CPL_OPERATION == CPL_IMAGE_IO_SET case CPL_TYPE_T: { CPL_TYPE * pi = (CPL_TYPE*)image->pixels; pi[index] = value; break ; } #elif CPL_OPERATION == CPL_IMAGE_IO_GET_PIXELS /* Test entries */ cpl_ensure(img, CPL_ERROR_NULL_INPUT, NULL); cpl_ensure(img->type == CPL_TYPE_T, CPL_ERROR_TYPE_MISMATCH, NULL); return (CPL_TYPE*)img->pixels ; #elif CPL_OPERATION == CPL_IMAGE_IO_COPY case CPL_TYPE_T: dest = cpl_image_new(src->nx, src->ny, CPL_TYPE_T) ; memcpy(dest->pixels, src->pixels, src->nx * src->ny * sizeof(CPL_TYPE)); break ; #elif CPL_OPERATION == CPL_IMAGE_IO_LOAD case CPL_TYPE_T: im = cpl_image_new(naxes[0], naxes[1], CPL_TYPE_T) ; fits_read_pix(fptr, CPL_CFITSIO_TYPE, fpixel, im->nx*im->ny, NULL, im->pixels, NULL, &fio_status) ; break ; #elif CPL_OPERATION == CPL_IMAGE_IO_LOAD_WIN case CPL_TYPE_T: im = cpl_image_new(urx - llx + 1, ury - lly + 1, CPL_TYPE_T) ; fits_read_subset(fptr, CPL_CFITSIO_TYPE, fpixel, lpixel, inc, NULL, im->pixels, NULL, &fio_status) ; break ; #elif CPL_OPERATION == CPL_IMAGE_IO_SET_BADPIXEL case CPL_TYPE_T: { CPL_TYPE * pi; const CPL_TYPE acast = (CPL_TYPE) a; int i ; pi = (CPL_TYPE*)im->pixels ; for (i=0 ; inx*im->ny ; i++) if (pbpm[i] == CPL_BINARY_1) pi[i] = acast ; break ; } #elif CPL_OPERATION == CPL_IMAGE_IO_SAVE case CPL_TYPE_T: /* Write the pixels */ fits_write_img(fptr, CPL_CFITSIO_TYPE, 1, outima->nx*outima->ny, (CPL_TYPE*)(outima->pixels), &fio_status); break ; #endif #undef CPL_TYPE #undef CPL_TYPE_T #undef CPL_CFITSIO_TYPE