From 2798067d54bb8595d731a3aef09c7ad972a1790d Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Fri, 23 Feb 2024 00:03:17 -0800 Subject: [PATCH] add Refresh_Image_Info --- include/Refresh_Image.h | 14 ++++++++++++++ src/Refresh_Image.c | 26 ++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/Refresh_Image.h b/include/Refresh_Image.h index 063de6a..d5a23a1 100644 --- a/include/Refresh_Image.h +++ b/include/Refresh_Image.h @@ -63,6 +63,20 @@ REFRESHAPI uint8_t* Refresh_Image_Load( int32_t *len ); +/* Get image dimensions without fully decoding the image. + * + * w: Filled with the width of the image. + * h: Filled with the height of the image. + * len: Filled with the length of pixel data in bytes. + */ +REFRESHAPI uint8_t Refresh_Image_Info( + uint8_t *bufferPtr, + int32_t bufferLength, + int32_t *w, + int32_t *h, + int32_t *len +); + /* Frees memory returned by Refresh_Image_Load. Do NOT free the memory yourself! * * mem: A pointer previously returned by Refresh_Image_LoadPNG. diff --git a/src/Refresh_Image.c b/src/Refresh_Image.c index 49f2a00..b82b70d 100644 --- a/src/Refresh_Image.c +++ b/src/Refresh_Image.c @@ -232,6 +232,32 @@ uint8_t* Refresh_Image_Load( return result; } +uint8_t Refresh_Image_Info( + uint8_t *bufferPtr, + int32_t bufferLength, + int32_t *w, + int32_t *h, + int32_t *len +) { + int32_t format; + int32_t result; + + result = stbi_info_from_memory( + bufferPtr, + bufferLength, + w, + h, + &format + ); + + if (result == 0) + { + SDL_LogWarn(SDL_LOG_CATEGORY_ERROR, "Image info failed: %s", stbi_failure_reason()); + } + + return (uint8_t) result; +} + void Refresh_Image_Free(uint8_t *mem) { SDL_SIMDFree(mem);