1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
| #include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct entete entete;
struct entete
{
char format [3];
int taille;
int reserve;
int BMP_Off;
int BMP_Width;
int BMP_Height;
};
typedef struct sCoul sCoul;
struct sCoul
{
unsigned char R;
unsigned char V;
unsigned char B;
};
entete RecupEntete(FILE *fpin)
{
entete E1;
fread(&E1.format,2,1,fpin);
fread(&E1.taille,4,1,fpin);
fread(&E1.reserve,4,1,fpin);
fread(&E1.BMP_Off,4,1,fpin);
fread(&E1.reserve,4,1,fpin);
fread(&E1.BMP_Width,4,1,fpin);
fread(&E1.BMP_Height,4,1,fpin);
return E1;
}
entete RecupEntete(FILE *fpin);
int main(void)
{
char nomFichier[]="";
int i=0;
int j=0;
int k=0;
int x=0;
int y=0;
FILE* f;
FILE* newFile;
entete E;
/*tabeau de couleurs ( R,V,B )*/
sCoul *couleurs=NULL;
sCoul *newColors=NULL;
printf("Entrez le nom de l'image: ");
scanf("%s",nomFichier);
strcat(nomFichier,".bmp");
printf("%s\n",nomFichier);
f = fopen(nomFichier,"rb");
if (f==NULL)
{
printf("Erreur de chargement de l'image");
return(0);
}
else
{
E=RecupEntete(f);
printf("format: %d\n",E.reserve);
printf("Taille du fichier: %d\n",E.taille);
printf("OFFSET: %d\n",E.BMP_Off);
printf("Largeur du fichier: %d\n",E.BMP_Width);
printf("Hauteur du fichier: %d\n",E.BMP_Height);
fseek(f, E.BMP_Off, SEEK_SET); /* positionnement du curseur
sur le debut du corps*/
i=0;
/* allocation dynamique du tableau contenant les couleurs*/
couleurs=malloc (E.taille*sizeof(sCoul));
while (!feof(f))
{
/* on remplis le tableau avec les valeurs de couleur des pixels*/
fread(&couleurs[i], sizeof(sCoul),1,f);
/*si le pixel est noir je le print*/
/* if (couleurs[i].B+couleurs[i].V+couleurs[i].R==0) */
/* { */
/* x=(i % E.BMP_Width); */
/* y=(i % E.BMP_Height); */
/* printf("PIXEL NOIR ! Coordonnée en (x:%d,y:%d)\n",x,y); */
/* j++; */
/* } */
i++;
}
j=0;
while (j<i)
{
newColors[j].R=255-couleurs[j].R ;
newColors[j].V=255-couleurs[j].V;
newColors[j].B-=255-couleurs[j].B;
j++;
}
// je crée mon nouveau fichier
newFile = fopen("Resu.bmp", "wb");
if (newFile == NULL)
printf ("Erreur ...");
else
{
fwrite(&E, sizeof(entete),1,newFile);
j=0;
while(j<i)
{
fwrite(&newColors[j], (sizeof(sCoul)),1,newFile);
j++;
}
}
fclose(newFile); /* ajoute EOF au fichier et ferme le fichier */
printf("appuyez sur une touche");
getchar();
getchar();
return EXIT_SUCCESS;
}
} |
Partager