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 _PHIMAGE_H 00027 #define _PHIMAGE_H 00028 00029 #include <phStdint.h> 00030 #include <ImageDefinitions.h> 00031 #include <ImageUtil.h> 00032 #include <phDataObject.h> 00033 00034 /* ---------------------------------------------------------------------- */ 00041 typedef enum 00042 { 00043 phFileAuto = 0, 00044 phFileUnknown, 00045 phFilePPM, 00046 phFileJPEG 00047 00048 } phFileType; 00049 00050 /* ---------------------------------------------------------------------- */ 00058 PHAPI(class) phImage : public phDataObject 00059 { 00060 protected: 00062 uint32_t m_width; 00064 uint32_t m_height; 00066 uint32_t m_format; 00067 00081 uint32_t calculateSize(uint32_t w, uint32_t h, int32_t f); 00082 00083 /* Conversion methods: 00084 * 00085 * Do not call these; They are called from convert and conversions 00086 * should only be performed by calling convert. 00087 * 00088 * These return 1 if a conversion was made into temporary memory 00089 * and the image data needs to be swapped with converted data */ 00090 int initConversion (); 00091 int resetConversion(); 00092 00093 uint32_t m_conv_dst_format; 00094 uint8_t *m_conv_dst; 00095 uint32_t m_conv_dstsize; 00096 00097 /* for faster bilinear resizing */ 00098 int initResize(); 00099 int resetResize(); 00100 00101 ph_bilinear_table_type m_bilinear_table; 00102 ph_nearest_neighbor_table_type m_nn_table; 00103 00104 uint8_t *m_resize_buf; 00105 uint32_t m_resize_buf_size; 00106 00107 /* for cropping images */ 00108 int initCrop(); 00109 int resetCrop(); 00110 00111 uint8_t *m_crop_buf; 00112 uint32_t m_crop_buf_size; 00113 00114 /* for ZLIB compression */ 00115 int initZlibCompression (); 00116 int resetZlibCompression(); 00117 00118 int m_compressed; 00119 int m_compress_level; 00120 void *m_compress_buffer; 00121 uint32_t m_compress_buffer_size; 00122 void *m_decompress_buffer; 00123 uint32_t m_decompress_buffer_size; 00124 00125 /* for JPEG compression */ 00126 int initJPEGCompression (); 00127 int resetJPEGCompression(); 00128 00129 int m_jpegCompressed; 00130 int m_jpegQuality; /* TODO */ 00131 void *m_jpegCompress_handle; 00132 void *m_jpegCompress_buffer; 00133 uint32_t m_jpegCompress_buffer_size; 00134 void *m_jpegDecompress_handle; 00135 void *m_jpegDecompress_buffer; 00136 uint32_t m_jpegDecompress_buffer_size; 00137 00138 /* Save and load methods */ 00139 int initFileSave (); 00140 int resetFileSave(); 00141 00142 phImage *m_saveImageBuf; 00143 phFileType fileTypeFromName( char *filename ); 00144 int saveJPEG ( char *filename ); 00145 int loadJPEG ( char *filename ); 00146 int savePPM ( char *filename ); 00147 int loadPPM ( char *filename ); 00148 int savePPM_old ( char *filename ); 00149 00150 public: 00151 phImage(); 00152 virtual ~phImage(); 00153 00154 uint32_t getWidth (); 00155 uint32_t getHeight(); 00156 int32_t getFormat(); 00168 int setFormat( uint32_t type ); 00169 00170 /* print: temporary for debugging java stuffs 00171 void print(); 00172 */ 00179 const uint8_t *getImage(); 00180 00185 int getImage( int8_t image[] ); 00186 00187 /* These are from the phObject level, mostly for phLiveObject */ 00188 int copy( phObject *copyto_obj ); 00189 int swap( phObject *obj ); 00190 00191 int getCopy( phImage &data ); 00192 int getCopy( uint32_t *w, 00193 uint32_t *h, 00194 uint32_t *format, 00195 uint32_t *s, 00196 uint8_t *image[] ); 00197 00198 int setImage( phImage &image ); 00199 int setImage( uint32_t w, 00200 uint32_t h, 00201 int32_t f, 00202 /* if s is zero, a guess is made based on the format */ 00203 uint32_t s, 00204 const uint8_t image[] ); 00205 00206 int swapImage( phImage &image ); 00207 int swapData( phImage &image ); 00208 int swapData( uint32_t *w, 00209 uint32_t *h, 00210 uint32_t *format, 00211 uint8_t *image[], 00212 /* if psize is supplied and it's not 0, it is used as 00213 * the size for copying */ 00214 uint32_t *psize = NULL ); 00215 00220 int allocate( uint32_t w, uint32_t h, uint32_t format ); 00221 00225 int reset(); 00226 00227 phImage& operator = (phImage &rightHandSide); 00228 00232 int resize( phImage &original, 00233 uint32_t w, uint32_t h, 00234 uint32_t algorithm = phResizeNN ); 00238 int resize( uint32_t w, uint32_t h, 00239 uint32_t algorithm = phResizeNN ); 00240 00244 int crop( phImage &original, 00245 uint32_t x1, uint32_t y1, 00246 uint32_t x2, uint32_t y2 ); 00250 int crop( uint32_t x1, uint32_t y1, 00251 uint32_t x2, uint32_t y2 ); 00252 00266 int convert( uint32_t to_format, uint32_t force_format = phImageNOFORMAT ); 00267 00268 /* -------------------------------------------------------------------- */ 00269 /* ZLIB SUPPORT: */ 00270 /* -------------------------------------------------------------------- */ 00275 int compress(); 00276 00281 int decompress(); 00282 00287 int isCompressed(); 00288 00293 int setCompressionLevel( int level ); 00294 00295 00297 static int isZlibAvailable(); 00298 00299 00300 /* -------------------------------------------------------------------- */ 00301 /* JPEG SUPPORT: */ 00302 /* -------------------------------------------------------------------- */ 00307 int jpegCompress(); 00308 00313 int jpegDecompress(); 00314 00319 int isJPEGCompressed(); 00320 00325 int setJPEGQuality( int q ); 00326 int getJPEGQuality(); 00327 00329 static int isJPEGAvailable(); 00330 00331 00332 /* -------------------------------------------------------------------- */ 00333 /* FILE SAVING/LOADING SUPPORT: */ 00334 /* -------------------------------------------------------------------- */ 00336 int save( char *filename, phFileType filetype = phFileAuto ); 00338 int load( char *filename, phFileType filetype = phFileAuto ); 00339 }; 00340 00341 #endif /* _PHIMAGE_H */
Copyright (C) 2002 - 2007 |
Philip D.S. Thoren ( pthoren@users.sourceforge.net ) University Of Massachusetts at Lowell Robotics Lab |