i'm trying reading a JPG\GIF file, it's a binary file true and i must see it's structure for it... now i have these link about JPG format image:
JPEG File Layout and Format
like we know the file is combined with 1 or 2 or 4 bytes on types.
for now, i just need read the size. so heres the information:
"SOF0 (Start Of Frame 0) marker:
Field Size Description
Marker Identifier 2 bytes 0xff, 0xc0 to identify SOF0 marker
Length 2 bytes This value equals to 8 + components*3 value
Data precision 1 byte This is in bits/sample, usually 8
(12 and 16 not supported by most software).
Image height 2 bytes This must be > 0
Image Width 2 bytes This must be > 0"
i must find the "SOF0" mark... but how can i search?
the file data is on these variable:
now heres how i test if is "SOF0":Code:BMPSize bmp; FILE* img = fopen(filename, "rb"); //read the file char header[256]; fread(header, sizeof(unsigned char), 256, img); // read the 54-byte header
so what i'm doing wrong for compare?Code:size_t i =0; do { if( strcmp(header, "SOF0")==0) { printf("hello"); width = *(int*)&header[i+2]; height= *(int*)&header[i+4]; break; } i++; }while(i<strlen(header));