Skip to content

Commit

Permalink
handle compression... this time?
Browse files Browse the repository at this point in the history
  • Loading branch information
isplunke committed Sep 19, 2024
1 parent 9126762 commit d076d31
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions DirectXTex/DirectXTexSwizzle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,12 @@ HRESULT DirectX::StandardSwizzle(const Image& srcImage, bool toSwizzle, ScratchI
uint32_t xBytesMask = 0b1010101010101010;
uint32_t yBytesMask = 0b0101010101010101;

for (size_t y = 0; y < srcImage.height; y++)
size_t height = IsCompressed(srcImage.format) ? (srcImage.height + 3) / 4 : srcImage.height;
size_t width = IsCompressed(srcImage.format) ? (srcImage.width + 3) / 4 : srcImage.width;

for (size_t y = 0; y < height; y++)
{
for (size_t x = 0; x < srcImage.width; x++)
for (size_t x = 0; x < width; x++)
{
uint32_t swizzleIndex = deposit_bits(x, xBytesMask) + deposit_bits(y, yBytesMask);
size_t swizzleOffset = swizzleIndex * bytesPerPixel;
Expand All @@ -94,8 +97,7 @@ HRESULT DirectX::StandardSwizzle(const Image* srcImages, size_t nimages, const T
if (!srcImages || !nimages || !IsValid(metadata.format) || nimages > metadata.mipLevels || !result.GetImages())
return E_INVALIDARG;

if (metadata.IsVolumemap()
|| IsCompressed(metadata.format) || IsTypeless(metadata.format) || IsPlanar(metadata.format) || IsPalettized(metadata.format))
if (metadata.IsVolumemap() || IsTypeless(metadata.format) || IsPlanar(metadata.format) || IsPalettized(metadata.format))
return HRESULT_E_NOT_SUPPORTED;

if (srcImages[0].format != metadata.format || srcImages[0].width != metadata.width || srcImages[0].height != metadata.height)
Expand All @@ -104,6 +106,9 @@ HRESULT DirectX::StandardSwizzle(const Image* srcImages, size_t nimages, const T
return E_FAIL;
}

size_t height = IsCompressed(metadata.format) ? (metadata.height + 3) / 4 : metadata.height;
size_t width = IsCompressed(metadata.format) ? (metadata.width + 3) / 4 : metadata.width;

for (size_t imageIndex = 0; imageIndex < nimages; imageIndex++)
{
const uint8_t* sptr = srcImages[imageIndex].pixels;
Expand All @@ -119,9 +124,9 @@ HRESULT DirectX::StandardSwizzle(const Image* srcImages, size_t nimages, const T
uint32_t xBytesMask = 0b1010101010101010;
uint32_t yBytesMask = 0b0101010101010101;

for (size_t y = 0; y < srcImages[imageIndex].height; y++)
for (size_t y = 0; y <height; y++)
{
for (size_t x = 0; x < srcImages[imageIndex].width; x++)
for (size_t x = 0; x < width; x++)
{
uint32_t swizzleIndex = deposit_bits(x, xBytesMask) + deposit_bits(y, yBytesMask);
size_t swizzleOffset = swizzleIndex * bytesPerPixel;
Expand Down Expand Up @@ -149,8 +154,7 @@ HRESULT DirectX::StandardSwizzle3D(const Image* srcImages, size_t depth, const T
if (!srcImages || !depth || !IsValid(metadata.format) || depth > metadata.depth || !result.GetImages())
return E_INVALIDARG;

if (metadata.IsVolumemap()
|| IsCompressed(metadata.format) || IsTypeless(metadata.format) || IsPlanar(metadata.format) || IsPalettized(metadata.format))
if (metadata.IsVolumemap() || IsTypeless(metadata.format) || IsPlanar(metadata.format) || IsPalettized(metadata.format))
return HRESULT_E_NOT_SUPPORTED;

if (srcImages[0].format != metadata.format || srcImages[0].width != metadata.width || srcImages[0].height != metadata.height)
Expand All @@ -159,16 +163,19 @@ HRESULT DirectX::StandardSwizzle3D(const Image* srcImages, size_t depth, const T
return E_FAIL;
}

size_t height = IsCompressed(metadata.format) ? (metadata.height + 3) / 4 : metadata.height;
size_t width = IsCompressed(metadata.format) ? (metadata.width + 3) / 4 : metadata.width;

size_t bytesPerPixel = BitsPerPixel(srcImages[0].format) / 8;
uint32_t xBytesMask = 0b1001001001001001;
uint32_t yBytesMask = 0b0100100100100100;
uint32_t zBytesMask = 0b0010010010010010;

for (size_t z = 0; z < depth; z++)
{
for (size_t y = 0; y < metadata.height; y++)
for (size_t y = 0; y < height; y++)
{
for (size_t x = 0; x < metadata.width; x++)
for (size_t x = 0; x < width; x++)
{
uint32_t swizzle3Dindex = deposit_bits(x, xBytesMask) + deposit_bits(y, yBytesMask) + deposit_bits(z, zBytesMask);
uint32_t swizzle2Dindex = swizzle3Dindex % (metadata.width * metadata.height);
Expand Down

0 comments on commit d076d31

Please sign in to comment.