# 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-2009 Torus Knot Software Ltd
    00008
    00009 Permission is hereby granted, free of charge, to any person obtaining a copy
    00010 of this software and associated documentation files (the "Software"), to deal
    00011 in the Software without restriction, including without limitation the rights
    00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00013 copies of the Software, and to permit persons to whom the Software is
    00014 furnished to do so, subject to the following conditions:
    00015
    00016 The above copyright notice and this permission notice shall be included in
    00017 all copies or substantial portions of the Software.
    00018
    00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    00025 THE SOFTWARE.
    00026 -----------------------------------------------------------------------------
    00027 */
    00028 #ifndef _Image_H__
    00029 #define _Image_H__
    00030
    00031 #include "OgrePrerequisites.h"
    00032 #include "OgreCommon.h"
    00033 #include "OgrePixelFormat.h"
    00034 #include "OgreDataStream.h"
    00035
    00036 namespace Ogre {
    00044     enum ImageFlags
    00045     {
    00046         IF_COMPRESSED = 0x00000001,
    00047         IF_CUBEMAP    = 0x00000002,
    00048         IF_3D_TEXTURE = 0x00000004
    00049     };
    00061     class _OgreExport Image : public ImageAlloc
    00062     {
    00063     public:
    00064         typedef Ogre::Box Box;
    00065         typedef Ogre::Rect Rect;
    00066     public:
    00069         Image();
    00072         Image( const Image &img );
    00073
    00076         virtual ~Image();
    00077
    00080         Image & operator = ( const Image & img );
    00081
    00101         Image & flipAroundY();
    00102
    00117         Image & flipAroundX();
    00118
    00165         Image& loadDynamicImage( uchar* pData, size_t uWidth, size_t uHeight,
    00166                             size_t depth,
    00167                              PixelFormat eFormat, bool autoDelete = false,
    00168                              size_t numFaces = 1, size_t numMipMaps = 0);
    00169
    00205         Image& loadDynamicImage( uchar* pData, size_t uWidth,
    00206                                  size_t uHeight, PixelFormat eFormat)
    00207         {
    00208             return loadDynamicImage(pData, uWidth, uHeight, 1, eFormat);
    00209         }
    00229         Image & loadRawData(
    00230             DataStreamPtr& stream,
    00231             size_t uWidth, size_t uHeight, size_t uDepth,
    00232             PixelFormat eFormat,
    00233             size_t numFaces = 1, size_t numMipMaps = 0);
    00253         Image & loadRawData(
    00254             DataStreamPtr& stream,
    00255             size_t uWidth, size_t uHeight,
    00256             PixelFormat eFormat )
    00257         {
    00258             return loadRawData(stream, uWidth, uHeight, 1, eFormat);
    00259         }
    00260
    00276         Image & load( const String& strFileName, const String& groupName );
    00277
    00298         Image & load(DataStreamPtr& stream, const String& type = StringUtil::BLANK );
    00299
    00310         Image & loadTwoImagesAsRGBA(const String& rgbFilename, const String& alphaFilename,
    00311             const String& groupName, PixelFormat format = PF_BYTE_RGBA);
    00312
    00328         Image & loadTwoImagesAsRGBA(DataStreamPtr& rgbStream, DataStreamPtr& alphaStream, PixelFormat = PF_BYTE_RGBA,
    00329             const String& rgbType = StringUtil::BLANK, const String& alphaType = StringUtil::BLANK);
    00330
    00340         Image & combineTwoImagesAsRGBA(const Image& rgb, const Image& alpha, PixelFormat format = PF_BYTE_RGBA);
    00341
    00342
    00352         void save(const String& filename);
    00353
    00358         DataStreamPtr encode(const String& formatextension);
    00359
    00366         uchar* getData(void);
    00367
    00374         const uchar * getData() const;
    00375
    00378         size_t getSize() const;
    00379
    00382         size_t getNumMipmaps() const;
    00383
    00386         bool hasFlag(const ImageFlags imgFlag) const;
    00387
    00390         size_t getWidth(void) const;
    00391
    00394         size_t getHeight(void) const;
    00395
    00398         size_t getDepth(void) const;
    00399
    00403         size_t getNumFaces(void) const;
    00404
    00407         size_t getRowSpan(void) const;
    00408
    00411         PixelFormat getFormat() const;
    00412
    00415         uchar getBPP() const;
    00416
    00419         bool getHasAlpha() const;
    00420
    00426         static void applyGamma( uchar *buffer, Real gamma, size_t size, uchar bpp );
    00427
    00433         ColourValue getColourAt(int x, int y, int z) const;
    00434
    00438         PixelBox getPixelBox(size_t face = 0, size_t mipmap = 0) const;
    00439
    00441         void freeMemory();
    00442
    00443         enum Filter
    00444         {
    00445             FILTER_NEAREST,
    00446             FILTER_LINEAR,
    00447             FILTER_BILINEAR,
    00448             FILTER_BOX,
    00449             FILTER_TRIANGLE,
    00450             FILTER_BICUBIC
    00451         };
    00459         static void scale(const PixelBox &src, const PixelBox &dst, Filter filter = FILTER_BILINEAR);
    00460
    00462         void resize(ushort width, ushort height, Filter filter = FILTER_BILINEAR);
    00463
    00464         // Static function to calculate size in bytes from the number of mipmaps, faces and the dimensions
    00465         static size_t calculateSize(size_t mipmaps, size_t faces, size_t width, size_t height, size_t depth, PixelFormat format);
    00466
    00468         static String getFileExtFromMagic(DataStreamPtr stream);
    00469
    00470     protected:
    00471         // The width of the image in pixels
    00472         size_t m_uWidth;
    00473         // The height of the image in pixels
    00474         size_t m_uHeight;
    00475         // The depth of the image
    00476         size_t m_uDepth;
    00477         // The size of the image buffer
    00478         size_t m_uSize;
    00479         // The number of mipmaps the image contains
    00480         size_t m_uNumMipmaps;
    00481         // Image specific flags.
    00482         int m_uFlags;
    00483
    00484         // The pixel format of the image
    00485         PixelFormat m_eFormat;
    00486
    00487         // The number of bytes per pixel
    00488         uchar m_ucPixelSize;
    00489         uchar* m_pBuffer;
    00490
    00491         // A bool to determine if we delete the buffer or the calling app does
    00492         bool m_bAutoDelete;
    00493     };
    00494
    00495     typedef vector<Image*>::type ImagePtrList;
    00496     typedef vector<const Image*>::type ConstImagePtrList;
    00497
    00501 } // namespace
    00502
    00503 #endif

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Wed Nov 3 2010 19:24:51