int png(FILE *fileptr);
typedef struct _PngSignature
{
BYTE Signature[8]; /* Identifier (always 89504E470D0A1A0Ah) */
} PNGSIGNATURE;
typedef struct _PngChunk
{
DWORD DataLength; /* Size of Data field in bytes */
DWORD Type; /* Code identifying the type of chunk */
BYTE Data[]; /* The actual data stored by the chunk */
DWORD Crc; /* CRC-32 value of the Type and Data fields */
} PNGCHUNK;
typedef struct _IHDRChunk
{
DWORD Width; /* Width of image in pixels */
DWORD Height; /* Height of image in pixels */
BYTE BitDepth; /* Bits per pixel or per sample */
BYTE ColorType; /* Color interpretation indicator */
BYTE Compression; /* Compression type indicator */
BYTE Filter; /* Filter type indicator */
BYTE Interlace; /* Type of interlacing scheme used */
} IHDRCHUNK;
int png(FILE *fileptr)
{
PNGSIGNATURE syg;
PNGCHUNK pngchunk;
IHDRCHUNK ihdrchunk;
fread(&syg, sizeof(PNGSIGNATURE),1,fileptr);
fread(&pngchunk, sizeof(PNGCHUNK),1,fileptr);
fread(&ihdrchunk, sizeof(IHDRCHUNK),1,fileptr);
printf("Szerokosc %ld, wysokosc %ld, rozmiar %ld", ihdrchunk.Width ,ihdrchunk.Height);
fclose(fileptr);
return 0;
}
int bmp(FILE *fileptr)
{
BITMAPINFOHEADER bitmapInfoHeader; //our bitmap file header
BITMAPFILEHEADER bitmapFileHeader;
fread(&bitmapFileHeader, sizeof(BITMAPFILEHEADER),1,fileptr);
//verify that this is a bmp file by check bitmap id
if (bitmapFileHeader.bfType !=0x4D42)
{
fclose(fileptr);
return 1;
}
fread(&bitmapInfoHeader, sizeof(BITMAPINFOHEADER),1,fileptr);
// printf("Szerokosc %ld, wysokosc %ld, rozmiar %ld",bitmapInfoHeader.biWidth, bitmapInfoHeader.biheight, bitmapInfoHeader.biSizeImage);
fclose(fileptr);
return 0;
}
No dobra, na podstawie http://www.fileformat.info/format/png/egff.htm Napisałem to co wyżej. Ale jest problem z _PngChunk, BYTE Data[]; może mieć różną wielkość.
Jak to ominąć ? Właściwie jest mi potrzebne tylko IHDRChunk, ale nie wiem jak dojść do tego bez czytania poprzednich.