Changed function and file naming to comply with assignment

This commit is contained in:
Nikola
2026-07-03 14:43:44 +02:00
parent d2ba15339d
commit 97a8d40771
6 changed files with 72 additions and 9 deletions
+2 -2
View File
@@ -6,7 +6,7 @@
#include <getopt.h> // for getopt_long
#include <string.h> // 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);
@@ -1,9 +1,12 @@
#include "tricorn_simd.h"
#include "tricorn_V0.h"
#include <immintrin.h>
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
+6
View File
@@ -0,0 +1,6 @@
#include <complex.h>
#include <stddef.h>
#include <math.h>
#include <sys/types.h>
#include<stdbool.h>
void tricorn_V0(float complex start, size_t width, ssize_t height, float res, unsigned n, bool color, unsigned char* img);
+54
View File
@@ -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;
}
+5
View File
@@ -0,0 +1,5 @@
#include <complex.h>
#include <stddef.h>
#include <math.h>
#include <sys/types.h>
void tricorn_V1(float complex start, size_t width, ssize_t height, float res, unsigned n, _Bool color, unsigned char* img);
-5
View File
@@ -1,5 +0,0 @@
#include <complex.h>
#include <stddef.h>
#include <math.h>
#include <sys/types.h>
void tricorn_simd(float complex start, size_t width, ssize_t height, float res, unsigned n, _Bool color, unsigned char* img);