/* $Id: overscan.c,v 1.3 2002/01/11 16:22:57 fors Exp $ * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * COPYRIGHT (c) 2001 European Southern Observatory * LICENSE: GNU General Public License version 2 or later * * PROJECT: VLT Data Flow System * AUTHOR: Ralf Palsa -- ESO/DMD/DPG * SUBSYSTEM: Instrument pipelines * * PURPOSE: * DESCRIPTION: * * $Name: fsmosaic-1_0 $ * $Revision: 1.3 $ * ---------------------------------------------------------------------------- */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include "overscan.h" #include "qfits_ext.h" /** * @memo * Remove prescan areas from an image. * * @return The function returns #EXIT_SUCCESS# if the prescan areas were * properly removed, otherwise the return value is #EXIT_FAILURE#. * * @param header FITS header corresponding to the image. * @param image Image from which the prescan areas should be removed. * @param flag Selector of prescan area to be removed. * * @doc * The function gets the configuration of the prescan area from the * image header \textbf{header} and removes the correspondig pixels * from the image \textbf{image}, therby modifying the input image. * The switch \textbf{flag} controls if the prescan area along the X, * Y or both axes. * * If the image does not contain any prescan areas, i.e. the FITS keyword * characterizing the size of the prescan area are zero the function does * nothing. * * After removing the prescan areas the FITS keywords describing the * size of the prescan areas are set to zero. * * @author R. Palsa */ int trim_prescan(qfits_header *header, image_t *image, unsigned int flag) { char card[FITS_CARD_SIZE + 1]; register int i; int npixel; size_t size, offset; double crpix; assert(header != 0); assert(image != 0); assert(flag <= 2); /* * Remove prescan along x-axis */ if (flag != 1) { if ((npixel = qfits_header_getint(header, PRESCAN_X, -1)) > 0) { unsigned char *start; size_t step; if ((crpix = qfits_header_getdouble(header, "CRPIX1", -1)) < 0) return EXIT_FAILURE; image->hsize -= npixel; size = image->hsize * sizeof(pixel_t); start = (unsigned char *)image->data; step = npixel * sizeof(pixel_t); offset = step; for (i = 0; i < image->vsize; i++) { memmove(start, start + offset, size); start += size; offset += step; } if (!(image->data = realloc(image->data, size * image->vsize))) return EXIT_FAILURE; /* * Update the FITS header */ sprintf(card, "%d", image->hsize); fits_header_set_value(header, "NAXIS1", card); sprintf(card, "%.1f", crpix - npixel); fits_header_set_value(header, "CRPIX1", card); fits_header_set_value(header, PRESCAN_X, "0"); } } /* * Remove prescan along y-axis */ if (flag >= 1) { if ((npixel = qfits_header_getint(header, PRESCAN_Y, -1)) > 0) { if ((crpix = qfits_header_getdouble(header, "CRPIX2", -1)) < 0) return EXIT_FAILURE; image->vsize -= npixel; size = image->vsize * image->hsize * sizeof(pixel_t); offset = npixel * image->hsize; memmove(image->data, image->data + offset, size); if (!(image->data = realloc(image->data, size))) return EXIT_FAILURE; /* * Update the FITS header */ sprintf(card, "%d", image->vsize); fits_header_set_value(header, "NAXIS2", card); sprintf(card, "%.1f", crpix - npixel); fits_header_set_value(header, "CRPIX2", card); fits_header_set_value(header, PRESCAN_Y, "0"); } } return EXIT_SUCCESS; } /** * @memo * Remove overscan areas from an image. * * @return The function returns #EXIT_SUCCESS# if the overscan areas were * properly removed, otherwise the return value is #EXIT_FAILURE#. * * @param header FITS header corresponding to the image. * @param image Image from which the overscan areas should be removed. * @param flag Selector of overscan area to be removed. * * @doc * The function gets the configuration of the overscan area from the * image header \textbf{header} and removes the correspondig pixels * from the image \textbf{image}, therby modifying the input image. * The switch \textbf{flag} controls if the overscan area along the X, * Y or both axes. * * If the image does not contain any overscan areas, i.e. the FITS keyword * characterizing the size of the overscan area are zero the function does * nothing. * * After removing the overscan areas the FITS keywords describing the * size of the overscan areas are set to zero. * * @author R. Palsa */ int trim_overscan(qfits_header *header, image_t *image, unsigned int flag) { char card[FITS_CARD_SIZE + 1]; register int i; int npixel; size_t size, offset; assert(header != 0); assert(image != 0); assert(flag <= 2); /* * Remove overscan along x-axis */ if (flag != 1) { if ((npixel = qfits_header_getint(header, OVERSCAN_X, -1)) > 0) { unsigned char *start; size_t step; image->hsize -= npixel; size = image->hsize * sizeof(pixel_t); start = (unsigned char *)image->data + size; step = npixel * sizeof(pixel_t); offset = step; for (i = 0; i < image->vsize - 1; i++) { memmove(start, start + offset, size); start += size; offset += step; } if (!(image->data = realloc(image->data, size * image->vsize))) return EXIT_FAILURE; /* * Update the FITS header */ sprintf(card, "%d", image->hsize); fits_header_set_value(header, "NAXIS1", card); fits_header_set_value(header, OVERSCAN_X, "0"); } } /* * Remove overscan along y-axis */ if (flag >= 1) { if ((npixel = qfits_header_getint(header, OVERSCAN_Y, -1)) > 0) { image->vsize -= npixel; size = image->vsize * image->hsize * sizeof(pixel_t); if (!(image->data = realloc(image->data, size))) return EXIT_FAILURE; /* * Update the FITS header */ sprintf(card, "%d", image->vsize); fits_header_set_value(header, "NAXIS2", card); fits_header_set_value(header, OVERSCAN_Y, "0"); } } return EXIT_SUCCESS; }