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
| bitmap *bmp; // variable renvoyée par la fonction
FILE * fichier; // un pointeur sur FILE
bmp=(bitmap*)malloc(sizeof(bitmap)); // on alloue dynamiquement le pointeur sur bitmap
fichier = fopen ("Frame-00001.bmp","r"); // on ouvre le fichier en lecture seule
fread (bmp->sign,2,1,fichier); // on récupère la signature
fread (&temp,4,1,fichier); // puis la taille de l'image
bmp->taille = conv (temp,4); // que l'on converti en décimal
fread (&temp,4,1,fichier); // la zone réservée
fread (&temp,4,1,fichier); // l'offset
bmp->offset = conv (temp,4); // que l'on converti aussi
fread (&temp,4,1,fichier); // taille de la zone info
bmp->info = conv (temp,4);
fread (&temp,4,1,fichier); // la largeur de l'image
bmp->largeur = conv(temp,4);
fread (&temp,4,1,fichier); // la hauteur de l'image
bmp->longueur = conv(temp,4);
fread (&temp,2,1,fichier); // le nombre d'info
bmp->nbplan = conv (temp,2);
fread (&temp,2,1,fichier); // le mode d'affichage
bmp->bppixel = conv (temp,2);
fread (&temp,4,1,fichier); // le format de compression
bmp->comp = conv (temp,4);
fread (&temp,4,1,fichier); // la taille de l'image
bmp->tim = conv (temp,4);
fread (&temp,4,1,fichier); // les résolutions horizontale
bmp->Hres = conv (temp,4); // et verticale
fread (&temp,4,1,fichier);
bmp->Vres = conv (temp,4);
fread (&temp,4,1,fichier);
bmp->nbco = conv (temp,4); // nbre de couleurs utilisées
fread (&temp,4,1,fichier);
bmp->impco = conv (temp,4); // nbre de couleurs importantes
fclose (fichier); // on ferme le fichier
fichier = fopen ("Frame-00001.bmp","r");
bmp->pixel=(unsigned char*)malloc(bmp->taille);
fread(bmp->pixel,1,bmp->taille,fichier);
Largeur = bmp->largeur ;
Longueur = bmp->longueur;
IMAGE = malloc((bmp->largeur * bmp->longueur) * sizeof (int));
R = malloc((bmp->largeur * bmp->longueur) * sizeof (int));
G = malloc((bmp->largeur * bmp->longueur) * sizeof (int));
B = malloc((bmp->largeur * bmp->longueur) * sizeof (int));
//si le nbre de pixel d'une ligne n'est pas un multiple de 4 on ajoute des bits a 0
bourrage = bmp->largeur % 4;
for(j=bmp->offset;j< ((bmp->taille - bourrage)-2);j=j+3) // soustraie bourrage à la taille
{
if (flag == bmp->largeur)
{
flag=0; //flag permet de détecter une fin de ligne
j=j+bourrage;
}
if(index < (Largeur*Longueur) )
{
R[index] = bmp->pixel[j];
}
if(( index < (2*Largeur*Longueur) ) && (index >= (Largeur*Longueur) ) )
{
G[index] = bmp->pixel[j];
}
if(( index < (3*Largeur*Longueur) ) && (index >= (2*Largeur*Longueur) ) )
{
B[index] = bmp->pixel[j];
}
flag++;
index++;
}
for (i=0;i<(Largeur*Longueur);i++)
{
IMAGE[i] = 0.3*R[i] + 0.59*G[i] + 0.11*B[i];
} |
Partager