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
+17 -6
View File
@@ -22,6 +22,10 @@ typedef struct {
const_args* consts;
} compute_args;
unsigned char color_lookup_table[256][3];
/**
* @brief Generates a Tricorn fractal image using an optimized SIMD + Threading implementation.
* @param start The starting complex coordinate (bottom-left or top-left depending on height sign).
@@ -33,6 +37,13 @@ typedef struct {
* @param img Pointer to the pre-allocated memory buffer where the bitmap data will be stored.
*/
void tricorn_V3(float complex start, size_t width, ssize_t height, float res, unsigned n, _Bool color, unsigned char* img){
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);
}
}
const ssize_t min_rows_per_thread = 10;
const _Bool flipped = height < 0;
@@ -153,9 +164,9 @@ static void* compute(void * vargs){
c->img[position] = value;
}
else {
c->img[position] = ((value*3) % 255);
c->img[position + 1] = ((value*2) % 255);
c->img[position + 2] = ((value*5) % 255);
c->img[position] = color_lookup_table[value][0];
c->img[position + 1] = color_lookup_table[value][1];
c->img[position + 2] = color_lookup_table[value][2];
}
}
c_real_vector = _mm_add_ps(c_real_vector,_mm_set1_ps(four_res));
@@ -171,9 +182,9 @@ static void* compute(void * vargs){
c->img[position] = value;
}
else {
c->img[position] = ((value*3) % 255);
c->img[position + 1] = ((value*2) % 255);
c->img[position + 2] = ((value*5) % 255);
c->img[position] = color_lookup_table[value][0];
c->img[position + 1] = color_lookup_table[value][1];
c->img[position + 2] = color_lookup_table[value][2];
}
}
c_imag += vertical_step;