From 28f4f42454027dd40dcf1f14750a43c10121c7e7 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Wed, 18 Feb 2015 00:43:09 -0400 Subject: [PATCH] Cleaned up the code for determining whether an image can be decoded using stb_image. --HG-- branch : minor --- src/modules/image/magpie/STBHandler.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/modules/image/magpie/STBHandler.cpp b/src/modules/image/magpie/STBHandler.cpp index 3b56dbc23..8b1e8c5f5 100644 --- a/src/modules/image/magpie/STBHandler.cpp +++ b/src/modules/image/magpie/STBHandler.cpp @@ -48,11 +48,14 @@ namespace magpie bool STBHandler::canDecode(love::filesystem::FileData *data) { - stbi__context s = {}; - stbi__start_mem(&s, (const stbi_uc *) data->getData(), (int) data->getSize()); + int w = 0; + int h = 0; + int comp = 0; - // These are internal stb_image functions, but we can still use them! - return stbi__bmp_test(&s) || stbi__tga_test(&s); + int status = stbi_info_from_memory((const stbi_uc *) data->getData(), + (int) data->getSize(), &w, &h, &comp); + + return status == 1 && w > 0 && h > 0; } bool STBHandler::canEncode(ImageData::Format format)