From 734ef434c289abdcb7771989fcc73f12c95f5a63 Mon Sep 17 00:00:00 2001 From: JNDTUHH Date: Tue, 16 Jan 2018 20:22:04 +0100 Subject: Streukacke gefixt --- .cproject | 2 +- .settings/language.settings.xml | 4 ++-- src/sets.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.cproject b/.cproject index cb5ddb6..139f076 100644 --- a/.cproject +++ b/.cproject @@ -132,7 +132,7 @@ - diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml index 76dd30c..e62d81b 100644 --- a/.settings/language.settings.xml +++ b/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -16,7 +16,7 @@ - + diff --git a/src/sets.c b/src/sets.c index 6787a6e..eb09e6a 100644 --- a/src/sets.c +++ b/src/sets.c @@ -28,7 +28,7 @@ u32 mandelbrot_r(double x, double y, u32 iterations) u32 _mandelbrot_r(double x, double y, double zx, double zy, u32 n, u32 iterations, double threshold) { - if ((n <= iterations) && ((zx * zx + zy * zy) < threshold)) { + if ((n < iterations) && ((zx * zx + zy * zy) < threshold)) { double zx_new = (zx * zx - zy * zy + x); double zy_new = (2 * zx * zy + y); if ((zx_new == zx) && (zy_new == zy)) { -- cgit v1.2.1 From b0c6664cc9a37626baf344caacf80219b5e38b33 Mon Sep 17 00:00:00 2001 From: Jan Niklas Diercks Date: Tue, 16 Jan 2018 20:05:26 +0000 Subject: README --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..3ab2a6c --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# Mandelbrot Render - ProzProg Projekt + +Ideen: + + - Mandelbrot ist symetrisch zur x-Achse + - Color Smoothing + \ No newline at end of file -- cgit v1.2.1 From 809511996c83b9fa1f07bbf00ad70dbd9250471d Mon Sep 17 00:00:00 2001 From: JNDTUHH Date: Tue, 16 Jan 2018 21:29:02 +0100 Subject: Fixed Benchmark --- Test - Benchmark/Mandelbrot.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/Test - Benchmark/Mandelbrot.c b/Test - Benchmark/Mandelbrot.c index d06d154..cffa090 100644 --- a/Test - Benchmark/Mandelbrot.c +++ b/Test - Benchmark/Mandelbrot.c @@ -8,11 +8,11 @@ #define x_MIN -2.0 #define x_MAX 1.0 -#define y_MIN -1.0 +#define y_MIN 0 #define y_MAX 1.0 -#define BMP_HEIGHT 800 -#define BMP_WIDTH 1000 +#define BMP_HEIGHT 1080 +#define BMP_WIDTH 1920 #define N_MAX 250 @@ -30,7 +30,7 @@ void toMath(int X, int Y, double* x, double* y) { int mandelbrot(double x, double y, double zx, double zy, int n, int n_max, double threshold) { - if ((n <= n_max) && ((zx * zx + zy * zy) < threshold)) { + if ((n < n_max) && ((zx * zx + zy * zy) < threshold)) { double zx_new = (zx * zx - zy * zy + x); double zy_new = (2 * zx * zy + y); if ((zx_new == zx) && (zy_new == zy)) { @@ -64,8 +64,8 @@ int main(){ } } end = clock(); - // printf("Rekursion Ende"); - // getchar(); + printf("Rekursion Ende\n"); + //getchar(); // for(int i = 0; i < BMP_HEIGHT*BMP_WIDTH; i++){ // printf("%d\n",data[i]); @@ -73,7 +73,6 @@ int main(){ begin2 = clock(); uint32_t* data2 = (uint32_t*) malloc(BMP_WIDTH * BMP_HEIGHT * sizeof(uint32_t)); - int m = 0; for (int Y = 0; Y < BMP_HEIGHT; Y++) { for (int X = 0; X < BMP_WIDTH; X++) { @@ -81,20 +80,25 @@ int main(){ toMath(X, Y, &x, &y); double cx = x; double cy = y; - while(m <=n_max && (x*x)+(y*y) <= 4){ + int m = 0; + while(m <=n_max && (x*x)+(y*y) < 4){ x2 = x; x = (x*x) - (y*y) + cx; y = 2.0*x2*y + cy; m++; } - data2[Y * BMP_WIDTH + X] = n; + data2[Y * BMP_WIDTH + X] = m; } } end2 = clock(); + printf("Schleife Ende\n"); - // for(int i = 0; i < BMP_HEIGHT*BMP_WIDTH; i++){ - // printf("%d\n",data2[i]); + // for(int i = 0; i < BMP_WIDTH * BMP_HEIGHT; i++){ + // if(data[i] != data[2]){ + // printf("Unterschied\n"); + // } // } + printf("Rekursion:\n"); @@ -114,6 +118,11 @@ int main(){ z/=CLOCKS_PER_SEC; printf("Zeit zwischen begin und end: %f Sekunden\n", z); printf("CLOCKS_PER_SEC: %d\n", CLOCKS_PER_SEC); + + for(int i = 0; i < BMP_HEIGHT*BMP_WIDTH; i++){ + printf("Schleife: %d -- Rekursion: %d\n",data2[i], data[i]); + getch(); + } -- cgit v1.2.1 From bce8d1b1e019e12402feff28ee2abeb1bbef63f4 Mon Sep 17 00:00:00 2001 From: cxp2249 Date: Sun, 21 Jan 2018 17:24:19 +0100 Subject: added multithreading --- src/render.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 73 insertions(+), 19 deletions(-) diff --git a/src/render.c b/src/render.c index e06c967..528d775 100644 --- a/src/render.c +++ b/src/render.c @@ -6,6 +6,8 @@ */ #include "render.h" +#define HAVE_STRUCT_TIMESPEC +#include void render_init(Config *config, u32 (*sfunc) (double, double, u32)) { @@ -39,34 +41,86 @@ void on_draw(GtkWidget *widget, cairo_t *cr, gpointer data) cairo_paint(cr); } +struct arg_thread { + cairo_surface_t *result; + unsigned short threadCount; + unsigned short threadNumber; + unsigned char *current_row; +}; + +void *imageCalcThread(void *arguments) +{ + + + struct arg_thread *args = arguments; + cairo_surface_t *result = args->result; + unsigned int threadCount = args->threadCount; + unsigned int threadNumber = args->threadNumber; + unsigned char *current_row = args->current_row; + + + + int stride; + double x_math, y_math; + u32 iterations; + + printf("thread calculating %s",result); + current_row = cairo_image_surface_get_data(result); + stride = cairo_image_surface_get_stride(result); + + + //Calculating start and endpoint for current thread to calculate + int startingPoint = (_config->height/threadCount)*(threadNumber); + int endPoint = ((_config->height/threadCount)*(threadNumber + 1)) - 1; + + + for (int y = startingPoint; y < endPoint && y < _config->height; y++) { + u32 *row = (void *) current_row; + for (int x = 0; x < _config->width; x++) { + x_math = /*x_MIN*/-2.0 + ((double) x * (/*x_MAX*/1.0 - /*x_MIN*/-2.0)) / _config->width; + y_math = /*y_MIN*/-1.0 + ((double) (_config->height - y) * (/*y_MAX*/1.0 - /*y_MIN*/-1.0)) / _config->height; + iterations = _sfunc(x_math, y_math, _config->iterations); + row[x] = (((1<<24)-1)*iterations)/_config->iterations; +// if (iterations > 1<<8) +// printf("schon gruen\n"); + } + + current_row += stride; + } + +} + cairo_surface_t *render_surface() { cairo_surface_t *result; + unsigned short threadCount = 4; unsigned char *current_row; - int stride; - double x_math, y_math; - u32 iterations; - result = cairo_image_surface_create(CAIRO_FORMAT_RGB24, _config->width, _config->height); - if (cairo_surface_status(result) != CAIRO_STATUS_SUCCESS) - return result; + result = cairo_image_surface_create(CAIRO_FORMAT_RGB24, _config->width, _config->height); + if (cairo_surface_status(result) != CAIRO_STATUS_SUCCESS) + return result; cairo_surface_flush(result); - current_row = cairo_image_surface_get_data(result); - stride = cairo_image_surface_get_stride(result); - for (int y = 0; y < _config->height; y++) { - u32 *row = (void *) current_row; - for (int x = 0; x < _config->width; x++) { - x_math = /*x_MIN*/-2.0 + ((double) x * (/*x_MAX*/1.0 - /*x_MIN*/-2.0)) / _config->width; - y_math = /*y_MIN*/-1.0 + ((double) (_config->height - y) * (/*y_MAX*/1.0 - /*y_MIN*/-1.0)) / _config->height; - iterations = _sfunc(x_math, y_math, _config->iterations); - row[x] = (((1<<24)-1)*iterations)/_config->iterations; -// if (iterations > 1<<8) -// printf("schon gruen\n"); - } - current_row += stride; + + + //initialize thread related values and put them into a struct, as just one parameter is passed + struct arg_thread args; + args.result = result; + args.threadCount = threadCount; + args.current_row = current_row; + + pthread_t tid; + + //Create threads up to the number specified in threadCount + for (int i = 0; i < threadCount; i++){ + args.threadNumber = i; + pthread_create(&tid, NULL, imageCalcThread, (void *)&args); } + + //Wait for threads to finish and continue with the program + pthread_join(tid,NULL); + cairo_surface_mark_dirty(result); return result; } -- cgit v1.2.1