Browse Source

Replaced GenImageGradientH and GenImageGradientV with GenImageLinearGradient (#3074)

* Replaced GenImageGradientH and GenImageGradientV with GenImageLinearGradient

* renamed GenImageLinearGradient to GenImageGradientLinear
pull/3077/head
Dane Madsen 1 year ago
committed by GitHub
parent
commit
e96dc46d38
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 359 additions and 408 deletions
  1. +14
    -11
      examples/textures/textures_image_generation.c
  2. +12
    -26
      parser/output/raylib_api.json
  3. +12
    -17
      parser/output/raylib_api.lua
  4. +281
    -287
      parser/output/raylib_api.txt
  5. +9
    -13
      parser/output/raylib_api.xml
  6. +1
    -2
      projects/Geany/raylib.c.tags
  7. +5
    -12
      projects/Notepad++/raylib_npp_parser/raylib_npp.xml
  8. +1
    -2
      projects/Notepad++/raylib_npp_parser/raylib_to_parse.h
  9. +1
    -2
      src/raylib.h
  10. +23
    -36
      src/rtextures.c

+ 14
- 11
examples/textures/textures_image_generation.c View File

@ -13,7 +13,7 @@
#include "raylib.h"
#define NUM_TEXTURES 6 // Currently we have 7 generation algorithms
#define NUM_TEXTURES 7 // Currently we have 7 generation algorithms
//------------------------------------------------------------------------------------
// Program main entry point
@ -27,8 +27,9 @@ int main(void)
InitWindow(screenWidth, screenHeight, "raylib [textures] example - procedural images generation");
Image verticalGradient = GenImageGradientV(screenWidth, screenHeight, RED, BLUE);
Image horizontalGradient = GenImageGradientH(screenWidth, screenHeight, RED, BLUE);
Image verticalGradient = GenImageGradientLinear(screenWidth, screenHeight, 0, RED, BLUE);
Image horizontalGradient = GenImageGradientLinear(screenWidth, screenHeight, 90, RED, BLUE);
Image diagonalGradient = GenImageGradientLinear(screenWidth, screenHeight, 45, RED, BLUE);
Image radialGradient = GenImageGradientRadial(screenWidth, screenHeight, 0.0f, WHITE, BLACK);
Image checked = GenImageChecked(screenWidth, screenHeight, 32, 32, RED, BLUE);
Image whiteNoise = GenImageWhiteNoise(screenWidth, screenHeight, 0.5f);
@ -38,10 +39,11 @@ int main(void)
textures[0] = LoadTextureFromImage(verticalGradient);
textures[1] = LoadTextureFromImage(horizontalGradient);
textures[2] = LoadTextureFromImage(radialGradient);
textures[3] = LoadTextureFromImage(checked);
textures[4] = LoadTextureFromImage(whiteNoise);
textures[5] = LoadTextureFromImage(cellular);
textures[2] = LoadTextureFromImage(diagonalGradient);
textures[3] = LoadTextureFromImage(radialGradient);
textures[4] = LoadTextureFromImage(checked);
textures[5] = LoadTextureFromImage(whiteNoise);
textures[6] = LoadTextureFromImage(cellular);
// Unload image data (CPU RAM)
UnloadImage(verticalGradient);
@ -83,10 +85,11 @@ int main(void)
{
case 0: DrawText("VERTICAL GRADIENT", 560, 10, 20, RAYWHITE); break;
case 1: DrawText("HORIZONTAL GRADIENT", 540, 10, 20, RAYWHITE); break;
case 2: DrawText("RADIAL GRADIENT", 580, 10, 20, LIGHTGRAY); break;
case 3: DrawText("CHECKED", 680, 10, 20, RAYWHITE); break;
case 4: DrawText("WHITE NOISE", 640, 10, 20, RED); break;
case 5: DrawText("CELLULAR", 670, 10, 20, RAYWHITE); break;
case 2: DrawText("DIAGONAL GRADIENT", 540, 10, 20, RAYWHITE); break;
case 3: DrawText("RADIAL GRADIENT", 580, 10, 20, LIGHTGRAY); break;
case 4: DrawText("CHECKED", 680, 10, 20, RAYWHITE); break;
case 5: DrawText("WHITE NOISE", 640, 10, 20, RED); break;
case 6: DrawText("CELLULAR", 670, 10, 20, RAYWHITE); break;
default: break;
}

+ 12
- 26
parser/output/raylib_api.json View File

@ -15,7 +15,7 @@
{
"name": "RAYLIB_VERSION_MINOR",
"type": "INT",
"value": 5,
"value": 6,
"description": ""
},
{
@ -27,7 +27,7 @@
{
"name": "RAYLIB_VERSION",
"type": "STRING",
"value": "4.5",
"value": "4.6-dev",
"description": ""
},
{
@ -1032,6 +1032,11 @@
"type": "Transform **",
"name": "framePoses",
"description": "Poses array by frame"
},
{
"type": "char[32]",
"name": "name",
"description": "Animation name"
}
]
},
@ -6236,8 +6241,8 @@
]
},
{
"name": "GenImageGradientV",
"description": "Generate image: vertical gradient",
"name": "GenImageGradientLinear",
"description": "Generate image: linear gradient",
"returnType": "Image",
"params": [
{
@ -6248,36 +6253,17 @@
"type": "int",
"name": "height"
},
{
"type": "Color",
"name": "top"
},
{
"type": "Color",
"name": "bottom"
}
]
},
{
"name": "GenImageGradientH",
"description": "Generate image: horizontal gradient",
"returnType": "Image",
"params": [
{
"type": "int",
"name": "width"
},
{
"type": "int",
"name": "height"
"name": "direction"
},
{
"type": "Color",
"name": "left"
"name": "start"
},
{
"type": "Color",
"name": "right"
"name": "end"
}
]
},

+ 12
- 17
parser/output/raylib_api.lua View File

@ -15,7 +15,7 @@ return {
{
name = "RAYLIB_VERSION_MINOR",
type = "INT",
value = 5,
value = 6,
description = ""
},
{
@ -27,7 +27,7 @@ return {
{
name = "RAYLIB_VERSION",
type = "STRING",
value = "4.5",
value = "4.6-dev",
description = ""
},
{
@ -1032,6 +1032,11 @@ return {
type = "Transform **",
name = "framePoses",
description = "Poses array by frame"
},
{
type = "char[32]",
name = "name",
description = "Animation name"
}
}
},
@ -4991,25 +4996,15 @@ return {
}
},
{
name = "GenImageGradientV",
description = "Generate image: vertical gradient",
returnType = "Image",
params = {
{type = "int", name = "width"},
{type = "int", name = "height"},
{type = "Color", name = "top"},
{type = "Color", name = "bottom"}
}
},
{
name = "GenImageGradientH",
description = "Generate image: horizontal gradient",
name = "GenImageGradientLinear",
description = "Generate image: linear gradient",
returnType = "Image",
params = {
{type = "int", name = "width"},
{type = "int", name = "height"},
{type = "Color", name = "left"},
{type = "Color", name = "right"}
{type = "int", name = "direction"},
{type = "Color", name = "start"},
{type = "Color", name = "end"}
}
},
{

+ 281
- 287
parser/output/raylib_api.txt
File diff suppressed because it is too large
View File


+ 9
- 13
parser/output/raylib_api.xml View File

@ -3,9 +3,9 @@
<Defines count="56">
<Define name="RAYLIB_H" type="GUARD" value="" desc="" />
<Define name="RAYLIB_VERSION_MAJOR" type="INT" value="4" desc="" />
<Define name="RAYLIB_VERSION_MINOR" type="INT" value="5" desc="" />
<Define name="RAYLIB_VERSION_MINOR" type="INT" value="6" desc="" />
<Define name="RAYLIB_VERSION_PATCH" type="INT" value="0" desc="" />
<Define name="RAYLIB_VERSION" type="STRING" value="4.5" desc="" />
<Define name="RAYLIB_VERSION" type="STRING" value="4.6-dev" desc="" />
<Define name="__declspec(x)" type="MACRO" value="__attribute__((x))" desc="" />
<Define name="RLAPI" type="UNKNOWN" value="__declspec(dllexport)" desc="We are building the library as a Win32 shared library (.dll)" />
<Define name="PI" type="FLOAT" value="3.14159265358979323846" desc="" />
@ -210,11 +210,12 @@
<Field type="BoneInfo *" name="bones" desc="Bones information (skeleton)" />
<Field type="Transform *" name="bindPose" desc="Bones base transformation (pose)" />
</Struct>
<Struct name="ModelAnimation" fieldCount="4" desc="ModelAnimation">
<Struct name="ModelAnimation" fieldCount="5" desc="ModelAnimation">
<Field type="int" name="boneCount" desc="Number of bones" />
<Field type="int" name="frameCount" desc="Number of animation frames" />
<Field type="BoneInfo *" name="bones" desc="Bones information (skeleton)" />
<Field type="Transform **" name="framePoses" desc="Poses array by frame" />
<Field type="char[32]" name="name" desc="Animation name" />
</Struct>
<Struct name="Ray" fieldCount="2" desc="Ray, ray for raycasting">
<Field type="Vector3" name="position" desc="Ray position (origin)" />
@ -655,7 +656,7 @@
<Param type="unsigned int" name="frames" desc="" />
</Callback>
</Callbacks>
<Functions count="517">
<Functions count="516">
<Function name="InitWindow" retType="void" paramCount="3" desc="Initialize window and OpenGL context">
<Param type="int" name="width" desc="" />
<Param type="int" name="height" desc="" />
@ -1548,17 +1549,12 @@
<Param type="int" name="height" desc="" />
<Param type="Color" name="color" desc="" />
</Function>
<Function name="GenImageGradientV" retType="Image" paramCount="4" desc="Generate image: vertical gradient">
<Function name="GenImageGradientLinear" retType="Image" paramCount="5" desc="Generate image: linear gradient">
<Param type="int" name="width" desc="" />
<Param type="int" name="height" desc="" />
<Param type="Color" name="top" desc="" />
<Param type="Color" name="bottom" desc="" />
</Function>
<Function name="GenImageGradientH" retType="Image" paramCount="4" desc="Generate image: horizontal gradient">
<Param type="int" name="width" desc="" />
<Param type="int" name="height" desc="" />
<Param type="Color" name="left" desc="" />
<Param type="Color" name="right" desc="" />
<Param type="int" name="direction" desc="" />
<Param type="Color" name="start" desc="" />
<Param type="Color" name="end" desc="" />
</Function>
<Function name="GenImageGradientRadial" retType="Image" paramCount="5" desc="Generate image: radial gradient">
<Param type="int" name="width" desc="" />

+ 1
- 2
projects/Geany/raylib.c.tags View File

@ -211,8 +211,7 @@ ImageColorContrast|void|(Image *image, float contrast);|
ImageColorBrightness|void|(Image *image, int brightness);|
ImageColorReplace|void|(Image *image, Color color, Color replace);|
GenImageColor|Image|(int width, int height, Color color);|
GenImageGradientV|Image|(int width, int height, Color top, Color bottom);|
GenImageGradientH|Image|(int width, int height, Color left, Color right);|
GenImageGradientLinear|Image|(int width, int height, int direction, Color start, Color end);|
GenImageGradientRadial|Image|(int width, int height, float density, Color inner, Color outer);|
GenImageChecked|Image|(int width, int height, int checksX, int checksY, Color col1, Color col2);|
GenImageWhiteNoise|Image|(int width, int height, float factor);|

+ 5
- 12
projects/Notepad++/raylib_npp_parser/raylib_npp.xml View File

@ -1378,20 +1378,13 @@
<Param name="Color color" />
</Overload>
</KeyWord>
<KeyWord name="GenImageGradientV" func="yes">
<Overload retVal="Image" descr="Generate image: vertical gradient">
<KeyWord name="GenImageGradientLinear" func="yes">
<Overload retVal="Image" descr="Generate image: linear gradient">
<Param name="int width" />
<Param name="int height" />
<Param name="Color top" />
<Param name="Color bottom" />
</Overload>
</KeyWord>
<KeyWord name="GenImageGradientH" func="yes">
<Overload retVal="Image" descr="Generate image: horizontal gradient">
<Param name="int width" />
<Param name="int height" />
<Param name="Color left" />
<Param name="Color right" />
<Param name="int direction" />
<Param name="Color start" />
<Param name="Color end" />
</Overload>
</KeyWord>
<KeyWord name="GenImageGradientRadial" func="yes">

+ 1
- 2
projects/Notepad++/raylib_npp_parser/raylib_to_parse.h View File

@ -317,8 +317,7 @@ RLAPI bool ExportImageAsCode(Image image, const char *fileName);
// Image generation functions
RLAPI Image GenImageColor(int width, int height, Color color); // Generate image: plain color
RLAPI Image GenImageGradientV(int width, int height, Color top, Color bottom); // Generate image: vertical gradient
RLAPI Image GenImageGradientH(int width, int height, Color left, Color right); // Generate image: horizontal gradient
RLAPI Image GenImageGradientLinear(int width, int height, int direction, Color start, Color end); // Generate image: linear gradient
RLAPI Image GenImageGradientRadial(int width, int height, float density, Color inner, Color outer); // Generate image: radial gradient
RLAPI Image GenImageChecked(int width, int height, int checksX, int checksY, Color col1, Color col2); // Generate image: checked
RLAPI Image GenImageWhiteNoise(int width, int height, float factor); // Generate image: white noise

+ 1
- 2
src/raylib.h View File

@ -1239,8 +1239,7 @@ RLAPI bool ExportImageAsCode(Image image, const char *fileName);
// Image generation functions
RLAPI Image GenImageColor(int width, int height, Color color); // Generate image: plain color
RLAPI Image GenImageGradientV(int width, int height, Color top, Color bottom); // Generate image: vertical gradient
RLAPI Image GenImageGradientH(int width, int height, Color left, Color right); // Generate image: horizontal gradient
RLAPI Image GenImageGradientLinear(int width, int height, int direction, Color start, Color end); // Generate image: linear gradient
RLAPI Image GenImageGradientRadial(int width, int height, float density, Color inner, Color outer); // Generate image: radial gradient
RLAPI Image GenImageChecked(int width, int height, int checksX, int checksY, Color col1, Color col2); // Generate image: checked
RLAPI Image GenImageWhiteNoise(int width, int height, float factor); // Generate image: white noise

+ 23
- 36
src/rtextures.c View File

@ -684,48 +684,35 @@ Image GenImageColor(int width, int height, Color color)
}
#if defined(SUPPORT_IMAGE_GENERATION)
// Generate image: vertical gradient
Image GenImageGradientV(int width, int height, Color top, Color bottom)
// Generate image: linear gradient
// The direction value specifies the direction of the gradient (in degrees)
// with 0 being vertical (from top to bottom), 90 being horizontal (from left to right).
// The gradient effectively rotates counter-clockwise by the specified amount.
Image GenImageGradientLinear(int width, int height, int direction, Color start, Color end)
{
Color *pixels = (Color *)RL_MALLOC(width*height*sizeof(Color));
for (int j = 0; j < height; j++)
{
float factor = (float)j/(float)height;
for (int i = 0; i < width; i++)
{
pixels[j*width + i].r = (int)((float)bottom.r*factor + (float)top.r*(1.f - factor));
pixels[j*width + i].g = (int)((float)bottom.g*factor + (float)top.g*(1.f - factor));
pixels[j*width + i].b = (int)((float)bottom.b*factor + (float)top.b*(1.f - factor));
pixels[j*width + i].a = (int)((float)bottom.a*factor + (float)top.a*(1.f - factor));
}
}
Image image = {
.data = pixels,
.width = width,
.height = height,
.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8,
.mipmaps = 1
};
return image;
}
// Generate image: horizontal gradient
Image GenImageGradientH(int width, int height, Color left, Color right)
{
Color *pixels = (Color *)RL_MALLOC(width*height*sizeof(Color));
float radianDirection = (float)(90 - direction) / 180.f * 3.14159f;
float cosDir = cos(radianDirection);
float sinDir = sin(radianDirection);
for (int i = 0; i < width; i++)
int i, j;
for (i = 0; i < width; i++)
{
float factor = (float)i/(float)width;
for (int j = 0; j < height; j++)
for (j = 0; j < height; j++)
{
pixels[j*width + i].r = (int)((float)right.r*factor + (float)left.r*(1.f - factor));
pixels[j*width + i].g = (int)((float)right.g*factor + (float)left.g*(1.f - factor));
pixels[j*width + i].b = (int)((float)right.b*factor + (float)left.b*(1.f - factor));
pixels[j*width + i].a = (int)((float)right.a*factor + (float)left.a*(1.f - factor));
// Calculate the relative position of the pixel along the gradient direction
float pos = (i * cosDir + j * sinDir) / (width * cosDir + height * sinDir);
float factor = pos;
factor = (factor > 1.f) ? 1.f : factor; // Clamp to [0,1]
factor = (factor < 0.f) ? 0.f : factor; // Clamp to [0,1]
// Generate the color for this pixel
pixels[j * width + i].r = (int)((float)end.r*factor + (float)start.r*(1.f - factor));
pixels[j * width + i].g = (int)((float)end.g*factor + (float)start.g*(1.f - factor));
pixels[j * width + i].b = (int)((float)end.b*factor + (float)start.b*(1.f - factor));
pixels[j * width + i].a = (int)((float)end.a*factor + (float)start.a*(1.f - factor));
}
}

Loading…
Cancel
Save