Skip to content

Commit 9f1a924

Browse files
rmodels.c, LoadImageFromCgltfImage() : fix base64 padding support
This should fix the issue related to `.gltf` embeded image in base64 format, by ignoring `=` padding and calculating the data size in bytes correctly.
1 parent 37205bb commit 9f1a924

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/rmodels.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -4815,7 +4815,9 @@ static Image LoadImageFromCgltfImage(cgltf_image *cgltfImage, const char *texPat
48154815
else
48164816
{
48174817
int base64Size = (int)strlen(cgltfImage->uri + i + 1);
4818-
int outSize = 3*(base64Size/4); // TODO: Consider padding (-numberOfPaddingCharacters)
4818+
while( cgltfImage->uri[ i + base64Size ] == '=' ) base64Size--; // remove optional paddings
4819+
int numberOfEncodedBits = base64Size * 6 - ( base64Size * 6 ) % 8 ; // ignore extra bits
4820+
int outSize = numberOfEncodedBits / 8 ; // actual encoded bytes
48194821
void *data = NULL;
48204822

48214823
cgltf_options options = { 0 };

0 commit comments

Comments
 (0)