1// tPixelFormat.h 
2// 
3// Pixel formats in Tacent. Not all formats are fully supported. Certainly BC 4, 5, and 7 may not have extensive HW 
4// support at this time. 
5// 
6// Copyright (c) 2004-2006, 2017, 2019 Tristan Grimmer. 
7// Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby 
8// granted, provided that the above copyright notice and this permission notice appear in all copies. 
9// 
10// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL 
11// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 
12// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 
13// AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 
14// PERFORMANCE OF THIS SOFTWARE. 
15 
16#pragma once 
17namespace tImage 
18
19 
20 
21// Unlike DirectX, which assumes all machines are little-endian, the enumeration below specifies the components in the 
22// order they appear in memory. To make matters worse, Microsoft's R8G8B8 format is B8R8G8 in memory, but their R5G6B5 
23// format is correctly the same order in memory. So a little inconsistent there. BC stands for Block Compression. 
24enum class tPixelFormat 
25
26 Invalid = -1
27 Auto = Invalid
28 
29 FirstNormal
30 R8G8B8 = FirstNormal, // 24 bit. Full colour. No alpha. Matches GL_BGR ordering. 
31 R8G8B8A8, // 32 bit. Full alpha. Matches GL_BGRA ordering. 
32 B8G8R8, // 24 bit. Full colour. No alpha. Matches GL_RGB ordering. 
33 B8G8R8A8, // 32 bit. Full alpha. Matches GL_RGBA ordering. 
34 G3B5A1R5G2, // 16 bit. 15 colour. Binary alpha. First bits are the low order ones. 
35 G4B4A4R4, // 16 bit. 12 colour. 4 bit alpha. 
36 G3B5R5G3, // 16 bit. No alpha. The first 3 green bits are the low order ones. 
37 L8A8, // 16 bit. Luminance and alpha. 
38 R32F
39 G32R32F
40 A32B32G32R32F
41 LastNormal = A32B32G32R32F
42 
43 FirstBlock
44 BC1_DXT1 = FirstBlock, // BC 1, DXT1. No alpha. 
45 BC1_DXT1BA, // BC 1, DXT1. Binary alpha. 
46 BC2_DXT3, // BC 2, DXT3. Large alpha gradients (outlines). 
47 BC3_DXT5, // BC 3, DXT5. Variable alpha. 
48 BC4_ATI1, // BC 4. One colour channel only. May not be HW supported. 
49 BC5_ATI2, // BC 5. Two colour channels only. May not be HW supported. 
50 BC6H, // BC 6 HDR. No alpha. 3 x 16bit half-floats. 
51 BC7, // BC 7. Full colour. Variable alpha 0 to 8 bits. 
52 LastBlock = BC7
53 
54 FirstHDR
55 HDR_RAD = FirstHDR, // Radiance hdr. 
56 HDR_EXR, // OpenEXR. 
57 LastHDR = HDR_EXR
58 
59 FirstPAL
60 PAL_8BIT = FirstPAL, // 8bit indexes to a Palette. ex. gif files. 
61 PAL_4BIT
62 PAL_1BIT
63 LastPAL = PAL_1BIT
64 
65 NumPixelFormats
66 NumNormalFormats = LastNormal - FirstNormal + 1
67 NumBlockFormats = LastBlock - FirstBlock + 1
68 NumHDRFormats = LastHDR - FirstHDR + 1
69 NumPALFormats = LastPAL - FirstPAL + 1 
70}; 
71 
72 
73bool tIsNormalFormat(tPixelFormat); 
74bool tIsBlockFormat(tPixelFormat); 
75bool tIsHDRFormat(tPixelFormat); 
76bool tIsPaletteFormat(tPixelFormat); 
77int tGetBitsPerPixel(tPixelFormat); // Some formats (dxt1) are only half a byte per pixel, so we report bits. 
78int tGetBytesPer4x4PixelBlock(tPixelFormat); // This function must be given a BC pixel format. 
79const char* tGetPixelFormatName(tPixelFormat); 
80 
81 
82}