00001 /** @file psPixels.h 00002 * 00003 * @brief Contains psPixel related functions 00004 * 00005 * @author Paul Price, IfA 00006 * @author Robert DeSonia, MHPCC 00007 * 00008 * @version $Revision: 1.24 $ $Name: $ 00009 * @date $Date: 2007/01/23 22:47:23 $ 00010 * 00011 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii 00012 */ 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 DataContainer Data Containers 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 00054 /** Allocates a new psPixels structure 00055 * 00056 * @return psPixels* new psPixels 00057 */ 00058 psPixels* psPixelsAlloc( 00059 long nalloc ///< the size of the coordinate vectors 00060 ) 00061 ; 00062 00063 /** Checks the type of a particular pointer. 00064 * 00065 * Uses the appropriate deallocation function in psMemBlock to check the ptr datatype. 00066 * 00067 * @return bool: True if the pointer matches a psPixels structure, false otherwise. 00068 */ 00069 bool psMemCheckPixels( 00070 psPtr ptr ///< the pointer whose type to check 00071 ); 00072 00073 00074 /** resizes a psPixels structure 00075 * 00076 * @return psPixels* resized psPixels 00077 */ 00078 psPixels* psPixelsRealloc( 00079 psPixels* pixels, ///< psPixels to resize, or NULL to create new psPixels 00080 long nalloc ///< the size of the coordinate vectors 00081 ); 00082 00083 /** Add a pixel location to a psPixels 00084 * 00085 * Grow the psPixels input by growth. If growth is less that 1, 10 is used. If a NULL 00086 * psPixels is given, a new one is created. 00087 * 00088 * @return psPixels* psPixels with the value appended. 00089 */ 00090 psPixels* p_psPixelsAppend( 00091 psPixels* pixels, ///< psPixels to append new coordinate to. 00092 long growth, ///< Number of elements to grow the pixels list if necessary. 00093 float x, ///< x coordinate to append 00094 float y ///< y coordinate to append 00095 ); 00096 00097 /** Copies a psPixels object 00098 * 00099 * Makes a deep copy of the data in a psPixels object. Any data in the OUT 00100 * parameter will be destroyed and OUT will be resized, if necessary. 00101 * 00102 * @return psPixels* a new psPixels that is a duplicate to IN 00103 */ 00104 psPixels* psPixelsCopy( 00105 psPixels* out, ///< psPixels struct to recycle, or NULL 00106 const psPixels* pixels ///< psPixels struct to copy 00107 ); 00108 00109 /** Generate a psImage from a psPixels 00110 * 00111 * psPixelsToMask shall return an image of type U8 with the pixels lying 00112 * within the specified region set to the maskVal. The out image shall be 00113 * modified if supplied, or allocated and returned if NULL. The size of the 00114 * output image shall be region->x1 - region->x0 by region->y1 - region->y0, 00115 * with out->x0 = region->x0 and out->y0 = region->y0. In the event that 00116 * either of pixels or region are NULL, the function shall generate an 00117 * error and return NULL. 00118 * 00119 * @return psImage* generated mask image 00120 */ 00121 psImage* psPixelsToMask( 00122 psImage* out, ///< psImage to recycle, or NULL 00123 const psPixels* pixels, ///< list of pixels to use 00124 psRegion region, ///< region to define the output mask image 00125 psMaskType maskVal ///< the mask bit-values to act upon 00126 ); 00127 00128 /** Generate a psPixels from a mask psImage 00129 * 00130 * psMaskToPixels shall return a psPixels consisting of the coordinates in 00131 * the mask that match the maskVal. The out pixel list shall be modified if 00132 * supplied, or allocated and returned if NULL. In hte event that mask is 00133 * NULL, the function shall generate an error and return NULL. 00134 * 00135 * @return psPixels* generated psPixels pixel list 00136 */ 00137 psPixels* psPixelsFromMask( 00138 psPixels *out, ///< psPixels to recycle, or NULL 00139 const psImage *mask, ///< the input mask psImage 00140 psMaskType maskVal ///< the mask bit-values to act upon 00141 ); 00142 00143 /** Concatenates two psPixels 00144 * 00145 * psPixelsConcatenate shall concatenate pixels onto out. In the event that 00146 * out is NULL, a new psPixels shall be allocated, and the contents of 00147 * pixels simply copied in. If pixels is NULL, the function shall generate 00148 * an error and return NULL. The function shall take care to ensure that 00149 * there are no duplicate pixels in out. 00150 * 00151 * @return psPixels Concatenated psPixel list 00152 */ 00153 psPixels* psPixelsConcatenate( 00154 psPixels *out, ///< psPixels to recycle, or NULL 00155 const psPixels *pixels ///< psPixels to append to OUT 00156 ); 00157 00158 /** Prints a psPixels to specified destination. 00159 * 00160 * @return bool: True if successful. 00161 */ 00162 bool p_psPixelsPrint( 00163 FILE *fd, ///< destination file descriptor 00164 psPixels* pixels, ///< psPixels to print 00165 const char *name ///< printf-style format of header line 00166 ); 00167 00168 /** Sets the value of the the pixels array at the specified position to value. 00169 * 00170 * A negative position means index from the end. 00171 * 00172 * @return bool: True if Successful, otherwise false. 00173 */ 00174 bool psPixelsSet( 00175 psPixels *pixels, ///< pixels to set 00176 long position, ///< position to set 00177 psPixelCoord value ///< pixels value to be set 00178 ); 00179 00180 /** Returns the value of the pixels array at the specified position. 00181 * 00182 * A negative position means index from the end. 00183 * 00184 * @return psPixelCoord: The value of the pixels at the specified position. 00185 */ 00186 psPixelCoord psPixelsGet( 00187 const psPixels *pixels, ///< input pixels from which to get 00188 long position ///< position to get 00189 ); 00190 00191 /** Get the number of elements in use from a specified psPixels. (pixels.n) 00192 * 00193 * @return long: The number of elements in use. 00194 */ 00195 long psPixelsLength( 00196 const psPixels *pixels ///< input psPixels 00197 ); 00198 00199 /// @} 00200 #endif // #ifndef PS_PIXELS_H
1.5.1