mirror of
https://github.com/raysan5/raylib.git
synced 2025-10-03 08:28:30 +00:00
REVIEWED: Coding conventions
This commit is contained in:
@@ -829,11 +829,11 @@ Image GenImageGradientLinear(int width, int height, int direction, Color start,
|
||||
|
||||
// Calculate how far the top-left pixel is along the gradient direction from the center of said gradient
|
||||
float startingPos = 0.5f - (cosDir*width/2) - (sinDir*height/2);
|
||||
// With directions that lie in the first or third quadrant (i.e. from top-left to
|
||||
// With directions that lie in the first or third quadrant (i.e. from top-left to
|
||||
// bottom-right or vice-versa), pixel (0, 0) is the farthest point on the gradient
|
||||
// (i.e. the pixel which should become one of the gradient's ends color); while for
|
||||
// directions that lie in the second or fourth quadrant, that point is pixel (width, 0).
|
||||
float maxPosValue =
|
||||
float maxPosValue =
|
||||
((signbit(sinDir) != 0) == (signbit(cosDir) != 0))
|
||||
? fabsf(startingPos)
|
||||
: fabsf(startingPos+width*cosDir);
|
||||
@@ -842,12 +842,12 @@ Image GenImageGradientLinear(int width, int height, int direction, Color start,
|
||||
for (int j = 0; j < height; j++)
|
||||
{
|
||||
// Calculate the relative position of the pixel along the gradient direction
|
||||
float pos = (startingPos + (i*cosDir + j*sinDir)) / maxPosValue;
|
||||
float pos = (startingPos + (i*cosDir + j*sinDir))/maxPosValue;
|
||||
|
||||
float factor = pos;
|
||||
factor = (factor > 1.0f)? 1.0f : factor; // Clamp to [-1,1]
|
||||
factor = (factor < -1.0f)? -1.0f : factor; // Clamp to [-1,1]
|
||||
factor = factor / 2 + 0.5f;
|
||||
factor = factor/2.0f + 0.5f;
|
||||
|
||||
// Generate the color for this pixel
|
||||
pixels[j*width + i].r = (int)((float)end.r*factor + (float)start.r*(1.0f - factor));
|
||||
@@ -1007,7 +1007,8 @@ Image GenImagePerlinNoise(int width, int height, int offsetX, int offsetY, float
|
||||
{
|
||||
Color *pixels = (Color *)RL_MALLOC(width*height*sizeof(Color));
|
||||
|
||||
float aspectRatio = (float)width / (float)height;
|
||||
float aspectRatio = (float)width/(float)height;
|
||||
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
for (int x = 0; x < width; x++)
|
||||
@@ -5387,7 +5388,7 @@ static float HalfToFloat(unsigned short x)
|
||||
const unsigned int e = (x & 0x7C00) >> 10; // Exponent
|
||||
const unsigned int m = (x & 0x03FF) << 13; // Mantissa
|
||||
const float fm = (float)m;
|
||||
const unsigned int v = (*(unsigned int*)&fm) >> 23; // Evil log2 bit hack to count leading zeros in denormalized format
|
||||
const unsigned int v = (*(unsigned int *)&fm) >> 23; // Evil log2 bit hack to count leading zeros in denormalized format
|
||||
const unsigned int r = (x & 0x8000) << 16 | (e != 0)*((e + 112) << 23 | m) | ((e == 0)&(m != 0))*((v - 37) << 23 | ((m << (150 - v)) & 0x007FE000)); // sign : normalized : denormalized
|
||||
|
||||
result = *(float *)&r;
|
||||
@@ -5400,7 +5401,7 @@ static unsigned short FloatToHalf(float x)
|
||||
{
|
||||
unsigned short result = 0;
|
||||
|
||||
const unsigned int b = (*(unsigned int*) & x) + 0x00001000; // Round-to-nearest-even: add last bit after truncated mantissa
|
||||
const unsigned int b = (*(unsigned int *) & x) + 0x00001000; // Round-to-nearest-even: add last bit after truncated mantissa
|
||||
const unsigned int e = (b & 0x7F800000) >> 23; // Exponent
|
||||
const unsigned int m = b & 0x007FFFFF; // Mantissa; in line below: 0x007FF000 = 0x00800000-0x00001000 = decimal indicator flag - initial rounding
|
||||
|
||||
|
Reference in New Issue
Block a user