Skip to content

Commit

Permalink
Alternative fix for unused functions warnings on stb_truetype.h (and …
Browse files Browse the repository at this point in the history
…stb_image.h)
  • Loading branch information
ubkp committed Aug 10, 2023
1 parent 0959f6e commit 1615c42
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 37 deletions.
8 changes: 8 additions & 0 deletions src/external/stb_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

/*
Expand Down
35 changes: 35 additions & 0 deletions src/external/stb_truetype.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 2 additions & 11 deletions src/rtext.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,12 @@
#include <ctype.h> // 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

//----------------------------------------------------------------------------------
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
34 changes: 8 additions & 26 deletions src/rtextures.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,22 +138,13 @@
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

#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) || \
Expand All @@ -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)
Expand All @@ -184,7 +166,7 @@
#pragma warning(push)
#pragma warning(disable : 4267)
#endif

#define QOI_IMPLEMENTATION
#include "external/qoi.h"

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1615c42

Please sign in to comment.