OgrePixelFormat.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4  (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2013 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef _PixelFormat_H__
29 #define _PixelFormat_H__
30 
31 #include "OgrePrerequisites.h"
32 #include "OgreCommon.h"
33 #include "OgreHeaderPrefix.h"
34 
35 namespace Ogre {
44  {
48  PF_L8 = 1,
51  PF_L16 = 2,
54  PF_A8 = 3,
57  PF_A4L4 = 4,
61  PF_R5G6B5 = 6,
63  PF_B5G6R5 = 7,
65  PF_R3G3B2 = 31,
71  PF_R8G8B8 = 10,
73  PF_B8G8R8 = 11,
88 #if OGRE_ENDIAN == OGRE_ENDIAN_BIG
97 #else
101  PF_BYTE_BGR = PF_R8G8B8,
103  PF_BYTE_BGRA = PF_A8R8G8B8,
105  PF_BYTE_RGBA = PF_A8B8G8R8,
106 #endif
107  PF_A2R10G10B10 = 15,
112  PF_DXT1 = 17,
114  PF_DXT2 = 18,
116  PF_DXT3 = 19,
118  PF_DXT4 = 20,
120  PF_DXT5 = 21,
127  // 32-bit pixel format, 32 bits (float) for red
138  PF_DEPTH = 29,
226  PF_R8 = 78,
228  PF_RG8 = 79,
259  // Number of pixel formats currently defined
260  PF_COUNT = 95
261  };
263 
269  PFF_HASALPHA = 0x00000001,
272  PFF_COMPRESSED = 0x00000002,
274  PFF_FLOAT = 0x00000004,
276  PFF_DEPTH = 0x00000008,
279  PFF_NATIVEENDIAN = 0x00000010,
282  PFF_LUMINANCE = 0x00000020,
284  PFF_INTEGER = 0x00000040
285  };
286 
289  {
290  PCT_BYTE = 0,
291  PCT_SHORT = 1,
294  PCT_SINT = 4,
295  PCT_UINT = 5,
297  };
298 
304  class _OgreExport PixelBox: public Box, public ImageAlloc {
305  public:
307  PixelBox() {}
316  PixelBox(const Box &extents, PixelFormat pixelFormat, void *pixelData=0):
317  Box(extents), data(pixelData), format(pixelFormat)
318  {
319  setConsecutive();
320  }
330  PixelBox(uint32 width, uint32 height, uint32 depth, PixelFormat pixelFormat, void *pixelData=0):
331  Box(0, 0, 0, width, height, depth),
332  data(pixelData), format(pixelFormat)
333  {
334  setConsecutive();
335  }
336 
338  void *data;
345  size_t rowPitch;
351  size_t slicePitch;
352 
357  {
358  rowPitch = getWidth();
359  slicePitch = getWidth()*getHeight();
360  }
365  size_t getRowSkip() const { return rowPitch - getWidth(); }
370  size_t getSliceSkip() const { return slicePitch - (getHeight() * rowPitch); }
371 
375  bool isConsecutive() const
376  {
377  return rowPitch == getWidth() && slicePitch == getWidth()*getHeight();
378  }
382  size_t getConsecutiveSize() const;
391  PixelBox getSubVolume(const Box &def) const;
392 
396  void* getTopLeftFrontPixelPtr() const;
397 
403  ColourValue getColourAt(size_t x, size_t y, size_t z);
404 
410  void setColourAt(ColourValue const &cv, size_t x, size_t y, size_t z);
411  };
412 
413 
418  public:
425  static size_t getNumElemBytes( PixelFormat format );
426 
433  static size_t getNumElemBits( PixelFormat format );
434 
452  static size_t getMemorySize(uint32 width, uint32 height, uint32 depth, PixelFormat format);
453 
461  static unsigned int getFlags( PixelFormat format );
462 
464  static bool hasAlpha(PixelFormat format);
466  static bool isFloatingPoint(PixelFormat format);
468  static bool isInteger(PixelFormat format);
470  static bool isCompressed(PixelFormat format);
472  static bool isDepth(PixelFormat format);
474  static bool isNativeEndian(PixelFormat format);
476  static bool isLuminance(PixelFormat format);
477 
490  static bool isValidExtent(size_t width, size_t height, size_t depth, PixelFormat format);
491 
495  static void getBitDepths(PixelFormat format, int rgba[4]);
496 
500  static void getBitMasks(PixelFormat format, uint64 rgba[4]);
501 
505  static void getBitShifts(PixelFormat format, unsigned char rgba[4]);
506 
509  static String getFormatName(PixelFormat srcformat);
510 
518  static bool isAccessible(PixelFormat srcformat);
519 
524  static PixelComponentType getComponentType(PixelFormat fmt);
525 
529  static size_t getComponentCount(PixelFormat fmt);
530 
538  static PixelFormat getFormatFromName(const String& name, bool accessibleOnly = false, bool caseSensitive = false);
539 
547  static String getBNFExpressionOfPixelFormats(bool accessibleOnly = false);
548 
558  static PixelFormat getFormatForBitDepths(PixelFormat fmt, ushort integerBits, ushort floatBits);
559 
565  static void packColour(const ColourValue &colour, const PixelFormat pf, void* dest);
573  static void packColour(const uint8 r, const uint8 g, const uint8 b, const uint8 a, const PixelFormat pf, void* dest);
581  static void packColour(const float r, const float g, const float b, const float a, const PixelFormat pf, void* dest);
582 
588  static void unpackColour(ColourValue *colour, PixelFormat pf, const void* src);
600  static void unpackColour(uint8 *r, uint8 *g, uint8 *b, uint8 *a, PixelFormat pf, const void* src);
609  static void unpackColour(float *r, float *g, float *b, float *a, PixelFormat pf, const void* src);
610 
619  static void bulkPixelConversion(void *src, PixelFormat srcFormat, void *dst, PixelFormat dstFormat, unsigned int count);
620 
628  static void bulkPixelConversion(const PixelBox &src, const PixelBox &dst);
629 
634  static void bulkPixelVerticalFlip(const PixelBox &box);
635  };
639 }
640 
641 #include "OgreHeaderSuffix.h"
642 
643 #endif

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Wed Oct 23 2013 06:57:24