summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/src/image.cpp
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/bgfx/src/image.cpp')
-rw-r--r--3rdparty/bgfx/src/image.cpp174
1 files changed, 103 insertions, 71 deletions
diff --git a/3rdparty/bgfx/src/image.cpp b/3rdparty/bgfx/src/image.cpp
index eea632fed29..ed3b7ca8343 100644
--- a/3rdparty/bgfx/src/image.cpp
+++ b/3rdparty/bgfx/src/image.cpp
@@ -12,54 +12,61 @@ namespace bgfx
{
static const ImageBlockInfo s_imageBlockInfo[] =
{
- { 4, 4, 4, 8 }, // BC1
- { 8, 4, 4, 16 }, // BC2
- { 8, 4, 4, 16 }, // BC3
- { 4, 4, 4, 8 }, // BC4
- { 8, 4, 4, 16 }, // BC5
- { 8, 4, 4, 16 }, // BC6H
- { 8, 4, 4, 16 }, // BC7
- { 4, 4, 4, 8 }, // ETC1
- { 4, 4, 4, 8 }, // ETC2
- { 8, 4, 4, 16 }, // ETC2A
- { 4, 4, 4, 8 }, // ETC2A1
- { 2, 8, 4, 8 }, // PTC12
- { 4, 4, 4, 8 }, // PTC14
- { 2, 8, 4, 8 }, // PTC12A
- { 4, 4, 4, 8 }, // PTC14A
- { 2, 8, 4, 8 }, // PTC22
- { 4, 4, 4, 8 }, // PTC24
- { 0, 0, 0, 0 }, // Unknown
- { 1, 8, 1, 1 }, // R1
- { 8, 1, 1, 1 }, // R8
- { 16, 1, 1, 2 }, // R16
- { 16, 1, 1, 2 }, // R16F
- { 32, 1, 1, 4 }, // R32
- { 32, 1, 1, 4 }, // R32F
- { 16, 1, 1, 2 }, // RG8
- { 32, 1, 1, 4 }, // RG16
- { 32, 1, 1, 4 }, // RG16F
- { 64, 1, 1, 8 }, // RG32
- { 64, 1, 1, 8 }, // RG32F
- { 32, 1, 1, 4 }, // BGRA8
- { 64, 1, 1, 8 }, // RGBA16
- { 64, 1, 1, 8 }, // RGBA16F
- { 128, 1, 1, 16 }, // RGBA32
- { 128, 1, 1, 16 }, // RGBA32F
- { 16, 1, 1, 2 }, // R5G6B5
- { 16, 1, 1, 2 }, // RGBA4
- { 16, 1, 1, 2 }, // RGB5A1
- { 32, 1, 1, 4 }, // RGB10A2
- { 32, 1, 1, 4 }, // R11G11B10F
- { 0, 0, 0, 0 }, // UnknownDepth
- { 16, 1, 1, 2 }, // D16
- { 24, 1, 1, 3 }, // D24
- { 32, 1, 1, 4 }, // D24S8
- { 32, 1, 1, 4 }, // D32
- { 16, 1, 1, 2 }, // D16F
- { 24, 1, 1, 3 }, // D24F
- { 32, 1, 1, 4 }, // D32F
- { 8, 1, 1, 1 }, // D0S8
+ // +------------------ bits per pixel
+ // | +--------------- block width
+ // | | +------------ block height
+ // | | | +-------- block size
+ // | | | | +----- min blocks x
+ // | | | | | +-- min blocks y
+ // | | | | | |
+ { 4, 4, 4, 8, 1, 1 }, // BC1
+ { 8, 4, 4, 16, 1, 1 }, // BC2
+ { 8, 4, 4, 16, 1, 1 }, // BC3
+ { 4, 4, 4, 8, 1, 1 }, // BC4
+ { 8, 4, 4, 16, 1, 1 }, // BC5
+ { 8, 4, 4, 16, 1, 1 }, // BC6H
+ { 8, 4, 4, 16, 1, 1 }, // BC7
+ { 4, 4, 4, 8, 1, 1 }, // ETC1
+ { 4, 4, 4, 8, 1, 1 }, // ETC2
+ { 8, 4, 4, 16, 1, 1 }, // ETC2A
+ { 4, 4, 4, 8, 1, 1 }, // ETC2A1
+ { 2, 8, 4, 8, 2, 2 }, // PTC12
+ { 4, 4, 4, 8, 2, 2 }, // PTC14
+ { 2, 8, 4, 8, 2, 2 }, // PTC12A
+ { 4, 4, 4, 8, 2, 2 }, // PTC14A
+ { 2, 8, 4, 8, 2, 2 }, // PTC22
+ { 4, 4, 4, 8, 2, 2 }, // PTC24
+ { 0, 0, 0, 0, 1, 1 }, // Unknown
+ { 1, 8, 1, 1, 1, 1 }, // R1
+ { 8, 1, 1, 1, 1, 1 }, // R8
+ { 16, 1, 1, 2, 1, 1 }, // R16
+ { 16, 1, 1, 2, 1, 1 }, // R16F
+ { 32, 1, 1, 4, 1, 1 }, // R32
+ { 32, 1, 1, 4, 1, 1 }, // R32F
+ { 16, 1, 1, 2, 1, 1 }, // RG8
+ { 32, 1, 1, 4, 1, 1 }, // RG16
+ { 32, 1, 1, 4, 1, 1 }, // RG16F
+ { 64, 1, 1, 8, 1, 1 }, // RG32
+ { 64, 1, 1, 8, 1, 1 }, // RG32F
+ { 32, 1, 1, 4, 1, 1 }, // BGRA8
+ { 64, 1, 1, 8, 1, 1 }, // RGBA16
+ { 64, 1, 1, 8, 1, 1 }, // RGBA16F
+ { 128, 1, 1, 16, 1, 1 }, // RGBA32
+ { 128, 1, 1, 16, 1, 1 }, // RGBA32F
+ { 16, 1, 1, 2, 1, 1 }, // R5G6B5
+ { 16, 1, 1, 2, 1, 1 }, // RGBA4
+ { 16, 1, 1, 2, 1, 1 }, // RGB5A1
+ { 32, 1, 1, 4, 1, 1 }, // RGB10A2
+ { 32, 1, 1, 4, 1, 1 }, // R11G11B10F
+ { 0, 0, 0, 0, 1, 1 }, // UnknownDepth
+ { 16, 1, 1, 2, 1, 1 }, // D16
+ { 24, 1, 1, 3, 1, 1 }, // D24
+ { 32, 1, 1, 4, 1, 1 }, // D24S8
+ { 32, 1, 1, 4, 1, 1 }, // D32
+ { 16, 1, 1, 2, 1, 1 }, // D16F
+ { 24, 1, 1, 3, 1, 1 }, // D24F
+ { 32, 1, 1, 4, 1, 1 }, // D32F
+ { 8, 1, 1, 1, 1, 1 }, // D0S8
};
BX_STATIC_ASSERT(TextureFormat::Count == BX_COUNTOF(s_imageBlockInfo) );
@@ -1309,10 +1316,9 @@ namespace bgfx
{
uint32_t m_format;
TextureFormat::Enum m_textureFormat;
-
};
- static TranslateDdsFormat s_translateDdsFormat[] =
+ static TranslateDdsFormat s_translateDdsFourccFormat[] =
{
{ DDS_DXT1, TextureFormat::BC1 },
{ DDS_DXT2, TextureFormat::BC2 },
@@ -1376,6 +1382,22 @@ namespace bgfx
{ DXGI_FORMAT_R10G10B10A2_UNORM, TextureFormat::RGB10A2 },
};
+ struct TranslateDdsPixelFormat
+ {
+ uint32_t m_bitCount;
+ uint32_t m_bitmask[4];
+ TextureFormat::Enum m_textureFormat;
+ };
+
+ static TranslateDdsPixelFormat s_translateDdsPixelFormat[] =
+ {
+ { 32, { 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, TextureFormat::BGRA8 },
+ { 32, { 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000 }, TextureFormat::BGRA8 },
+ { 32, { 0x000003ff, 0x000ffc00, 0x3ff00000, 0xc0000000 }, TextureFormat::RGB10A2 },
+ { 32, { 0x0000ffff, 0xffff0000, 0x00000000, 0x00000000 }, TextureFormat::RG16 },
+ { 32, { 0xffffffff, 0x00000000, 0x00000000, 0x00000000 }, TextureFormat::R32 },
+ };
+
bool imageParseDds(ImageContainer& _imageContainer, bx::ReaderSeekerI* _reader)
{
uint32_t headerSize;
@@ -1420,20 +1442,11 @@ namespace bgfx
uint32_t fourcc;
bx::read(_reader, fourcc);
- uint32_t rgbCount;
- bx::read(_reader, rgbCount);
-
- uint32_t rbitmask;
- bx::read(_reader, rbitmask);
-
- uint32_t gbitmask;
- bx::read(_reader, gbitmask);
-
- uint32_t bbitmask;
- bx::read(_reader, bbitmask);
+ uint32_t bitCount;
+ bx::read(_reader, bitCount);
- uint32_t abitmask;
- bx::read(_reader, abitmask);
+ uint32_t bitmask[4];
+ bx::read(_reader, bitmask, sizeof(bitmask) );
uint32_t caps[4];
bx::read(_reader, caps);
@@ -1479,14 +1492,31 @@ namespace bgfx
if (dxgiFormat == 0)
{
- uint32_t ddsFormat = pixelFlags & DDPF_FOURCC ? fourcc : pixelFlags;
-
- for (uint32_t ii = 0; ii < BX_COUNTOF(s_translateDdsFormat); ++ii)
+ if (DDPF_FOURCC == (pixelFlags & DDPF_FOURCC) )
{
- if (s_translateDdsFormat[ii].m_format == ddsFormat)
+ for (uint32_t ii = 0; ii < BX_COUNTOF(s_translateDdsFourccFormat); ++ii)
{
- format = s_translateDdsFormat[ii].m_textureFormat;
- break;
+ if (s_translateDdsFourccFormat[ii].m_format == fourcc)
+ {
+ format = s_translateDdsFourccFormat[ii].m_textureFormat;
+ break;
+ }
+ }
+ }
+ else
+ {
+ for (uint32_t ii = 0; ii < BX_COUNTOF(s_translateDdsPixelFormat); ++ii)
+ {
+ const TranslateDdsPixelFormat& pf = s_translateDdsPixelFormat[ii];
+ if (pf.m_bitCount == bitCount
+ && pf.m_bitmask[0] == bitmask[0]
+ && pf.m_bitmask[1] == bitmask[1]
+ && pf.m_bitmask[2] == bitmask[2]
+ && pf.m_bitmask[3] == bitmask[3])
+ {
+ format = pf.m_textureFormat;
+ break;
+ }
}
}
}
@@ -2103,6 +2133,8 @@ namespace bgfx
const uint32_t blockSize = blockInfo.blockSize;
const uint32_t blockWidth = blockInfo.blockWidth;
const uint32_t blockHeight = blockInfo.blockHeight;
+ const uint32_t minBlockX = blockInfo.minBlockX;
+ const uint32_t minBlockY = blockInfo.minBlockY;
if (UINT32_MAX == _imageContainer.m_offset)
{
@@ -2127,8 +2159,8 @@ namespace bgfx
// skip imageSize in KTX format.
offset += _imageContainer.m_ktx ? sizeof(uint32_t) : 0;
- width = bx::uint32_max(blockWidth, ( (width +blockWidth -1)/blockWidth )*blockWidth);
- height = bx::uint32_max(blockHeight, ( (height+blockHeight-1)/blockHeight)*blockHeight);
+ width = bx::uint32_max(blockWidth * minBlockX, ( (width + blockWidth - 1) / blockWidth )*blockWidth);
+ height = bx::uint32_max(blockHeight * minBlockY, ( (height + blockHeight - 1) / blockHeight)*blockHeight);
depth = bx::uint32_max(1, depth);
uint32_t size = width*height*depth*bpp/8;