Coverage Report

Created: 2025-08-25 06:48

/src/ogre/OgreMain/include/OgrePixelFormat.h
Line
Count
Source (jump to first uncovered line)
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-2014 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 "OgreColourValue.h"
34
#include "OgreHeaderPrefix.h"
35
36
namespace Ogre {
37
    /** \addtogroup Core
38
    *  @{
39
    */
40
    /** \addtogroup Image
41
    *  @{
42
    */
43
    /** The pixel format used for images, textures, and render surfaces
44
     *
45
     * A pixel format described the storage format of pixel data. It defines the way pixels are encoded in memory.
46
     * The components are specified in "packed" native byte order for native endian (16, 24 and 32 bit) integers.
47
     * This means that a pixel with format Ogre::PF_A8R8G8B8 can be seen as a 32 bit integer, written as @c 0xAARRGGBB in hexadecimal
48
     * on a little-endian (x86) machine or as @c 0xBBGGRRAA on a big-endian machine.
49
     * The example above would be expressed with an array of bytes as `{0xBB, 0xGG, 0xRR, 0xAA}` on both machines.
50
     * Therefore, one would use the Ogre::PF_BYTE_BGRA format when reading pixel data expressed in bytes.
51
     * This format aliases to either Ogre::PF_A8B8G8R8 or Ogre::PF_R8G8B8A8
52
     * depending on the machine endianness.
53
     */
54
    enum PixelFormat
55
    {
56
        /// Unknown pixel format.
57
        PF_UNKNOWN = 0,
58
        /// 8-bit pixel format, all bits luminance.
59
        PF_L8,
60
        PF_BYTE_L = PF_L8,
61
        /// 16-bit pixel format, all bits luminance.
62
        PF_L16,
63
        PF_SHORT_L = PF_L16,
64
        /// 8-bit pixel format, all bits alpha.
65
        PF_A8,
66
        PF_BYTE_A = PF_A8,
67
        /// 2 byte pixel format, 1 byte luminance, 1 byte alpha
68
        PF_BYTE_LA,
69
        /// 16-bit pixel format, 5 bits red, 6 bits green, 5 bits blue.
70
        PF_R5G6B5,
71
        /// 16-bit pixel format, 5 bits red, 6 bits green, 5 bits blue.
72
        PF_B5G6R5,
73
        /// 16-bit pixel format, 4 bits for alpha, red, green and blue.
74
        PF_A4R4G4B4,
75
        /// 16-bit pixel format, 5 bits for blue, green, red and 1 for alpha.
76
        PF_A1R5G5B5,
77
        /// 24-bit pixel format, 8 bits for red, green and blue.
78
        PF_R8G8B8,
79
        /// 24-bit pixel format, 8 bits for blue, green and red.
80
        PF_B8G8R8,
81
        /// 32-bit pixel format, 8 bits for alpha, red, green and blue.
82
        PF_A8R8G8B8,
83
        /// 32-bit pixel format, 8 bits for blue, green, red and alpha.
84
        PF_A8B8G8R8,
85
        /// 32-bit pixel format, 8 bits for blue, green, red and alpha.
86
        PF_B8G8R8A8,
87
        /// 32-bit pixel format, 2 bits for alpha, 10 bits for red, green and blue.
88
        PF_A2R10G10B10,
89
        /// 32-bit pixel format, 10 bits for blue, green and red, 2 bits for alpha.
90
        PF_A2B10G10R10,
91
        /// DDS (DirectDraw Surface) DXT1 format
92
        PF_DXT1,
93
        /// DDS (DirectDraw Surface) DXT2 format
94
        PF_DXT2,
95
        /// DDS (DirectDraw Surface) DXT3 format
96
        PF_DXT3,
97
        /// DDS (DirectDraw Surface) DXT4 format
98
        PF_DXT4,
99
        /// DDS (DirectDraw Surface) DXT5 format
100
        PF_DXT5,
101
        /// 48-bit pixel format, 16 bits (float) for red, 16 bits (float) for green, 16 bits (float) for blue
102
        PF_FLOAT16_RGB,
103
        /// 64-bit pixel format, 16 bits (float) for red, 16 bits (float) for green, 16 bits (float) for blue, 16 bits (float) for alpha
104
        PF_FLOAT16_RGBA,
105
        /// 96-bit pixel format, 32 bits (float) for red, 32 bits (float) for green, 32 bits (float) for blue
106
        PF_FLOAT32_RGB,
107
        /// 128-bit pixel format, 32 bits (float) for red, 32 bits (float) for green, 32 bits (float) for blue, 32 bits (float) for alpha
108
        PF_FLOAT32_RGBA,
109
        /// 32-bit pixel format, 8 bits for red, 8 bits for green, 8 bits for blue
110
        /// like Ogre::PF_A8R8G8B8, but alpha will get discarded
111
        PF_X8R8G8B8,
112
        /// 32-bit pixel format, 8 bits for blue, 8 bits for green, 8 bits for red
113
        /// like Ogre::PF_A8B8G8R8, but alpha will get discarded
114
        PF_X8B8G8R8,
115
        /// 32-bit pixel format, 8 bits for red, green, blue and alpha.
116
        PF_R8G8B8A8,
117
        /// Depth texture format, with 16-bit unsigned integer
118
        PF_DEPTH16,
119
        PF_DEPTH = PF_DEPTH16,
120
        /// 64-bit pixel format, 16 bits for red, green, blue and alpha
121
        PF_SHORT_RGBA,
122
        /// 8-bit pixel format, 2 bits blue, 3 bits green, 3 bits red.
123
        PF_R3G3B2,
124
        /// 16-bit pixel format, 16 bits (float) for red
125
        PF_FLOAT16_R,
126
        /// 32-bit pixel format, 32 bits (float) for red
127
        PF_FLOAT32_R,
128
        /// 32-bit pixel format, 16-bit green, 16-bit red
129
        PF_SHORT_GR,
130
        /// 32-bit, 2-channel s10e5 floating point pixel format, 16-bit green, 16-bit red
131
        PF_FLOAT16_GR,
132
        /// 64-bit, 2-channel floating point pixel format, 32-bit green, 32-bit red
133
        PF_FLOAT32_GR,
134
        /// 48-bit pixel format, 16 bits for red, green and blue
135
        PF_SHORT_RGB,
136
        /// PVRTC (PowerVR) RGB 2 bpp
137
        PF_PVRTC_RGB2,
138
        /// PVRTC (PowerVR) RGBA 2 bpp
139
        PF_PVRTC_RGBA2,
140
        /// PVRTC (PowerVR) RGB 4 bpp
141
        PF_PVRTC_RGB4,
142
        /// PVRTC (PowerVR) RGBA 4 bpp
143
        PF_PVRTC_RGBA4,
144
        /// PVRTC (PowerVR) Version 2, 2 bpp
145
        PF_PVRTC2_2BPP,
146
        /// PVRTC (PowerVR) Version 2, 4 bpp
147
        PF_PVRTC2_4BPP,
148
        /// 32-bit pixel format, 11 bits (float) for red, 11 bits (float) for green, 10 bits (float) for blue
149
        PF_R11G11B10_FLOAT,
150
        /// 8-bit pixel format, 8 bits red (unsigned int).
151
        PF_R8_UINT,
152
        /// 16-bit pixel format, 8 bits red (unsigned int), 8 bits blue (unsigned int).
153
        PF_R8G8_UINT,
154
        /// 24-bit pixel format, 8 bits red (unsigned int), 8 bits blue (unsigned int), 8 bits green (unsigned int).
155
        PF_R8G8B8_UINT,
156
        /// 32-bit pixel format, 8 bits red (unsigned int), 8 bits blue (unsigned int), 8 bits green (unsigned int), 8 bits alpha (unsigned int).
157
        PF_R8G8B8A8_UINT,
158
        /// 16-bit pixel format, 16 bits red (unsigned int).
159
        PF_R16_UINT,
160
        /// 32-bit pixel format, 16 bits red (unsigned int), 16 bits blue (unsigned int).
161
        PF_R16G16_UINT,
162
        /// 48-bit pixel format, 16 bits red (unsigned int), 16 bits blue (unsigned int), 16 bits green (unsigned int).
163
        PF_R16G16B16_UINT,
164
        /// 64-bit pixel format, 16 bits red (unsigned int), 16 bits blue (unsigned int), 16 bits green (unsigned int), 16 bits alpha (unsigned int).
165
        PF_R16G16B16A16_UINT,
166
        /// 32-bit pixel format, 32 bits red (unsigned int).
167
        PF_R32_UINT,
168
        /// 64-bit pixel format, 32 bits red (unsigned int), 32 bits blue (unsigned int).
169
        PF_R32G32_UINT,
170
        /// 96-bit pixel format, 32 bits red (unsigned int), 32 bits blue (unsigned int), 32 bits green (unsigned int).
171
        PF_R32G32B32_UINT,
172
        /// 128-bit pixel format, 32 bits red (unsigned int), 32 bits blue (unsigned int), 32 bits green (unsigned int), 32 bits alpha (unsigned int).
173
        PF_R32G32B32A32_UINT,
174
        /// 8-bit pixel format, 8 bits red (signed int).
175
        PF_R8_SINT,
176
        /// 16-bit pixel format, 8 bits red (signed int), 8 bits blue (signed int).
177
        PF_R8G8_SINT,
178
        /// 24-bit pixel format, 8 bits red (signed int), 8 bits blue (signed int), 8 bits green (signed int).
179
        PF_R8G8B8_SINT,
180
        /// 32-bit pixel format, 8 bits red (signed int), 8 bits blue (signed int), 8 bits green (signed int), 8 bits alpha (signed int).
181
        PF_R8G8B8A8_SINT,
182
        /// 16-bit pixel format, 16 bits red (signed int).
183
        PF_R16_SINT,
184
        /// 32-bit pixel format, 16 bits red (signed int), 16 bits blue (signed int).
185
        PF_R16G16_SINT,
186
        /// 48-bit pixel format, 16 bits red (signed int), 16 bits blue (signed int), 16 bits green (signed int).
187
        PF_R16G16B16_SINT,
188
        /// 64-bit pixel format, 16 bits red (signed int), 16 bits blue (signed int), 16 bits green (signed int), 16 bits alpha (signed int).
189
        PF_R16G16B16A16_SINT,
190
        /// 32-bit pixel format, 32 bits red (signed int).
191
        PF_R32_SINT,
192
        /// 64-bit pixel format, 32 bits red (signed int), 32 bits blue (signed int).
193
        PF_R32G32_SINT,
194
        /// 96-bit pixel format, 32 bits red (signed int), 32 bits blue (signed int), 32 bits green (signed int).
195
        PF_R32G32B32_SINT,
196
        /// 128-bit pixel format, 32 bits red (signed int), 32 bits blue (signed int), 32 bits green (signed int), 32 bits alpha (signed int).
197
        PF_R32G32B32A32_SINT,
198
        /// 32-bit pixel format, 9 bits for blue, green, red plus a 5 bit exponent.
199
        PF_R9G9B9E5_SHAREDEXP,
200
        /// DDS (DirectDraw Surface) BC4 format (unsigned normalised)
201
        PF_BC4_UNORM,
202
        /// DDS (DirectDraw Surface) BC4 format (signed normalised)
203
        PF_BC4_SNORM,
204
        /// DDS (DirectDraw Surface) BC5 format (unsigned normalised)
205
        PF_BC5_UNORM,
206
        /// DDS (DirectDraw Surface) BC5 format (signed normalised)
207
        PF_BC5_SNORM,
208
        /// DDS (DirectDraw Surface) BC6H format (unsigned 16 bit float)
209
        PF_BC6H_UF16,
210
        /// DDS (DirectDraw Surface) BC6H format (signed 16 bit float)
211
        PF_BC6H_SF16,
212
        /// DDS (DirectDraw Surface) BC7 format (unsigned normalised)
213
        PF_BC7_UNORM,
214
        /// 8-bit pixel format, all bits red.
215
        PF_R8,
216
        /// 16-bit pixel format, 8 bits red, 8 bits green.
217
        PF_R8G8,
218
        PF_RG8 = PF_R8G8,
219
        /// 8-bit pixel format, 8 bits red (signed normalised int).
220
        PF_R8_SNORM,
221
        /// 16-bit pixel format, 8 bits red (signed normalised int), 8 bits blue (signed normalised int).
222
        PF_R8G8_SNORM,
223
        /// 24-bit pixel format, 8 bits red (signed normalised int), 8 bits blue (signed normalised int), 8 bits green (signed normalised int).
224
        PF_R8G8B8_SNORM,
225
        /// 32-bit pixel format, 8 bits red (signed normalised int), 8 bits blue (signed normalised int), 8 bits green (signed normalised int), 8 bits alpha (signed normalised int).
226
        PF_R8G8B8A8_SNORM,
227
        /// 16-bit pixel format, 16 bits red (signed normalised int).
228
        PF_R16_SNORM,
229
        /// 32-bit pixel format, 16 bits red (signed normalised int), 16 bits blue (signed normalised int).
230
        PF_R16G16_SNORM,
231
        /// 48-bit pixel format, 16 bits red (signed normalised int), 16 bits blue (signed normalised int), 16 bits green (signed normalised int).
232
        PF_R16G16B16_SNORM,
233
        /// 64-bit pixel format, 16 bits red (signed normalised int), 16 bits blue (signed normalised int), 16 bits green (signed normalised int), 16 bits alpha (signed normalised int).
234
        PF_R16G16B16A16_SNORM,
235
        /// ETC1 (Ericsson Texture Compression)
236
        PF_ETC1_RGB8,
237
        /// ETC2 (Ericsson Texture Compression)
238
        PF_ETC2_RGB8,
239
        /// ETC2 (Ericsson Texture Compression)
240
        PF_ETC2_RGBA8,
241
        /// ETC2 (Ericsson Texture Compression)
242
        PF_ETC2_RGB8A1,
243
        /// ATC (AMD_compressed_ATC_texture)
244
        PF_ATC_RGB,
245
        /// ATC (AMD_compressed_ATC_texture)
246
        PF_ATC_RGBA_EXPLICIT_ALPHA,
247
        /// ATC (AMD_compressed_ATC_texture)
248
        PF_ATC_RGBA_INTERPOLATED_ALPHA,
249
        /// ASTC (ARM Adaptive Scalable Texture Compression RGBA, block size 4x4)
250
        PF_ASTC_RGBA_4X4_LDR,
251
        /// ASTC (ARM Adaptive Scalable Texture Compression RGBA, block size 5x4)
252
        PF_ASTC_RGBA_5X4_LDR,
253
        /// ASTC (ARM Adaptive Scalable Texture Compression RGBA, block size 5x5)
254
        PF_ASTC_RGBA_5X5_LDR,
255
        /// ASTC (ARM Adaptive Scalable Texture Compression RGBA, block size 6x5)
256
        PF_ASTC_RGBA_6X5_LDR,
257
        /// ASTC (ARM Adaptive Scalable Texture Compression RGBA, block size 6x6)
258
        PF_ASTC_RGBA_6X6_LDR,
259
        /// ASTC (ARM Adaptive Scalable Texture Compression RGBA, block size 8x5)
260
        PF_ASTC_RGBA_8X5_LDR,
261
        /// ASTC (ARM Adaptive Scalable Texture Compression RGBA, block size 8x6)
262
        PF_ASTC_RGBA_8X6_LDR,
263
        /// ASTC (ARM Adaptive Scalable Texture Compression RGBA, block size 8x8)
264
        PF_ASTC_RGBA_8X8_LDR,
265
        /// ASTC (ARM Adaptive Scalable Texture Compression RGBA, block size 10x5)
266
        PF_ASTC_RGBA_10X5_LDR,
267
        /// ASTC (ARM Adaptive Scalable Texture Compression RGBA, block size 10x6)
268
        PF_ASTC_RGBA_10X6_LDR,
269
        /// ASTC (ARM Adaptive Scalable Texture Compression RGBA, block size 10x8)
270
        PF_ASTC_RGBA_10X8_LDR,
271
        /// ASTC (ARM Adaptive Scalable Texture Compression RGBA, block size 10x10)
272
        PF_ASTC_RGBA_10X10_LDR,
273
        /// ASTC (ARM Adaptive Scalable Texture Compression RGBA, block size 12x10)
274
        PF_ASTC_RGBA_12X10_LDR,
275
        /// ASTC (ARM Adaptive Scalable Texture Compression RGBA, block size 12x12)
276
        PF_ASTC_RGBA_12X12_LDR,
277
        PF_DEPTH32,
278
        /// Depth texture format with 32-bit floating point
279
        PF_DEPTH32F,
280
        /// Depth texture format with 24-bit unsigned integer and 8-bit stencil
281
        PF_DEPTH24_STENCIL8,
282
        /// Number of pixel formats currently defined
283
        PF_COUNT,
284
        // endianness aware aliases
285
#if OGRE_ENDIAN == OGRE_ENDIAN_BIG
286
        /// @copydoc PF_R8G8B8
287
        PF_BYTE_RGB = PF_R8G8B8,
288
        /// @copydoc PF_B8G8R8
289
        PF_BYTE_BGR = PF_B8G8R8,
290
        /// @copydoc PF_B8G8R8A8
291
        PF_BYTE_BGRA = PF_B8G8R8A8,
292
        /// @copydoc PF_R8G8B8A8
293
        PF_BYTE_RGBA = PF_R8G8B8A8,
294
#else
295
        /// @copydoc PF_B8G8R8
296
        PF_BYTE_RGB = PF_B8G8R8,
297
        /// @copydoc PF_R8G8B8
298
        PF_BYTE_BGR = PF_R8G8B8,
299
        /// @copydoc PF_A8R8G8B8
300
        PF_BYTE_BGRA = PF_A8R8G8B8,
301
        /// @copydoc PF_A8B8G8R8
302
        PF_BYTE_RGBA = PF_A8B8G8R8,
303
#endif
304
    };
305
    typedef std::vector<PixelFormat> PixelFormatList;
306
307
    /**
308
     * Flags defining some on/off properties of pixel formats
309
     */
310
    enum PixelFormatFlags {
311
        /// This format has an alpha channel
312
        PFF_HASALPHA        = 0x00000001,      
313
        /** This format is compressed. This invalidates the values in elemBytes,
314
            elemBits and the bit counts as these might not be fixed in a compressed format. */
315
        PFF_COMPRESSED    = 0x00000002,
316
        /// This is a floating point format
317
        PFF_FLOAT           = 0x00000004,         
318
        /// This is a depth format (for depth textures)
319
        PFF_DEPTH           = 0x00000008,
320
        /** Format is in native endian. Generally true for the 16, 24 and 32 bits
321
            formats which can be represented as machine integers. */
322
        PFF_NATIVEENDIAN    = 0x00000010,
323
        /** This is an intensity format instead of a RGB one. The luminance
324
            replaces R,G and B. (but not A) */
325
        PFF_LUMINANCE       = 0x00000020,
326
        /// This is an integer format
327
        PFF_INTEGER         = 0x00000040
328
    };
329
    
330
    /** Pixel component format */
331
    enum PixelComponentType
332
    {
333
        PCT_BYTE = 0,    /// Byte per component (8 bit fixed 0.0..1.0)
334
        PCT_SHORT = 1,   /// Short per component (16 bit fixed 0.0..1.0))
335
        PCT_FLOAT16 = 2, /// 16 bit float per component
336
        PCT_FLOAT32 = 3, /// 32 bit float per component
337
        PCT_SINT = 4,   /// Signed integer per component
338
        PCT_UINT = 5,   /// Unsigned integer per component
339
        PCT_COUNT = 6    /// Number of pixel types
340
    };
341
    
342
    /** A primitive describing a volume (3D), image (2D) or line (1D) of pixels in memory.
343
        In case of a rectangle, depth must be 1. 
344
        Pixels are stored as a succession of "depth" slices, each containing "height" rows of 
345
        "width" pixels.
346
347
        @copydetails Ogre::Box
348
    */
349
    class _OgreExport PixelBox: public Box, public ImageAlloc {
350
    public:
351
        /// Parameter constructor for setting the members manually
352
0
        PixelBox() : data(NULL), rowPitch(0), slicePitch(0), format(PF_UNKNOWN) {}
353
0
        ~PixelBox() {}
354
        /** Constructor providing extents in the form of a Box object. This constructor
355
            assumes the pixel data is laid out consecutively in memory. (this
356
            means row after row, slice after slice, with no space in between)
357
            @param extents      Extents of the region defined by data
358
            @param pixelFormat  Format of this buffer
359
            @param pixelData    Pointer to the actual data
360
        */
361
        PixelBox(const Box &extents, PixelFormat pixelFormat, void *pixelData=0):
362
0
            Box(extents), data((uchar*)pixelData), format(pixelFormat)
363
0
        {
364
0
            setConsecutive();
365
0
        }
366
        /** Constructor providing width, height and depth. This constructor
367
            assumes the pixel data is laid out consecutively in memory. (this
368
            means row after row, slice after slice, with no space in between)
369
            @param width        Width of the region
370
            @param height       Height of the region
371
            @param depth        Depth of the region
372
            @param pixelFormat  Format of this buffer
373
            @param pixelData    Pointer to the actual data
374
        */
375
        PixelBox(uint32 width, uint32 height, uint32 depth, PixelFormat pixelFormat, void *pixelData=0):
376
0
            Box(0, 0, 0, width, height, depth),
377
0
            data((uchar*)pixelData), format(pixelFormat)
378
0
        {
379
0
            setConsecutive();
380
0
        }
381
        
382
        /// The data pointer 
383
        uchar* data;
384
        /** Number of elements between the leftmost pixel of one row and the left
385
            pixel of the next. This value must always be equal to getWidth() (consecutive) 
386
            for compressed formats.
387
        */
388
        size_t rowPitch;
389
        /** Number of elements between the top left pixel of one (depth) slice and 
390
            the top left pixel of the next. This can be a negative value. Must be a multiple of
391
            rowPitch. This value must always be equal to getWidth()*getHeight() (consecutive) 
392
            for compressed formats.
393
        */
394
        size_t slicePitch;
395
        /// The pixel format
396
        PixelFormat format;
397
        /** Set the rowPitch and slicePitch so that the buffer is laid out consecutive 
398
            in memory.
399
        */        
400
        void setConsecutive()
401
0
        {
402
0
            rowPitch = getWidth();
403
0
            slicePitch = getWidth()*getHeight();
404
0
        }
405
        /** Get the number of elements between one past the rightmost pixel of 
406
            one row and the leftmost pixel of the next row. (IE this is zero if rows
407
            are consecutive).
408
        */
409
0
        size_t getRowSkip() const { return rowPitch - getWidth(); }
410
        /** Get the number of elements between one past the right bottom pixel of
411
            one slice and the left top pixel of the next slice. (IE this is zero if slices
412
            are consecutive).
413
        */
414
0
        size_t getSliceSkip() const { return slicePitch - (getHeight() * rowPitch); }
415
416
        /** Return whether this buffer is laid out consecutive in memory (ie the pitches
417
            are equal to the dimensions)
418
        */        
419
        bool isConsecutive() const 
420
0
        { 
421
0
            return rowPitch == getWidth() && slicePitch == getWidth()*getHeight(); 
422
0
        }
423
        /** Return the size (in bytes) this image would take if it was
424
            laid out consecutive in memory
425
        */
426
        size_t getConsecutiveSize() const;
427
        /** Return a subvolume of this PixelBox.
428
            @param def  Defines the bounds of the subregion to return
429
            @param resetOrigin Whether to reset left/top/front of returned PixelBox to zero 
430
                together with adjusting data pointer to compensate this, or do nothing 
431
                so that returned PixelBox will have left/top/front of requested Box
432
            @return A pixel box describing the region and the data in it
433
            @remarks    This function does not copy any data, it just returns
434
                a PixelBox object with a data pointer pointing somewhere inside 
435
                the data of object.
436
            @throws Exception(ERR_INVALIDPARAMS) if def is not fully contained
437
        */
438
        PixelBox getSubVolume(const Box &def, bool resetOrigin = true) const;
439
        
440
        /** Return a data pointer pointing to top left front pixel of the pixel box.
441
            @remarks Non consecutive pixel boxes are supported.
442
         */
443
        uchar* getTopLeftFrontPixelPtr() const;
444
        
445
        /**
446
         * Get colour value from a certain location in the PixelBox. The z coordinate
447
         * is only valid for cubemaps and volume textures. This uses the first (largest)
448
         * mipmap.
449
         */
450
        ColourValue getColourAt(size_t x, size_t y, size_t z) const;
451
452
        /**
453
         * Set colour value at a certain location in the PixelBox. The z coordinate
454
         * is only valid for cubemaps and volume textures. This uses the first (largest)
455
         * mipmap.
456
         */
457
        void setColourAt(ColourValue const &cv, size_t x, size_t y, size_t z);
458
    };
459
    
460
461
    /**
462
     * Some utility functions for packing and unpacking pixel data
463
     */
464
    class _OgreExport PixelUtil {
465
    public:
466
        /** Returns the size in bytes of an element of the given pixel format.
467
         @return
468
               The size in bytes of an element. See Remarks.
469
470
               Passing PF_UNKNOWN will result in returning a size of 0 bytes.
471
        */
472
        static uint8 getNumElemBytes( PixelFormat format );
473
474
        /** Returns the size in bits of an element of the given pixel format.
475
          @return
476
               The size in bits of an element. See Remarks.
477
478
               Passing PF_UNKNOWN will result in returning a size of 0 bits.
479
        */
480
        static uint8 getNumElemBits( PixelFormat format );
481
482
        /** Returns the size in memory of a region with the given extents and pixel
483
            format with consecutive memory layout.
484
            @param width
485
                The width of the area
486
            @param height
487
                The height of the area
488
            @param depth
489
                The depth of the area
490
            @param format
491
                The format of the area
492
            @return
493
                The size in bytes
494
495
                In case that the format is non-compressed, this simply returns
496
                width * height * depth * PixelUtil::getNumElemBytes(format). In the compressed
497
                case, this does serious magic.
498
        */
499
        static size_t getMemorySize(uint32 width, uint32 height, uint32 depth, PixelFormat format);
500
        
501
        /** Returns the property flags for this pixel format
502
          @return
503
               A bitfield combination of PFF_HASALPHA, PFF_ISCOMPRESSED,
504
               PFF_FLOAT, PFF_DEPTH, PFF_NATIVEENDIAN, PFF_LUMINANCE
505
506
               This replaces the separate functions for formatHasAlpha, formatIsFloat, ...
507
        */
508
        static unsigned int getFlags( PixelFormat format );
509
510
        /** Shortcut method to determine if the format has an alpha component */
511
        static bool hasAlpha(PixelFormat format);
512
        /** Shortcut method to determine if the format is floating point */
513
        static bool isFloatingPoint(PixelFormat format);
514
        /** Shortcut method to determine if the format is integer */
515
        static bool isInteger(PixelFormat format);
516
        /** Shortcut method to determine if the format is compressed */
517
        static bool isCompressed(PixelFormat format);
518
        /** Shortcut method to determine if the format is a depth format. */
519
        static bool isDepth(PixelFormat format);
520
        /** Shortcut method to determine if the format is in native endian format. */
521
        static bool isNativeEndian(PixelFormat format);
522
        /** Shortcut method to determine if the format is a luminance format. */
523
        static bool isLuminance(PixelFormat format);
524
525
        /** Gives the number of bits (RGBA) for a format. See remarks.          
526
          @remarks      For non-colour formats (dxt, depth) this returns [0,0,0,0].
527
        */
528
        static void getBitDepths(PixelFormat format, int rgba[4]);
529
530
        /** Gives the masks for the R, G, B and A component
531
          @note         Only valid for native endian formats
532
        */
533
        static void getBitMasks(PixelFormat format, uint64 rgba[4]);
534
535
        /** Gives the bit shifts for R, G, B and A component
536
        @note           Only valid for native endian formats
537
        */
538
        static void getBitShifts(PixelFormat format, unsigned char rgba[4]);
539
540
        /** Gets the name of an image format
541
        */
542
        static const String& getFormatName(PixelFormat srcformat);
543
544
        /** Returns whether the format can be packed or unpacked with the packColour()
545
        and unpackColour() functions. This is generally not true for compressed
546
        formats as they are special. It can only be true for formats with a
547
        fixed element size.
548
        */
549
        static bool isAccessible(PixelFormat srcformat);
550
        
551
        /** Returns the component type for a certain pixel format. Returns PCT_BYTE
552
            in case there is no clear component type like with compressed formats.
553
            This is one of PCT_BYTE, PCT_SHORT, PCT_FLOAT16, PCT_FLOAT32.
554
        */
555
        static PixelComponentType getComponentType(PixelFormat fmt);
556
        
557
        /** Returns the component count for a certain pixel format. Returns 3(no alpha) or 
558
            4 (has alpha) in case there is no clear component type like with compressed formats.
559
         */
560
        static uint8 getComponentCount(PixelFormat fmt);
561
562
        /** Gets the format from given name.
563
            @param  name            The string of format name
564
            @param  accessibleOnly  If true, non-accessible format will treat as invalid format,
565
                                    otherwise, all supported format are valid.
566
            @param  caseSensitive   Should be set true if string match should use case sensitivity.
567
            @return                The format match the format name, or PF_UNKNOWN if is invalid name.
568
        */
569
        static PixelFormat getFormatFromName(const String& name, bool accessibleOnly = false, bool caseSensitive = false);
570
571
        /** Returns the similar format but according with given bit depths.
572
            @param fmt      The original format.
573
            @param integerBits Preferred bit depth (pixel bits) for integer pixel format.
574
                            Available values: 0, 16 and 32, where 0 (the default) means as it is.
575
            @param floatBits Preferred bit depth (channel bits) for float pixel format.
576
                            Available values: 0, 16 and 32, where 0 (the default) means as it is.
577
            @return        The format that similar original format with bit depth according
578
                            with preferred bit depth, or original format if no conversion occurring.
579
        */
580
        static PixelFormat getFormatForBitDepths(PixelFormat fmt, ushort integerBits, ushort floatBits);
581
582
        /** Pack a colour value to memory
583
            @param colour   The colour
584
            @param pf       Pixelformat in which to write the colour
585
            @param dest     Destination memory location
586
        */
587
        static void packColour(const ColourValue& colour, const PixelFormat pf, void* dest)
588
0
        {
589
0
            packColour(colour.r, colour.g, colour.b, colour.a, pf, dest);
590
0
        }
591
        /** Pack a colour value to memory
592
            @param r,g,b,a  The four colour components, range 0.0f to 1.0f
593
                            (an exception to this case exists for floating point pixel
594
                            formats, which don't clamp to 0.0f..1.0f)
595
            @param pf       Pixelformat in which to write the colour
596
            @param dest     Destination memory location
597
        */
598
        static void packColour(const uint8 r, const uint8 g, const uint8 b, const uint8 a, const PixelFormat pf,  void* dest);
599
        /// @overload
600
        static void packColour(const float r, const float g, const float b, const float a, const PixelFormat pf,  void* dest);
601
602
        /** Unpack a colour value from memory
603
            @param colour   The colour is returned here
604
            @param pf       Pixelformat in which to read the colour
605
            @param src      Source memory location
606
        */
607
        static void unpackColour(ColourValue& colour, PixelFormat pf, const void* src)
608
0
        {
609
0
            unpackColour(&colour.r, &colour.g, &colour.b, &colour.a, pf, src);
610
0
        }
611
        /// @overload
612
        static void unpackColour(ColourValue* colour, PixelFormat pf, const void* src)
613
0
        {
614
0
            unpackColour(&colour->r, &colour->g, &colour->b, &colour->a, pf, src);
615
0
        }
616
        /** Unpack a colour value from memory
617
            @param r,g,b,a  The four colour channels are returned here
618
            @param pf       Pixelformat in which to read the colour
619
            @param src      Source memory location
620
        */
621
        static void unpackColour(float *r, float *g, float *b, float *a, PixelFormat pf,  const void* src); 
622
        /** @overload
623
            @note This function returns the colour components in 8 bit precision,
624
                this will lose precision when coming from #PF_A2R10G10B10 or floating
625
                point formats.
626
        */
627
        static void unpackColour(uint8 *r, uint8 *g, uint8 *b, uint8 *a, PixelFormat pf,  const void* src);
628
        
629
        /** Convert consecutive pixels from one format to another. No dithering or filtering is being done. 
630
            Converting from RGB to luminance takes the R channel.  In case the source and destination format match,
631
            just a copy is done.
632
            @param  src         Pointer to source region
633
            @param  srcFormat   Pixel format of source region
634
            @param  dst         Pointer to destination region
635
            @param  dstFormat   Pixel format of destination region
636
            @param  count       The number of pixels to convert
637
         */
638
        static void bulkPixelConversion(void *src, PixelFormat srcFormat, void *dst, PixelFormat dstFormat, unsigned int count)
639
0
        {
640
0
            bulkPixelConversion(PixelBox(count, 1, 1, srcFormat, src), PixelBox(count, 1, 1, dstFormat, dst));
641
0
        }
642
643
        /** Convert pixels from one format to another. No dithering or filtering is being done. Converting
644
            from RGB to luminance takes the R channel. 
645
            @param  src         PixelBox containing the source pixels, pitches and format
646
            @param  dst         PixelBox containing the destination pixels, pitches and format
647
            @remarks The source and destination boxes must have the same
648
            dimensions. In case the source and destination format match, a plain copy is done.
649
        */
650
        static void bulkPixelConversion(const PixelBox &src, const PixelBox &dst);
651
652
        /** Flips pixels inplace in vertical direction.
653
            @param  box         PixelBox containing pixels, pitches and format
654
            @remarks Non consecutive pixel boxes are supported.
655
         */
656
        static void bulkPixelVerticalFlip(const PixelBox &box);
657
    };
658
659
0
    inline const String& to_string(PixelFormat v) { return PixelUtil::getFormatName(v); }
660
    /** @} */
661
    /** @} */
662
663
}
664
665
#include "OgreHeaderSuffix.h"
666
667
#endif