mirror of
https://github.com/raysan5/raylib.git
synced 2026-08-25 13:48:27 -04:00
Compare commits
7 Commits
c85cd07db0
...
f00317bead
| Author | SHA1 | Date | |
|---|---|---|---|
| f00317bead | |||
| 8805ab3ee2 | |||
| ebec978443 | |||
| cfe56d97ea | |||
| 97d2b0146c | |||
| c31666fe2a | |||
| ab35e0f712 |
21
src/external/tinyobj_loader_c.h
vendored
21
src/external/tinyobj_loader_c.h
vendored
@ -1020,7 +1020,12 @@ static int parseLine(Command *command, const char *p, unsigned int p_len,
|
|||||||
int triangulate) {
|
int triangulate) {
|
||||||
char linebuf[4096];
|
char linebuf[4096];
|
||||||
const char *token;
|
const char *token;
|
||||||
assert(p_len < 4095);
|
|
||||||
|
// @raysan5:
|
||||||
|
// WARNING: If -DNDEBUG is set when compiling, assertions will not
|
||||||
|
// be present in the compiled binary, replacing by a runtime check
|
||||||
|
//assert(p_len < 4095);
|
||||||
|
if (p_len > 4095) return 0;
|
||||||
|
|
||||||
memcpy(linebuf, p, p_len);
|
memcpy(linebuf, p, p_len);
|
||||||
linebuf[p_len] = '\0';
|
linebuf[p_len] = '\0';
|
||||||
@ -1102,7 +1107,11 @@ static int parseLine(Command *command, const char *p, unsigned int p_len,
|
|||||||
tinyobj_vertex_index_t i1;
|
tinyobj_vertex_index_t i1;
|
||||||
tinyobj_vertex_index_t i2 = f[1];
|
tinyobj_vertex_index_t i2 = f[1];
|
||||||
|
|
||||||
assert(3 * num_f < TINYOBJ_MAX_FACES_PER_F_LINE);
|
// @raysan5:
|
||||||
|
// WARNING: If -DNDEBUG is set when compiling, assertions will not
|
||||||
|
// be present in the compiled binary, replacing by a runtime check
|
||||||
|
//assert(3 * num_f < TINYOBJ_MAX_FACES_PER_F_LINE);
|
||||||
|
if (3*num_f > TINYOBJ_MAX_FACES_PER_F_LINE) return 0;
|
||||||
|
|
||||||
for (k = 2; k < num_f; k++) {
|
for (k = 2; k < num_f; k++) {
|
||||||
i1 = i2;
|
i1 = i2;
|
||||||
@ -1119,7 +1128,13 @@ static int parseLine(Command *command, const char *p, unsigned int p_len,
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
unsigned int k = 0;
|
unsigned int k = 0;
|
||||||
assert(num_f < TINYOBJ_MAX_FACES_PER_F_LINE);
|
|
||||||
|
// @raysan5:
|
||||||
|
// WARNING: If -DNDEBUG is set when compiling, assertions will not
|
||||||
|
// be present in the compiled binary, replacing by a runtime check
|
||||||
|
//assert(num_f < TINYOBJ_MAX_FACES_PER_F_LINE);
|
||||||
|
if (num_f > TINYOBJ_MAX_FACES_PER_F_LINE) return 0;
|
||||||
|
|
||||||
for (k = 0; k < num_f; k++) {
|
for (k = 0; k < num_f; k++) {
|
||||||
command->f[k] = f[k];
|
command->f[k] = f[k];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3601,10 +3601,14 @@ AutomationEventList LoadAutomationEventList(const char *fileName)
|
|||||||
case 'c': sscanf(buffer, "c %i", &list.count); break;
|
case 'c': sscanf(buffer, "c %i", &list.count); break;
|
||||||
case 'e':
|
case 'e':
|
||||||
{
|
{
|
||||||
sscanf(buffer, "e %d %d %d %d %d %d %[^\n]s", &list.events[counter].frame, &list.events[counter].type,
|
if (counter < list.capacity)
|
||||||
|
{
|
||||||
|
sscanf(buffer, "e %d %d %d %d %d %d %63[^\n]s", &list.events[counter].frame, &list.events[counter].type,
|
||||||
&list.events[counter].params[0], &list.events[counter].params[1], &list.events[counter].params[2], &list.events[counter].params[3], eventDesc);
|
&list.events[counter].params[0], &list.events[counter].params[1], &list.events[counter].params[2], &list.events[counter].params[3], eventDesc);
|
||||||
|
|
||||||
counter++;
|
counter++;
|
||||||
|
}
|
||||||
|
else TRACELOG(LOG_WARNING, "AUTOMATION: Event goes beyond automated list capacity (MAX: %i): %s", buffer, list.capacity);
|
||||||
} break;
|
} break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|||||||
19
src/rlgl.h
19
src/rlgl.h
@ -910,6 +910,7 @@ RLAPI void rlLoadDrawQuad(void); // Load and draw a quad
|
|||||||
#include <stdlib.h> // Required for: calloc(), free()
|
#include <stdlib.h> // Required for: calloc(), free()
|
||||||
#include <string.h> // Required for: strcmp(), strlen() [Used in rlglInit(), on extensions loading]
|
#include <string.h> // Required for: strcmp(), strlen() [Used in rlglInit(), on extensions loading]
|
||||||
#include <math.h> // Required for: sqrtf(), sinf(), cosf(), floor(), log()
|
#include <math.h> // Required for: sqrtf(), sinf(), cosf(), floor(), log()
|
||||||
|
#include <limits.h> // Required for: INT_MAX
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Defines and Macros
|
// Defines and Macros
|
||||||
@ -5236,7 +5237,9 @@ static int rlGetPixelDataSize(int width, int height, int format)
|
|||||||
{
|
{
|
||||||
int blockWidth = (width + 3)/4;
|
int blockWidth = (width + 3)/4;
|
||||||
int blockHeight = (height + 3)/4;
|
int blockHeight = (height + 3)/4;
|
||||||
dataSize = blockWidth*blockHeight*8;
|
unsigned long long dataSizeBytes = blockWidth*blockHeight*8;
|
||||||
|
if (dataSizeBytes < INT_MAX) dataSize = (int)dataSizeBytes;
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case RL_PIXELFORMAT_COMPRESSED_DXT3_RGBA:
|
case RL_PIXELFORMAT_COMPRESSED_DXT3_RGBA:
|
||||||
case RL_PIXELFORMAT_COMPRESSED_DXT5_RGBA:
|
case RL_PIXELFORMAT_COMPRESSED_DXT5_RGBA:
|
||||||
@ -5245,13 +5248,17 @@ static int rlGetPixelDataSize(int width, int height, int format)
|
|||||||
{
|
{
|
||||||
int blockWidth = (width + 3)/4;
|
int blockWidth = (width + 3)/4;
|
||||||
int blockHeight = (height + 3)/4;
|
int blockHeight = (height + 3)/4;
|
||||||
dataSize = blockWidth*blockHeight*16;
|
unsigned long long dataSizeBytes = blockWidth*blockHeight*16;
|
||||||
|
if (dataSizeBytes < INT_MAX) dataSize = (int)dataSizeBytes;
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case RL_PIXELFORMAT_COMPRESSED_ASTC_8x8_RGBA: // 4 bytes per each 4x4 block
|
case RL_PIXELFORMAT_COMPRESSED_ASTC_8x8_RGBA: // 4 bytes per each 4x4 block
|
||||||
{
|
{
|
||||||
int blockWidth = (width + 3)/4;
|
int blockWidth = (width + 3)/4;
|
||||||
int blockHeight = (height + 3)/4;
|
int blockHeight = (height + 3)/4;
|
||||||
dataSize = blockWidth*blockHeight*4;
|
unsigned long long dataSizeBytes = blockWidth*blockHeight*4;
|
||||||
|
if (dataSizeBytes < INT_MAX) dataSize = (int)dataSizeBytes;
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
@ -5260,10 +5267,12 @@ static int rlGetPixelDataSize(int width, int height, int format)
|
|||||||
if ((format >= RL_PIXELFORMAT_UNCOMPRESSED_GRAYSCALE) &&
|
if ((format >= RL_PIXELFORMAT_UNCOMPRESSED_GRAYSCALE) &&
|
||||||
(format <= RL_PIXELFORMAT_UNCOMPRESSED_R16G16B16A16))
|
(format <= RL_PIXELFORMAT_UNCOMPRESSED_R16G16B16A16))
|
||||||
{
|
{
|
||||||
double bytesPerPixel = (double)bpp/8.0;
|
unsigned long long dataSizeBytes = (width*height*bpp) >> 3; // Get size in bytes (dividing by 8)
|
||||||
dataSize = (int)(bytesPerPixel*width*height); // Total data size in bytes
|
if (dataSizeBytes < INT_MAX) dataSize = (int)dataSizeBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dataSize == 0) TRACELOG(LOG_WARNING, "Requested image size is larger than 2GB, it can not be allocated");
|
||||||
|
|
||||||
return dataSize;
|
return dataSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2320,7 +2320,7 @@ void UpdateModelAnimation(Model model, ModelAnimation anim, float frame)
|
|||||||
Matrix currentPoseMatrix = { 0 };
|
Matrix currentPoseMatrix = { 0 };
|
||||||
|
|
||||||
// Update all bones and bone matrices of model
|
// Update all bones and bone matrices of model
|
||||||
for (int boneIndex = 0; boneIndex < model.skeleton.boneCount; boneIndex++)
|
for (unsigned int boneIndex = 0; boneIndex < model.skeleton.boneCount; boneIndex++)
|
||||||
{
|
{
|
||||||
// Compute interpolated pose between current and next frame
|
// Compute interpolated pose between current and next frame
|
||||||
// NOTE: Storing animation frame data in model.currentPose
|
// NOTE: Storing animation frame data in model.currentPose
|
||||||
@ -2390,7 +2390,7 @@ void UpdateModelAnimationEx(Model model, ModelAnimation animA, float frameA, Mod
|
|||||||
Matrix bindPoseMatrix = { 0 };
|
Matrix bindPoseMatrix = { 0 };
|
||||||
Matrix currentPoseMatrix = { 0 };
|
Matrix currentPoseMatrix = { 0 };
|
||||||
|
|
||||||
for (int boneIndex = 0; boneIndex < model.skeleton.boneCount; boneIndex++)
|
for (unsigned int boneIndex = 0; boneIndex < model.skeleton.boneCount; boneIndex++)
|
||||||
{
|
{
|
||||||
// Get frame-interpolation for first animation
|
// Get frame-interpolation for first animation
|
||||||
Vector3 frameATranslation = Vector3Lerp(
|
Vector3 frameATranslation = Vector3Lerp(
|
||||||
@ -5013,7 +5013,7 @@ static Model LoadIQM(const char *fileName)
|
|||||||
// Initialize runtime animation data: current pose and bone matrices
|
// Initialize runtime animation data: current pose and bone matrices
|
||||||
model.currentPose = (Transform *)RL_CALLOC(model.skeleton.boneCount, sizeof(Transform));
|
model.currentPose = (Transform *)RL_CALLOC(model.skeleton.boneCount, sizeof(Transform));
|
||||||
model.boneMatrices = (Matrix *)RL_CALLOC(model.skeleton.boneCount, sizeof(Matrix));
|
model.boneMatrices = (Matrix *)RL_CALLOC(model.skeleton.boneCount, sizeof(Matrix));
|
||||||
for (int j = 0; j < model.skeleton.boneCount; j++) model.boneMatrices[j] = MatrixIdentity();
|
for (unsigned int j = 0; j < model.skeleton.boneCount; j++) model.boneMatrices[j] = MatrixIdentity();
|
||||||
|
|
||||||
UnloadFileData(fileData);
|
UnloadFileData(fileData);
|
||||||
|
|
||||||
@ -5241,7 +5241,7 @@ static ModelAnimation *LoadModelAnimationsIQM(const char *fileName, int *animCou
|
|||||||
// Build frameposes
|
// Build frameposes
|
||||||
for (unsigned int frame = 0; frame < anim[a].num_frames; frame++)
|
for (unsigned int frame = 0; frame < anim[a].num_frames; frame++)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < animations[a].boneCount; i++)
|
for (unsigned int i = 0; i < animations[a].boneCount; i++)
|
||||||
{
|
{
|
||||||
if (bones[i].parent >= 0)
|
if (bones[i].parent >= 0)
|
||||||
{
|
{
|
||||||
@ -5371,7 +5371,7 @@ static Image LoadImageFromCgltfImage(cgltf_image *cgltfImage, const char *texPat
|
|||||||
// Load bone info from GLTF skin data
|
// Load bone info from GLTF skin data
|
||||||
static BoneInfo *LoadBoneInfoGLTF(cgltf_skin skin, unsigned int *boneCount)
|
static BoneInfo *LoadBoneInfoGLTF(cgltf_skin skin, unsigned int *boneCount)
|
||||||
{
|
{
|
||||||
*boneCount = skin.joints_count;
|
*boneCount = (unsigned int)skin.joints_count;
|
||||||
BoneInfo *bones = (BoneInfo *)RL_CALLOC(skin.joints_count, sizeof(BoneInfo));
|
BoneInfo *bones = (BoneInfo *)RL_CALLOC(skin.joints_count, sizeof(BoneInfo));
|
||||||
|
|
||||||
for (unsigned int i = 0; i < skin.joints_count; i++)
|
for (unsigned int i = 0; i < skin.joints_count; i++)
|
||||||
@ -6144,7 +6144,7 @@ static Model LoadGLTF(const char *fileName)
|
|||||||
model.skeleton.bones = LoadBoneInfoGLTF(skin, &model.skeleton.boneCount);
|
model.skeleton.bones = LoadBoneInfoGLTF(skin, &model.skeleton.boneCount);
|
||||||
model.skeleton.bindPose = (Transform *)RL_CALLOC(model.skeleton.boneCount, sizeof(Transform));
|
model.skeleton.bindPose = (Transform *)RL_CALLOC(model.skeleton.boneCount, sizeof(Transform));
|
||||||
|
|
||||||
for (int i = 0; i < model.skeleton.boneCount; i++)
|
for (unsigned int i = 0; i < model.skeleton.boneCount; i++)
|
||||||
{
|
{
|
||||||
Matrix bindMatrix = { 0 };
|
Matrix bindMatrix = { 0 };
|
||||||
cgltf_float inverseBindTransform[16] = { 0 };
|
cgltf_float inverseBindTransform[16] = { 0 };
|
||||||
@ -6309,7 +6309,7 @@ static Model LoadGLTF(const char *fileName)
|
|||||||
if ((data->skins_count > 0) && !hasJoints && (node->parent != NULL) && (node->parent->mesh == NULL))
|
if ((data->skins_count > 0) && !hasJoints && (node->parent != NULL) && (node->parent->mesh == NULL))
|
||||||
{
|
{
|
||||||
int parentBoneId = -1;
|
int parentBoneId = -1;
|
||||||
for (int joint = 0; joint < model.skeleton.boneCount; joint++)
|
for (unsigned int joint = 0; joint < model.skeleton.boneCount; joint++)
|
||||||
{
|
{
|
||||||
if (data->skins[0].joints[joint] == node->parent)
|
if (data->skins[0].joints[joint] == node->parent)
|
||||||
{
|
{
|
||||||
@ -6347,7 +6347,7 @@ static Model LoadGLTF(const char *fileName)
|
|||||||
// Initialize runtime animation data: current pose and bone matrices
|
// Initialize runtime animation data: current pose and bone matrices
|
||||||
model.currentPose = (Transform *)RL_CALLOC(model.skeleton.boneCount, sizeof(Transform));
|
model.currentPose = (Transform *)RL_CALLOC(model.skeleton.boneCount, sizeof(Transform));
|
||||||
model.boneMatrices = (Matrix *)RL_CALLOC(model.skeleton.boneCount, sizeof(Matrix));
|
model.boneMatrices = (Matrix *)RL_CALLOC(model.skeleton.boneCount, sizeof(Matrix));
|
||||||
for (int j = 0; j < model.skeleton.boneCount; j++) model.boneMatrices[j] = MatrixIdentity();
|
for (unsigned int j = 0; j < model.skeleton.boneCount; j++) model.boneMatrices[j] = MatrixIdentity();
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Free unused allocated memory in case of no bones defined
|
// Free unused allocated memory in case of no bones defined
|
||||||
@ -6670,7 +6670,7 @@ static ModelAnimation *LoadModelAnimationsGLTF(const char *fileName, int *animCo
|
|||||||
animations[a].keyframePoses[j] = (Transform *)RL_CALLOC(animations[a].boneCount, sizeof(Transform));
|
animations[a].keyframePoses[j] = (Transform *)RL_CALLOC(animations[a].boneCount, sizeof(Transform));
|
||||||
float time = (float)j / GLTF_FRAMERATE;
|
float time = (float)j / GLTF_FRAMERATE;
|
||||||
|
|
||||||
for (int k = 0; k < animations[a].boneCount; k++)
|
for (unsigned int k = 0; k < animations[a].boneCount; k++)
|
||||||
{
|
{
|
||||||
Vector3 translation = {skin.joints[k]->translation[0], skin.joints[k]->translation[1], skin.joints[k]->translation[2]};
|
Vector3 translation = {skin.joints[k]->translation[0], skin.joints[k]->translation[1], skin.joints[k]->translation[2]};
|
||||||
Quaternion rotation = {skin.joints[k]->rotation[0], skin.joints[k]->rotation[1], skin.joints[k]->rotation[2], skin.joints[k]->rotation[3]};
|
Quaternion rotation = {skin.joints[k]->rotation[0], skin.joints[k]->rotation[1], skin.joints[k]->rotation[2], skin.joints[k]->rotation[3]};
|
||||||
@ -7204,7 +7204,7 @@ static Model LoadM3D(const char *fileName)
|
|||||||
// Initialize runtime animation data: current pose and bone matrices
|
// Initialize runtime animation data: current pose and bone matrices
|
||||||
model.currentPose = (Transform *)RL_CALLOC(model.skeleton.boneCount, sizeof(Transform));
|
model.currentPose = (Transform *)RL_CALLOC(model.skeleton.boneCount, sizeof(Transform));
|
||||||
model.boneMatrices = (Matrix *)RL_CALLOC(model.skeleton.boneCount, sizeof(Matrix));
|
model.boneMatrices = (Matrix *)RL_CALLOC(model.skeleton.boneCount, sizeof(Matrix));
|
||||||
for (int j = 0; j < model.skeleton.boneCount; j++) model.boneMatrices[j] = MatrixIdentity();
|
for (unsigned int j = 0; j < model.skeleton.boneCount; j++) model.boneMatrices[j] = MatrixIdentity();
|
||||||
}
|
}
|
||||||
|
|
||||||
m3d_free(m3d);
|
m3d_free(m3d);
|
||||||
|
|||||||
24
src/rtext.c
24
src/rtext.c
@ -1699,7 +1699,7 @@ const char *TextSubtext(const char *text, int position, int length)
|
|||||||
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
||||||
memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH);
|
memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH);
|
||||||
|
|
||||||
if (text != NULL)
|
if ((text != NULL) && (position > 0) && (length > 0))
|
||||||
{
|
{
|
||||||
int textLength = TextLength(text);
|
int textLength = TextLength(text);
|
||||||
|
|
||||||
@ -1975,10 +1975,11 @@ char *TextInsert(const char *text, const char *insert, int position)
|
|||||||
{
|
{
|
||||||
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
||||||
memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH);
|
memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH);
|
||||||
|
|
||||||
if ((text != NULL) && (insert != NULL))
|
|
||||||
{
|
|
||||||
int textLen = TextLength(text);
|
int textLen = TextLength(text);
|
||||||
|
|
||||||
|
if ((text != NULL) && (insert != NULL) && (position >= 0))
|
||||||
|
{
|
||||||
|
if (position > textLen) position = textLen; // End of text string
|
||||||
int insertLen = TextLength(insert);
|
int insertLen = TextLength(insert);
|
||||||
|
|
||||||
if ((textLen + insertLen) < (MAX_TEXT_BUFFER_LENGTH - 1))
|
if ((textLen + insertLen) < (MAX_TEXT_BUFFER_LENGTH - 1))
|
||||||
@ -1987,7 +1988,7 @@ char *TextInsert(const char *text, const char *insert, int position)
|
|||||||
|
|
||||||
for (int i = 0; i < position; i++) buffer[i] = text[i];
|
for (int i = 0; i < position; i++) buffer[i] = text[i];
|
||||||
for (int i = position; i < insertLen + position; i++) buffer[i] = insert[i - position];
|
for (int i = position; i < insertLen + position; i++) buffer[i] = insert[i - position];
|
||||||
for (int i = (insertLen + position); i < (textLen + insertLen); i++) buffer[i] = text[i];
|
for (int i = (insertLen + position); i < (textLen + insertLen); i++) buffer[i] = text[i - insertLen];
|
||||||
|
|
||||||
buffer[textLen + insertLen] = '\0'; // Add EOL
|
buffer[textLen + insertLen] = '\0'; // Add EOL
|
||||||
}
|
}
|
||||||
@ -2002,17 +2003,18 @@ char *TextInsert(const char *text, const char *insert, int position)
|
|||||||
char *TextInsertAlloc(const char *text, const char *insert, int position)
|
char *TextInsertAlloc(const char *text, const char *insert, int position)
|
||||||
{
|
{
|
||||||
char *result = NULL;
|
char *result = NULL;
|
||||||
|
|
||||||
if ((text != NULL) && (insert != NULL))
|
|
||||||
{
|
|
||||||
int textLen = TextLength(text);
|
int textLen = TextLength(text);
|
||||||
|
|
||||||
|
if ((text != NULL) && (insert != NULL) && (position >= 0))
|
||||||
|
{
|
||||||
|
if (position > textLen) position = textLen; // End of text string
|
||||||
int insertLen = TextLength(insert);
|
int insertLen = TextLength(insert);
|
||||||
|
|
||||||
result = (char *)RL_MALLOC(textLen + insertLen + 1);
|
result = (char *)RL_MALLOC(textLen + insertLen + 1);
|
||||||
|
|
||||||
for (int i = 0; i < position; i++) result[i] = text[i];
|
for (int i = 0; i < position; i++) result[i] = text[i];
|
||||||
for (int i = position; i < insertLen + position; i++) result[i] = insert[i - position];
|
for (int i = position; i < (insertLen + position); i++) result[i] = insert[i - position];
|
||||||
for (int i = (insertLen + position); i < (textLen + insertLen); i++) result[i] = text[i];
|
for (int i = (insertLen + position); i < (textLen + insertLen + position); i++) result[i] = text[i - insertLen];
|
||||||
|
|
||||||
result[textLen + insertLen] = '\0'; // Add EOL
|
result[textLen + insertLen] = '\0'; // Add EOL
|
||||||
}
|
}
|
||||||
@ -2036,7 +2038,7 @@ char *TextJoin(char **textList, int count, const char *delimiter)
|
|||||||
int textLength = TextLength(textList[i]);
|
int textLength = TextLength(textList[i]);
|
||||||
|
|
||||||
// Make sure joined text could fit inside MAX_TEXT_BUFFER_LENGTH
|
// Make sure joined text could fit inside MAX_TEXT_BUFFER_LENGTH
|
||||||
if ((totalLength + textLength) < MAX_TEXT_BUFFER_LENGTH)
|
if ((totalLength + textLength + delimiterLen) < MAX_TEXT_BUFFER_LENGTH)
|
||||||
{
|
{
|
||||||
memcpy(textPtr, textList[i], textLength);
|
memcpy(textPtr, textList[i], textLength);
|
||||||
totalLength += textLength;
|
totalLength += textLength;
|
||||||
|
|||||||
@ -70,6 +70,7 @@
|
|||||||
#include <string.h> // Required for: strlen() [Used in ImageTextEx()], strcmp() [Used in LoadImageFromMemory()/LoadImageAnimFromMemory()/ExportImageToMemory()]
|
#include <string.h> // Required for: strlen() [Used in ImageTextEx()], strcmp() [Used in LoadImageFromMemory()/LoadImageAnimFromMemory()/ExportImageToMemory()]
|
||||||
#include <math.h> // Required for: fabsf() [Used in DrawTextureRec()]
|
#include <math.h> // Required for: fabsf() [Used in DrawTextureRec()]
|
||||||
#include <stdio.h> // Required for: sprintf() [Used in ExportImageAsCode()]
|
#include <stdio.h> // Required for: sprintf() [Used in ExportImageAsCode()]
|
||||||
|
#include <limits.h> // Required for: INT_MAX
|
||||||
|
|
||||||
// Support only desired texture formats on stb_image
|
// Support only desired texture formats on stb_image
|
||||||
#if !SUPPORT_FILEFORMAT_BMP
|
#if !SUPPORT_FILEFORMAT_BMP
|
||||||
@ -843,9 +844,10 @@ bool ExportImageAsCode(Image image, const char *fileName)
|
|||||||
// Generate image: plain color
|
// Generate image: plain color
|
||||||
Image GenImageColor(int width, int height, Color color)
|
Image GenImageColor(int width, int height, Color color)
|
||||||
{
|
{
|
||||||
Color *pixels = (Color *)RL_CALLOC(width*height, sizeof(Color));
|
int dataSize = GetPixelDataSize(width, height, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8);
|
||||||
|
Color *pixels = (Color *)RL_CALLOC(dataSize, 1);
|
||||||
|
|
||||||
for (int i = 0; i < width*height; i++) pixels[i] = color;
|
for (int i = 0; (pixels != NULL) && (i < width*height); i++) pixels[i] = color;
|
||||||
|
|
||||||
Image image = {
|
Image image = {
|
||||||
.data = pixels,
|
.data = pixels,
|
||||||
@ -1228,6 +1230,11 @@ Image ImageFromImage(Image image, Rectangle rec)
|
|||||||
{
|
{
|
||||||
Image result = { 0 };
|
Image result = { 0 };
|
||||||
|
|
||||||
|
// Basic rectangle validation: size smaller than image size
|
||||||
|
if ((rec.x > 0) && (rec.y > 0) && (rec.width > 0) && (rec.height > 0) &&
|
||||||
|
(((int)rec.x + (int)rec.width) < image.width) &&
|
||||||
|
(((int)rec.y + (int)rec.height) < image.height))
|
||||||
|
{
|
||||||
int bytesPerPixel = GetPixelDataSize(1, 1, image.format);
|
int bytesPerPixel = GetPixelDataSize(1, 1, image.format);
|
||||||
|
|
||||||
result.width = (int)rec.width;
|
result.width = (int)rec.width;
|
||||||
@ -1240,6 +1247,8 @@ Image ImageFromImage(Image image, Rectangle rec)
|
|||||||
{
|
{
|
||||||
memcpy(((unsigned char *)result.data) + y*(int)rec.width*bytesPerPixel, ((unsigned char *)image.data) + ((y + (int)rec.y)*image.width + (int)rec.x)*bytesPerPixel, (int)rec.width*bytesPerPixel);
|
memcpy(((unsigned char *)result.data) + y*(int)rec.width*bytesPerPixel, ((unsigned char *)image.data) + ((y + (int)rec.y)*image.width + (int)rec.x)*bytesPerPixel, (int)rec.width*bytesPerPixel);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else TRACELOG(LOG_WARNING, "IMAGE: Rectangle provided for ImageToImage not valid");
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -2684,9 +2693,11 @@ void ImageRotate(Image *image, int degrees)
|
|||||||
int width = (int)(fabsf(image->width*cosRadius) + fabsf(image->height*sinRadius));
|
int width = (int)(fabsf(image->width*cosRadius) + fabsf(image->height*sinRadius));
|
||||||
int height = (int)(fabsf(image->height*cosRadius) + fabsf(image->width*sinRadius));
|
int height = (int)(fabsf(image->height*cosRadius) + fabsf(image->width*sinRadius));
|
||||||
|
|
||||||
int bytesPerPixel = GetPixelDataSize(1, 1, image->format);
|
int bytesPerPixel = GetPixelDataSize(width, height, image->format);
|
||||||
unsigned char *rotatedData = (unsigned char *)RL_CALLOC(width*height, bytesPerPixel);
|
unsigned char *rotatedData = (unsigned char *)RL_CALLOC(bytesPerPixel, 1);
|
||||||
|
|
||||||
|
if (rotatedData != NULL)
|
||||||
|
{
|
||||||
for (int y = 0; y < height; y++)
|
for (int y = 0; y < height; y++)
|
||||||
{
|
{
|
||||||
for (int x = 0; x < width; x++)
|
for (int x = 0; x < width; x++)
|
||||||
@ -2725,6 +2736,7 @@ void ImageRotate(Image *image, int degrees)
|
|||||||
image->height = height;
|
image->height = height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Rotate image clockwise 90deg
|
// Rotate image clockwise 90deg
|
||||||
void ImageRotateCW(Image *image)
|
void ImageRotateCW(Image *image)
|
||||||
@ -5502,8 +5514,11 @@ int GetPixelDataSize(int width, int height, int format)
|
|||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
double bytesPerPixel = (double)bpp/8.0;
|
unsigned long long dataSizeBytes = (width*height*bpp) >> 3; // Get size in bytes (dividing by 8)
|
||||||
dataSize = (int)(bytesPerPixel*width*height); // Total data size in bytes
|
|
||||||
|
if (dataSizeBytes < INT_MAX)
|
||||||
|
{
|
||||||
|
dataSize = (int)dataSizeBytes;
|
||||||
|
|
||||||
// Most compressed formats works on 4x4 blocks,
|
// Most compressed formats works on 4x4 blocks,
|
||||||
// if texture is smaller, minimum dataSize is 8 or 16
|
// if texture is smaller, minimum dataSize is 8 or 16
|
||||||
@ -5512,6 +5527,10 @@ int GetPixelDataSize(int width, int height, int format)
|
|||||||
if ((format >= PIXELFORMAT_COMPRESSED_DXT1_RGB) && (format < PIXELFORMAT_COMPRESSED_DXT3_RGBA)) dataSize = 8;
|
if ((format >= PIXELFORMAT_COMPRESSED_DXT1_RGB) && (format < PIXELFORMAT_COMPRESSED_DXT3_RGBA)) dataSize = 8;
|
||||||
else if ((format >= PIXELFORMAT_COMPRESSED_DXT3_RGBA) && (format < PIXELFORMAT_COMPRESSED_ASTC_8x8_RGBA)) dataSize = 16;
|
else if ((format >= PIXELFORMAT_COMPRESSED_DXT3_RGBA) && (format < PIXELFORMAT_COMPRESSED_ASTC_8x8_RGBA)) dataSize = 16;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: In case required image data larger than 2GB, no memory allocated at all (NULL)
|
||||||
|
if (dataSize == 0) TRACELOG(LOG_WARNING, "Requested image size is larger than 2GB, it can not be allocated");
|
||||||
|
|
||||||
return dataSize;
|
return dataSize;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user