Fixed grayscale handling in main.c and tricorn.c

Now grayscale files use a color pallete and in general should be smaller.
This commit is contained in:
go38coz
2026-06-28 21:38:55 +02:00
parent cd30d4aea6
commit 03d8253206
2 changed files with 24 additions and 11 deletions
+2 -3
View File
@@ -7,6 +7,7 @@ void tricorn(float complex start, size_t width, ssize_t height, float res, unsig
// Absolute height for iteration purposes
height = height < 0 ? height*-1 : height;
unsigned bytesPerColor = color ? 3 : 1;
// Simple iteration over every pixel in the picture
for(size_t i = 0; i < width; i++){
@@ -15,13 +16,11 @@ void tricorn(float complex start, size_t width, ssize_t height, float res, unsig
unsigned value = converge(start + (i*res - I*j*res),n);
// Pixel value position in the output array
size_t position = (j*width +i) *3;
size_t position = (j*width +i) * bytesPerColor;
if(!color){ // Grayscale colors as specified by the assignment r = g = b
img[position] = value;
img[position + 1] = value;
img[position + 2] = value;
}
else{ // Temporary colors with random multipliers
img[position] = ((value*3) % 255);