Added lookup table for the colors for optimization

Made test output a bit prettier
Made tests run function 10 times for higher accuracy
This commit is contained in:
Nikola
2026-07-14 00:15:07 +02:00
parent 1318798ac2
commit f9bd827b2c
5 changed files with 96 additions and 23 deletions
+13 -3
View File
@@ -15,6 +15,16 @@ static unsigned converge(float c_real, float c_imag, unsigned n);
*/
void tricorn_V1(float complex start, size_t width, ssize_t height, float res, unsigned n, _Bool color, unsigned char* img){
int bytesPerColor = color ? 3 : 1;
unsigned char color_lookup_table[256][3];
if(color) {
for (int i = 0; i < 256; i++) {
color_lookup_table[i][0] = (unsigned char)((i * 3) % 255);
color_lookup_table[i][1] = (unsigned char)((i * 2) % 255);
color_lookup_table[i][2] = (unsigned char)((i * 5) % 255);
}
}
// Absolute height for iteration purposes
ssize_t actual_height = height > 0 ? height : (ssize_t)(-height);
@@ -44,9 +54,9 @@ void tricorn_V1(float complex start, size_t width, ssize_t height, float res, un
img[position] = value;
}
else{ // Temporary colors with random multipliers
img[position] = ((value*3) % 255);
img[position + 1] = ((value*2) % 255) ;
img[position + 2] = ((value*5) % 255);
img[position] = color_lookup_table[value][0];
img[position + 1] = color_lookup_table[value][1];
img[position + 2] = color_lookup_table[value][2];
}
position += bytesPerColor;