|
|
|
@ -29,7 +29,7 @@ pixel_t incolor() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Computes the visual representation of a mandelbrot set for a given line. */
|
|
|
|
|
void compmandelbrot_line(bitmap_t* mbrot, size_t y) {
|
|
|
|
|
void compmandelbrot_line(bitmap_t * mbrot, size_t y) {
|
|
|
|
|
|
|
|
|
|
for (size_t x = 0; x < mbrot->width; x++) {
|
|
|
|
|
|
|
|
|
@ -70,7 +70,7 @@ pthread_mutex_t next_y_mutex;
|
|
|
|
|
|
|
|
|
|
/* Thread to compute mandelbrot. */
|
|
|
|
|
void *compmandelbrot(void *arg) {
|
|
|
|
|
bitmap_t* mbrot = (bitmap_t*) arg;
|
|
|
|
|
bitmap_t *mbrot = (bitmap_t *) arg;
|
|
|
|
|
|
|
|
|
|
size_t y = 0;
|
|
|
|
|
while (y < mbrot->height) {
|
|
|
|
@ -147,7 +147,7 @@ static int save_png_to_file(bitmap_t * bitmap, const char *path) {
|
|
|
|
|
png_malloc(png_ptr, sizeof(uint8_t) * bitmap->width * pixel_size);
|
|
|
|
|
row_pointers[y] = row;
|
|
|
|
|
for (x = 0; x < bitmap->width; ++x) {
|
|
|
|
|
pixel_t *pixel = bitmap->pixels + (y*bitmap->width + x);
|
|
|
|
|
pixel_t *pixel = bitmap->pixels + (y * bitmap->width + x);
|
|
|
|
|
*row++ = (*pixel & 0x00ff0000) >> 16;
|
|
|
|
|
*row++ = (*pixel & 0x0000ff00) >> 8;
|
|
|
|
|
*row++ = (*pixel & 0x000000ff);
|
|
|
|
@ -181,7 +181,7 @@ int main(int argc, char *argv[]) {
|
|
|
|
|
|
|
|
|
|
/* Get command line options. */
|
|
|
|
|
int num_threads = 1;
|
|
|
|
|
char* options = "j:";
|
|
|
|
|
char *options = "j:";
|
|
|
|
|
if (getopt(argc, argv, options) == 'j') {
|
|
|
|
|
num_threads = (int) strtol(optarg, NULL, 10);
|
|
|
|
|
assert(num_threads != 0);
|
|
|
|
@ -199,14 +199,15 @@ int main(int argc, char *argv[]) {
|
|
|
|
|
|
|
|
|
|
/* Start computing threads. */
|
|
|
|
|
int ret;
|
|
|
|
|
pthread_t* threads;
|
|
|
|
|
pthread_t *threads;
|
|
|
|
|
threads = calloc(sizeof(pthread_t), num_threads);
|
|
|
|
|
|
|
|
|
|
ret = pthread_mutex_init(&next_y_mutex, NULL);
|
|
|
|
|
assert(ret == 0);
|
|
|
|
|
|
|
|
|
|
for (int t = 0; t < num_threads; t++) {
|
|
|
|
|
ret = pthread_create(&threads[t], NULL, compmandelbrot, (void *) &mbrot);
|
|
|
|
|
ret =
|
|
|
|
|
pthread_create(&threads[t], NULL, compmandelbrot, (void *) &mbrot);
|
|
|
|
|
assert(ret == 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|