From 9f1a92441a804833a1c7b04c7ae67ad9ca3761a9 Mon Sep 17 00:00:00 2001 From: SuperUserNameMan <9801802+SuperUserNameMan@users.noreply.github.com> Date: Thu, 27 Jun 2024 12:48:40 +0200 Subject: [PATCH 1/4] 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. --- src/rmodels.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/rmodels.c b/src/rmodels.c index a323292ca7d8..4d1dbb9a203e 100644 --- a/src/rmodels.c +++ b/src/rmodels.c @@ -4815,7 +4815,9 @@ static Image LoadImageFromCgltfImage(cgltf_image *cgltfImage, const char *texPat else { int base64Size = (int)strlen(cgltfImage->uri + i + 1); - int outSize = 3*(base64Size/4); // TODO: Consider padding (-numberOfPaddingCharacters) + while( cgltfImage->uri[ i + base64Size ] == '=' ) base64Size--; // remove optional paddings + int numberOfEncodedBits = base64Size * 6 - ( base64Size * 6 ) % 8 ; // ignore extra bits + int outSize = numberOfEncodedBits / 8 ; // actual encoded bytes void *data = NULL; cgltf_options options = { 0 }; From c55e579271e17f6150391ca66fd508e03ac73af0 Mon Sep 17 00:00:00 2001 From: SuperUserNameMan <9801802+SuperUserNameMan@users.noreply.github.com> Date: Thu, 27 Jun 2024 13:17:48 +0200 Subject: [PATCH 2/4] follow guidelin convention --- src/rmodels.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rmodels.c b/src/rmodels.c index 4d1dbb9a203e..8f052b098ac2 100644 --- a/src/rmodels.c +++ b/src/rmodels.c @@ -4815,8 +4815,8 @@ static Image LoadImageFromCgltfImage(cgltf_image *cgltfImage, const char *texPat else { int base64Size = (int)strlen(cgltfImage->uri + i + 1); - while( cgltfImage->uri[ i + base64Size ] == '=' ) base64Size--; // remove optional paddings - int numberOfEncodedBits = base64Size * 6 - ( base64Size * 6 ) % 8 ; // ignore extra bits + while (cgltfImage->uri[i+base64Size] == '=') base64Size--; // remove optional paddings + int numberOfEncodedBits = base64Size * 6 - (base64Size * 6) % 8 ; // ignore extra bits int outSize = numberOfEncodedBits / 8 ; // actual encoded bytes void *data = NULL; From 3900e9c7651066b24b11f6743626c6d4af7870eb Mon Sep 17 00:00:00 2001 From: SuperUserNameMan <9801802+SuperUserNameMan@users.noreply.github.com> Date: Thu, 27 Jun 2024 13:20:45 +0200 Subject: [PATCH 3/4] try to follow guideline convention as much as possible --- src/rmodels.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rmodels.c b/src/rmodels.c index 8f052b098ac2..ecd2e67d9790 100644 --- a/src/rmodels.c +++ b/src/rmodels.c @@ -4815,9 +4815,9 @@ static Image LoadImageFromCgltfImage(cgltf_image *cgltfImage, const char *texPat else { int base64Size = (int)strlen(cgltfImage->uri + i + 1); - while (cgltfImage->uri[i+base64Size] == '=') base64Size--; // remove optional paddings - int numberOfEncodedBits = base64Size * 6 - (base64Size * 6) % 8 ; // ignore extra bits - int outSize = numberOfEncodedBits / 8 ; // actual encoded bytes + while (cgltfImage->uri[i + base64Size] == '=') base64Size--; // remove optional paddings + int numberOfEncodedBits = base64Size*6 - (base64Size*6) % 8 ; // ignore extra bits + int outSize = numberOfEncodedBits/8 ; // actual encoded bytes void *data = NULL; cgltf_options options = { 0 }; From ec5165f58eaf820b80236dfc8f70295f5402e683 Mon Sep 17 00:00:00 2001 From: SuperUserNameMan <9801802+SuperUserNameMan@users.noreply.github.com> Date: Thu, 27 Jun 2024 14:24:00 +0200 Subject: [PATCH 4/4] clarify comments i hope it's clear ennough --- src/rmodels.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rmodels.c b/src/rmodels.c index ecd2e67d9790..a6209f39f817 100644 --- a/src/rmodels.c +++ b/src/rmodels.c @@ -4815,9 +4815,9 @@ static Image LoadImageFromCgltfImage(cgltf_image *cgltfImage, const char *texPat else { int base64Size = (int)strlen(cgltfImage->uri + i + 1); - while (cgltfImage->uri[i + base64Size] == '=') base64Size--; // remove optional paddings - int numberOfEncodedBits = base64Size*6 - (base64Size*6) % 8 ; // ignore extra bits - int outSize = numberOfEncodedBits/8 ; // actual encoded bytes + while (cgltfImage->uri[i + base64Size] == '=') base64Size--; // Ignore optional paddings + int numberOfEncodedBits = base64Size*6 - (base64Size*6) % 8 ; // Encoded bits minus extra bits, so it becomes a multiple of 8 bits + int outSize = numberOfEncodedBits/8 ; // Actual encoded bytes void *data = NULL; cgltf_options options = { 0 };