diff --git a/Implementierung/main.c b/Implementierung/main.c index 1122c5b..5274c5b 100644 --- a/Implementierung/main.c +++ b/Implementierung/main.c @@ -6,7 +6,7 @@ #include // for getopt_long #include // for strcpy #include "tricorn.h" -#include "tricorn_simd.h" +#include "tricorn_V0.h" void save_bmp(const char *filename, unsigned char *img, size_t width, ssize_t height,_Bool color); @@ -201,7 +201,7 @@ int main(int argc, char** argv) printf("yashar\n"); if(version_to_use == 0) { // -V0 uses optimized SIMD-Version - tricorn_simd(complexA,width,height,resolution,n,colored,tempArr); + tricorn_V0(complexA,width,height,resolution,n,colored,tempArr); } else if (version_to_use == 1){ // -V1 uses unoptimized version tricorn(complexA,width,height,resolution,n,colored,tempArr); diff --git a/Implementierung/tricorn_simd.c b/Implementierung/tricorn_V0.c similarity index 95% rename from Implementierung/tricorn_simd.c rename to Implementierung/tricorn_V0.c index cc474c0..6df52c7 100644 --- a/Implementierung/tricorn_simd.c +++ b/Implementierung/tricorn_V0.c @@ -1,9 +1,12 @@ -#include "tricorn_simd.h" +#include "tricorn_V0.h" #include static unsigned converge(float c_rea, float c_imag, unsigned n); -void tricorn_simd(float complex start, size_t width, ssize_t height, float res, unsigned n, _Bool color, unsigned char* img){ + +// HIGHLY OPTIMIZED SIMD VERSION + +void tricorn_V0(float complex start, size_t width, ssize_t height, float res, unsigned n, _Bool color, unsigned char* img){ int bytesPerColor = color ? 3 : 1; // Absolute height for iteration purposes diff --git a/Implementierung/tricorn_V0.h b/Implementierung/tricorn_V0.h new file mode 100644 index 0000000..42025fa --- /dev/null +++ b/Implementierung/tricorn_V0.h @@ -0,0 +1,6 @@ +#include +#include +#include +#include +#include +void tricorn_V0(float complex start, size_t width, ssize_t height, float res, unsigned n, bool color, unsigned char* img); \ No newline at end of file diff --git a/Implementierung/tricorn_V1.c b/Implementierung/tricorn_V1.c new file mode 100644 index 0000000..512fe60 --- /dev/null +++ b/Implementierung/tricorn_V1.c @@ -0,0 +1,54 @@ +#include "tricorn_V1.h" + +static const float convergenceLimit = 2.0f; // Mandelbrot set limit +static unsigned converge(float complex position,unsigned n); + + +// OPTIMIZED SISD VERSION + +void tricorn_V1(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; + unsigned bytesPerColor = color ? 3 : 1; + + // 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+1); + + // Pixel value position in the output array + size_t position = (j*width +i) * bytesPerColor; + + + if(!color){ // Grayscale colors as specified by the assignment r = g = b + 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); + } + + } + } +} + +// 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++){ + // 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); + + // Application of the given complex equation with m = 2 + result = cpowf(conjf(result),2) + position; + + } + return 0; +} \ No newline at end of file diff --git a/Implementierung/tricorn_V1.h b/Implementierung/tricorn_V1.h new file mode 100644 index 0000000..3ddd155 --- /dev/null +++ b/Implementierung/tricorn_V1.h @@ -0,0 +1,5 @@ +#include +#include +#include +#include +void tricorn_V1(float complex start, size_t width, ssize_t height, float res, unsigned n, _Bool color, unsigned char* img); \ No newline at end of file diff --git a/Implementierung/tricorn_simd.h b/Implementierung/tricorn_simd.h deleted file mode 100644 index 60b9618..0000000 --- a/Implementierung/tricorn_simd.h +++ /dev/null @@ -1,5 +0,0 @@ -#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