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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
| #include <stdio.h>
#include <stdlib.h>
typedef struct
{
unsigned char B;
unsigned char V;
unsigned char R;
} JPGdata;
typedef struct
{
//L'entête du fichier
char signature[2]; //La signature du fichier
unsigned int taille_fichier; //La taille totale du fichier (en octets)
unsigned int champ_reserve; //Un champ réservé
unsigned int offset; //L'offset de l'image
//L'entête de l'image
unsigned int taille_entete; //La taille de l'ente de l'image
unsigned int largeur;
unsigned int hauteur;
unsigned short nombre_plans;
unsigned short profondeur;
unsigned int methode_compression;
unsigned int taille_image;
unsigned int resolution_horizontale;
unsigned int resolution_verticale;
unsigned int nombre_couleurs_palette;
unsigned int nombre_couleurs_importantes_palette;
unsigned char palette_b;
unsigned char palette_v;
unsigned char palette_r;
unsigned char palette_reserve;
JPGdata** raster;
} JPGfile;
void JPGload(char JPGpath[], JPGfile *fichier_image);
void displayJPGheader(JPGfile *fichier_image);
void getJPGpx(JPGfile *JPG, int x, int y, JPGdata* couleur);
void JPGclose (JPGfile *JPG);
int main()
{
int i;
JPGfile image;
JPGdata couleur;
char JPGpath[100];
printf("Entrez le nom de votre image JPG : ");
fgets(JPGpath, 100, stdin);
for (i = 0 ; i < 100 ; i++)
{
if (JPGpath[i] == '\n') JPGpath[i] = '\0';
}
JPGload(JPGpath, &image);
displayJPGheader(&image);
printf("==============================================\n");
printf("R : %i\n", couleur.R);
printf("V : %i\n", couleur.V);
printf("B : %i\n\n", couleur.B);
printf("==============================================\n");
JPGclose(&image);
return 0;
}
void JPGload(char JPGpath[], JPGfile *JPG)
{
FILE *fichier = NULL;
int i, x, y;
fichier = fopen(JPGpath, "rb");
if (fichier == NULL)
{
printf("\nErreur : Impossible de localiser le fichier %s.\n", JPGpath);
exit(0);
}
fread(&(JPG->signature), 2, 1, fichier); //On récupère la signature
fread(&(JPG->taille_fichier), 4, 1, fichier); //Puis sa taille (en octets)
fread(&(JPG->champ_reserve), 4, 1, fichier); //Puis la valeur du champ réservé
fread(&(JPG->offset), 4, 1, fichier); //Puis l'offset
fread(&(JPG->taille_entete), 4, 1, fichier); //La taille de l'entête de l'image
fread(&(JPG->largeur), 4, 1, fichier); //La largeur de l'image
fread(&(JPG->hauteur), 4, 1, fichier); //Sa hauteur
fread(&(JPG->nombre_plans), 2, 1, fichier); //Le nombre de plans
fread(&(JPG->profondeur), 2, 1, fichier); //La profondeur
fread(&(JPG->methode_compression), 4, 1, fichier); //La compression
fread(&(JPG->taille_image), 4, 1, fichier); //La taille de l'image
fread(&(JPG->resolution_horizontale), 4, 1, fichier); //La resolution horizontale
fread(&(JPG->resolution_verticale), 4, 1, fichier); ///La resolution Verticale
fread(&(JPG->nombre_couleurs_palette), 4, 1, fichier);
fread(&(JPG->nombre_couleurs_importantes_palette), 4, 1, fichier);
JPG->raster = (JPGdata**) malloc(sizeof(JPGdata*) * JPG->hauteur);
for (i = 0 ; i < JPG->hauteur ; i++)
{
JPG->raster[i] = (JPGdata*) malloc (JPG->largeur * sizeof(JPGdata));
}
//matrice
for (y = 0 ; y < JPG->hauteur ; y++)
{
for (x = 0 ; x < JPG->largeur ; x++)
{
fread(&(JPG->raster[y][x].R), 1, 1, fichier);
fread(&(JPG->raster[y][x].V), 1, 1, fichier);
fread(&(JPG->raster[y][x].B), 1, 1, fichier);
}
}
fclose(fichier);
}
void displayJPGheader(JPGfile *JPG)
{
printf("\n");
printf("Entête du fichier :\n");
printf("-------------------\n");
printf("Signature : %s\n", JPG->signature);
printf("Taille totale du fichier : %io\n", JPG->taille_fichier);
printf("Valeur du champ réservé : %i\n", JPG->champ_reserve);
printf("Offset : %i\n\n", JPG->offset);
printf("Entête de l'image :\n");
printf("-------------------\n");
printf("Taille de l'entête : %i\n", JPG->taille_entete);
printf("Largeur de l'image : %ipx\n", JPG->largeur);
printf("Hauteur de l'image : %ipx\n", JPG->hauteur);
printf("Le nombre de plans de l'image : %i\n", JPG->nombre_plans);
printf("Profondeur de l'image : %i\n", JPG->profondeur);
printf("Méthode de compression : %i\n", JPG->methode_compression);
printf("Taille de l'image : %i\n", JPG->taille_image);
printf("Resolution horizontale : %i\n", JPG->resolution_horizontale);
printf("Resolution verticale : %i\n", JPG->resolution_verticale);
printf("Nombre de couleurs de la palette : %i\n", JPG->nombre_couleurs_palette);
printf("Nombre de couleurs importantes de la palette : %i\n\n", JPG->nombre_couleurs_importantes_palette);
if (JPG->profondeur != 24)
{
printf("Palette de l'image :\n");
printf("--------------------\n");
printf("Bleu : %i\n", JPG->palette_b);
printf("Vert : %i\n", JPG->palette_v);
printf("Rouge : %i\n", JPG->palette_r);
printf("Champ réservé : %i\n\n", JPG->palette_reserve);
}
}
void getJPGpx(JPGfile *JPG, int x, int y, JPGdata* couleur)
{
// couleur->B = JPG->raster[JPG->hauteur - (JPG->hauteur - y) - 1][x].B;
// couleur->V = JPG->raster[JPG->hauteur - (JPG->hauteur - y) - 1][x].V;
// couleur->R = JPG->raster[JPG->hauteur - (JPG->hauteur - y) - 1][x].R;
}
void JPGclose (JPGfile *JPG)
{
free (JPG->raster);
} |
Partager