From ee2b6b950679034a55dd03907c90c23c9ed4d329 Mon Sep 17 00:00:00 2001 From: go38coz Date: Fri, 26 Jun 2026 19:31:25 +0200 Subject: [PATCH] Copied tricorn to tricorn_simd .h and .c files to be later modified into SIMD optimization. Changed converge definition to static in order to not have conflicts with other versions of the function as it is an internal helper function --- Implementierung/tricorn.c | 4 +-- Implementierung/tricorn_simd.c | 51 ++++++++++++++++++++++++++++++++++ Implementierung/tricorn_simd.h | 5 ++++ 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 Implementierung/tricorn_simd.c create mode 100644 Implementierung/tricorn_simd.h diff --git a/Implementierung/tricorn.c b/Implementierung/tricorn.c index dec0b17..7c54c14 100644 --- a/Implementierung/tricorn.c +++ b/Implementierung/tricorn.c @@ -1,7 +1,7 @@ #include "tricorn.h" static const float convergenceLimit = 2.0f; // Mandelbrot set limit -unsigned converge(float complex position,unsigned n); +static unsigned converge(float complex position,unsigned n); void tricorn(float complex start, size_t width, ssize_t height, float res, unsigned n, _Bool color, unsigned char* img){ @@ -34,7 +34,7 @@ void tricorn(float complex start, size_t width, ssize_t height, float res, unsig } // Iterative application of the equation given by the assignment -unsigned converge(float complex position,unsigned n){ +static unsigned converge(float complex position,unsigned n){ complex float result = 0; for(unsigned i = 0; i < n; i++){ diff --git a/Implementierung/tricorn_simd.c b/Implementierung/tricorn_simd.c new file mode 100644 index 0000000..e40f95f --- /dev/null +++ b/Implementierung/tricorn_simd.c @@ -0,0 +1,51 @@ +#include "tricorn.h" + +static const float convergenceLimit = 2.0f; // Mandelbrot set limit +static unsigned converge(float complex position,unsigned n); + +void tricorn_simd(float complex start, size_t width, ssize_t height, float res, unsigned n, _Bool color, unsigned char* img){ + + // Absolute height for iteration purposes + height = height < 0 ? height*-1 : height; + + // Simple iteration over every pixel in the picture + for(size_t i = 0; i < width; i++){ + for(ssize_t j = 0; j < height; j++){ + + unsigned value = converge(start + (i*res - I*j*res),n); + + // Pixel value position in the output array + size_t position = (j*width +i) *3; + + + 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); + img[position + 1] = ((value*2) % 255) ; + img[position + 2] = ((value*5) % 255); + } + + } + } +} + +// Iterative application of the equation given by the assignment +static unsigned converge(float complex position,unsigned n){ + + complex float result = 0; + for(unsigned i = 0; i < n; i++){ + // Application of the given complex equation with m = 2 + result = cpowf(conjf(result),2) + position; + + // Detection of unbounded behaviour + // If the magnitude of the result vector is greater than the convergence limit, we know that the function will grow unbounded + // Current convergence limit taken from mandelbrot set + if(sqrtf(powf (crealf(result),2)+powf(cimagf(result),2)) > convergenceLimit) + return 255-4*(i % 64); + } + return 0; +} \ No newline at end of file diff --git a/Implementierung/tricorn_simd.h b/Implementierung/tricorn_simd.h new file mode 100644 index 0000000..60b9618 --- /dev/null +++ b/Implementierung/tricorn_simd.h @@ -0,0 +1,5 @@ +#include +#include +#include +#include +void tricorn_simd(float complex start, size_t width, ssize_t height, float res, unsigned n, _Bool color, unsigned char* img); \ No newline at end of file