/* $Id: image.c,v 1.2 2001/10/26 13:29:49 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.2 $ * ---------------------------------------------------------------------------- */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include "image.h" inline void image_del(image_t *); /** * @memo * Allocate a new image object. * * @return The function returns a pointer to the created image object if no * error occurs, otherwise a #NULL# pointer is returned. * * @param hsize Horizontal image size in pixels. * @param vsize Vertical image size in pixels. * * @doc * The function creates an image object with the pixel buffer large enough * to store an image having a horizontal size of \textbf{hsize} and a * vertical size of \textbf{vsize} pixels. The pixel buffer is initialized * with 0. * * @author R. Palsa */ inline image_t *image_new(int hsize, int vsize) { size_t sz; image_t *image = 0; if (hsize < 1 || hsize > IMAGE_HSIZE_MAX || vsize < 1 || vsize > IMAGE_VSIZE_MAX) return 0; if ((image = (image_t *)malloc(sizeof(image_t)))) { image->hsize = hsize; image->vsize = vsize; sz = image->hsize * image->vsize; if (!(image->data = (pixel_t *)malloc(sz * sizeof(pixel_t)))) { image_del(image); return 0; } memset(image->data, 0, sz * sizeof(pixel_t)); } return image; } /** * @memo * Destroy an image object. * * @return Nothing. * * @param image Image object. * * @doc * The function deallocates the image object \textbf{image}. If a pixel * buffer is present, i.e. the pointer to the pixel data is not #NULL# * the pixel buffer is deallocated before the image object is destroyed. * * If \textbf{image} is a #NULL# pointer, no operation is performed. * * @author R. Palsa */ inline void image_del(image_t *image) { if (!image) return; if (image->data) { free(image->data); image->data = 0; } free(image); return; } /** * @memo * Insert an image into another. * * @return The function returns #EXIT_SUCCESS# if no error occurred, otherwise * the return value is #EXIT_FAILURE#. * * @param target Target image object. * @param source Source image object. * @param xstart Start position along the x axis. * @param ystart Start position along the y axis. * * @doc * The function replaces the pixels of the target image \textbf{target} * with the pixel data from the source image \textbf{source}. The * source image is inserted at the pixel position specified by * \textbf{xstart} and \textbf{ystart}. * * The source image must completely fit into the target image when it is * inserted at the given position. * * @author R. Palsa */ inline int image_insert(image_t *target, image_t *source, int xstart, int ystart) { register int i, j, k; /* * Check if the source fits into the target image. */ if (xstart + source->hsize - 1 > target->hsize || ystart + source->vsize - 1 > target->vsize) return EXIT_FAILURE; /* * Copy the pixel data */ for (i = 0; i < source->vsize; i++) { k = (i + ystart) * target->hsize; for (j = 0; j < source->hsize; j++) target->data[k + j + xstart] = source->data[i * source->hsize + j]; } return EXIT_SUCCESS; }