contrib/gel/gevd/gevd_pixel.h
Go to the documentation of this file.
00001 //:
00002 // \file
00003 #ifndef gevd_pixel_h_
00004 #define gevd_pixel_h_
00005 // <begin copyright notice>
00006 // ---------------------------------------------------------------------------
00007 //
00008 //                   Copyright (c) 1997 TargetJr Consortium
00009 //               GE Corporate Research and Development (GE CRD)
00010 //                             1 Research Circle
00011 //                            Niskayuna, NY 12309
00012 //                            All Rights Reserved
00013 //              Reproduction rights limited as described below.
00014 //
00015 //      Permission to use, copy, modify, distribute, and sell this software
00016 //      and its documentation for any purpose is hereby granted without fee,
00017 //      provided that (i) the above copyright notice and this permission
00018 //      notice appear in all copies of the software and related documentation,
00019 //      (ii) the name TargetJr Consortium (represented by GE CRD), may not be
00020 //      used in any advertising or publicity relating to the software without
00021 //      the specific, prior written permission of GE CRD, and (iii) any
00022 //      modifications are clearly marked and summarized in a change history
00023 //      log.
00024 //
00025 //      THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
00026 //      EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
00027 //      WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
00028 //      IN NO EVENT SHALL THE TARGETJR CONSORTIUM BE LIABLE FOR ANY SPECIAL,
00029 //      INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND OR ANY
00030 //      DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
00031 //      WHETHER OR NOT ADVISED OF THE POSSIBILITY OF SUCH DAMAGES, OR ON
00032 //      ANY THEORY OF LIABILITY ARISING OUT OF OR IN CONNECTION WITH THE
00033 //      USE OR PERFORMANCE OF THIS SOFTWARE.
00034 //
00035 // ---------------------------------------------------------------------------
00036 // <end copyright notice>
00037 
00038 #include "gevd_bufferxy.h"
00039 
00040 typedef unsigned char byte;                     // 8-bit  [0 255]
00041 const int bits_per_ptr = sizeof(void*) * 8;
00042 const int bits_per_float = sizeof(float) * 8;   // number of bits for a pixel
00043 const int bits_per_short = sizeof(short) * 8;
00044 const int bits_per_char = sizeof(char) * 8;
00045 const int bits_per_byte = sizeof(byte) * 8;
00046 
00047 
00048 // These macros will be used to get pixels with known type.
00049 // GetElementAddr is now overloaded with both gevd_bufferxy and const gevd_bufferxy.
00050 
00051 //: Get reference to pixel as a byte/char, unsigned/signed char (8-bit) number, at indexes (x, y) in buf.
00052 // This function is used to get and set pixel on non-const gevd_bufferxy.
00053 
00054 inline byte&
00055 bytePixel(gevd_bufferxy& buf, int x, int y)
00056 {
00057   return (*((byte*) buf.GetElementAddr(x,y)));
00058 }
00059 
00060 //: Get reference to pixel as a byte/char, unsigned/signed char (8-bit) number, at indexes (x, y) in buf.
00061 // This function is used to get and set pixel on non-const gevd_bufferxy.
00062 
00063 inline char&
00064 charPixel(gevd_bufferxy& buf, int x, int y)
00065 {
00066   return (*((char*) buf.GetElementAddr(x,y)));
00067 }
00068 
00069 //: Get reference to pixel as a short (16-bit) number, at indexes (x, y) in buf.
00070 
00071 inline short&
00072 shortPixel(gevd_bufferxy& buf, int x, int y)
00073 {
00074   return (*((short*) buf.GetElementAddr(x,y)));
00075 }
00076 
00077 //: Get reference to pixel as an unsigned short (16-bit) number, at indices (x, y) in buf.
00078 
00079 inline unsigned short&
00080 ushortPixel(gevd_bufferxy& buf, int x, int y)
00081 {
00082   return (*((unsigned short*) buf.GetElementAddr(x,y)));
00083 }
00084 
00085 //: Get reference to pixel as a float number, at indexes (x, y) in buf.
00086 // float is generally used to avoid overflow and unnecessary conversion
00087 // between float/double for math computation and byte/short for storage.
00088 
00089 inline float&
00090 floatPixel(gevd_bufferxy& buf, int x, int y)
00091 {
00092   return (*((float*) buf.GetElementAddr(x,y)));
00093 }
00094 
00095 //: Get reference to pixel as a pointer, at indexes (x, y).
00096 
00097 inline void*&
00098 ptrPixel(gevd_bufferxy& buf, int x, int y)
00099 {
00100   return (*((void**) buf.GetElementAddr(x,y)));
00101 }
00102 
00103 //: Get reference to pixel as a byte, at indexes (x, y).
00104 
00105 inline const byte&
00106 bytePixel(const gevd_bufferxy& buf, int x, int y)
00107 {
00108   return (*((const byte*) buf.GetElementAddr(x,y)));
00109 }
00110 
00111 
00112 //: Get reference to pixel as a char, at indexes (x, y).
00113 
00114 inline const char&
00115 charPixel(const gevd_bufferxy& buf, int x, int y)
00116 {
00117   return (*((const char*)buf.GetElementAddr(x,y)));
00118 }
00119 
00120 //: Get reference to pixel as a short, at indexes (x, y).
00121 
00122 inline const short&
00123 shortPixel(const gevd_bufferxy& buf, int x, int y)
00124 {
00125   return (*((const short*)buf.GetElementAddr(x,y)));
00126 }
00127 
00128 //: Get reference to pixel as an unsigned short, at indices (x, y).
00129 
00130 inline const unsigned short&
00131 ushortPixel(const gevd_bufferxy& buf, int x, int y)
00132 {
00133   return (*((const unsigned short*)buf.GetElementAddr(x,y)));
00134 }
00135 
00136 //: Get reference to pixel as a float, at indexes (x, y).
00137 
00138 inline const float&
00139 floatPixel(const gevd_bufferxy& buf, int x, int y)
00140 {
00141   return (*((const float*)buf.GetElementAddr(x,y)));
00142 }
00143 
00144 //: Get const reference to pixel at indexes (x, y).
00145 // This function is used to get pixel on const gevd_bufferxy,
00146 // as a const reference to a byte/char/short/float/void*.
00147 
00148 inline void*const&
00149 ptrPixel(const gevd_bufferxy& buf, int x, int y)
00150 {
00151   return (*((void*const*)buf.GetElementAddr(x,y)));
00152 }
00153 
00154 #endif