summaryrefslogtreecommitdiff
path: root/tools/gfx-unit-test/gfx-test-texture-util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/gfx-unit-test/gfx-test-texture-util.cpp')
-rw-r--r--tools/gfx-unit-test/gfx-test-texture-util.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/tools/gfx-unit-test/gfx-test-texture-util.cpp b/tools/gfx-unit-test/gfx-test-texture-util.cpp
index e9d884894..bf9a54dc0 100644
--- a/tools/gfx-unit-test/gfx-test-texture-util.cpp
+++ b/tools/gfx-unit-test/gfx-test-texture-util.cpp
@@ -4,6 +4,12 @@
#include <slang-com-ptr.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#define STB_IMAGE_WRITE_IMPLEMENTATION
+#include "external/stb/stb_image_write.h"
+
#define GFX_ENABLE_RENDERDOC_INTEGRATION 0
#if GFX_ENABLE_RENDERDOC_INTEGRATION
@@ -196,4 +202,49 @@ namespace gfx_test
}
}
}
+
+ List<uint8_t> removePadding(ISlangBlob* pixels, GfxCount width, GfxCount height, Size rowPitch, Size pixelSize)
+ {
+ List<uint8_t> buffer;
+ buffer.setCount(height * rowPitch);
+ for (GfxIndex i = 0; i < height; ++i)
+ {
+ Offset srcOffset = i * rowPitch;
+ Offset dstOffset = i * width * pixelSize;
+ memcpy(buffer.getBuffer() + dstOffset, (char*)pixels->getBufferPointer() + srcOffset, width * pixelSize);
+ }
+
+ return buffer;
+ }
+
+ Slang::Result writeImage(
+ const char* filename,
+ ISlangBlob* pixels,
+ uint32_t width,
+ uint32_t height)
+ {
+ int stbResult =
+ stbi_write_hdr(filename, width, height, 4, (float*)pixels->getBufferPointer());
+
+ return stbResult ? SLANG_OK : SLANG_FAIL;
+ }
+
+ Slang::Result writeImage(
+ const char* filename,
+ ISlangBlob* pixels,
+ uint32_t width,
+ uint32_t height,
+ uint32_t rowPitch,
+ uint32_t pixelSize)
+ {
+ if (rowPitch == width * pixelSize)
+ return writeImage(filename, pixels, width, height);
+
+ List<uint8_t> buffer = removePadding(pixels, width, height, rowPitch, pixelSize);
+
+ int stbResult =
+ stbi_write_hdr(filename, width, height, 4, (float*)buffer.getBuffer());
+
+ return stbResult ? SLANG_OK : SLANG_FAIL;
+ }
}