Alien-FreeImage
view release on metacpan or search on metacpan
src/Source/FreeImage/PluginBMP.cpp view on Meta::CPAN
BYTE second_byte = 0;
int scanline = 0;
int bits = 0;
for (;;) {
if( io->read_proc(&status_byte, sizeof(BYTE), 1, handle) != 1) {
return FALSE;
}
switch (status_byte) {
case RLE_COMMAND :
if(io->read_proc(&status_byte, sizeof(BYTE), 1, handle) != 1) {
return FALSE;
}
switch (status_byte) {
case RLE_ENDOFLINE :
bits = 0;
scanline++;
break;
case RLE_ENDOFBITMAP :
return TRUE;
case RLE_DELTA :
{
// read the delta values
BYTE delta_x = 0;
BYTE delta_y = 0;
if(io->read_proc(&delta_x, sizeof(BYTE), 1, handle) != 1) {
return FALSE;
}
if(io->read_proc(&delta_y, sizeof(BYTE), 1, handle) != 1) {
return FALSE;
}
// apply them
bits += delta_x;
scanline += delta_y;
break;
}
default :
{
if(scanline >= abs(height)) {
return TRUE;
}
int count = MIN((int)status_byte, width - bits);
BYTE *sline = FreeImage_GetScanLine(dib, scanline);
if(io->read_proc((void *)(sline + bits), sizeof(BYTE) * count, 1, handle) != 1) {
return FALSE;
}
// align run length to even number of bytes
if ((status_byte & 1) == 1) {
if(io->read_proc(&second_byte, sizeof(BYTE), 1, handle) != 1) {
return FALSE;
}
}
bits += status_byte;
break;
}
}
break;
default :
{
if(scanline >= abs(height)) {
return TRUE;
}
int count = MIN((int)status_byte, width - bits);
BYTE *sline = FreeImage_GetScanLine(dib, scanline);
if(io->read_proc(&second_byte, sizeof(BYTE), 1, handle) != 1) {
return FALSE;
}
for (int i = 0; i < count; i++) {
*(sline + bits) = second_byte;
bits++;
}
break;
}
}
}
}
// --------------------------------------------------------------------------
static FIBITMAP *
LoadWindowsBMP(FreeImageIO *io, fi_handle handle, int flags, unsigned bitmap_bits_offset, int type) {
FIBITMAP *dib = NULL;
try {
BOOL header_only = (flags & FIF_LOAD_NOPIXELS) == FIF_LOAD_NOPIXELS;
// load the info header
BITMAPINFOHEADER bih;
io->read_proc(&bih, sizeof(BITMAPINFOHEADER), 1, handle);
#ifdef FREEIMAGE_BIGENDIAN
SwapInfoHeader(&bih);
#endif
// keep some general information about the bitmap
( run in 0.567 second using v1.01-cache-2.11-cpan-119454b85a5 )