REVIEWED: Comments to impersonal format

This commit is contained in:
Ray
2026-02-12 18:55:40 +01:00
parent 4e7c38ac43
commit 070082f8c9
9 changed files with 70 additions and 77 deletions

View File

@ -883,7 +883,7 @@ Image GenImageGradientRadial(int width, int height, float density, Color inner,
float factor = (dist - radius*density)/(radius*(1.0f - density));
factor = (float)fmax(factor, 0.0f);
factor = (float)fmin(factor, 1.f); // dist can be bigger than radius, so we have to check
factor = (float)fmin(factor, 1.f); // Distance can be bigger than radius, so it needs to be checked
pixels[y*width + x].r = (int)((float)outer.r*factor + (float)inner.r*(1.0f - factor));
pixels[y*width + x].g = (int)((float)outer.g*factor + (float)inner.g*(1.0f - factor));
@ -1032,7 +1032,7 @@ Image GenImagePerlinNoise(int width, int height, int offsetX, int offsetY, float
if (p < -1.0f) p = -1.0f;
if (p > 1.0f) p = 1.0f;
// We need to normalize the data from [-1..1] to [0..1]
// Data needs to be normalized from [-1..1] to [0..1]
float np = (p + 1.0f)/2.0f;
unsigned char intensity = (unsigned char)(np*255.0f);
@ -1264,7 +1264,7 @@ void ImageFormat(Image *image, int newFormat)
{
Vector4 *pixels = LoadImageDataNormalized(*image); // Supports 8 to 32 bit per channel
RL_FREE(image->data); // WARNING! We loose mipmaps data --> Regenerated at the end...
RL_FREE(image->data); // WARNING! Loosing mipmaps data --> Regenerated at the end
image->data = NULL;
image->format = newFormat;
@ -1759,7 +1759,7 @@ void ImageResize(Image *image, int newWidth, int newHeight)
// Security check to avoid program crash
if ((image->data == NULL) || (image->width == 0) || (image->height == 0)) return;
// Check if we can use a fast path on image scaling
// Check if a fast path can be used on image scaling
// It can be for 8 bit per channel images with 1 to 4 channels per pixel
if ((image->format == PIXELFORMAT_UNCOMPRESSED_GRAYSCALE) ||
(image->format == PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA) ||
@ -2026,7 +2026,7 @@ void ImageAlphaMask(Image *image, Image alphaMask)
Image mask = ImageCopy(alphaMask);
if (mask.format != PIXELFORMAT_UNCOMPRESSED_GRAYSCALE) ImageFormat(&mask, PIXELFORMAT_UNCOMPRESSED_GRAYSCALE);
// In case image is only grayscale, we just add alpha channel
// In case image is only grayscale, just add alpha channel
if (image->format == PIXELFORMAT_UNCOMPRESSED_GRAYSCALE)
{
unsigned char *data = (unsigned char *)RL_MALLOC(image->width*image->height*2);
@ -2479,7 +2479,7 @@ void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp)
TRACELOG(LOG_WARNING, "IMAGE: Unsupported dithered OpenGL internal format: %ibpp (R%iG%iB%iA%i)", (rBpp+gBpp+bBpp+aBpp), rBpp, gBpp, bBpp, aBpp);
}
// NOTE: We will store the dithered data as unsigned short (16bpp)
// NOTE: Storing the dithered data as unsigned short (16bpp)
image->data = (unsigned short *)RL_MALLOC(image->width*image->height*sizeof(unsigned short));
Color oldPixel = WHITE;
@ -2507,8 +2507,8 @@ void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp)
newPixel.b = oldPixel.b >> (8 - bBpp); // B bits
newPixel.a = oldPixel.a >> (8 - aBpp); // A bits (not used on dithering)
// NOTE: Error must be computed between new and old pixel but using same number of bits!
// We want to know how much color precision we have lost...
// NOTE: Error must be computed between new and old pixel but using same number of bits,
// to know how much color precision has been lost
rError = (int)oldPixel.r - (int)(newPixel.r << (8 - rBpp));
gError = (int)oldPixel.g - (int)(newPixel.g << (8 - gBpp));
bError = (int)oldPixel.b - (int)(newPixel.b << (8 - bBpp));
@ -3134,7 +3134,7 @@ Color *LoadImagePalette(Image image, int maxPaletteSize, int *colorCount)
palette[palCount] = pixels[i]; // Add pixels[i] to palette
palCount++;
// We reached the limit of colors supported by palette
// Reached the limit of colors supported by palette
if (palCount >= maxPaletteSize)
{
i = image.width*image.height; // Finish palette get
@ -3806,7 +3806,7 @@ void ImageDrawTriangle(Image *dst, Vector2 v1, Vector2 v2, Vector2 v3, Color col
for (int x = xMin; x <= xMax; x++)
{
// Check if the pixel is inside the triangle using barycentric coordinates
// If it is then we can draw the pixel with the given color
// If it is, the pixel can be drawn with the given color
if ((w1 | w2 | w3) >= 0) ImageDrawPixel(dst, x, y, color);
// Increment the barycentric coordinates for the next pixel
@ -3863,9 +3863,6 @@ void ImageDrawTriangleEx(Image *dst, Vector2 v1, Vector2 v2, Vector2 v3, Color c
int w3Row = (int)((xMin - v1.x)*w3XStep + w3YStep*(yMin - v1.y));
// Calculate the inverse of the sum of the barycentric coordinates for normalization
// NOTE 1: Here, we act as if we multiply by 255 the reciprocal, which avoids additional
// calculations in the loop. This is acceptable because we are only interpolating colors
// NOTE 2: This sum remains constant throughout the triangle
float wInvSum = 255.0f/(w1Row + w2Row + w3Row);
// Rasterization loop
@ -3965,11 +3962,11 @@ void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec, Color
if ((srcRec.y + srcRec.height) > src.height) srcRec.height = src.height - srcRec.y;
// Check if source rectangle needs to be resized to destination rectangle
// In that case, we make a copy of source, and we apply all required transform
// In that case, make a copy of source, and apply all required transform
if (((int)srcRec.width != (int)dstRec.width) || ((int)srcRec.height != (int)dstRec.height))
{
srcMod = ImageFromImage(src, srcRec); // Create image from another image
ImageResize(&srcMod, (int)dstRec.width, (int)dstRec.height); // Resize to destination rectangle
srcMod = ImageFromImage(src, srcRec); // Create image from another image
ImageResize(&srcMod, (int)dstRec.width, (int)dstRec.height); // Resize to destination rectangle
srcRec = (Rectangle){ 0, 0, (float)srcMod.width, (float)srcMod.height };
srcPtr = &srcMod;
@ -5126,7 +5123,7 @@ Color ColorAlphaBlend(Color dst, Color src, Color tint)
else if (src.a == 255) out = src;
else
{
unsigned int alpha = (unsigned int)src.a + 1; // We are shifting by 8 (dividing by 256), so we need to take that excess into account
unsigned int alpha = (unsigned int)src.a + 1; // Shifting by 8 (dividing by 256), so need to take that excess into account
out.a = (unsigned char)(((unsigned int)alpha*256 + (unsigned int)dst.a*(256 - alpha)) >> 8);
if (out.a > 0)