diff options
author | chai <chaifix@163.com> | 2019-04-02 08:47:15 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-04-02 08:47:15 +0800 |
commit | 250e30d73f09e9da2b5a81d0fbae63744ae12a73 (patch) | |
tree | 0f55daf334c073e1779d7a1284799a2056aad714 /source/modules/asura-core/graphics/stb_decoder.cpp | |
parent | 66fe16dd5ed57ae958fc25158d0defae2e6fae6a (diff) |
*misc
Diffstat (limited to 'source/modules/asura-core/graphics/stb_decoder.cpp')
-rw-r--r-- | source/modules/asura-core/graphics/stb_decoder.cpp | 70 |
1 files changed, 0 insertions, 70 deletions
diff --git a/source/modules/asura-core/graphics/stb_decoder.cpp b/source/modules/asura-core/graphics/stb_decoder.cpp deleted file mode 100644 index 9a14141..0000000 --- a/source/modules/asura-core/graphics/stb_decoder.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include <asura-utils/exceptions/exception.h> - -#include "stb_decoder.h" -#include "stb/stb_image.h" - -namespace AsuraEngine -{ - namespace Graphics - { - - bool STBDecoder::CanDecode(IO::DataBuffer& buffer) - { - int w = 0; - int h = 0; - int comp = 0; - - int status = stbi_info_from_memory((const stbi_uc*)buffer.GetData(), buffer.GetSize(), &w, &h, &comp); - - return status == 1 && w > 0 && h > 0; - } - - void STBDecoder::Decode(IO::DataBuffer& db, ImageData& imageData) - { - const stbi_uc *buffer = (const stbi_uc *)db.GetData(); - // databufferݳ - int bufferlen = db.GetSize(); - - int width, height; - int comp = 0; - byte* data = nullptr; - ColorFormat format = COLOR_FORMAT_UNKNOWN; - std::size_t size = 0; - - if (stbi_is_hdr_from_memory(buffer, bufferlen)) - { - // 4channelfloat - data = (byte*)stbi_loadf_from_memory(buffer, bufferlen, &width, &height, &comp, STBI_rgb_alpha); - format = COLOR_FORMAT_RGBA32F; - size = width * height * 4 * sizeof(float); - } - else - { - data = (byte*)stbi_load_from_memory(buffer, bufferlen, &width, &height, &comp, STBI_rgb_alpha); - format = COLOR_FORMAT_RGBA8; - size = width * height * 4; - } - if (data) - { - imageData.Lock(); - - if (imageData.pixels) - delete[] imageData.pixels; - imageData.pixels = (byte*)data; - imageData.format = format; - imageData.width = width; - imageData.height = height; - - imageData.Unlock(); - } - else - { - const char *err = stbi_failure_reason(); - if (err == nullptr) - err = "unknown error"; - throw Exception("Could not decode image with stb_image (%s).", err); - } - } - - } -}
\ No newline at end of file |