# OgreImage.h

Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004     (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright (c) 2000-2006 Torus Knot Software Ltd
    00008 Also see acknowledgements in Readme.html
    00009
    00010 This program is free software; you can redistribute it and/or modify it under
    00011 the terms of the GNU Lesser General Public License as published by the Free Software
    00012 Foundation; either version 2 of the License, or (at your option) any later
    00013 version.
    00014
    00015 This program is distributed in the hope that it will be useful, but WITHOUT
    00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser General Public License along with
    00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00022 http://www.gnu.org/copyleft/lesser.txt.
    00023
    00024 You may alternatively use this source under the terms of a specific version of
    00025 the OGRE Unrestricted License provided you have obtained such a license from
    00026 Torus Knot Software Ltd.
    00027 -----------------------------------------------------------------------------
    00028 */
    00029 #ifndef _Image_H__
    00030 #define _Image_H__
    00031
    00032 #include "OgrePrerequisites.h"
    00033 #include "OgreCommon.h"
    00034 #include "OgrePixelFormat.h"
    00035 #include "OgreDataStream.h"
    00036
    00037 namespace Ogre {
    00038
    00039     enum ImageFlags
    00040     {
    00041         IF_COMPRESSED = 0x00000001,
    00042         IF_CUBEMAP    = 0x00000002,
    00043         IF_3D_TEXTURE = 0x00000004
    00044     };
    00056     class _OgreExport Image : public ImageAlloc
    00057     {
    00058     public:
    00059         typedef Ogre::Box Box;
    00060         typedef Ogre::Rect Rect;
    00061     public:
    00064         Image();
    00067         Image( const Image &img );
    00068
    00071         virtual ~Image();
    00072
    00075         Image & operator = ( const Image & img );
    00076
    00096         Image & flipAroundY();
    00097
    00112         Image & flipAroundX();
    00113
    00160         Image& loadDynamicImage( uchar* pData, size_t uWidth, size_t uHeight,
    00161                             size_t depth,
    00162                              PixelFormat eFormat, bool autoDelete = false,
    00163                              size_t numFaces = 1, size_t numMipMaps = 0);
    00164
    00200         Image& loadDynamicImage( uchar* pData, size_t uWidth,
    00201                                  size_t uHeight, PixelFormat eFormat)
    00202         {
    00203             return loadDynamicImage(pData, uWidth, uHeight, 1, eFormat);
    00204         }
    00224         Image & loadRawData(
    00225             DataStreamPtr& stream,
    00226             size_t uWidth, size_t uHeight, size_t uDepth,
    00227             PixelFormat eFormat,
    00228             size_t numFaces = 1, size_t numMipMaps = 0);
    00248         Image & loadRawData(
    00249             DataStreamPtr& stream,
    00250             size_t uWidth, size_t uHeight,
    00251             PixelFormat eFormat )
    00252         {
    00253             return loadRawData(stream, uWidth, uHeight, 1, eFormat);
    00254         }
    00255
    00271         Image & load( const String& strFileName, const String& groupName );
    00272
    00293         Image & load(DataStreamPtr& stream, const String& type = StringUtil::BLANK );
    00294
    00296         void save(const String& filename);
    00297
    00302         DataStreamPtr encode(const String& formatextension);
    00303
    00310         uchar* getData(void);
    00311
    00318         const uchar * getData() const;
    00319
    00322         size_t getSize() const;
    00323
    00326         size_t getNumMipmaps() const;
    00327
    00330         bool hasFlag(const ImageFlags imgFlag) const;
    00331
    00334         size_t getWidth(void) const;
    00335
    00338         size_t getHeight(void) const;
    00339
    00342         size_t getDepth(void) const;
    00343
    00347         size_t getNumFaces(void) const;
    00348
    00351         size_t getRowSpan(void) const;
    00352
    00355         PixelFormat getFormat() const;
    00356
    00359         uchar getBPP() const;
    00360
    00363         bool getHasAlpha() const;
    00364
    00370         static void applyGamma( uchar *buffer, Real gamma, size_t size, uchar bpp );
    00371
    00377         ColourValue getColourAt(int x, int y, int z) const;
    00378
    00382         PixelBox getPixelBox(size_t face = 0, size_t mipmap = 0) const;
    00383
    00384         enum Filter
    00385         {
    00386             FILTER_NEAREST,
    00387             FILTER_LINEAR,
    00388             FILTER_BILINEAR,
    00389             FILTER_BOX,
    00390             FILTER_TRIANGLE,
    00391             FILTER_BICUBIC
    00392         };
    00400         static void scale(const PixelBox &src, const PixelBox &dst, Filter filter = FILTER_BILINEAR);
    00401
    00403         void resize(ushort width, ushort height, Filter filter = FILTER_BILINEAR);
    00404
    00405         // Static function to calculate size in bytes from the number of mipmaps, faces and the dimensions
    00406         static size_t calculateSize(size_t mipmaps, size_t faces, size_t width, size_t height, size_t depth, PixelFormat format);
    00407
    00409         static String getFileExtFromMagic(DataStreamPtr stream);
    00410
    00411     protected:
    00412         // The width of the image in pixels
    00413         size_t m_uWidth;
    00414         // The height of the image in pixels
    00415         size_t m_uHeight;
    00416         // The depth of the image
    00417         size_t m_uDepth;
    00418         // The size of the image buffer
    00419         size_t m_uSize;
    00420         // The number of mipmaps the image contains
    00421         size_t m_uNumMipmaps;
    00422         // Image specific flags.
    00423         int m_uFlags;
    00424
    00425         // The pixel format of the image
    00426         PixelFormat m_eFormat;
    00427
    00428         // The number of bytes per pixel
    00429         uchar m_ucPixelSize;
    00430         uchar* m_pBuffer;
    00431
    00432         // A bool to determine if we delete the buffer or the calling app does
    00433         bool m_bAutoDelete;
    00434     };
    00435
    00436     typedef std::vector<Image*> ImagePtrList;
    00437     typedef std::vector<const Image*> ConstImagePtrList;
    00438
    00439
    00440 } // namespace
    00441
    00442 #endif

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Dec 27 17:31:05 2009