Добрый день, уважаемые!
Собственно, и снова я, как и ожидалось
Функция получения ширины/высоты графического файла формата PCX (*.pcx):
//---------------------------------------------------------------------------
bool GetPCXDim(const char* FileName, int& Width, int& Height)
{
Width = Height = -1;
FILE* hFile = fopen(FileName,"rb");
if(!hFile) return false;
unsigned char signature=0;
if(!fread(&signature,1,1,hFile)) {
fclose(hFile);
return false;
}
if(signature!=10) {// bad signature
fclose(hFile);
return false;
}
if(fseek(hFile,3,SEEK_SET)!=0) {
fclose(hFile);
return false;
}
unsigned char bpp=0; // bit per pixel
if(!fread(&bpp,1,1,hFile)) {
fclose(hFile);
return false;
}
struct {
unsigned short xMin;
unsigned short yMin;
unsigned short xMax;
unsigned short yMax;
} sWindow;
if(!fread(&sWindow,8,1,hFile)) { // read image dimensions
fclose(hFile);
return false;
}
Width = sWindow.xMax - sWindow.xMin +1;
Height = sWindow.yMax - sWindow.yMin +1;
fclose(hFile);
return true;
}
//---------------------------------------------------------------------------
Пример использования:
int Width, Height;
GetPCXDim("C:\\test.pcx",Width,Height); // в Width - ширина, в Height - высота