Browse Source

Merge pull request #504 from Martinfx/master

Fix potential bugs from static analysis
pull/518/head
Ray 7 years ago
committed by GitHub
parent
commit
3e0de31424
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 110 additions and 126 deletions
  1. +11
    -12
      examples/core/core_3d_picking.c
  2. +33
    -33
      examples/models/models_yaw_pitch_roll.c
  3. +9
    -9
      examples/others/audio_standalone.c
  4. +11
    -12
      examples/others/bunnymark.c
  5. +3
    -3
      examples/physac/physics_shatter.c
  6. +1
    -1
      src/audio.c
  7. +2
    -16
      src/external/jar_xm.h
  8. +0
    -1
      src/external/rgif.h
  9. +1
    -1
      src/gestures.h
  10. +7
    -7
      src/models.c
  11. +2
    -2
      src/rlgl.c
  12. +30
    -29
      src/textures.c

+ 11
- 12
examples/core/core_3d_picking.c View File

@ -29,11 +29,11 @@ int main()
Vector3 cubePosition = { 0.0f, 1.0f, 0.0f };
Vector3 cubeSize = { 2.0f, 2.0f, 2.0f };
Ray ray; // Picking line ray
Ray ray = {0.0f, 0.0f, 0.0f}; // Picking line ray
bool collision = false;
SetCameraMode(camera, CAMERA_FREE); // Set a free camera mode
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
@ -45,11 +45,11 @@ int main()
// Update
//----------------------------------------------------------------------------------
UpdateCamera(&camera); // Update camera
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
{
ray = GetMouseRay(GetMousePosition(), camera);
// Check collision between ray and box
collision = CheckCollisionRayBox(ray,
(BoundingBox){(Vector3){ cubePosition.x - cubeSize.x/2, cubePosition.y - cubeSize.y/2, cubePosition.z - cubeSize.z/2 },
@ -65,7 +65,7 @@ int main()
Begin3dMode(camera);
if (collision)
if (collision)
{
DrawCube(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, RED);
DrawCubeWires(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, MAROON);
@ -77,15 +77,14 @@ int main()
DrawCube(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, GRAY);
DrawCubeWires(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, DARKGRAY);
}
DrawRay(ray, MAROON);
DrawGrid(10, 1.0f);
End3dMode();
DrawText("Try selecting the box with mouse!", 240, 10, 20, DARKGRAY);
if(collision) DrawText("BOX SELECTED", (screenWidth - MeasureText("BOX SELECTED", 30)) / 2, screenHeight * 0.1f, 30, GREEN);
DrawFPS(10, 10);
@ -100,4 +99,4 @@ int main()
//--------------------------------------------------------------------------------------
return 0;
}
}

+ 33
- 33
examples/models/models_yaw_pitch_roll.c View File

@ -5,7 +5,7 @@
* This example has been created using raylib 1.8 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Example based on Berni work on Raspberry Pi:
* Example based on Berni work on Raspberry Pi:
* http://forum.raylib.com/index.php?p=/discussion/124/line-versus-triangle-drawing-order
*
* Copyright (c) 2017 Ramon Santamaria (@raysan5)
@ -30,25 +30,25 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [models] example - plane rotations (yaw, pitch, roll)");
Texture2D texAngleGauge = LoadTexture("resources/angle_gauge.png");
Texture2D texAngleGauge = LoadTexture("resources/angle_gauge.png");
Texture2D texBackground = LoadTexture("resources/background.png");
Texture2D texPitch = LoadTexture("resources/pitch.png");
Texture2D texPitch = LoadTexture("resources/pitch.png");
Texture2D texPlane = LoadTexture("resources/plane.png");
RenderTexture2D framebuffer = LoadRenderTexture(192, 192);
// Model loading
Model model = LoadModel("resources/plane.obj"); // Load OBJ model
model.material.maps[MAP_DIFFUSE].texture = LoadTexture("resources/plane_diffuse.png"); // Set map diffuse texture
GenTextureMipmaps(&model.material.maps[MAP_DIFFUSE].texture);
Camera camera = { 0 };
camera.position = (Vector3){ 0.0f, 60.0f, -120.0f };// Camera position perspective
camera.target = (Vector3){ 0.0f, 12.0f, 0.0f }; // Camera looking at point
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
camera.fovy = 30.0f; // Camera field-of-view Y
float pitch = 0.0f;
float roll = 0.0f;
float yaw = 0.0f;
@ -61,7 +61,7 @@ int main()
{
// Update
//----------------------------------------------------------------------------------
// Plane roll (x-axis) controls
if (IsKeyDown(KEY_LEFT)) roll += 1.0f;
else if (IsKeyDown(KEY_RIGHT)) roll -= 1.0f;
@ -70,7 +70,7 @@ int main()
if (roll > 0.0f) roll -= 0.5f;
else if (roll < 0.0f) roll += 0.5f;
}
// Plane yaw (y-axis) controls
if (IsKeyDown(KEY_S)) yaw += 1.0f;
else if (IsKeyDown(KEY_A)) yaw -= 1.0f;
@ -79,7 +79,7 @@ int main()
if (yaw > 0.0f) yaw -= 0.5f;
else if (yaw < 0.0f) yaw += 0.5f;
}
// Plane pitch (z-axis) controls
if (IsKeyDown(KEY_DOWN)) pitch += 0.6f;
else if (IsKeyDown(KEY_UP)) pitch -= 0.6f;
@ -88,7 +88,7 @@ int main()
if (pitch > 0.3f) pitch -= 0.3f;
else if (pitch < -0.3f) pitch += 0.3f;
}
// Wraps the phase of an angle to fit between -180 and +180 degrees
int pitchOffset = pitch;
while (pitchOffset > 180) pitchOffset -= 360;
@ -96,20 +96,20 @@ int main()
pitchOffset *= 10;
Matrix transform = MatrixIdentity();
transform = MatrixMultiply(transform, MatrixRotateZ(DEG2RAD*roll));
transform = MatrixMultiply(transform, MatrixRotateX(DEG2RAD*pitch));
transform = MatrixMultiply(transform, MatrixRotateY(DEG2RAD*yaw));
model.transform = transform;
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
// Draw framebuffer texture (Ahrs Display)
int centerX = framebuffer.texture.width/2;
int centerY = framebuffer.texture.height/2;
@ -126,11 +126,11 @@ int main()
DrawTexturePro(texPitch, (Rectangle){ 0, 0, texPitch.width, texPitch.height },
(Rectangle){ centerX, centerY, texPitch.width*scaleFactor, texPitch.height*scaleFactor },
(Vector2){ texPitch.width/2*scaleFactor, texPitch.height/2*scaleFactor + pitchOffset*scaleFactor }, roll, WHITE);
DrawTexturePro(texPlane, (Rectangle){ 0, 0, texPlane.width, texPlane.height },
(Rectangle){ centerX, centerY, texPlane.width*scaleFactor, texPlane.height*scaleFactor },
(Rectangle){ centerX, centerY, texPlane.width*scaleFactor, texPlane.height*scaleFactor },
(Vector2){ texPlane.width/2*scaleFactor, texPlane.height/2*scaleFactor }, 0, WHITE);
EndBlendMode();
EndTextureMode();
@ -147,7 +147,7 @@ int main()
DrawAngleGauge(texAngleGauge, 80, 70, roll, "roll", RED);
DrawAngleGauge(texAngleGauge, 190, 70, pitch, "pitch", GREEN);
DrawAngleGauge(texAngleGauge, 300, 70, yaw, "yaw", SKYBLUE);
DrawRectangle(30, 360, 260, 70, Fade(SKYBLUE, 0.5f));
DrawRectangleLines(30, 360, 260, 70, Fade(DARKBLUE, 0.5f));
DrawText("Pitch controlled with: KEY_UP / KEY_DOWN", 40, 370, 10, DARKGRAY);
@ -155,31 +155,31 @@ int main()
DrawText("Yaw controlled with: KEY_A / KEY_S", 40, 410, 10, DARKGRAY);
// Draw framebuffer texture
DrawTextureRec(framebuffer.texture, (Rectangle){ 0, 0, framebuffer.texture.width, -framebuffer.texture.height },
DrawTextureRec(framebuffer.texture, (Rectangle){ 0, 0, framebuffer.texture.width, -framebuffer.texture.height },
(Vector2){ screenWidth - framebuffer.texture.width - 20, 20 }, Fade(WHITE, 0.8f));
DrawRectangleLines(screenWidth - framebuffer.texture.width - 20, 20, framebuffer.texture.width, framebuffer.texture.height, DARKGRAY);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
// Unload all loaded data
UnloadModel(model);
UnloadRenderTexture(framebuffer);
UnloadTexture(texAngleGauge);
UnloadTexture(texAngleGauge);
UnloadTexture(texBackground);
UnloadTexture(texPitch);
UnloadTexture(texPitch);
UnloadTexture(texPlane);
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}
@ -192,7 +192,7 @@ void DrawAngleGauge(Texture2D angleGauge, int x, int y, float angle, char title[
int textSize = 20;
DrawTexturePro(angleGauge, srcRec, dstRec, origin, angle, color);
DrawText(FormatText("%5.1f°", angle), x - MeasureText(FormatText("%5.1f°", angle), textSize) / 2, y + 10, textSize, DARKGRAY);
DrawText(title, x - MeasureText(title, textSize) / 2, y + 60, textSize, DARKGRAY);
}
DrawText(FormatText("%5.1f", angle), x - MeasureText(FormatText("%5.1f", angle), textSize) / 2, y + 10, textSize, DARKGRAY);
DrawText(title, x - MeasureText(title, textSize) / 2, y + 60, textSize, DARKGRAY);
}

+ 9
- 9
examples/others/audio_standalone.c View File

@ -76,13 +76,13 @@ int main()
{
// Initialization
//--------------------------------------------------------------------------------------
unsigned char key;
">static unsigned char key;
InitAudioDevice();
Sound fxWav = LoadSound("resources/audio/weird.wav"); // Load WAV audio file
Sound fxOgg = LoadSound("resources/audio/tanatana.ogg"); // Load OGG audio file
Music music = LoadMusicStream("resources/audio/guitar_noodling.ogg");
PlayMusicStream(music);
@ -99,23 +99,23 @@ int main()
PlaySound(fxWav);
key = 0;
}
if (key == 'd')
{
PlaySound(fxOgg);
key = 0;
}
UpdateMusicStream(music);
}
// De-Initialization
//--------------------------------------------------------------------------------------
UnloadSound(fxWav); // Unload sound data
UnloadSound(fxOgg); // Unload sound data
UnloadMusicStream(music); // Unload music stream data
CloseAudioDevice();
//--------------------------------------------------------------------------------------

+ 11
- 12
examples/others/bunnymark.c View File

@ -10,7 +10,6 @@
********************************************************************************************/
#include "raylib.h"
#include <stdlib.h> // Required for: malloc(), free()
#define MAX_BUNNIES 100000 // 100K bunnies
@ -29,15 +28,16 @@ int main()
int screenHeight = 960;
InitWindow(screenWidth, screenHeight, "raylib example - Bunnymark");
Texture2D texBunny = LoadTexture("resources/wabbit_alpha.png");
Bunny *bunnies = (Bunny *)malloc(MAX_BUNNIES*sizeof(Bunny)); // Bunnies array
int bunniesCount = 0; // Bunnies counter
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
@ -54,7 +54,7 @@ int main()
bunniesCount++;
}
}
// Update bunnies
for (int i = 0; i < bunniesCount; i++)
{
@ -65,14 +65,14 @@ int main()
if ((bunnies[i].position.y > GetScreenHeight()) || (bunnies[i].position.y < 0)) bunnies[i].speed.y *= -1;
}
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
for (int i = 0; i <= bunniesCount; i++)
for (int i = 0; i < bunniesCount; i++)
{
// NOTE: When internal QUADS batch limit is reached, a draw call is launched and
// batching buffer starts being filled again; before launching the draw call,
@ -80,11 +80,10 @@ int main()
// a stall and consequently a frame drop, limiting number of bunnies drawn at 60 fps
DrawTexture(texBunny, bunnies[i].position.x, bunnies[i].position.y, RAYWHITE);
}
DrawRectangle(0, 0, screenWidth, 40, LIGHTGRAY);
DrawText("raylib bunnymark", 10, 10, 20, DARKGRAY);
DrawText(FormatText("bunnies: %i", bunniesCount), 400, 10, 20, RED);
DrawFPS(260, 10);
EndDrawing();
@ -94,9 +93,9 @@ int main()
// De-Initialization
//--------------------------------------------------------------------------------------
free(bunnies);
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}
}

+ 3
- 3
examples/physac/physics_shatter.c View File

@ -39,8 +39,8 @@ int main()
SetPhysicsGravity(0, 0);
// Create random polygon physics body to shatter
PhysicsBody body = CreatePhysicsBodyPolygon((Vector2){ screenWidth/2, screenHeight/2 }, GetRandomValue(80, 200), GetRandomValue(3, 8), 10);
CreatePhysicsBodyPolygon((Vector2){ screenWidth/2, screenHeight/2 }, GetRandomValue(80, 200), GetRandomValue(3, 8), 10);
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
@ -53,7 +53,7 @@ int main()
if (needsReset)
{
// Create random polygon physics body to shatter
body = CreatePhysicsBodyPolygon((Vector2){ screenWidth/2, screenHeight/2 }, GetRandomValue(80, 200), GetRandomValue(3, 8), 10);
CreatePhysicsBodyPolygon((Vector2){ screenWidth/2, screenHeight/2 }, GetRandomValue(80, 200), GetRandomValue(3, 8), 10);
}
if (IsKeyPressed('R')) // Reset physics input

+ 1
- 1
src/audio.c View File

@ -1553,7 +1553,7 @@ void UpdateMusicStream(Music music)
case MUSIC_AUDIO_OGG:
{
// NOTE: Returns the number of samples to process (be careful! we ask for number of shorts!)
kt">int numSamplesOgg = stb_vorbis_get_samples_short_interleaved(music->ctxOgg, music->stream.channels, (short *)pcm, samplesCount*music->stream.channels);
stb_vorbis_get_samples_short_interleaved(music->ctxOgg, music->stream.channels, (short *)pcm, samplesCount*music->stream.channels);
} break;
#if defined(SUPPORT_FILEFORMAT_FLAC)

+ 2
- 16
src/external/jar_xm.h View File

@ -855,8 +855,6 @@ size_t jar_xm_get_memory_needed_for_context(const char* moddata, size_t moddata_
uint16_t num_instruments;
/* Read the module header */
num_channels = READ_U16(offset + 8);
num_channels = READ_U16(offset + 8);
num_patterns = READ_U16(offset + 10);
@ -2561,28 +2559,22 @@ uint64_t jar_xm_get_remaining_samples(jar_xm_context_t* ctx)
uint64_t total = 0;
uint8_t currentLoopCount = jar_xm_get_loop_count(ctx);
jar_xm_set_max_loop_count(ctx, 0);
while(jar_xm_get_loop_count(ctx) == currentLoopCount)
{
total += ctx->remaining_samples_in_tick;
ctx->remaining_samples_in_tick = 0;
jar_xm_tick(ctx);
}
ctx->loop_count = currentLoopCount;
return total;
}
//--------------------------------------------
//FILE LOADER - TODO - NEEDS TO BE CLEANED UP
//--------------------------------------------
#undef DEBUG
#define DEBUG(...) do { \
fprintf(stderr, __VA_ARGS__); \
@ -2668,13 +2660,7 @@ int jar_xm_create_context_from_file(jar_xm_context_t** ctx, uint32_t rate, const
return 0;
}
#endif//end of JAR_XM_IMPLEMENTATION
//-------------------------------------------------------------------------------
#endif//end of INCLUDE_JAR_XM_H

+ 0
- 1
src/external/rgif.h View File

@ -911,7 +911,6 @@ static void GifWriteLzwImage(FILE *f, unsigned char *image, unsigned int left, u
GifWriteCode(f, &stat, clearCode, codeSize); // clear tree
memset(codetree, 0, sizeof(GifLzwNode)*4096);
curCode = -1;
codeSize = minCodeSize + 1;
maxCode = clearCode + 1;
}

+ 1
- 1
src/gestures.h View File

@ -493,7 +493,7 @@ float GetGesturePinchAngle(void)
// Returns angle from two-points vector with X-axis
static float Vector2Angle(Vector2 v1, Vector2 v2)
{
float angle = angle = atan2f(v2.y - v1.y, v2.x - v1.x)*(180.0f/PI);
float angle = atan2f(v2.y - v1.y, v2.x - v1.x)*(180.0f/PI);
if (angle < 0) angle += 360.0f;

+ 7
- 7
src/models.c View File

@ -2347,7 +2347,7 @@ static Mesh LoadOBJ(const char *fileName)
// NOTE: Texture map parameters are not supported
static Material LoadMTL(const char *fileName)
{
#define MAX_BUFFER_SIZE 128
#define MAX_BUFFER_SIZE 128
Material material = { 0 };
@ -2375,7 +2375,7 @@ static Material LoadMTL(const char *fileName)
case 'n': // newmtl string Material name. Begins a new material description.
{
// TODO: Support multiple materials in a single .mtl
sscanf(buffer, "newmtl %s", mapFileName);
sscanf(buffer, "newmtl %127s", mapFileName);
TraceLog(LOG_INFO, "[%s] Loading material...", mapFileName);
}
@ -2440,12 +2440,12 @@ static Material LoadMTL(const char *fileName)
{
if (buffer[5] == 'd') // map_Kd string Diffuse color texture map.
{
result = sscanf(buffer, "map_Kd %s", mapFileName);
result = sscanf(buffer, "map_Kd %127s", mapFileName);
if (result != EOF) material.maps[MAP_DIFFUSE].texture = LoadTexture(mapFileName);
}
else if (buffer[5] == 's') // map_Ks string Specular color texture map.
{
result = sscanf(buffer, "map_Ks %s", mapFileName);
result = sscanf(buffer, "map_Ks %127s", mapFileName);
if (result != EOF) material.maps[MAP_SPECULAR].texture = LoadTexture(mapFileName);
}
else if (buffer[5] == 'a') // map_Ka string Ambient color texture map.
@ -2455,12 +2455,12 @@ static Material LoadMTL(const char *fileName)
} break;
case 'B': // map_Bump string Bump texture map.
{
result = sscanf(buffer, "map_Bump %s", mapFileName);
result = sscanf(buffer, "map_Bump %127s", mapFileName);
if (result != EOF) material.maps[MAP_NORMAL].texture = LoadTexture(mapFileName);
} break;
case 'b': // map_bump string Bump texture map.
{
result = sscanf(buffer, "map_bump %s", mapFileName);
result = sscanf(buffer, "map_bump %127s", mapFileName);
if (result != EOF) material.maps[MAP_NORMAL].texture = LoadTexture(mapFileName);
} break;
case 'd': // map_d string Opacity texture map.
@ -2485,7 +2485,7 @@ static Material LoadMTL(const char *fileName)
} break;
case 'b': // bump string Bump texture map
{
result = sscanf(buffer, "bump %s", mapFileName);
result = sscanf(buffer, "bump %127s", mapFileName);
if (result != EOF) material.maps[MAP_NORMAL].texture = LoadTexture(mapFileName);
} break;
case 'T': // Tr float Transparency Tr (alpha). Tr is inverse of d

+ 2
- 2
src/rlgl.c View File

@ -3373,9 +3373,9 @@ static void LoadBuffersDefault(void)
quads.texcoords = (float *)malloc(sizeof(float)*2*4*MAX_QUADS_BATCH); // 2 float by texcoord, 4 texcoord by quad
quads.colors = (unsigned char *)malloc(sizeof(unsigned char)*4*4*MAX_QUADS_BATCH); // 4 float by color, 4 colors by quad
#if defined(GRAPHICS_API_OPENGL_33)
quads.indices = (unsigned int *)malloc(sizeof(int)*6*MAX_QUADS_BATCH); // 6 int by quad (indices)
quads.indices = (unsigned int *)malloc(sizeof(unsigned int)*6*MAX_QUADS_BATCH); // 6 int by quad (indices)
#elif defined(GRAPHICS_API_OPENGL_ES2)
quads.indices = (unsigned short *)malloc(sizeof(short)*6*MAX_QUADS_BATCH); // 6 int by quad (indices)
quads.indices = (unsigned short *)malloc(sizeof(unsigned short)*6*MAX_QUADS_BATCH); // 6 int by quad (indices)
#endif
for (int i = 0; i < (3*4*MAX_QUADS_BATCH); i++) quads.vertices[i] = 0.0f;

+ 30
- 29
src/textures.c View File

@ -16,7 +16,7 @@
* #define SUPPORT_FILEFORMAT_KTX
* #define SUPPORT_FILEFORMAT_PVR
* #define SUPPORT_FILEFORMAT_ASTC
* Selecte desired fileformats to be supported for image data loading. Some of those formats are
* Selecte desired fileformats to be supported for image data loading. Some of those formats are
* supported by default, to remove support, just comment unrequired #define in this module
*
* #define SUPPORT_IMAGE_MANIPULATION
@ -112,7 +112,7 @@
#include "external/stb_image.h" // Required for: stbi_load_from_file()
// NOTE: Used to read image data (multiple formats support)
#endif
#if defined(SUPPORT_IMAGE_MANIPULATION)
#define STB_IMAGE_RESIZE_IMPLEMENTATION
#include "external/stb_image_resize.h" // Required for: stbir_resize_uint8()
@ -188,14 +188,14 @@ Image LoadImage(const char *fileName)
int imgWidth = 0;
int imgHeight = 0;
int imgBpp = 0;
FILE *imFile = fopen(fileName, "rb");
if (imFile != NULL)
{
// NOTE: Using stb_image to load images (Supports: BMP, TGA, PNG, JPG, ...)
image.data = stbi_load_from_file(imFile, &imgWidth, &imgHeight, &imgBpp, 0);
fclose(imFile);
image.width = imgWidth;
@ -212,24 +212,24 @@ Image LoadImage(const char *fileName)
else if (IsFileExtension(fileName, ".hdr"))
{
int imgBpp = 0;
FILE *imFile = fopen(fileName, "rb");
stbi_set_flip_vertically_on_load(true);
// Load 32 bit per channel floats data
// Load 32 bit per channel floats data
image.data = stbi_loadf_from_file(imFile, &image.width, &image.height, &imgBpp, 0);
stbi_set_flip_vertically_on_load(false);
fclose(imFile);
image.mipmaps = 1;
if (imgBpp == 1) image.format = UNCOMPRESSED_R32;
else if (imgBpp == 3) image.format = UNCOMPRESSED_R32G32B32;
else if (imgBpp == 4) image.format = UNCOMPRESSED_R32G32B32A32;
else
else
{
TraceLog(LOG_WARNING, "[%s] Image fileformat not supported", fileName);
UnloadImage(image);
@ -319,10 +319,10 @@ Image LoadImageRaw(const char *fileName, int width, int height, int format, int
if (headerSize > 0) fseek(rawFile, headerSize, SEEK_SET);
unsigned int size = GetPixelDataSize(width, height, format);
image.data = malloc(size); // Allocate required memory in bytes
// NOTE: fread() returns num read elements instead of bytes,
// NOTE: fread() returns num read elements instead of bytes,
// to get bytes we need to read (1 byte size, elements) instead of (x byte size, 1 element)
int bytes = fread(image.data, 1, size, rawFile);
@ -430,7 +430,7 @@ Color *GetImageData(Image image)
pixels[i].g = ((unsigned char *)image.data)[i];
pixels[i].b = ((unsigned char *)image.data)[i];
pixels[i].a = 255;
} break;
case UNCOMPRESSED_GRAY_ALPHA:
{
@ -469,7 +469,7 @@ Color *GetImageData(Image image)
pixels[i].g = (unsigned char)((float)((pixel & 0b0000111100000000) >> 8)*(255/15));
pixels[i].b = (unsigned char)((float)((pixel & 0b0000000011110000) >> 4)*(255/15));
pixels[i].a = (unsigned char)((float)(pixel & 0b0000000000001111)*(255/15));
} break;
case UNCOMPRESSED_R8G8B8A8:
{
@ -516,7 +516,7 @@ int GetPixelDataSize(int width, int height, int format)
case UNCOMPRESSED_R32G32B32: bpp = 32*3; break;
case UNCOMPRESSED_R32G32B32A32: bpp = 32*4; break;
case COMPRESSED_DXT1_RGB:
case COMPRESSED_DXT1_RGBA:
case COMPRESSED_DXT1_RGBA:
case COMPRESSED_ETC1_RGB:
case COMPRESSED_ETC2_RGB:
case COMPRESSED_PVRT_RGB:
@ -530,7 +530,7 @@ int GetPixelDataSize(int width, int height, int format)
}
dataSize = width*height*bpp/8; // Total data size in bytes
return dataSize;
}
@ -539,7 +539,7 @@ int GetPixelDataSize(int width, int height, int format)
Image GetTextureData(Texture2D texture)
{
Image image = { 0 };
if (texture.format < 8)
{
image.data = rlReadTexturePixels(texture);
@ -550,7 +550,7 @@ Image GetTextureData(Texture2D texture)
image.height = texture.height;
image.format = texture.format;
image.mipmaps = 1;
// NOTE: Data retrieved on OpenGL ES 2.0 should be RGBA
// coming from FBO color buffer, but it seems original
// texture format is retrieved on RPI... weird...
@ -597,15 +597,15 @@ Image ImageCopy(Image image)
for (int i = 0; i < image.mipmaps; i++)
{
size += GetPixelDataSize(width, height, image.format);
width /= 2;
height /= 2;
// Security check for NPOT textures
if (width < 1) width = 1;
if (height < 1) height = 1;
}
newImage.data = malloc(size);
if (newImage.data != NULL)
@ -677,7 +677,7 @@ void ImageFormat(Image *image, int newFormat)
Color *pixels = GetImageData(*image);
free(image->data); // WARNING! We loose mipmaps data --> Regenerated at the end...
image->data = NULL;
image->format = newFormat;
int k = 0;
@ -771,7 +771,7 @@ void ImageFormat(Image *image, int newFormat)
g = (unsigned char)(round((float)pixels[i].g*15.0f/255));
b = (unsigned char)(round((float)pixels[i].b*15.0f/255));
a = (unsigned char)(round((float)pixels[i].a*15.0f/255));
((unsigned short *)image->data)[i] = (unsigned short)r << 12 | (unsigned short)g << 8 | (unsigned short)b << 4 | (unsigned short)a;
}
@ -791,7 +791,7 @@ void ImageFormat(Image *image, int newFormat)
case UNCOMPRESSED_R32:
{
image->data = (float *)malloc(image->width*image->height*sizeof(float));
for (int i = 0; i < image->width*image->height; i++)
{
((float *)image->data)[i] = (float)((float)pixels[i].r*0.299f/255.0f + (float)pixels[i].g*0.587f/255.0f + (float)pixels[i].b*0.114f/255.0f);
@ -824,12 +824,13 @@ void ImageFormat(Image *image, int newFormat)
}
free(pixels);
pixels = NULL;
// In case original image had mipmaps, generate mipmaps for formated image
// NOTE: Original mipmaps are replaced by new ones, if custom mipmaps were used, they are lost
if (image->mipmaps > 1)
if (image->mipmaps > 1)
{
image->mipmaps = 1;
assert(image->data != NULL);
ImageMipmaps(image);
}
}

Loading…
Cancel
Save