Пример #1
0
void pile_free_images() {
  detruire_image(cur_image);
  gtk_label_set_text (GTK_LABEL (pLabel_Nomf), "Pas d image chargee");
  gtk_label_set_text (GTK_LABEL (pLabel_Res), "Resolution Image");
  cur_image = NULL;
  gtk_widget_queue_draw_area(pDA, 0, 0, 0, 0);
  //gtk_widget_queue_draw_area(pDA, 0, 0, pDA->allocation.width, pDA->allocation.height);
}
image_t *rotation(image_t *src, int angle)
	{
	//creation d'une nouvelle image avec la largeur égale à la hauteur de l'image rentrante et vice-versa
	image_t *rot=creer_image();
	if(rot==NULL) return NULL;
	rot->w=src->h;
	rot->h=src->w;
	rot->path=strdup(src->path);
	rot->buff=malloc(src->w*src->h*sizeof(unsigned char));
	angle=angle/90; //simplification des angles, 1=90, 2=180, 3=270
	int i,j;
	for(j=0;j<(src->h);j++){
		for (i = 0; i < (src->w); i += 1)
		{
			VAL(rot,src->w-i-1,j)=VAL(src,j,i);
		}
	}
	
	//Faire une rotation supplémentaire (180°)
	if (angle>1)
	{
		if (angle>2) //Encore un rotation (180+90=270) peut être facilement amélioré (en une transformation au lieu de 3)
		{
			image_t *cop=rotation(rot,180);
			detruire_image(rot);
			return cop;
		}
		image_t *cp=creer_image();  //nouvelle image tampon crée, libérée avant la fin de la fonction
		if(cp==NULL) return NULL;
		cp->w=rot->h;
		cp->h=rot->w;
		cp->path=strdup(rot->path);
		cp->buff=malloc(rot->w*rot->h*sizeof(unsigned char));
		for(j=0;j<(rot->h);j++){
			for (i = 0; i < (rot->w); i += 1)
			{
				VAL(cp,rot->w-i-1,j)=VAL(rot,j,i);
			}
		}
		detruire_image(rot);
		return cp;
	}
	//fin de fct en cas de rotation à 90°
	return rot;
}
Пример #3
0
void pile_new_image(image_t *new_image) {
  char str_res[32];

  detruire_image(cur_image);
  cur_image = new_image;
  gtk_label_set_text (GTK_LABEL (pLabel_Nomf), cur_image->path);
  snprintf(str_res, 32, "%ldx%ld", cur_image->w, cur_image->h);
  gtk_label_set_text (GTK_LABEL (pLabel_Res), str_res);
  gtk_widget_queue_draw_area(pDA, 0, 0, pDA->allocation.width, pDA->allocation.height);
}
Пример #4
0
int main(int argc, char *argv[]) {
  if (argc == 2) {
    char *path = my_strdup(argv[1]);
    image_t *img = charger_image_pgm(path);
    if (!img) { fprintf(stderr, "main: Invalid image abort\n"); return 1;}
    image_t *new_img = rotation(img, 90);
    image_t *tmp = rotation(new_img, 180);
    detruire_image(new_img);
    new_img = rotation(tmp, 270);
    detruire_image(tmp);
    tmp = rotation(new_img, 90);
    detruire_image(new_img);
    new_img = tmp;
    if (memcmp(new_img->buff, img->buff, img->h * img->w)) {
      fprintf(stderr, "Error image are differents after 4 * 90 rot.\n");
    } else {
      fprintf(stderr, "Images are equals rotation is OK!\n");
    }
    sauver_image_pgm("replique2.pgm", new_img);
    char const *noyaux[11] = {
      "noyaux/noyau_deriv.txt",
      "noyaux/noyau_deriv2.txt",
      "noyaux/noyau_derivxy2.txt",
      "noyaux/noyau_derivy2.txt",
      "noyaux/noyau_exp.txt",
      "noyaux/noyau_gauss.txt",
      "noyaux/noyau_laplace4.txt",
      "noyaux/noyau_laplace8.txt",
      "noyaux/noyau_moy.txt",
      "noyaux/noyau_sobelx.txt",
      "noyaux/noyau_sobely.txt"};
    for (size_t x = 0; x < 11; x += 1) {
      noyau_t *core = charger_noyau(noyaux[x]);
      fprintf(stderr, "%zu: core.path: %s"
          " | core.dim: %d\n",x, noyaux[x], core->dim);
      for (size_t i = 0; i < core->dim; i += 1) {
        for (size_t j = 0; j < core->dim; j += 1) {
          fprintf(stderr, "%d ", core->coeffs[j + core->dim * i]);
        }
        putchar('\n');
      }
      image_t *img2 = convoluer(new_img, core);
      detruire_image(img2);
      detruire_noyau(core);
    }

    detruire_image(img);
    img = filtrer_median(new_img);
    detruire_image(img);
    detruire_image(new_img);
    free(path);
  }
  return (0);
}