Example #1
0
static void fb_shutdown_palette(void)
{
	if (have_cmap)
	{
		if (fb_active)
			set_palette(&old_palette);
		free_palette(&old_palette);
		free_palette(&global_pal);
	}
}
Example #2
0
int dragon_draw_pthread(char **canvas, struct rgb *image, int width, int height, uint64_t size, int nb_thread)
{
	printf("Started dragon_draw_pthread\n");
	pthread_t *threads = NULL;
	pthread_barrier_t barrier;
	limits_t limits;
	struct draw_data info;
	char *dragon = NULL;
	int scale_x;
	int scale_y;
	struct draw_data *data = NULL;
	struct palette *palette = NULL;
	int ret = 0;

	palette = init_palette(nb_thread);
	if (palette == NULL)
		goto err;

	if (pthread_barrier_init(&barrier, NULL, nb_thread) != 0) {
		printf("barrier init error\n");
		goto err;
	}

	/* 1. Calculer les limites du dragon */
	if (dragon_limits_pthread(&limits, size, nb_thread) < 0)
		goto err;

	info.dragon_width = limits.maximums.x - limits.minimums.x;
	info.dragon_height = limits.maximums.y - limits.minimums.y;

	if ((dragon = (char *) malloc(info.dragon_width * info.dragon_height)) == NULL) {
		printf("malloc error dragon\n");
		goto err;
	}

	if ((data = malloc(sizeof(struct draw_data) * nb_thread)) == NULL) {
		printf("malloc error data\n");
		goto err;
	}

	if ((threads = malloc(sizeof(pthread_t) * nb_thread)) == NULL) {
		printf("malloc error threads\n");
		goto err;
	}

	info.image_height = height;
	info.image_width = width;
	scale_x = info.dragon_width / width + 1;
	scale_y = info.dragon_height / height + 1;
	info.scale = (scale_x > scale_y ? scale_x : scale_y);
	info.deltaJ = (info.scale * width - info.dragon_width) / 2;
	info.deltaI = (info.scale * height - info.dragon_height) / 2;
	info.nb_thread = nb_thread;
	info.dragon = dragon;
	info.image = image;
	info.size = size;
	info.limits = limits;
	info.barrier = &barrier;
	info.palette = palette;

    //int area = info.dragon_width * info.dragon_height;

    //printf("-----------------\n");
    //printf("Total area size: %d\n", area);
    //printf("Draw area block size: %d\n", area / nb_thread);
    //printf("-----------------\n");
    //printf("Total draw size:%" PRIu64 "\n", size);
    //printf("Draw block size:%" PRIu64 "\n", size / nb_thread);
    //printf("-----------------\n");
    //printf("Total scale size: %d\n", info.image_height);
    //printf("Scale block size: %d\n", info.image_height / nb_thread);
    //printf("-----------------\n");
    /* 2. Lancement du calcul parallèle principal avec draw_dragon_worker */
	int i = 0;
    for (; i < nb_thread; ++i)
	{
		data[i].image_height = info.image_height;
        data[i].image_width = info.image_width;
        data[i].scale = info.scale;
        data[i].deltaJ = info.deltaJ;
        data[i].deltaI = info.deltaI;
        data[i].dragon = info.dragon;
        data[i].dragon_width = info.dragon_width;
        data[i].dragon_height = info.dragon_height;
        data[i].image = info.image;
        data[i].size = info.size;
        data[i].limits = info.limits;
        data[i].barrier = info.barrier;
        data[i].palette = info.palette;
        data[i].id = i;
        data[i].nb_thread = info.nb_thread;
		pthread_create(&threads[i], NULL, dragon_draw_worker, &data[i]); 
	}

	/* 3. Attendre la fin du traitement */
    for (i = 0; i < nb_thread; ++i)
    {
        pthread_join(threads[i], NULL);
    }

	if (pthread_barrier_destroy(&barrier) != 0) {
		printf("barrier destroy error\n");
		goto err;
	}
    printf("Finished dragon_draw_pthread\n");
   
done:
	FREE(data);
	FREE(threads);
	free_palette(palette);
	*canvas = dragon;
	return ret;

err:
	FREE(dragon);
	ret = -1;
	goto done;
}