mirror of
https://github.com/raysan5/raylib.git
synced 2025-10-05 01:16:28 +00:00
Merge branch 'master' of https://github.com/raysan5/raylib
This commit is contained in:
@@ -48,8 +48,14 @@
|
||||
*
|
||||
**********************************************************************************************/
|
||||
|
||||
#include "SDL.h" // SDL base library (window/rendered, input, timming... functionality)
|
||||
#include "SDL_opengl.h" // SDL OpenGL functionality (if required, instead of internal renderer)
|
||||
#include "SDL.h" // SDL base library (window/rendered, input, timming... functionality)
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_ES2)
|
||||
// It seems it does not need to be included to work
|
||||
//#include "SDL_opengles2.h"
|
||||
#else
|
||||
#include "SDL_opengl.h" // SDL OpenGL functionality (if required, instead of internal renderer)
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
|
@@ -167,6 +167,10 @@ typedef struct tagBITMAPINFOHEADER {
|
||||
#define MA_NO_WAV
|
||||
#define MA_NO_FLAC
|
||||
#define MA_NO_MP3
|
||||
#define MA_NO_RESOURCE_MANAGER
|
||||
#define MA_NO_NODE_GRAPH
|
||||
#define MA_NO_ENGINE
|
||||
#define MA_NO_GENERATION
|
||||
|
||||
// Threading model: Default: [0] COINIT_MULTITHREADED: COM calls objects on any thread (free threading)
|
||||
#define MA_COINIT_VALUE 2 // [2] COINIT_APARTMENTTHREADED: Each object has its own thread (apartment model)
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/**********************************************************************************************
|
||||
*
|
||||
* raylib v5.0 - A simple and easy-to-use library to enjoy videogames programming (www.raylib.com)
|
||||
* raylib v5.1-dev - A simple and easy-to-use library to enjoy videogames programming (www.raylib.com)
|
||||
*
|
||||
* FEATURES:
|
||||
* - NO external dependencies, all required libraries included with raylib
|
||||
@@ -82,9 +82,9 @@
|
||||
#include <stdarg.h> // Required for: va_list - Only used by TraceLogCallback
|
||||
|
||||
#define RAYLIB_VERSION_MAJOR 5
|
||||
#define RAYLIB_VERSION_MINOR 0
|
||||
#define RAYLIB_VERSION_MINOR 1
|
||||
#define RAYLIB_VERSION_PATCH 0
|
||||
#define RAYLIB_VERSION "5.0"
|
||||
#define RAYLIB_VERSION "5.1-dev"
|
||||
|
||||
// Function specifiers in case library is build/used as a shared library (Windows)
|
||||
// NOTE: Microsoft specifiers to tell compiler that symbols are imported/exported from a .dll
|
||||
@@ -1329,6 +1329,7 @@ RLAPI void ImageAlphaClear(Image *image, Color color, float threshold);
|
||||
RLAPI void ImageAlphaMask(Image *image, Image alphaMask); // Apply alpha mask to image
|
||||
RLAPI void ImageAlphaPremultiply(Image *image); // Premultiply alpha channel
|
||||
RLAPI void ImageBlurGaussian(Image *image, int blurSize); // Apply Gaussian blur using a box blur approximation
|
||||
RLAPI void ImageKernelConvolution(Image *image, float* kernel, int kernelSize); // Apply Custom Square image convolution kernel
|
||||
RLAPI void ImageResize(Image *image, int newWidth, int newHeight); // Resize image (Bicubic scaling algorithm)
|
||||
RLAPI void ImageResizeNN(Image *image, int newWidth,int newHeight); // Resize image (Nearest-Neighbor scaling algorithm)
|
||||
RLAPI void ImageResizeCanvas(Image *image, int newWidth, int newHeight, int offsetX, int offsetY, Color fill); // Resize canvas and fill with color
|
||||
|
@@ -5155,16 +5155,29 @@ static Model LoadGLTF(const char *fileName)
|
||||
|
||||
if ((attribute->component_type == cgltf_component_type_r_8u) && (attribute->type == cgltf_type_vec4))
|
||||
{
|
||||
// Init raylib mesh bone ids to copy glTF attribute data
|
||||
// Handle 8-bit unsigned byte, vec4 format
|
||||
model.meshes[meshIndex].boneIds = RL_CALLOC(model.meshes[meshIndex].vertexCount*4, sizeof(unsigned char));
|
||||
|
||||
// Load 4 components of unsigned char data type into mesh.boneIds
|
||||
// for cgltf_attribute_type_joints we have:
|
||||
// - data.meshes[0] (256 vertices)
|
||||
// - 256 values, provided as cgltf_type_vec4 of bytes (4 byte per joint, stride 4)
|
||||
LOAD_ATTRIBUTE(attribute, 4, unsigned char, model.meshes[meshIndex].boneIds)
|
||||
}
|
||||
else TRACELOG(LOG_WARNING, "MODEL: [%s] Joint attribute data format not supported, use vec4 u8", fileName);
|
||||
else if ((attribute->component_type == cgltf_component_type_r_16u) && (attribute->type == cgltf_type_vec2))
|
||||
{
|
||||
// Handle 16-bit unsigned short, vec2 format
|
||||
model.meshes[meshIndex].boneIds = RL_CALLOC(model.meshes[meshIndex].vertexCount*2, sizeof(unsigned short));
|
||||
LOAD_ATTRIBUTE(attribute, 2, unsigned short, model.meshes[meshIndex].boneIds)
|
||||
}
|
||||
else if ((attribute->component_type == cgltf_component_type_r_32u) && (attribute->type == cgltf_type_vec4))
|
||||
{
|
||||
// Handle 32-bit unsigned int, vec4 format
|
||||
model.meshes[meshIndex].boneIds = RL_CALLOC(model.meshes[meshIndex].vertexCount*4, sizeof(unsigned int));
|
||||
LOAD_ATTRIBUTE(attribute, 4, unsigned int, model.meshes[meshIndex].boneIds)
|
||||
}
|
||||
else if ((attribute->component_type == cgltf_component_type_r_32f) && (attribute->type == cgltf_type_vec2))
|
||||
{
|
||||
// Handle 32-bit float, vec2 format
|
||||
model.meshes[meshIndex].boneIds = RL_CALLOC(model.meshes[meshIndex].vertexCount*2, sizeof(float));
|
||||
LOAD_ATTRIBUTE(attribute, 2, float, model.meshes[meshIndex].boneIds)
|
||||
}
|
||||
else TRACELOG(LOG_WARNING, "MODEL: [%s] Joint attribute data format not supported", fileName);
|
||||
}
|
||||
else if (data->meshes[i].primitives[p].attributes[j].type == cgltf_attribute_type_weights) // WEIGHTS_n (vec4 / u8, u16, f32)
|
||||
{
|
||||
|
142
src/rtextures.c
142
src/rtextures.c
@@ -2082,6 +2082,148 @@ void ImageBlurGaussian(Image *image, int blurSize) {
|
||||
ImageFormat(image, format);
|
||||
}
|
||||
|
||||
// The kernel matrix is assumed to be square. Only supply the width of the kernel.
|
||||
void ImageKernelConvolution(Image *image, float* kernel, int kernelSize){
|
||||
|
||||
if ((image->data == NULL) || (image->width == 0) || (image->height == 0) || kernel == NULL) return;
|
||||
|
||||
int kernelWidth = (int)sqrtf((float)kernelSize);
|
||||
if (kernelWidth*kernelWidth != kernelSize)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "IMAGE: Convolution kernel must be square to be applied");
|
||||
return;
|
||||
}
|
||||
|
||||
Color *pixels = LoadImageColors(*image);
|
||||
|
||||
Vector4 *imageCopy2 = RL_MALLOC((image->height)*(image->width)*sizeof(Vector4));
|
||||
Vector4 *temp = RL_MALLOC(kernelSize*sizeof(Vector4));
|
||||
|
||||
|
||||
for(int i = 0; i < kernelSize; i++){
|
||||
temp[i].x = 0.0f;
|
||||
temp[i].y = 0.0f;
|
||||
temp[i].z = 0.0f;
|
||||
temp[i].w = 0.0f;
|
||||
}
|
||||
|
||||
float rRes = 0.0f;
|
||||
float gRes = 0.0f;
|
||||
float bRes = 0.0f;
|
||||
float aRes = 0.0f;
|
||||
|
||||
|
||||
int startRange, endRange;
|
||||
if(kernelWidth % 2 == 0)
|
||||
{
|
||||
startRange = -kernelWidth/2;
|
||||
endRange = kernelWidth/2;
|
||||
} else
|
||||
{
|
||||
startRange = -kernelWidth/2;
|
||||
endRange = kernelWidth/2+1;
|
||||
}
|
||||
for(int x = 0; x < image->height; x++)
|
||||
{
|
||||
for(int y = 0; y < image->width; y++)
|
||||
{
|
||||
|
||||
for(int xk = startRange; xk < endRange; xk++)
|
||||
{
|
||||
for(int yk = startRange; yk < endRange; yk++)
|
||||
{
|
||||
int xkabs = xk + kernelWidth/2;
|
||||
int ykabs = yk + kernelWidth/2;
|
||||
size_t imgindex = image->width * (x+xk) + (y+yk);
|
||||
if(imgindex < 0 || imgindex >= image->width * image->height){
|
||||
temp[kernelWidth * xkabs + ykabs].x = 0.0f;
|
||||
temp[kernelWidth * xkabs + ykabs].y = 0.0f;
|
||||
temp[kernelWidth * xkabs + ykabs].z = 0.0f;
|
||||
temp[kernelWidth * xkabs + ykabs].w = 0.0f;
|
||||
} else {
|
||||
temp[kernelWidth * xkabs + ykabs].x = ((float)pixels[imgindex].r)/255.0f * kernel[kernelWidth * xkabs + ykabs];
|
||||
temp[kernelWidth * xkabs + ykabs].y = ((float)pixels[imgindex].g)/255.0f * kernel[kernelWidth * xkabs + ykabs];
|
||||
temp[kernelWidth * xkabs + ykabs].z = ((float)pixels[imgindex].b)/255.0f * kernel[kernelWidth * xkabs + ykabs];
|
||||
temp[kernelWidth * xkabs + ykabs].w = ((float)pixels[imgindex].a)/255.0f * kernel[kernelWidth * xkabs + ykabs];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < kernelSize; i++)
|
||||
{
|
||||
rRes += temp[i].x;
|
||||
gRes += temp[i].y;
|
||||
bRes += temp[i].z;
|
||||
aRes += temp[i].w;
|
||||
}
|
||||
|
||||
if(rRes < 0.0f)
|
||||
{
|
||||
rRes = 0.0f;
|
||||
}
|
||||
if(gRes < 0.0f)
|
||||
{
|
||||
gRes = 0.0f;
|
||||
}
|
||||
if(bRes < 0.0f)
|
||||
{
|
||||
bRes = 0.0f;
|
||||
}
|
||||
|
||||
if(rRes > 1.0f)
|
||||
{
|
||||
rRes = 1.0f;
|
||||
}
|
||||
if(gRes > 1.0f)
|
||||
{
|
||||
gRes = 1.0f;
|
||||
}
|
||||
if(bRes > 1.0f)
|
||||
{
|
||||
bRes = 1.0f;
|
||||
}
|
||||
|
||||
imageCopy2[image->width * (x) + (y)].x = rRes;
|
||||
imageCopy2[image->width * (x) + (y)].y = gRes;
|
||||
imageCopy2[image->width * (x) + (y)].z = bRes;
|
||||
imageCopy2[image->width * (x) + (y)].w = aRes;
|
||||
|
||||
rRes = 0.0f;
|
||||
gRes = 0.0f;
|
||||
bRes = 0.0f;
|
||||
aRes = 0.0f;
|
||||
|
||||
for(int i = 0; i < kernelSize; i++)
|
||||
{
|
||||
temp[i].x = 0.0f;
|
||||
temp[i].y = 0.0f;
|
||||
temp[i].z = 0.0f;
|
||||
temp[i].w = 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < (image->width) * (image->height); i++)
|
||||
{
|
||||
float alpha = (float)imageCopy2[i].w;
|
||||
pixels[i].r = (unsigned char)((imageCopy2[i].x)*255.0f);
|
||||
pixels[i].g = (unsigned char)((imageCopy2[i].y)*255.0f);
|
||||
pixels[i].b = (unsigned char)((imageCopy2[i].z)*255.0f);
|
||||
pixels[i].a = (unsigned char)((alpha)*255.0f);
|
||||
// printf("pixels[%d] = %d", i, pixels[i].r);
|
||||
}
|
||||
|
||||
|
||||
int format = image->format;
|
||||
RL_FREE(image->data);
|
||||
RL_FREE(imageCopy2);
|
||||
RL_FREE(temp);
|
||||
|
||||
image->data = pixels;
|
||||
image->format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8;
|
||||
ImageFormat(image, format);
|
||||
}
|
||||
|
||||
// Generate all mipmap levels for a provided image
|
||||
// NOTE 1: Supports POT and NPOT images
|
||||
// NOTE 2: image.data is scaled to include mipmap levels
|
||||
|
Reference in New Issue
Block a user