Skip to content

Commit a9a0c04

Browse files
GideonSerfgideons
andauthored
Fix pixel data size regressions (#5984)
Co-authored-by: gideons <gse@newspacesystems.com>
1 parent d224912 commit a9a0c04

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

src/rlgl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5237,7 +5237,7 @@ static int rlGetPixelDataSize(int width, int height, int format)
52375237
{
52385238
int blockWidth = (width + 3)/4;
52395239
int blockHeight = (height + 3)/4;
5240-
unsigned long long dataSizeBytes = blockWidth*blockHeight*8;
5240+
unsigned long long dataSizeBytes = (unsigned long long)blockWidth*blockHeight*8;
52415241
if (dataSizeBytes < INT_MAX) dataSize = (int)dataSizeBytes;
52425242

52435243
} break;
@@ -5248,15 +5248,15 @@ static int rlGetPixelDataSize(int width, int height, int format)
52485248
{
52495249
int blockWidth = (width + 3)/4;
52505250
int blockHeight = (height + 3)/4;
5251-
unsigned long long dataSizeBytes = blockWidth*blockHeight*16;
5251+
unsigned long long dataSizeBytes = (unsigned long long)blockWidth*blockHeight*16;
52525252
if (dataSizeBytes < INT_MAX) dataSize = (int)dataSizeBytes;
52535253

52545254
} break;
52555255
case RL_PIXELFORMAT_COMPRESSED_ASTC_8x8_RGBA: // 4 bytes per each 4x4 block
52565256
{
52575257
int blockWidth = (width + 3)/4;
52585258
int blockHeight = (height + 3)/4;
5259-
unsigned long long dataSizeBytes = blockWidth*blockHeight*4;
5259+
unsigned long long dataSizeBytes = (unsigned long long)blockWidth*blockHeight*4;
52605260
if (dataSizeBytes < INT_MAX) dataSize = (int)dataSizeBytes;
52615261

52625262
} break;
@@ -5267,7 +5267,7 @@ static int rlGetPixelDataSize(int width, int height, int format)
52675267
if ((format >= RL_PIXELFORMAT_UNCOMPRESSED_GRAYSCALE) &&
52685268
(format <= RL_PIXELFORMAT_UNCOMPRESSED_R16G16B16A16))
52695269
{
5270-
unsigned long long dataSizeBytes = (width*height*bpp) >> 3; // Get size in bytes (dividing by 8)
5270+
unsigned long long dataSizeBytes = ((unsigned long long)width*height*bpp) >> 3; // Get size in bytes (dividing by 8)
52715271
if (dataSizeBytes < INT_MAX) dataSize = (int)dataSizeBytes;
52725272
}
52735273

src/rtextures.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2693,8 +2693,9 @@ void ImageRotate(Image *image, int degrees)
26932693
int width = (int)(fabsf(image->width*cosRadius) + fabsf(image->height*sinRadius));
26942694
int height = (int)(fabsf(image->height*cosRadius) + fabsf(image->width*sinRadius));
26952695

2696-
int bytesPerPixel = GetPixelDataSize(width, height, image->format);
2697-
unsigned char *rotatedData = (unsigned char *)RL_CALLOC(bytesPerPixel, 1);
2696+
int dataSize = GetPixelDataSize(width, height, image->format);
2697+
int bytesPerPixel = GetPixelDataSize(1, 1, image->format);
2698+
unsigned char *rotatedData = (unsigned char *)RL_CALLOC(dataSize, 1);
26982699

26992700
if (rotatedData != NULL)
27002701
{
@@ -5514,7 +5515,7 @@ int GetPixelDataSize(int width, int height, int format)
55145515
default: break;
55155516
}
55165517

5517-
unsigned long long dataSizeBytes = (width*height*bpp) >> 3; // Get size in bytes (dividing by 8)
5518+
unsigned long long dataSizeBytes = ((unsigned long long)width*height*bpp) >> 3; // Get size in bytes (dividing by 8)
55185519

55195520
if (dataSizeBytes < INT_MAX)
55205521
{

0 commit comments

Comments
 (0)