Bonjour à tous !
J'ai écrit un programme pour stocker les valeurs des pixels (0->65535) d'une image BMP dans un tableau de unsigned short int. J'ai essayé avec une image moitié noire moitié blanche. Pour vérifier que le remplissage du tableau s'était correctement effectué, j'ai comparé les valeurs d'un tableau unsigned short int que j'ai rempli avec moitié de 0 (noir) et moitié de 65535 (blanc). Mais je n'obtiens pas le même résultat avec le tableau construit à partir de l'image.
Voilà, en 4 étapes principales ce que je fais :
1. Ouvrir la BMP en mode binaire
2. Stocker la BMP dans un buffer de <taille du fichier>
3. Enregistrer les données image seulement dans un buffer de taille 1024*1024
4. Comparer le tableau rempli "artificiellement" et le tableau vraiment extrait de l'image ; afficher seulement les éléments qui diffèrent
A l'exécution, j'obtiens cela :
** Remplissage tableau artificiel
** Remplissage tableau de données image de la BMP
** n_frame : 524288 # table_to_fill[] : 65535 frame[] = 0
** n_frame : 524289 # table_to_fill[] : 65535 frame[] = 0
** n_frame : 524290 # table_to_fill[] : 65535 frame[] = 0
** (...)
Cela veut donc dire qu'à partir de la case 524288, les éléments des tableaux diffèrent. Est-ce que quelqu'un voit d'où cela vient ?
Merci pour vos aides et suggestions.
Vous trouverez le code ci-dessous.
Merci beaucoup,
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 void main() { FILE *pFile; // Pointer to the image file to process (to extract the drop profile from) unsigned short int* table_to_fill; // half black half white unsigned short int* frame; // The frame is supposed to store only image data (and not header information) unsigned short int* frame_total; // The frame is supposed to store the whole image file int n_frame; long lSize; // Size of the file to analyse (including both image and header data) // Notice ! // lSize : length of the file in bytes (8bits) // buffer defined as (unsigned) short int (16bits or 2 bytes) //************OPENING AND SETTING UP FILE POINTER************// if((pFile=fopen(PHOTOBW,"rb"))==0) printf("Open file failed\n"); // Read only Opening BMP file fseek (pFile , 0 , SEEK_END); // obtain file size lSize = ftell (pFile); rewind (pFile); // Replace the pointer to the beginning of the file frame_total = (unsigned short int*) malloc (lSize * sizeof(unsigned short int)); // allocates memory frame = (unsigned short int*) malloc ((1048576) * sizeof(unsigned short int)); table_to_fill = (unsigned short int*) malloc ((1048576) * sizeof(unsigned short int)); if (frame == NULL || frame_total == NULL || table_to_fill==NULL) // Problem by buffer allocation { printf("Error by buffer allocation \n"); exit (2); } fread (frame_total,1,lSize,pFile); // copy the file into the buffer. The whole file is loaded in the buffer. printf("Filling artificially table \n"); for(n_frame=0;n_frame<(1024*1024);n_frame++) { if(n_frame<(1024*1024*0.5)) table_to_fill[n_frame]=0; else table_to_fill[n_frame]=65535; } printf("\n"); printf("Filling table from real picture"); for(n_frame=0;n_frame<(1024*1024);n_frame++) { frame[n_frame] = frame_total[n_frame+28]; // Copy the BMP data } // Compares the 2 tables for(n_frame=0;n_frame<(1024*1024);n_frame++) { if((table_to_fill[n_frame]-frame[n_frame])!=0) { printf("n_frame : %d # ",n_frame); printf("table_to_fill[] : %d frame[] = %d \n",table_to_fill[n_frame],frame[n_frame]); } } printf("\n"); }
Guilhem Martin.
Partager