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-2012 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* data, size_t width, size_t height,
    00166                             size_t depth,
    00167                              PixelFormat format, bool autoDelete = false,
    00168                              size_t numFaces = 1, size_t numMipMaps = 0);
    00169
    00205         Image& loadDynamicImage( uchar* data, size_t width,
    00206                                  size_t height, PixelFormat format)
    00207         {
    00208             return loadDynamicImage(data, width, height, 1, format);
    00209         }
    00229         Image & loadRawData(
    00230             DataStreamPtr& stream,
    00231             size_t width, size_t height, size_t depth,
    00232             PixelFormat format,
    00233             size_t numFaces = 1, size_t numMipMaps = 0);
    00253         Image & loadRawData(
    00254             DataStreamPtr& stream,
    00255             size_t width, size_t height,
    00256             PixelFormat format )
    00257         {
    00258             return loadRawData(stream, width, height, 1, format);
    00259         }
    00260
    00276         Image & load( const String& filename, 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(size_t x, size_t y, size_t z) const;
    00434
    00440         void setColourAt(ColourValue const &cv, size_t x, size_t y, size_t z);
    00441
    00445         PixelBox getPixelBox(size_t face = 0, size_t mipmap = 0) const;
    00446
    00448         void freeMemory();
    00449
    00450         enum Filter
    00451         {
    00452             FILTER_NEAREST,
    00453             FILTER_LINEAR,
    00454             FILTER_BILINEAR,
    00455             FILTER_BOX,
    00456             FILTER_TRIANGLE,
    00457             FILTER_BICUBIC
    00458         };
    00466         static void scale(const PixelBox &src, const PixelBox &dst, Filter filter = FILTER_BILINEAR);
    00467
    00469         void resize(ushort width, ushort height, Filter filter = FILTER_BILINEAR);
    00470
    00471         // Static function to calculate size in bytes from the number of mipmaps, faces and the dimensions
    00472         static size_t calculateSize(size_t mipmaps, size_t faces, size_t width, size_t height, size_t depth, PixelFormat format);
    00473
    00475         static String getFileExtFromMagic(DataStreamPtr stream);
    00476
    00477     protected:
    00478         // The width of the image in pixels
    00479     size_t mWidth;
    00480         // The height of the image in pixels
    00481     size_t mHeight;
    00482         // The depth of the image
    00483     size_t mDepth;
    00484         // The size of the image buffer
    00485     size_t mBufSize;
    00486         // The number of mipmaps the image contains
    00487     size_t mNumMipmaps;
    00488         // Image specific flags.
    00489     int mFlags;
    00490
    00491         // The pixel format of the image
    00492     PixelFormat mFormat;
    00493
    00494         // The number of bytes per pixel
    00495     uchar mPixelSize;
    00496     uchar* mBuffer;
    00497
    00498         // A bool to determine if we delete the buffer or the calling app does
    00499         bool mAutoDelete;
    00500     };
    00501
    00502     typedef vector<Image*>::type ImagePtrList;
    00503     typedef vector<const Image*>::type ConstImagePtrList;
    00504
    00508 } // namespace
    00509
    00510 #endif

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun Sep 2 2012 07:27:22