From 1615c42ea68d39c874892e410f44be1c78876ae1 Mon Sep 17 00:00:00 2001 From: ubkp <118854183+ubkp@users.noreply.github.com> Date: Wed, 9 Aug 2023 21:12:02 -0300 Subject: [PATCH] Alternative fix for unused functions warnings on stb_truetype.h (and stb_image.h) --- src/external/stb_image.h | 8 ++++++++ src/external/stb_truetype.h | 35 +++++++++++++++++++++++++++++++++++ src/rtext.c | 13 ++----------- src/rtextures.c | 34 ++++++++-------------------------- 4 files changed, 53 insertions(+), 37 deletions(-) diff --git a/src/external/stb_image.h b/src/external/stb_image.h index 5e807a0a6..40bf37664 100644 --- a/src/external/stb_image.h +++ b/src/external/stb_image.h @@ -7758,6 +7758,14 @@ STBIDEF int stbi_is_16_bit_from_callbacks(stbi_io_callbacks const *c, void *user return stbi__is_16_main(&s); } +// Workaround to hide the following unused functions warnings while compiling raylib +void unused_stb_image(void) +{ + (void)&stbi__addints_valid; + (void)&stbi__mul2shorts_valid; + return; +} + #endif // STB_IMAGE_IMPLEMENTATION /* diff --git a/src/external/stb_truetype.h b/src/external/stb_truetype.h index bbf2284b1..484d48756 100644 --- a/src/external/stb_truetype.h +++ b/src/external/stb_truetype.h @@ -4964,6 +4964,41 @@ STBTT_DEF int stbtt_CompareUTF8toUTF16_bigendian(const char *s1, int len1, const return stbtt_CompareUTF8toUTF16_bigendian_internal((char *) s1, len1, (char *) s2, len2); } +// Workaround to hide the following unused functions warnings while compiling raylib +void unused_stb_truetype(void) +{ + (void)&stbtt_CompareUTF8toUTF16_bigendian; + (void)&stbtt_FindMatchingFont; + (void)&stbtt_GetNumberOfFonts; + (void)&stbtt_BakeFontBitmap; + (void)&stbtt_GetFontNameString; + (void)&stbtt_FreeSDF; + (void)&stbtt_GetPackedQuad; + (void)&stbtt_GetScaledFontVMetrics; + (void)&stbtt_PackFontRange; + (void)&stbtt_PackSetSkipMissingCodepoints; + (void)&stbtt_PackSetOversampling; + (void)&stbtt_PackEnd; + (void)&stbtt_PackBegin; + (void)&stbtt_GetBakedQuad; + (void)&stbtt_MakeCodepointBitmap; + (void)&stbtt_MakeCodepointBitmapSubpixelPrefilter; + (void)&stbtt_GetGlyphBitmap; + (void)&stbtt_FreeBitmap; + (void)&stbtt_GetCodepointBitmapBox; + (void)&stbtt_GetCodepointSVG; + (void)&stbtt_FreeShape; + (void)&stbtt_GetFontBoundingBox; + (void)&stbtt_GetFontVMetricsOS2; + (void)&stbtt_GetCodepointKernAdvance; + (void)&stbtt_GetKerningTable; + (void)&stbtt_GetKerningTableLength; + (void)&stbtt_IsGlyphEmpty; + (void)&stbtt_GetCodepointBox; + (void)&stbtt_GetCodepointShape; + return; +} + #if defined(__GNUC__) || defined(__clang__) #pragma GCC diagnostic pop #endif diff --git a/src/rtext.c b/src/rtext.c index f5234ecf9..933651d1a 100644 --- a/src/rtext.c +++ b/src/rtext.c @@ -71,21 +71,12 @@ #include // Required for: toupper(), tolower() [Used in TextToUpper(), TextToLower()] #if defined(SUPPORT_FILEFORMAT_TTF) - #if defined(__GNUC__) // GCC and Clang - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wunused-function" - #endif - #define STB_RECT_PACK_IMPLEMENTATION #include "external/stb_rect_pack.h" // Required for: ttf font rectangles packaging #define STBTT_STATIC #define STB_TRUETYPE_IMPLEMENTATION #include "external/stb_truetype.h" // Required for: ttf font data reading - - #if defined(__GNUC__) // GCC and Clang - #pragma GCC diagnostic pop - #endif #endif //---------------------------------------------------------------------------------- @@ -852,7 +843,7 @@ Image GenImageFontAtlas(const GlyphInfo *chars, Rectangle **charRecs, int glyphC RL_FREE(nodes); RL_FREE(context); } - + #if defined(SUPPORT_FONT_ATLAS_WHITE_REC) // Add a 3x3 white rectangle at the bottom-right corner of the generated atlas, // useful to use as the white texture to draw shapes with raylib, using this rectangle @@ -865,7 +856,7 @@ Image GenImageFontAtlas(const GlyphInfo *chars, Rectangle **charRecs, int glyphC k -= atlas.width; } #endif - + // Convert image data from GRAYSCALE to GRAY_ALPHA unsigned char *dataGrayAlpha = (unsigned char *)RL_MALLOC(atlas.width*atlas.height*sizeof(unsigned char)*2); // Two channels diff --git a/src/rtextures.c b/src/rtextures.c index f6e7e49c3..338376a31 100644 --- a/src/rtextures.c +++ b/src/rtextures.c @@ -138,11 +138,6 @@ defined(SUPPORT_FILEFORMAT_PIC) || \ defined(SUPPORT_FILEFORMAT_PNM)) - #if defined(__GNUC__) // GCC and Clang - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wunused-function" - #endif - #define STBI_MALLOC RL_MALLOC #define STBI_FREE RL_FREE #define STBI_REALLOC RL_REALLOC @@ -150,10 +145,6 @@ #define STB_IMAGE_IMPLEMENTATION #include "external/stb_image.h" // Required for: stbi_load_from_file() // NOTE: Used to read image data (multiple formats support) - - #if defined(__GNUC__) // GCC and Clang - #pragma GCC diagnostic pop - #endif #endif #if (defined(SUPPORT_FILEFORMAT_DDS) || \ @@ -162,18 +153,9 @@ defined(SUPPORT_FILEFORMAT_PVR) || \ defined(SUPPORT_FILEFORMAT_ASTC)) - #if defined(__GNUC__) // GCC and Clang - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wunused-function" - #endif - #define RL_GPUTEX_IMPLEMENTATION #include "external/rl_gputex.h" // Required for: rl_load_xxx_from_memory() // NOTE: Used to read compressed textures data (multiple formats support) - - #if defined(__GNUC__) // GCC and Clang - #pragma GCC diagnostic pop - #endif #endif #if defined(SUPPORT_FILEFORMAT_QOI) @@ -184,7 +166,7 @@ #pragma warning(push) #pragma warning(disable : 4267) #endif - + #define QOI_IMPLEMENTATION #include "external/qoi.h" @@ -3300,13 +3282,13 @@ void ImageDrawRectangleRec(Image *dst, Rectangle rec, Color color) { memcpy(pSrcPixel + x*bytesPerPixel, pSrcPixel, bytesPerPixel); } - - // Repeat the first row data for all other rows - int bytesPerRow = bytesPerPixel * (int)rec.width; - for (int y = 1; y < (int)rec.height; y++) - { - memcpy(pSrcPixel + (y*dst->width)*bytesPerPixel, pSrcPixel, bytesPerRow); - } + + // Repeat the first row data for all other rows + int bytesPerRow = bytesPerPixel * (int)rec.width; + for (int y = 1; y < (int)rec.height; y++) + { + memcpy(pSrcPixel + (y*dst->width)*bytesPerPixel, pSrcPixel, bytesPerRow); + } } // Draw rectangle lines within an image