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
|
#include <stdio.h>
#include <io.h>
#include <stdlib.h> // to use malloc (memory allocation)
//#include <windows.h> // to work with BMP
#define PHOTOBW "C:\\C++-Programme\\Guilhem_Martin\\test01.bmp"
// TEST SEEMS OK FOR ENTIRE WHITE FUNCTION OR ENTIRE BLACK FUNCTION
#define PHOTOBW2 "C:\\C++-Programme\\Guilhem_Martin\\halfblack_halfwhite_totest_coordinatesystem_and_getlev.bmp"
#define PHOTOBW3 "C:\\C++-Programme\\Guilhem_Martin\\halfblack_halfwhite_reverse.bmp"
#define PHOTOBW4 "C:\\C++-Programme\\Guilhem_Martin\\wasser486bmp10241024_centered_worked_b2.bmp"
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 char * frame_total; // The frame is supposed to store the whole image file
unsigned char * frame_intensity; // (R+G+B)/3
// unsigned short int * frame_pixel; // Compute the R+G+B for one pixel
int n_frame; //long n_frame;
//unsigned short int lSize; // Causes error by execution
long lSize; // Size of the file to analyse (including both image and header data)
int number_of_element_read;
int offset_image;
int n_frame2=0;
// Notice !
// lSize : length of the file in bytes (8bits) :
// For instance 32 bits for lSize is 4 bytes
// buffer defined as (unsigned) short int (16bits ou 2 bytes)
//************OPENING AND SETTING UP FILE POINTER************//
//** fopen returns a pointer to the file, Opening the file in binary mode
//** Variables to be passed in parameter for fread
//** lSize : same size as the one displayed in the property dialog in the explorer
if((pFile=fopen(PHOTOBW4,"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
// fseek (pFile,55,SEEK_SET); // Place the cursor to the beginning of BMP data (54 bytes are designed for the header)
fseek (pFile,10,SEEK_SET);
printf("offset_image = %d \n",offset_image=fgetc(pFile));
fseek (pFile,offset_image,SEEK_SET);
//mybmp=pFile;//mybmp//biBitCount
frame_total = (unsigned char*) malloc (3 * 1024 * 1024 * sizeof(unsigned char)); // allocate memory to contain the whole file.
frame_intensity = (unsigned char*) malloc (1024 * 1024 * sizeof(unsigned char));
if(frame_total == NULL)
{
printf("Error by buffer allocation \n");
exit (2);
}
number_of_element_read=fread (frame_total,1,3 * 1024 * 1024 * sizeof(unsigned char),pFile); // copy the file into the buffer. The whole file is loaded in the buffer.
// 3*1024*1024 = 3145728
printf("FREAD VALUE IS : %d \n",number_of_element_read);
printf("FREAD/3 VALUE IS : %d \n",number_of_element_read/3);
//printf("%d %d %d \n",frame_total[0],frame_total[1],frame_total[2]);
//printf("%d %d %d \n",frame_total[3069],frame_total[3070],frame_total[3071]);
// frame_total[3069]=(frame_total[3070]+frame_total[3071])/2-58; Ca ca marche
/*
for(n_frame=0;n_frame<(3 * 1024 * 1024);n_frame=n_frame+3)
{
// printf("n_frame %d R %d G %d B %d # \n",n_frame,frame_total[n_frame],frame_total[n_frame+1],frame_total[n_frame+2]);
/* if((n_frame+3)<(3 * 1024 * 1024))
if(frame_total[n_frame]!=frame_total[n_frame+3])
{
printf("n_frame %d R %d G %d B %d # \n",n_frame,frame_total[n_frame],frame_total[n_frame+1],frame_total[n_frame+2]);
printf("n_frame %d R %d G %d B %d # \n",n_frame+3,frame_total[n_frame+3],frame_total[n_frame+1+3],frame_total[n_frame+2+3]);
}
}*/
for(n_frame=0;n_frame<(1024 * 1024);n_frame=n_frame+1)
{
frame_intensity[n_frame]=(n_frame,frame_total[n_frame]+frame_total[n_frame+1]+frame_total[n_frame+2])/3;
n_frame2=n_frame2+3;
}
} |
Partager