Ejemplo n.º 1
0
color_table create_color_table(image img)
{
	
	color_table new_table = malloc(sizeof(color_table));
	int i, *pixel_color;
	
	/* Conditions d'erreur qui permetent de quitter la focntion si necessaire*/
	assert(img != NULL);
	assert(image_give_hauteur(img) == 1);

	new_table->owner = true;


	new_table->nb_colors = image_give_largeur(img);

	new_table->colors = malloc(sizeof(color) * new_table->nb_colors);

  	image_debut(img);

	/* On créer la nouvelle table pixel par pixel*/
	
  	for(i = 0; i < new_table->nb_colors; i++)
  	{

		pixel_color = image_lire_pixel(img);
		
		new_table->colors[i] = malloc(sizeof(color));

		new_table->colors[i]->red = pixel_color[0];
		new_table->colors[i]->green = pixel_color[1];
		new_table->colors[i]->blue = pixel_color[2];

		image_pixel_suivant(img);

	}

	return new_table; 

}
Ejemplo n.º 2
0
color_table create_color_table(image img)
{
	assert(img != NULL);	

	color_table table = malloc(sizeof(struct color_table));

	table->size   = image_give_largeur(img)*image_give_dim(img);
	table->colors = malloc(sizeof(color) * table->size);
	table->owner  = true;

	image_debut(img);

	int * pixel = NULL, i = 0;
	do 
	{
		pixel = image_lire_pixel(img);
		table->colors[i] = (color) (pixel[0]);
		table->colors[i+1] = (color) (pixel[1]);
		table->colors[i+2] = (color) (pixel[2]);
		i+=3;
	} while (image_pixel_suivant(img) != faux);

	return table;
}