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
| #include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <math.h>
typedef struct
{
long TailleFichier; // taille totale du fichier
long Reserves; // 4 octets reserves usage futur
long PositionImage; // position de l'image dans le fichier (déplacement
// par rapport au début du fichier)
long TailleEntete; // taille de l'entête d'information (ce champ + ce qui suit
long Largeur; // largeur de l'image en pixel
long Hauteur; // hauteur de l'image en pixel
short NombrePlan; // nombre de plans utilises par la carte d'affichage
short NombreBit; // nombre de bits utilises pour coder un pixel
long TypeCompres; // type de compression utilisee (0 => RIEN)
long TailleImage; // taille de l'image (hauteur * largeur)
long ResolutionH; // resolution horizontale en pixel par metre
long ResolutionV; // resolution verticale en pixel par metre
long NombreCouleur; // nombre de couleurs => C dans le tableau
long CouleurImport; // nombre de couleurs importantes
}EnteteBmp;
// Declaration des prototypes
void affiche_params_structEnteteBMP( EnteteBmp argEntete );
int main(void)
{
FILE* image = NULL;
char firstChars[3] ; // Obligatoirement « BM » pour du BMP
EnteteBmp enteteStruct; // La structure contenant les donnees d'entete
char* nomFichierSource = "image.bmp";
// Ouverture du fichier source
image = fopen( nomFichierSource,"rb");
if( image == NULL) // Si l'image n'a pas pu etre ouverte
{
printf("Erreur d'ouverture du fichier %s:\n", nomFichierSource);
perror("Error");
exit( __LINE__ );
}
// Lecture des deux premiers chars
fread( firstChars, sizeof( char ), 2, image );
firstChars[2] = '\0';
// Verification des firstChars
if( strcmp( firstChars, "BM" ) != 0 )
{
printf("Le fichier %s n'est pas une image BMP !!\n", nomFichierSource);
fclose( image );
exit( __LINE__ );
}
// Lecture de l'en-tête
fread( &enteteStruct, sizeof( EnteteBmp ), 1, image );
// Affichage des parametres
affiche_params_structEnteteBMP( enteteStruct );
// Fermeture du fichier source
fclose( image );
return EXIT_SUCCESS;
}
void affiche_params_structEnteteBMP( EnteteBmp argEntete )
{
printf("Taille fichier \t= %ld\n", argEntete.TailleFichier );
printf("Reserves \t\t= %ld\n", argEntete.Reserves );
printf("Position image \t= %ld\n", argEntete.PositionImage );
printf("Taille entete \t= %ld\n", argEntete.TailleEntete );
printf("Largeur \t\t= %ld\n", argEntete.Largeur );
printf("Hauteur \t\t= %ld\n", argEntete.Hauteur);
printf("Nombre plans \t= %hd\n", argEntete.NombrePlan );
printf("Nombre bits \t= %hd\n", argEntete.NombreBit );
printf("Type Compress. \t= %ld\n", argEntete.TypeCompres );
printf("Taille Img \t\t= %ld\n", argEntete.TailleImage );
printf("Resolution H \t= %ld\n", argEntete.ResolutionH );
printf("Resolution V \t= %ld\n", argEntete.ResolutionV );
printf("Nombre de couleurs \t= %ld\n", argEntete.NombreCouleur );
printf("Couleur importantes \t= %ld\n", argEntete.CouleurImport );
fflush( stdout );
return;
} |
Partager