Answer the question
In order to leave comments, you need to log in
How to figure out what's going on in this header file?
The theme of the project is working with bmp-images.
https://ru.wikipedia.org/wiki/BMP
C++ builder. The bmp.h header file declares: structures, a class (maybe it's a constructor?) and functions. Please explain how it all works to a newbie.
How was this header file included in the project, just #include "bmp.h" or through the c++builder-a menu?
#include <io.h>
#include <stdio.h>
#pragma pack(1)
struct FileHeader
{
WORD bfType;
DWORD bfSize;
WORD bfReserved1; //не используется
WORD bfReserved2; //не используется
DWORD bfOffbits; //смещение данных битового образа от заголовка в байтах
};
struct MAPINFO
{
DWORD Size; //число байт, занимаемых структурой InfoHeader
DWORD Width; //ширина битового образа в пикселях
DWORD Height; //высота битового образа в пикселях
WORD Planes; //число битовых плоскостей устройства
WORD BitCount; //число битов на пиксель
DWORD Compression; //тип сжатия
DWORD SizeImage; //размер картинки в байтах
long XPelsPerMeter; //горизонтальное разрешение устройства, пиксель/м
long YPelPerMeter; //вертикальное разрешение устройства, пиксель/м
DWORD ClrUsed; //число используемых цветов
DWORD ClrImportant; //число "важных" цветов
};
struct RGBquad
{
BYTE rgbBlue; //интенсивность голубого
BYTE rgbGreen; //интенсивность зеленого
BYTE rgbRed; //интенсивность красного
BYTE rgbReserved; //не используется
};
class CBmp
{
private:
void *pBmp;
long SizeFile;
public:
CBmp();
~CBmp();
void Open(char* fn);
void Save(char* fn);
FileHeader *GetFH();
MAPINFO *GetMapInfo();
RGBquad *GetMap();
};
void CBmp::Save(char* fn)
{
FILE* File;
File=fopen(fn,"wb");
fwrite(pBmp,1,SizeFile,File);
fclose(File);
}
RGBquad *CBmp::GetMap()
{
RGBquad *rgb;
rgb=(RGBquad *)((long)pBmp+sizeof(FileHeader)+sizeof(MAPINFO));
return rgb;
}
MAPINFO *CBmp::GetMapInfo()
{
MAPINFO *mi;
mi=(MAPINFO*)((long)pBmp+sizeof(FileHeader));
return mi;
}
FileHeader *CBmp::GetFH()
{
FileHeader *fh;
fh=(FileHeader *)pBmp;
return fh;
}
CBmp::CBmp()
{
pBmp=0;
SizeFile=0;
}
CBmp::~CBmp()
{
delete [] pBmp;
}
void CBmp::Open(char* fn)
{
FILE* File;
int hFile;
File=fopen(fn,"rb");
hFile=_fileno(File);
SizeFile=filelength(hFile);
pBmp=(BYTE*)malloc(SizeFile);
fread(pBmp,1,SizeFile,File);
fclose(File);
}
Answer the question
In order to leave comments, you need to log in
Learn the concept of "compilation unit". Here, unfortunately, there are things that should be in the CPP file, and things that should be in the H file.
We need data structures "one to one", without padding bytes.
struct FileHeader
struct MAPINFO
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question