Image.h
Go to the documentation of this file.00001 /**<!--------------------------------------------------------------------> 00002 @class Image 00003 @author Travis Fischer (fisch0920@gmail.com) 00004 @date Fall 2008 00005 00006 @brief 00007 Abstract image class supporting a standard 32-bit Rgba pixel format, as 00008 well as an extended, 128- or 256-bit floating-point RgbaHDR pixel format 00009 for high dynamic range images 00010 00011 @note 00012 In addition to Qt's normal image loading / saving, represented by the 00013 following table, this class also supports loading / saving of images in 00014 HDR, OpenEXR, and PFM image formats. 00015 00016 Default / built-in image formats supported by Qt: 00017 00018 Format Description Qt Support 00019 ------ ------------------------------------------- -------------- 00020 BMP Windows Bitmap Read / Write 00021 GIF Graphic Interchange Format (optional) Read 00022 JPG Joint Photographic Experts Group Read / Write 00023 JPEG Joint Photographic Experts Group Read / Write 00024 PNG Portable Network Graphics Read / Write 00025 PBM Portable Bitmap Read 00026 PGM Portable Graymap Read 00027 PPM Portable Pixmap Read / Write 00028 TIFF Tagged Image File Format Read / Write 00029 XBM X11 Bitmap Read / Write 00030 XPM X11 Pixmap Read / Write 00031 00032 Extra High Dynamic Range image formats supported by Milton: 00033 00034 Format Description Support 00035 ------ ------------------------------------------- ----------- 00036 HDR Also known as RGBE (Radiance, by Greg Ward) Read / Write 00037 EXR ILM's OpenEXR Format Read / Write* 00038 PFM Portable Float Map Format Read / Write 00039 00040 @note 00041 * OpenEXR is only supported on platforms / builds with ILM's OpenEXR 00042 libraries which do not come bundled with Milton. 00043 <!-------------------------------------------------------------------->**/ 00044 00045 #ifndef MILTON_IMAGE_H_ 00046 #define MILTON_IMAGE_H_ 00047 00048 #include <common/image/Rgba.h> 00049 #include <boost/shared_ptr.hpp> 00050 00051 class Image { 00052 public: 00053 ///@name Constructors 00054 //@{----------------------------------------------------------------- 00055 00056 inline Image(unsigned width = 640, unsigned height = 480); 00057 virtual ~Image() 00058 { } 00059 00060 00061 //@}----------------------------------------------------------------- 00062 ///@name Saving / Loading 00063 //@{----------------------------------------------------------------- 00064 00065 /** 00066 * @brief 00067 * Attempts to load an image from the given file, inferring the 00068 * image file format by the filename's extension 00069 * 00070 * @note If the actual file loaded is RgbaHDR and the requested image 00071 * format is RgbaImage, the loaded HDRImage image will be converted to 00072 * an RgbaImage before returning. Similarly, if the image was stored 00073 * in an Rgba32 format (PNG, JPEG, etc.), and the requested image 00074 * format is HDRImage, the loaded RgbaImage will be converted to an 00075 * HDRImage before returning. 00076 * 00077 * @returns a new image of the desired type upon success or NULL upon 00078 * failur 00079 */ 00080 static Image *load(const std::string &filename); 00081 00082 /** 00083 * @brief 00084 * Attempts to save this image out to the given file, inferring the 00085 * desired file format by the filename's extension 00086 * 00087 * @returns whether or not file was successfully saved 00088 */ 00089 virtual bool save(const std::string &filename) const; 00090 00091 00092 //@}----------------------------------------------------------------- 00093 ///@name Data Accessors / Mutators 00094 //@{----------------------------------------------------------------- 00095 00096 /** 00097 * @returns whether or not the underlying data for this image is stored 00098 * in a floating-point HDR format 00099 * 00100 * @note that some operations will be more of less efficient when 00101 * performed on an HDR image versus a standard 32-bit Rgba image, 00102 * and knowing whether or not an image is in HDR format can 00103 * facilitate efficient usage (cutting down on the number of 00104 * implicit conversions between HDR and non-HDR pixel formats that 00105 * must be performed) 00106 */ 00107 virtual bool isHDR() const = 0; 00108 00109 /** 00110 * @returns the pixel in the given row and column in the desired template 00111 * format (either Rgba32 or RgbaHDR) 00112 * 00113 * @note if this image is an HDR image and an Rgba32 is requested, an 00114 * implicit conversion is performed (and vice-versa if this image is 00115 * non-HDR and the caller requests an RgbaHDR) 00116 */ 00117 template <typename T> 00118 inline T getPixel(unsigned row, unsigned col) const; 00119 00120 /** 00121 * @brief 00122 * Sets the pixel in the given row and column to the pixel value in 00123 * the desired template format (either Rgba32 or RgbaHDR) 00124 * 00125 * @note if this image is an HDR image and an Rgba32 value is given, an 00126 * implicit conversion is performed (and vice-versa if this image is 00127 * non-HDR and the caller gives an RgbaHDR) 00128 */ 00129 template <typename T> 00130 inline void setPixel(unsigned row, unsigned col, const T &val); 00131 00132 /** 00133 * @returns the luminance of the pixel at the given row and column which 00134 * is guaranteed to lie in [0, 1] 00135 */ 00136 virtual real_t getLuminance(unsigned row, unsigned col) const = 0; 00137 00138 00139 //@}----------------------------------------------------------------- 00140 ///@name Size accessors 00141 //@{----------------------------------------------------------------- 00142 00143 /// @returns the image width 00144 inline unsigned getWidth() const; 00145 00146 /// @returns the image height 00147 inline unsigned getHeight() const; 00148 00149 /// @returns width * height 00150 inline unsigned getSize() const; 00151 00152 00153 //@}----------------------------------------------------------------- 00154 ///@name Large Mutators 00155 //@{----------------------------------------------------------------- 00156 00157 /** 00158 * @brief 00159 * Sets the dimensions of this image, most likely allocating a new 00160 * underlying buffer and erasing its previous contents 00161 */ 00162 virtual void setSize(unsigned width, unsigned height) = 0; 00163 00164 /** 00165 * @brief 00166 * Sets the underlying data - data should be the size of the image 00167 * 00168 * @note copies the given data into the underlying buffer, leaving 00169 * the given data unmodified 00170 * @note if this image is an HDR image and Rgba32 data is given, an 00171 * implicit conversion is performed (and vice-versa if this image is 00172 * non-HDR and the caller gives RgbaHDR data) 00173 */ 00174 template <typename T> 00175 inline void setData(const T *data); 00176 00177 /** 00178 * @brief 00179 * Sets the underlying data and image dimensions, where the given data 00180 * should be preallocated to the desired size of the image 00181 * 00182 * @note copies the given data into a new underlying buffer, leaving 00183 * the given data unmodified 00184 * @note if this image is an HDR image and Rgba32 data is given, an 00185 * implicit conversion is performed (and vice-versa if this image is 00186 * non-HDR and the caller gives RgbaHDR data) 00187 */ 00188 template <typename T> 00189 inline void setData(const T *data, unsigned width, unsigned height); 00190 00191 00192 //@}----------------------------------------------------------------- 00193 ///@name Miscellaneous 00194 //@{----------------------------------------------------------------- 00195 00196 /** 00197 * @returns a copy of this Image and its underlying data 00198 */ 00199 virtual Image *clone() const = 0; 00200 00201 /** 00202 * @brief 00203 * Overwrites this image's data with the given image which is assumed 00204 * to have the same dimensions as this image (and may have been created 00205 * from this image by, for example, the clone function) 00206 */ 00207 virtual void copyData(const Image *image) = 0; 00208 00209 00210 //@}----------------------------------------------------------------- 00211 00212 protected: 00213 virtual Rgba32 _getPixelRgba32 (unsigned row, unsigned col) const = 0; 00214 virtual RgbaHDR _getPixelRgbaHDR(unsigned row, unsigned col) const = 0; 00215 00216 virtual void _setPixel(unsigned row, unsigned col, const Rgba32 &val) = 0; 00217 virtual void _setPixel(unsigned row, unsigned col, const RgbaHDR &val) = 0; 00218 00219 virtual void _setData(const Rgba32 *data) = 0; 00220 virtual void _setData(const RgbaHDR *data) = 0; 00221 00222 protected: 00223 unsigned m_width; 00224 unsigned m_height; 00225 unsigned m_size; 00226 }; 00227 00228 typedef boost::shared_ptr<Image> ImagePtr; 00229 00230 // include inline definitions 00231 #include <common/image/Image.inl> 00232 00233 #endif // MILTON_IMAGE_H_ 00234
Generated on 28 Feb 2009 for Milton by
1.5.6