diff options
author | chai <chaifix@163.com> | 2019-03-30 21:49:29 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-03-30 21:49:29 +0800 |
commit | 8164adb15b76f537f8b6c78b9992786b61d61cc8 (patch) | |
tree | 6e42919e32258a3c495dcec54b0fda3e8e1977d8 /source/modules/asura-core/graphics/stb_decoder.cpp | |
parent | c270d033fa04873ee7a8925dbb00cae5edc4555c (diff) |
*misc
Diffstat (limited to 'source/modules/asura-core/graphics/stb_decoder.cpp')
-rw-r--r-- | source/modules/asura-core/graphics/stb_decoder.cpp | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/source/modules/asura-core/graphics/stb_decoder.cpp b/source/modules/asura-core/graphics/stb_decoder.cpp index eff2e65..9a14141 100644 --- a/source/modules/asura-core/graphics/stb_decoder.cpp +++ b/source/modules/asura-core/graphics/stb_decoder.cpp @@ -8,49 +8,54 @@ namespace AsuraEngine namespace Graphics { - bool STBDecoder::CanDecode(const Filesystem::DataBuffer& buffer) + 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.data, buffer.size, &w, &h, &comp); + 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(const Filesystem::DataBuffer& db, ImageData& imageData) + void STBDecoder::Decode(IO::DataBuffer& db, ImageData& imageData) { - const stbi_uc *buffer = (const stbi_uc *)db.data; - int bufferlen = db.size; + const stbi_uc *buffer = (const stbi_uc *)db.GetData(); + // databufferݳ + int bufferlen = db.GetSize(); + int width, height; int comp = 0; byte* data = nullptr; - PixelFormat format = PIXELFORMAT_UNKNOWN; + 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 = PIXELFORMAT_RGBA32F; + 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 = PIXELFORMAT_ASTC_8x5; + format = COLOR_FORMAT_RGBA8; size = width * height * 4; } if (data) { - // ֤ڴ汻ͷţһϲûͷŵΪimage dataһԵģimageǶεġ + imageData.Lock(); + if (imageData.pixels) delete[] imageData.pixels; imageData.pixels = (byte*)data; imageData.format = format; imageData.width = width; imageData.height = height; + + imageData.Unlock(); } else { |