diff options
| author | chai <chaifix@163.com> | 2019-06-06 00:12:17 +0800 |
|---|---|---|
| committer | chai <chaifix@163.com> | 2019-06-06 00:12:17 +0800 |
| commit | 8bfe54676f728076a92d802bb5d064e58265c8f2 (patch) | |
| tree | 5d8ea1bd063f2d01dc979915db546449d68277bf /source/libs/asura-lib-core/graphics/stb_decoder.cpp | |
| parent | 88b882ed0b432c6aff2063213e2f793a36dd25f7 (diff) | |
-文件夹名
Diffstat (limited to 'source/libs/asura-lib-core/graphics/stb_decoder.cpp')
| -rw-r--r-- | source/libs/asura-lib-core/graphics/stb_decoder.cpp | 65 |
1 files changed, 0 insertions, 65 deletions
diff --git a/source/libs/asura-lib-core/graphics/stb_decoder.cpp b/source/libs/asura-lib-core/graphics/stb_decoder.cpp deleted file mode 100644 index a13d6b8..0000000 --- a/source/libs/asura-lib-core/graphics/stb_decoder.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include <asura-lib-utils/exceptions/exception.h> - -#include "stb_decoder.h" -#include "stb/stb_image.h" - -namespace AsuraEngine -{ - namespace Graphics - { - - bool STBDecoder::CanDecode(const Filesystem::DataBuffer& buffer) - { - int w = 0; - int h = 0; - int comp = 0; - - int status = stbi_info_from_memory((const stbi_uc*)buffer.data, buffer.size, &w, &h, &comp); - - return status == 1 && w > 0 && h > 0; - } - - void STBDecoder::Decode(const Filesystem::DataBuffer& db, ImageData& imageData) - { - const stbi_uc *buffer = (const stbi_uc *)db.data; - int bufferlen = db.size; - int width, height; - int comp = 0; - byte* data = nullptr; - PixelFormat format = PIXELFORMAT_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 = PIXELFORMAT_RGBA32F; - size = width * height * 4 * sizeof(float); - } - else - { - data = (byte*)stbi_load_from_memory(buffer, bufferlen, &width, &height, &comp, STBI_rgb_alpha); - format = PIXELFORMAT_ASTC_8x5; - size = width * height * 4; - } - if (data) - { - // ֤ڴ汻ͷţһϲûͷŵΪimage dataһԵģimageǶεġ - if (imageData.pixels) - delete[] imageData.pixels; - imageData.pixels = (byte*)data; - imageData.format = format; - imageData.width = width; - imageData.height = height; - } - 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 |
