00001 /** @file psPixels.h 00002 * 00003 * @brief Contains psPixel related functions 00004 * 00005 * @ingroup Image 00006 * 00007 * @author Robert DeSonia, MHPCC 00008 * 00009 * @version $Revision: 1.20 $ $Name: rel12 $ 00010 * @date $Date: 2006/04/17 22:00:03 $ 00011 * 00012 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii 00013 */ 00014 #ifndef PS_PIXELS_H 00015 #define PS_PIXELS_H 00016 00017 #include "psImage.h" 00018 #include "psVector.h" 00019 #include "psRegion.h" 00020 00021 /// @addtogroup Image 00022 /// @{ 00023 00024 /** Data structure for storing psPixel coordinates */ 00025 typedef struct 00026 { 00027 float x; ///< x coordinate 00028 float y; ///< y coordinate 00029 } 00030 psPixelCoord; 00031 00032 /** list of pixel coordinates 00033 * 00034 * Usually an image mask is the best way to carry information about what 00035 * pixels mean what. However, in the case where the number of pixels in which 00036 * we are interested is limited, it is more efficient to simply carry a list 00037 * of pixels. An example of this is in the image combination code, where we 00038 * want to perform an operation on a relatively small fraction of pixels, and 00039 * it is inefficient to go through an entire mask image checking each pixel. 00040 * 00041 */ 00042 typedef struct 00043 { 00044 long n; ///< Number in use 00045 const long nalloc; ///< Number allocated 00046 psPixelCoord* data; ///< The pixel coordinates 00047 void *lock; ///< Option lock for thread safety 00048 } 00049 psPixels; 00050 00051 #define P_PSPIXELS_SET_NALLOC(pix,n) *(long*)&pix->nalloc = n 00052 00053 /** Allocates a new psPixels structure 00054 * 00055 * @return psPixels* new psPixels 00056 */ 00057 psPixels* psPixelsAlloc( 00058 long nalloc ///< the size of the coordinate vectors 00059 ) 00060 ; 00061 00062 /** Checks the type of a particular pointer. 00063 * 00064 * Uses the appropriate deallocation function in psMemBlock to check the ptr datatype. 00065 * 00066 * @return bool: True if the pointer matches a psPixels structure, false otherwise. 00067 */ 00068 bool psMemCheckPixels( 00069 psPtr ptr ///< the pointer whose type to check 00070 ); 00071 00072 00073 /** resizes a psPixels structure 00074 * 00075 * @return psPixels* resized psPixels 00076 */ 00077 psPixels* psPixelsRealloc( 00078 psPixels* pixels, ///< psPixels to resize, or NULL to create new psPixels 00079 long nalloc ///< the size of the coordinate vectors 00080 ); 00081 00082 /** Add a pixel location to a psPixels 00083 * 00084 * @return psPixels* psPixels with the value appended. 00085 */ 00086 psPixels* p_psPixelsAppend( 00087 psPixels* pixels, ///< psPixels to append new coordinate to. NULL creates a new one. 00088 long growth, 00089 ///< number of elements to grow the psPixels list, if necessary. if growth < 1, 10 is used. 00090 float x, ///< x coordinate to append 00091 float y ///< y coordinate to append 00092 ); 00093 00094 /** Copies a psPixels object 00095 * 00096 * Makes a deep copy of the data in a psPixels object. Any data in the OUT 00097 * parameter will be destroyed and OUT will be resized, if necessary. 00098 * 00099 * @return psPixels* a new psPixels that is a duplicate to IN 00100 */ 00101 psPixels* psPixelsCopy( 00102 psPixels* out, ///< psPixels struct to recycle, or NULL 00103 const psPixels* pixels ///< psPixels struct to copy 00104 ); 00105 00106 /** Generate a psImage from a psPixels 00107 * 00108 * psPixelsToMask shall return an image of type U8 with the pixels lying 00109 * within the specified region set to the maskVal. The out image shall be 00110 * modified if supplied, or allocated and returned if NULL. The size of the 00111 * output image shall be region->x1 - region->x0 by region->y1 - region->y0, 00112 * with out->x0 = region->x0 and out->y0 = region->y0. In the event that 00113 * either of pixels or region are NULL, the function shall generate an 00114 * error and return NULL. 00115 * 00116 * @return psImage* generated mask image 00117 */ 00118 psImage* psPixelsToMask( 00119 psImage* out, ///< psImage to recycle, or NULL 00120 const psPixels* pixels, ///< list of pixels to use 00121 psRegion region, ///< region to define the output mask image 00122 psMaskType maskVal ///< the mask bit-values to act upon 00123 ); 00124 00125 /** Generate a psPixels from a mask psImage 00126 * 00127 * psMaskToPixels shall return a psPixels consisting of the coordinates in 00128 * the mask that match the maskVal. The out pixel list shall be modified if 00129 * supplied, or allocated and returned if NULL. In hte event that mask is 00130 * NULL, the function shall generate an error and return NULL. 00131 * 00132 * @return psPixels* generated psPixels pixel list 00133 */ 00134 psPixels* psPixelsFromMask( 00135 psPixels *out, ///< psPixels to recycle, or NULL 00136 const psImage *mask, ///< the input mask psImage 00137 psMaskType maskVal ///< the mask bit-values to act upon 00138 ); 00139 00140 /** Concatenates two psPixels 00141 * 00142 * psPixelsConcatenate shall concatenate pixels onto out. In the event that 00143 * out is NULL, a new psPixels shall be allocated, and the contents of 00144 * pixels simply copied in. If pixels is NULL, the function shall generate 00145 * an error and return NULL. The function shall take care to ensure that 00146 * there are no duplicate pixels in out. 00147 * 00148 * @return psPixels Concatenated psPixel list 00149 */ 00150 psPixels* psPixelsConcatenate( 00151 psPixels *out, ///< psPixels to recycle, or NULL 00152 const psPixels *pixels ///< psPixels to append to OUT 00153 ); 00154 00155 /** Prints a psPixels to specified destination. 00156 * 00157 * @return bool: True if successful. 00158 */ 00159 bool p_psPixelsPrint( 00160 FILE *fd, ///< destination file descriptor 00161 psPixels* pixels, ///< psPixels to print 00162 const char *name ///< printf-style format of header line 00163 ); 00164 00165 /** Sets the value of the the pixels array at the specified position to value. 00166 * 00167 * A negative position means index from the end. 00168 * 00169 * @return bool: True if Successful, otherwise false. 00170 */ 00171 bool psPixelsSet( 00172 psPixels *pixels, ///< pixels to set 00173 long position, ///< position to set 00174 psPixelCoord value ///< pixels value to be set 00175 ); 00176 00177 /** Returns the value of the pixels array at the specified position. 00178 * 00179 * A negative position means index from the end. 00180 * 00181 * @return psPixelCoord: The value of the pixels at the specified position. 00182 */ 00183 psPixelCoord psPixelsGet( 00184 const psPixels *pixels, ///< input pixels from which to get 00185 long position ///< position to get 00186 ); 00187 00188 /** Get the number of elements in use from a specified psPixels. (pixels.n) 00189 * 00190 * @return long: The number of elements in use. 00191 */ 00192 long psPixelsLength( 00193 const psPixels *pixels ///< input psPixels 00194 ); 00195 00196 #endif // #ifndef PS_PIXELS_H
1.4.4