Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ImageDefinitions.h

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------
00002     Phission : 
00003         Realtime Vision Processing System
00004     
00005     Copyright (C) 2003-2006 Philip D.S. Thoren (pthoren@cs.uml.edu)
00006     University of Massachusetts at Lowell,
00007     Laboratory for Artificial Intelligence and Robotics
00008     
00009     This file is part of Phission.
00010 
00011     Phission is free software; you can redistribute it and/or modify
00012     it under the terms of the GNU Lesser General Public License as published by
00013     the Free Software Foundation; either version 2 of the License, or
00014     (at your option) any later version.
00015 
00016     Phission is distributed in the hope that it will be useful,
00017     but WITHOUT ANY WARRANTY; without even the implied warranty of
00018     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019     GNU Lesser General Public License for more details.
00020 
00021     You should have received a copy of the GNU Lesser General Public License
00022     along with Phission; if not, write to the Free Software
00023     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024 
00025  ---------------------------------------------------------------------------*/
00026 #ifndef _IMAGEDEFINITIONS_H
00027 #define _IMAGEDEFINITIONS_H
00028 
00029 #include <phStandard.h>
00030 #include <phStdint.h>
00031 
00032 #ifdef __cplusplus
00033 extern "C" 
00034 {
00035 #endif
00036 
00049 /* Note: Color Types won't work correctly on a ZlibCompressed image.
00050  * Unexpected results may occur if the image isn't decompressed first. */
00051 #define phColorTypeArray    0
00052 #define phColorTypeRGB24    1
00053 #define phColorTypeBGR24    2
00054 #define phColorTypeABGR32   3
00055 #define phColorTypeRGBA32   4
00056 #define phColorTypeGREY8    5 /* ie Greyscale, depth = 1 */
00057 #define phColorTypeYUV9     6
00058 #define phColorTypeHSV24    7
00059 #define phColorTypeBGRA32   8
00060 #define phColorTypeSCT24    9
00061                
00062 #define phColorCount        10
00063 
00064 extern PHAPI_VAR(char)   *phColorNames[phColorCount]; /* def in the .c file */
00065 extern PHAPI_VAR(uint8_t) phColorDepth[phColorCount]; /* def in the .c file */
00066 
00067 /* ------------------------------------------------------------------------ */
00068 typedef struct phColorRGB24_t
00069 {
00070     uint8_t type;
00071     
00072     uint8_t r;
00073     uint8_t g;
00074     uint8_t b;
00075     
00076     uint8_t padding[4];
00077 } phColorRGB24;
00078 
00079 /* ------------------------------------------------------------------------ */
00080 typedef struct phColorBGR24_t
00081 {
00082     uint8_t type;
00083     
00084     uint8_t b;
00085     uint8_t g;
00086     uint8_t r;
00087     
00088     uint8_t padding[4];
00089 } phColorBGR24;
00090 
00091 /* ------------------------------------------------------------------------ */
00092 typedef struct phColorRGBA32_t
00093 {
00094     uint8_t type;
00095     
00096     uint8_t r;
00097     uint8_t g;
00098     uint8_t b;
00099     uint8_t a;
00100     
00101     uint8_t padding[3];
00102 } phColorRGBA32;
00103 
00104 /* ------------------------------------------------------------------------ */
00105 typedef struct phColorABGR32_t
00106 {
00107     uint8_t type;
00108     
00109     uint8_t a;
00110     uint8_t b;
00111     uint8_t g;
00112     uint8_t r;
00113     
00114     uint8_t padding[3];
00115 } phColorABGR32;
00116 
00117 /* ------------------------------------------------------------------------ */
00118 typedef struct phColorBGRA32_t
00119 {
00120     uint8_t type;
00121     
00122     uint8_t b;
00123     uint8_t g;
00124     uint8_t r;
00125     uint8_t a;
00126     
00127     uint8_t padding[3];
00128 } phColorBGRA32;
00129 
00130 /* ------------------------------------------------------------------------ */
00131 typedef struct phColorYUV9_t
00132 {
00133     uint8_t type;
00134     
00135     uint8_t y;
00136     uint8_t u;
00137     uint8_t v;
00138     
00139     uint8_t padding[4];
00140 } phColorYUV9;
00141 
00142 /* ------------------------------------------------------------------------ */
00143 typedef struct phColorHSV_t
00144 {
00145     uint8_t type;
00146     
00147     uint8_t h;
00148     uint8_t s;
00149     uint8_t v;
00150 
00151     uint8_t padding[4];
00152 } phColorHSV24;
00153 
00154 /* ------------------------------------------------------------------------ */
00155 typedef struct phColorGREY8_t
00156 {
00157     uint8_t type;
00158     
00159     uint8_t y;
00160     
00161     uint8_t padding[6];
00162 } phColorGREY8;
00163 
00164 /* ------------------------------------------------------------------------ */
00165 typedef struct phColorSCT24_t
00166 {
00167     uint8_t type;
00168     
00169     uint8_t s;
00170     uint8_t c;
00171     uint8_t t;
00172     
00173     uint8_t padding[4];
00174 } phColorSCT24;
00175 
00176 /* ------------------------------------------------------------------------ */
00177 /* The size of this type would be 5 bytes without the extra padding,
00178  * an even number of bytes makes more sense */
00179 /* so far, 4 is the max color array size */
00180 #define phCOLOR_MAXBYTES 4
00181 #define phCOLOR_MAXELEMS 4
00182 typedef struct phColorArray_t 
00183 {
00184     uint8_t type;
00185     uint8_t v[phCOLOR_MAXBYTES];
00186     uint8_t padding[3];
00187 } phColorArray;
00188 
00189 /* ------------------------------------------------------------------------ */
00190 typedef union phColor_t
00191 {
00192     uint8_t type;
00193     
00194     phColorArray  array;
00195     
00196     phColorRGB24  rgb24;
00197     phColorRGBA32 rgba32;
00198     phColorBGR24  bgr24;
00199     phColorABGR32 abgr32;
00200     phColorBGRA32 bgra32;
00201     phColorYUV9   yuv9;
00202     phColorHSV24  hsv24;
00203     phColorGREY8  grey8;
00204     phColorSCT24  sct24;
00205   
00206     /* This makes the union a power of two size in bytes: 8 */
00207     uint8_t       bytes[8];
00208     
00209 } phColor;
00210 
00211 /* ---------------------------------------------------------------------- */
00212 PHAPI(phColor) phColor_new       ( uint8_t t                                                   );
00213 PHAPI(phColor) phColor8_new      ( uint8_t t, uint8_t b                                        );
00214 PHAPI(phColor) phColor16_new     ( uint8_t t, uint8_t b0, uint8_t b1                           );
00215 PHAPI(phColor) phColor24_new     ( uint8_t t, uint8_t b0, uint8_t b1, uint8_t b2               );
00216 PHAPI(phColor) phColor32_new     ( uint8_t t, uint8_t b0, uint8_t b1, uint8_t b2, uint8_t b3   );
00217 PHAPI(phColor) phColorArray24_new( uint8_t b0,uint8_t b1, uint8_t b2                           );
00218 PHAPI(phColor) phColorArray32_new( uint8_t b0,uint8_t b1, uint8_t b2, uint8_t b3               );
00219 PHAPI(phColor) phColorRGB24_new  ( uint8_t r, uint8_t g,  uint8_t b                            );
00220 PHAPI(phColor) phColorRGBA32_new ( uint8_t r, uint8_t g,  uint8_t b,  uint8_t a                );
00221 PHAPI(phColor) phColorBGR24_new  ( uint8_t b, uint8_t g,  uint8_t r                            );
00222 PHAPI(phColor) phColorABGR32_new ( uint8_t a, uint8_t b,  uint8_t g,  uint8_t r                );
00223 PHAPI(phColor) phColorBGRA32_new ( uint8_t b, uint8_t g,  uint8_t r,  uint8_t a                );
00224 PHAPI(phColor) phColorYUV9_new   ( uint8_t y, uint8_t u,  uint8_t v                            );
00225 PHAPI(phColor) phColorHSV24_new  ( uint8_t h, uint8_t s,  uint8_t v                            );
00226 PHAPI(phColor) phColorGREY8_new  ( uint8_t y                                                   );
00227 PHAPI(phColor) phColorSCT24_new  ( uint8_t s, uint8_t c,  uint8_t t                            );
00228 
00229 PHAPI(uint8_t)      phColorStringToType     ( const char *str );
00230 const PHAPI(char)  *phColorTypeToString     ( uint8_t type );
00231 PHAPI(uint32_t)     phColorTypeToFormat     ( uint8_t type );
00232 PHAPI(uint8_t)      phColorTypeToDepth      ( uint8_t type );
00233 const PHAPI(char)  *phColorToString         ( const phColor c );
00234 PHAPI(uint32_t)     phColorToFormat         ( const phColor c );
00235 PHAPI(uint8_t)      phColorToDepth          ( const phColor c );
00236 /* one == two : return 1 | else returns 0 */
00237 PHAPI(int)         phColorEqual            ( phColor one, phColor two );
00238 
00239 /* ---------------------------------------------------------------------- */
00240 /* Print phColor to file descriptor fd */
00241 PHAPI(int) phColorPrint( int fd, phColor color );
00242 /* Save will write num_colors to the filename; the colors array must be 
00243  * initialized correctly and be an appropriate size */
00244 PHAPI(int) phColorSave( const char   *filename, 
00245                         uint32_t      num_colors, 
00246                         phColor      *colors       );
00247 
00248 /* ------------------------------------------------------------------------- */
00299 PHAPI(int) phColorRead( int          fd, 
00300                         uint32_t     max_colors,
00301                         uint32_t     *num_colors, 
00302                         phColor      **colors      );
00303 /* ------------------------------------------------------------------------- */
00344 PHAPI(int) phColorLoad( const char   *filename, 
00345                         uint32_t     max_colors,
00346                         uint32_t     *num_colors, 
00347                         phColor      **colors      );
00348  /* end \addtogroup Image_Colors */
00350 
00351 /* ---------------------------------------------------------------------- */
00369 typedef enum 
00370 {
00371         /* do not change the value of these; it breaks backward 
00372          * compatability. This holds starting now: 01/07/2004 */
00377         phImageRGB24    =(1<<0),
00382         phImageBGR24    =(1<<1),
00387         phImageABGR32   =(1<<2),
00392         phImageRGBA32   =(1<<3),
00399         phImageGREY8    =(1<<4),
00404         phImageYUV9     =(1<<5),
00410         phImageHSV24    =(1<<6),
00415         phImageBGRA32   =(1<<7),
00423         phImageSCT24    =(1<<8),
00424         
00425         /* Special format flags */
00426         phImageZlib     =(1<<20),
00427         phImageJPEG     =(1<<21),
00428         
00429         phImageNOFORMAT =(1<<30)
00430             
00431 } phImageType;
00432 
00434 #define phImageGRAY8 phImageGREY8
00435 
00436 #define phImageFormatCount 10
00437 
00444 #define phImageValidFormatMask \
00445     (phImageRGB24 | phImageBGR24 | phImageABGR32 | \
00446      phImageBGRA32 | \
00447      phImageRGBA32 | phImageGREY8 | phImageYUV9 | phImageHSV24 | \
00448      phImageSCT24 )
00449 
00455 #define phImagePackedFormatMask \
00456     (phImageRGB24 | phImageBGR24 | phImageABGR32 | \
00457      phImageBGRA32 | \
00458      phImageRGBA32 | phImageGREY8 | phImageHSV24 | \
00459      phImageSCT24 )
00460 
00467 #define phImagePlanarFormatMask phImageYUV9
00468 
00477 #define phImageSpecialMask (phImageZlib | phImageJPEG)
00478 
00479 /* ---------------------------------------------------------------------- */
00483 #define phCHANNEL_RED      0
00484 #define phCHANNEL_GREEN    1
00485 #define phCHANNEL_BLUE     2
00486 #define phCHANNEL_ALPHA    3
00487 
00488 typedef enum { phRedChannel     = 0,
00489                phGreenChannel   = 1,
00490                phBlueChannel    = 2,
00491                phAlphaChannel   = 3 } ChannelEnum;
00492 
00493 /* ---------------------------------------------------------------------- */
00494 /* defs in the .c file */
00495 extern PHAPI_VAR(int8_t)   phImageChannelIndex[phImageFormatCount][4];
00496 extern PHAPI_VAR(uint32_t) phImageChannelMasks[phImageFormatCount][4];
00497         
00498 /* ---------------------------------------------------------------------- */
00499 /* x 4 because of the following combinations:
00500  *  regular format
00501  *  zlib compressed format
00502  *  jpeg compressed format
00503  *  zlib and jpeg compressed format 
00504  */
00505 #define phImageFormatTotalCount (phImageFormatCount*4)
00506   
00507 /* ---------------------------------------------------------------------- */
00508 /* defs in the .c file */
00509 extern PHAPI(char)   *phImageNames[phImageFormatTotalCount];
00510 extern PHAPI(uint8_t) phImageDepth[phImageFormatTotalCount];
00511 
00512 PHAPI(uint32_t)     phImageFormatToIndex    ( uint32_t f );
00513 const PHAPI(char)  *phImageFormatToString   ( uint32_t f );
00514 PHAPI(uint8_t)      phImageFormatToDepth    ( uint32_t f );
00515 PHAPI(uint32_t)     phImageFormatTo32BitMask( uint32_t f, uint32_t c );
00516 PHAPI(uint8_t)      phImageFormatToColorType( uint32_t f );
00517 PHAPI(void)         phImageFormatIndecies   ( uint32_t f, uint8_t *r, 
00518                                                uint8_t *g, uint8_t *b, 
00519                                                uint8_t *a );
00520 
00521 /* ------------------------------------------------------------------------- */
00543 #define phIMAGE_SIZE(w,h,f) \
00544     ((f & (phImageRGB24 | phImageBGR24 | phImageHSV24 | phImageSCT24)) ? \
00545      (w * h * 3) : \
00546     ((f & (phImageRGBA32 | phImageABGR32 | phImageBGRA32)) ? \
00547      (w * h * 4) : \
00548     ((f & (phImageGREY8)) ? \
00549      (w * h * 1) : \
00550     ((f & (phImageYUV9)) ? \
00551      ((w * h) + (2 * ((w * h) / 16))) : \
00552      0 \
00553     ))))
00554 
00568 #define phIMAGE_SIZE_IN_BYTES(s,w,h,f)                  \
00569 {                                                       \
00570     if (f & (phImageRGB24 | phImageBGR24 | phImageHSV24|\
00571              phImageSCT24 ))                            \
00572     {                                                   \
00573         s = w * h * 3;                                  \
00574     }                                                   \
00575     else if (f & (phImageRGBA32 | phImageABGR32 |       \
00576                   phImageBGRA32))                       \
00577     {                                                   \
00578         s = w * h * 4;                                  \
00579     }                                                   \
00580     else if (f & phImageGREY8)                          \
00581     {                                                   \
00582         s = w * h * 1;                                  \
00583     }                                                   \
00584     else if (f & phImageYUV9)                           \
00585     {                                                   \
00586         s = (w * h) + (2 * ((w * h) / 16));             \
00587     }                                                   \
00588     else                                                \
00589     {                                                   \
00590         /*phPRINT_RC(-1,NULL,"Invalid image format [0x%08x].",f);*/ \
00591         s = 0;                                          \
00592     }                                                   \
00593 }
00594  /* end \addtogroup Image_Formats */ /* end \addtogroup Image */
00597 
00598 /* ---------------------------------------------------------------------- */
00599 #ifdef __cplusplus
00600 }
00601 #endif
00602     
00603 #endif /* _IMAGEDEFINITIONS_H */




Copyright (C) 2002 - 2007 Philip D.S. Thoren ( pthoren@users.sourceforge.net )
University Of Massachusetts at Lowell
Robotics Lab
SourceForge.net Logo

Generated on Sat Jun 16 02:44:01 2007 for phission by  doxygen 1.4.4