56 unsigned short Type()
const {
return *(
const unsigned short*)mType; }
57 unsigned int Size()
const {
return *(
const unsigned int*)mSize; }
58 unsigned short Reserved1()
const {
return *(
const unsigned short*)mReserved1; }
59 unsigned short Reserved2()
const {
return *(
const unsigned short*)mReserved2; }
60 unsigned int OffBits()
const {
return *(
const unsigned int*)mOffBits; }
65 unsigned int Size() {
return *(
unsigned int*)mSize; }
66 int Width() {
return *(
int*)mWidth; }
67 int Height() {
return *(
int*)mHeight; }
68 unsigned short Planes() {
return *(
unsigned short*)mPlanes; }
69 unsigned short BitCount() {
return *(
unsigned short*)mBitCount; }
70 unsigned int Compression() {
return *(
unsigned int*)mCompression; }
71 unsigned int SizeImage() {
return *(
unsigned int*)mSizeImage; }
72 int XPelsPerMeter() {
return *(
int*)mXPelsPerMeter; }
73 int YPelsPerMeter() {
return *(
int*)mYPelsPerMeter; }
74 unsigned int ClrUsed() {
return *(
unsigned int*)mClrUsed; }
75 unsigned int ClrImportant() {
return *(
unsigned int*)mClrImportant; }
84 char mXPelsPerMeter[4];
85 char mYPelsPerMeter[4];
87 char mClrImportant[4];
90 const unsigned int BMP_NoCompression = 0;
91 const unsigned int BMP_XRGB = 3;
127 BitmapFileHeader bfh;
128 memset(&bfh, 0,
sizeof(bfh));
129 BitmapInfoHeader bih;
130 memset(&bih, 0,
sizeof(bih));
132 file->
read(&bfh,
sizeof(bfh));
133 if (bfh.Type() != 0x4D42)
142 file->
read(&bih,
sizeof(bih));
145 if ( bih.Height() < 0 )
147 int *h = (
int*)bih.mHeight;
151 VL_CHECK( bih.Height() * bih.Width() );
154 if ( bih.Compression() != BMP_NoCompression && bih.Compression() != BMP_XRGB )
156 Log::error(
Say(
"Compression %n unsupported for %s\n") << bih.Compression() << file->
path() );
161 switch( bih.BitCount() )
169 memset(palette, 0, 256*4);
172 file->
seekSet( (
int)head + bih.Size() );
173 int palette_bytes = (bih.ClrUsed() ? bih.ClrUsed() : 256)*4;
174 br = (int)file->
read(palette, palette_bytes);
178 if(br != palette_bytes)
181 Log::error(
Say(
"File %s truncated: %n < %n.\n") << file->
path() << br << palette_bytes );
185 int pad_bytes = (4 - (img->
width() * 1) % 4) % 4;
186 int datasize = (img->
width() * 1 + pad_bytes) * img->
height();
190 if ( bih.Compression() == BMP_NoCompression )
192 br = (int)file->
read(img->
pixels(), datasize);
217 int pad_bytes = (4 - (img->
width() * 3) % 4) % 4;
219 int datasize = bih.BitCount() == 32 ? img->
width() * img->
height() * 4 : (img->
width() * 3 + pad_bytes) * img->
height();
220 int rd = (int)file->
read(img->
pixels(), datasize);
229 if (bih.BitCount() == 24)
237 Log::error(
Say(
"BitCount %n unsupported for %s\n") << (
int)bih.BitCount() << file->
path() );
248 for(
int h=0; h<img->
height(); ++h)
250 unsigned char* px = img->
pixels() + img->
pitch()*h;
251 for(
int x=0; x<img->
width()*4; x+=4)
267 BitmapFileHeader bfh;
268 memset(&bfh, 0,
sizeof(bfh));
269 BitmapInfoHeader bih;
270 memset(&bih, 0,
sizeof(bih));
272 file->
read(&bfh,
sizeof(bfh));
273 file->
read(&bih,
sizeof(bih));
276 if (bfh.Type() != 0x4D42)
282 switch( bih.BitCount() )
296 switch( bih.Compression() )
long long read(void *buffer, long long byte_count)
Reads byte_count bytes from a file. Returns the number of bytes actually read.
VLCORE_EXPORT FileSystem * defFileSystem()
Returns the default FileSystem used by VisualizationLibrary.
VLCORE_EXPORT ref< Image > loadBMP(VirtualFile *file)
An abstract class representing a file.
void convert8ToRGBA(const TPalette3x256 &palette, void *buf, int w, int h, unsigned char alpha, int bytealign=1)
A simple String formatting class.
const unsigned char * pixels() const
Raw pointer to pixels.
void setObjectName(const char *name)
The name of the object, by default set to the object's class name in debug builds.
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
static void error(const String &message)
Use this function to provide information about run-time errors: file not found, out of memory...
virtual ref< VirtualFile > locateFile(const String &full_path, const String &alternate_path=String()) const
Looks for a VirtualFile on the disk and in the currently active FileSystem.
virtual void close()=0
Closes the file.
const String & path() const
Returns the path of the file.
Visualization Library main namespace.
void convertRGBToRGBA(void *buf, int w, int h, unsigned char alpha, int bytealign=1)
virtual bool open(EOpenMode mode)=0
Opens the file in the specified mode.
bool seekSet(long long offset)
Changes the current read/write position of a file.
ref< Image > convertFormat(EImageFormat new_format) const
Converts the format() of an image.
VLCORE_EXPORT bool isBMP(VirtualFile *file)
Implements a generic 1d, 2d, 3d and cubemap image that can have mipmaps.
The ref<> class is used to reference-count an Object.
void allocate2D(int x, int y, int bytealign, EImageFormat format, EImageType type)
std::string toStdString() const
Returns a UTF8 encoded std::string.
long long position() const
Returns the current position in the file.
unsigned char TPalette4x256[256 *4]