Skip to content

Commit

Permalink
WARNING: API BREAK: Removed LoadImagePro()
Browse files Browse the repository at this point in the history
Actually this function is useless and potentially dangerous, internally, a shallow copy of data was done. Same could be accomplished accesing image.data directly.
  • Loading branch information
raysan5 committed Apr 10, 2020
1 parent b132da0 commit cc81634
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 30 deletions.
29 changes: 17 additions & 12 deletions src/models.c
Original file line number Diff line number Diff line change
Expand Up @@ -3430,13 +3430,18 @@ static Image LoadImageFromCgltfImage(cgltf_image *image, const char *texPath, Co
if (image->uri[i] == 0) TRACELOG(LOG_WARNING, "IMAGE: glTF data URI is not a valid image");
else
{
int size;
int size = 0;
unsigned char *data = DecodeBase64(image->uri + i + 1, &size);

int w, h;
unsigned char *raw = stbi_load_from_memory(data, size, &w, &h, NULL, 4);
int width, height;
unsigned char *raw = stbi_load_from_memory(data, size, &width, &height, NULL, 4);
free(data);

rimage = LoadImagePro(raw, w, h, UNCOMPRESSED_R8G8B8A8);
rimage.data = raw;
rimage.width = width;
rimage.height = height;
rimage.format = UNCOMPRESSED_R8G8B8A8;
rimage.mipmaps = 1;

// TODO: Tint shouldn't be applied here!
ImageColorTint(&rimage, tint);
Expand All @@ -3462,20 +3467,20 @@ static Image LoadImageFromCgltfImage(cgltf_image *image, const char *texPath, Co
n += stride;
}

int w, h;
unsigned char *raw = stbi_load_from_memory(data, image->buffer_view->size, &w, &h, NULL, 4);
int width, height;
unsigned char *raw = stbi_load_from_memory(data, image->buffer_view->size, &width, &height, NULL, 4);
free(data);

rimage = LoadImagePro(raw, w, h, UNCOMPRESSED_R8G8B8A8);
free(raw);
rimage.data = raw;
rimage.width = width;
rimage.height = height;
rimage.format = UNCOMPRESSED_R8G8B8A8;
rimage.mipmaps = 1;

// TODO: Tint shouldn't be applied here!
ImageColorTint(&rimage, tint);
}
else
{
rimage = LoadImageEx(&tint, 1, 1);
}
else rimage = GenImageColor(1, 1, tint);

return rimage;
}
Expand Down
1 change: 0 additions & 1 deletion src/raylib.h
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,6 @@ RLAPI bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Ve
// NOTE: This functions do not require GPU access
RLAPI Image LoadImage(const char *fileName); // Load image from file into CPU memory (RAM)
RLAPI Image LoadImageEx(Color *pixels, int width, int height); // Load image from Color array data (RGBA - 32bit)
RLAPI Image LoadImagePro(void *data, int width, int height, int format); // Load image from raw data with parameters
RLAPI Image LoadImageRaw(const char *fileName, int width, int height, int format, int headerSize); // Load image from RAW file data
RLAPI void UnloadImage(Image image); // Unload image from CPU memory (RAM)
RLAPI void ExportImage(Image image, const char *fileName); // Export image data to file
Expand Down
17 changes: 0 additions & 17 deletions src/textures.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,23 +332,6 @@ Image LoadImageEx(Color *pixels, int width, int height)
return image;
}

// Load image from raw data with parameters
// NOTE: This functions makes a copy of provided data
Image LoadImagePro(void *data, int width, int height, int format)
{
Image srcImage = { 0 };

srcImage.data = data;
srcImage.width = width;
srcImage.height = height;
srcImage.mipmaps = 1;
srcImage.format = format;

Image dstImage = ImageCopy(srcImage);

return dstImage;
}

// Load an image from RAW file data
Image LoadImageRaw(const char *fileName, int width, int height, int format, int headerSize)
{
Expand Down

0 comments on commit cc81634

Please sign in to comment.