diff options
| author | Miles Macklin <[email protected]> | 2018-03-19 15:10:24 +1300 |
|---|---|---|
| committer | Miles Macklin <[email protected]> | 2018-03-19 15:10:24 +1300 |
| commit | 8ee05c79ae1748ef132a12e4fb0af284899faec6 (patch) | |
| tree | 82bd5aa1892e28ce7886b6cfeafe66a47ff38e67 /core/png.cpp | |
| parent | Flex 1.2 (beta 2) (diff) | |
| download | flex-8ee05c79ae1748ef132a12e4fb0af284899faec6.tar.xz flex-8ee05c79ae1748ef132a12e4fb0af284899faec6.zip | |
Flex 1.2.0 release
Diffstat (limited to 'core/png.cpp')
| -rw-r--r-- | core/png.cpp | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/core/png.cpp b/core/png.cpp new file mode 100644 index 0000000..8c86bb1 --- /dev/null +++ b/core/png.cpp @@ -0,0 +1,70 @@ +#include "png.h" + +#include <iostream> + +#define STB_IMAGE_IMPLEMENTATION +#include "../external/stb_image/stb_image.h" + + +bool PngLoad(const char* filename, PngImage& image) +{ + int x, y, c; + + uint8_t* data = stbi_load(filename, &x, &y, &c, 4); + + if (data) + { + int s = x*y; + + image.m_data = new uint32_t[s]; + memcpy(image.m_data, data, s*sizeof(char)*4); + + image.m_width = (unsigned short)x; + image.m_height = (unsigned short)y; + + stbi_image_free(data); + + return true; + } + else + { + return false; + } +} + +void PngFree(PngImage& image) +{ + delete[] image.m_data; +} + +bool HdrLoad(const char* filename, HdrImage& image) +{ + int x, y, c; + + float* data = stbi_loadf(filename, &x, &y, &c, 4); + + if (data) + { + int s = x*y; + + image.m_data = new float[s*4]; + memcpy(image.m_data, data, s*sizeof(float)*4); + + image.m_width = (unsigned short)x; + image.m_height = (unsigned short)y; + + stbi_image_free(data); + + return true; + } + else + { + return false; + } +} + +void HdrFree(HdrImage& image) +{ + delete[] image.m_data; +} + |