Main Page   Class Hierarchy   Compound List   File List   Compound Members  

gfxImage.h

00001 //////////////////////////////////////////////////////////////////////
00002 // Copyright (c) 2001-2002 David Pritchard <drpritch@alumni.uwaterloo.ca>
00003 // 
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public License
00006 // as published by the Free Software Foundation; either
00007 // version 2 of the License, or (at your option) any later
00008 // version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU Lesser General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU Lesser General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 
00019 #ifndef freecloth_gfx_gfxImage_h
00020 #define freecloth_gfx_gfxImage_h
00021 
00022 #ifndef freecloth_gfx_package_h
00023 #include <freecloth/gfx/package.h>
00024 #endif
00025 
00026 #ifndef freecloth_resmgt_rcBase_h
00027 #include <freecloth/resmgt/rcBase.h>
00028 #endif
00029 
00030 #ifndef freecloth_resmgt_rcProxyShdPtr_h
00031 #include <freecloth/resmgt/rcProxyShdPtr.h>
00032 #endif
00033 
00034 #ifndef freecloth_base_vector
00035 #include <freecloth/base/vector>
00036 #endif
00037 
00038 ////////////////////////////////////////////////////////////////////////////////
00039 // FORWARD DECLARATIONS
00040 
00041 
00042 FREECLOTH_NAMESPACE_START
00043     template <class T> class RCShdPtr;
00044 FREECLOTH_NAMESPACE_END
00045 
00046 ////////////////////////////////////////////////////////////////////////////////
00047 /*!
00048  * \class GfxImage freecloth/gfx/gfxImage.h
00049  * \brief Class to hold an image.
00050  *
00051  * Image data is stored in row major format, starting with the top-left corner.
00052  * Rows are not guaranteed to be aligned to 4-byte boundaries.
00053  * Not very user-friendly yet, especially when dealing with 24-bit data.
00054  */
00055 class GfxImage : public RCBase
00056 {
00057 public:
00058     //----- types and enumerations -----
00059 
00060     typedef std::vector<UInt8> RawData;
00061     // This should really be a private pointer, not a shared pointer.
00062     typedef RCProxyShdPtr<RawData> RawDataPtr;
00063 
00064     enum Format {
00065         GREY8,
00066         RGB24
00067     };
00068     enum Component {
00069         RED = 0,
00070         GREEN = 1,
00071         BLUE = 2
00072     };
00073 
00074     //----- static member functions -----
00075 
00076     static UInt32 getBitsPerComponent( Format format );
00077     static UInt32 getNbComponents( Format format );
00078 
00079     //----- member functions -----
00080 
00081     GfxImage(
00082         const RawDataPtr& dataPtr,
00083         UInt32 width,
00084         UInt32 height,
00085         Format format
00086     );
00087     GfxImage(
00088         UInt32 width,
00089         UInt32 height,
00090         Format format
00091     );
00092     GfxImage(
00093         const GfxImage&
00094     );
00095     virtual ~GfxImage();
00096 
00097     UInt32 getWidth() const;
00098     UInt32 getHeight() const;
00099     Float getAspectRatio() const;
00100     Format getFormat() const;
00101     UInt32 getBitsPerPixel() const;
00102     UInt32 getBytesPerPixel() const;
00103     UInt32 getBytesPerRow() const;
00104     UInt32 getNbComponents() const;
00105     UInt32 getBitsPerComponent() const;
00106 
00107     UInt8* getRawData();
00108     const UInt8* getRawData() const;
00109     UInt32 getRawSize() const;
00110     UInt8 getData( UInt32 x, UInt32 y, UInt32 component = 0 ) const;
00111     UInt8& getData( UInt32 x, UInt32 y, UInt32 component = 0 );
00112 
00113     //! Create a new image with padding around the borders.
00114     RCShdPtr<GfxImage> pad(
00115         UInt32 padX, UInt32 padY, UInt8 r, UInt8 g, UInt8 b
00116     ) const;
00117     RCShdPtr<GfxImage> pad(
00118         UInt32 padX, UInt32 padY, UInt8 value
00119     ) const;
00120 
00121 private:
00122 
00123     //----- member functions -----
00124     // Disallowed. FIXME: allow it.
00125     GfxImage& operator = ( const GfxImage& );
00126 
00127     //----- data members -----
00128 
00129     const RawDataPtr _dataPtr;
00130     UInt32 _width;
00131     UInt32 _height;
00132     Format _format;
00133 };
00134 
00135 #include <freecloth/gfx/gfxImage.inline.h>
00136 
00137 #endif

Generated on Fri May 2 16:51:13 2003 for Freecloth by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002