diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2018-05-03 18:42:13 -0400 |
|---|---|---|
| committer | Tim Foley <tfoleyNV@users.noreply.github.com> | 2018-05-03 15:42:13 -0700 |
| commit | f8472940229e8582ec9f941069fc9576bd09b94c (patch) | |
| tree | 9b387a65abc42094e7a1e0687b793cb0fc5c5eaa /tools/render-test/png-serialize-util.cpp | |
| parent | c216f00f1eaff368229cb8430422972fcac801b7 (diff) | |
Added Surface type - as a simple value type to hold a 2d collection of pixels. (#548)
Added PngSerializeUtil allows currently for just writing Surface of RGBA format.
Removes dependency on stbi_image except for in PngSerializeUtil.
Removed use of gWindowWidth/Height globals - pass the height into initialize or Renderer.
Diffstat (limited to 'tools/render-test/png-serialize-util.cpp')
| -rw-r--r-- | tools/render-test/png-serialize-util.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tools/render-test/png-serialize-util.cpp b/tools/render-test/png-serialize-util.cpp new file mode 100644 index 000000000..a7f6aa83a --- /dev/null +++ b/tools/render-test/png-serialize-util.cpp @@ -0,0 +1,38 @@ +// png-serialize-util.cpp +#define _CRT_SECURE_NO_WARNINGS + +#include "png-serialize-util.h" + +#include <stdlib.h> +#include <stdio.h> + +#define STB_IMAGE_WRITE_IMPLEMENTATION +#include "external/stb/stb_image_write.h" + +namespace renderer_test { +using namespace Slang; + +/* static */Slang::Result PngSerializeUtil::write(const char* filename, const Surface& surface) +{ + int numComps = 0; + switch (surface.m_format) + { + case Format::RGBA_Unorm_UInt8: + { + numComps = 4; + break; + } + default: break; + } + + if (numComps <= 0) + { + return SLANG_FAIL; + } + + int stbResult = stbi_write_png(filename, surface.m_width, surface.m_height, numComps, surface.m_data, surface.m_rowStrideInBytes); + + return stbResult ? SLANG_OK : SLANG_FAIL; +} + +} // renderer_test |
