Kicking it Olde Sküül! Burgerlib on Github Follow Olde Sküül on Twitter Burgerbecky on LinkedIn Burgerbecky on LinkedIn
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Attributes | List of all members
Burger::FileBMP Class Reference

Reads and writes BMP files. More...

Collaboration diagram for Burger::FileBMP:
Collaboration graph
[legend]

Public Types

enum  {
  BMP_RGB =0 , BMP_RLE8 =1 , BMP_RLE4 =2 , BMP_BITFIELDS =3 ,
  BMP_JPEG =4 , BMP_PNG =5 , BMP_ALPHABITFIELDS =6 , BMP_CMYK =11 ,
  BMP_CMYKRLE8 =12 , BMP_CMYKTLE4 =13
}
 

Public Member Functions

 FileBMP ()
 Default constructor.
 
uint_t Load (Image *pOutput, InputMemoryStream *pInput)
 Parses a BMP file.
 
uint_t Save (OutputMemoryStream *pOutput, const Image *pImage, uint_t bCompression=0)
 Write an Image structure out as a BMP file image.
 
uint16_t GetReserved1 (void) const
 Get the file image's first reserved value.
 
void SetReserved1 (uint16_t uReserved1)
 Set the file image's first reserved value.
 
uint16_t GetReserved2 (void) const
 Get the file image's second reserved value.
 
void SetReserved2 (uint16_t uReserved2)
 Set the file image's second reserved value.
 
int32_t GetXPixelsPerMeter (void) const
 Get the file image's pixels per meter for X.
 
void SetXPixelsPerMeter (int32_t iXPixelsPerMeter)
 Set the file image's pixels per meter for X.
 
int32_t GetYPixelsPerMeter (void) const
 Get the file image's pixels per meter for Y.
 
void SetYPixelsPerMeter (int32_t iYPixelsPerMeter)
 Set the file image's pixels per meter for Y.
 
const RGBAWord8_tGetPalette (void) const
 Get the file image's palette.
 
RGBAWord8_tGetPalette (void)
 Get the file image's palette.
 
void SetPalette (const RGBWord8_t *pInput, uint_t uStartIndex=0, uint_t uPaletteSize=256)
 Set the file image's palette (RGB)
 
void SetPalette (const RGBAWord8_t *pInput, uint_t uStartIndex=0, uint_t uPaletteSize=256)
 Set the file image's palette (RGBA)
 

Static Public Member Functions

static void CompressRLE8 (OutputMemoryStream *pOutput, const uint8_t *pInput, uintptr_t uInputLength, uint_t bSendEOP)
 Take a line of 8 bit pixel data and compress is using the RLE8 format.
 
static const char * DecompressRLE8 (uint8_t *pOutput, uintptr_t uOutputLength, InputMemoryStream *pInput)
 Unpack a single line of RLE data for a BMP file using RLE8 format.
 

Static Public Attributes

static const uint32_t FILETYPE = 0x424D5070
 'BMPp' Mac File type for BMP files (Byte swapped on little endian machines)
 
static const uint32_t AUXTYPE = 0x6F676C65
 'ogle' Mac creator code for BMP files (Byte swapped on little endian machines)
 
static const int32_t DEFAULT_PIXELS_PER_METER = 2835
 Default pixels per meter value for BMP files (2834.6472f)
 

Private Attributes

uint16_t m_uReserved1
 BMP Header reserved field #1.
 
uint16_t m_uReserved2
 BMP Header reserved field #2.
 
int32_t m_iXPixelsPerMeter
 X Pixels per meter.
 
int32_t m_iYPixelsPerMeter
 Y Pixels per meter.
 
uint32_t m_uColorsUsed
 Number of colors used.
 
uint32_t m_uColorsImportant
 Number of important colors.
 
RGBAWord8_t m_Palette [256]
 Palette found in the image.
 

Detailed Description

Reads and writes BMP files.


This class will read and write out BMP files and use Burger::Image class instances as data transporters

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
BMP_RGB 

Raw pixels.

BMP_RLE8 

8 bit compression

BMP_RLE4 

4 bit compression

BMP_BITFIELDS 

RGB bit field masks.

BMP_JPEG 

JPEG compression.

BMP_PNG 

PNG compression.

BMP_ALPHABITFIELDS 

RGBA bit field masks.

BMP_CMYK 

CMYK pixels.

BMP_CMYKRLE8 

8 bit compression using a CMYK palette

BMP_CMYKTLE4 

4 bit compression using a CMYK palette

Constructor & Destructor Documentation

◆ FileBMP()

Burger::FileBMP::FileBMP ( )

Default constructor.


Initializes all extra file data to defaults

Member Function Documentation

◆ CompressRLE8()

void BURGER_API Burger::FileBMP::CompressRLE8 ( OutputMemoryStream * pOutput,
const uint8_t * pInput,
uintptr_t uInputLength,
uint_t bSendEOP )
static

Take a line of 8 bit pixel data and compress is using the RLE8 format.


The format itself sucks eggs.

First send a compress token of 0 or a fill count of 1-255 If it's 1-255, then follow the token with the byte to fill with.

If it's zero, then follow it with zero for EOL, 1 for EOP data and 3-FF for raw data (Followed by raw data). Don't use token 2 (Jump)

Since the format needs to know when to send the end of image token, the parameter bSendEOP must be set to TRUE when it's to be sent

Parameters
pOutputPointer to the memory stream to output the compressed bytes into
pInputPointer to a scan line of pixels
uInputLengthNumber of input bytes to process
bSendEOPTRUE when sending the last scan line

◆ DecompressRLE8()

const char *BURGER_API Burger::FileBMP::DecompressRLE8 ( uint8_t * pOutput,
uintptr_t uOutputLength,
InputMemoryStream * pInput )
static

Unpack a single line of RLE data for a BMP file using RLE8 format.


It's a little strange but here goes...

Grab a byte, if it's not zero then use it as a repeat count and grab the next byte as the fill byte.

If it is zero, then this is an escape code. 0 : end of line 1 : end of data 2 : Delta, get two bytes for a pen move code (Not used) 3-0xFF absolute run (But uint16_t align the source pointer after run)

Parameters
pOutputBuffer to accept the decompressed data
uOutputLengthLength of the buffer for decompressed data
pInputData stream to read compressed data from
Returns
NULL if success or a pointer to a string describing the error

◆ GetPalette() [1/2]

RGBAWord8_t * Burger::FileBMP::GetPalette ( void )
inline

Get the file image's palette.


Obtain a pointer to the 256 entry RGBA color palette found in the BMP file

Returns
Pointer to the 256 entry RGBAWord8_t palette
See also
Burger::FileBMP::GetPalette(void) const

◆ GetPalette() [2/2]

const RGBAWord8_t * Burger::FileBMP::GetPalette ( void ) const
inline

Get the file image's palette.


Obtain a constant pointer to the 256 entry RGBA color palette found in the BMP file

Returns
Constant pointer to the 256 entry RGBAWord8_t palette
See also
Burger::FileBMP::GetPalette(void)

◆ GetReserved1()

uint16_t Burger::FileBMP::GetReserved1 ( void ) const
inline

Get the file image's first reserved value.


Return the BMP file header's first reserved 16 bit value in native endian

Note
This value is usually zero. It's only to contain application specific data and is not recommended for storing data.
Returns
The first 16 bit reserved value.
See also
Burger::FileBMP::SetReserved1(uint16_t) or Burger::FileBMP::GetReserved2(void) const

◆ GetReserved2()

uint16_t Burger::FileBMP::GetReserved2 ( void ) const
inline

Get the file image's second reserved value.


Return the BMP file header's second reserved 16 bit value in native endian

Note
This value is usually zero. It's only to contain application specific data and is not recommended for storing data.
Returns
The second 16 bit reserved value.
See also
Burger::FileBMP::SetReserved2(uint16_t) or Burger::FileBMP::GetReserved1(void) const

◆ GetXPixelsPerMeter()

int32_t Burger::FileBMP::GetXPixelsPerMeter ( void ) const
inline

Get the file image's pixels per meter for X.


Return the pixels per meter constant, usually it's 2835 (2834.6472f)

Returns
The pixels per meter constant for the X direction
See also
Burger::FileBMP::SetXPixelsPerMeter(int32_t) or Burger::FileBMP::GetYPixelsPerMeter(void) const

◆ GetYPixelsPerMeter()

int32_t Burger::FileBMP::GetYPixelsPerMeter ( void ) const
inline

Get the file image's pixels per meter for Y.


Return the pixels per meter constant, usually it's 2835 (2834.6472f)

Returns
The pixels per meter constant for the Y direction
See also
Burger::FileBMP::SetYPixelsPerMeter(int32_t) or Burger::FileBMP::GetXPixelsPerMeter(void) const

◆ Load()

uint_t BURGER_API Burger::FileBMP::Load ( Image * pOutput,
InputMemoryStream * pInput )

Parses a BMP file.


Read in a BMP file and set the extra variables

Will parse 16, 24 and 32 bit uncompressed and 8 bit compressed and uncompressed BMP files only. Other formats are not supported

Note
A descriptive error message is passed to Debug::Warning()
Parameters
pOutputPointer to an Image record to store the new image into
pInputPointer to a memory stream that has a BMP file image
Returns
Zero for success or non-zero on failure

◆ Save()

uint_t Burger::FileBMP::Save ( OutputMemoryStream * pOutput,
const Image * pImage,
uint_t bCompress = 0 )

Write an Image structure out as a BMP file image.


Given an image in 8, 15, 16, 24 or 32 bit format, write it out as a BMP file.

8, 15, 24 and 32 bit images are written out without alteration. 16 bit formats will have any alpha data from them stripped, this is a limitation of the BMP file format

Note
The BMP file format only supports compression on 8 bit paletted images. For all other image formats, the bCompress parameter is ignored.
Parameters
pOutputPointer to the output stream to store the file image
pImagePointer to a valid Image structure containing the image data
bCompressTRUE to apply compression to 8 bit images
Returns
Zero if successful

◆ SetPalette() [1/2]

void Burger::FileBMP::SetPalette ( const RGBAWord8_t * pInput,
uint_t uStartIndex = 0,
uint_t uPaletteSize = 256 )
inline

Set the file image's palette (RGBA)


Given a pointer to a palette, copy the colors into this class for writing to an 8 bit BMP file.

If the starting index is greater than 255, this function does nothing. If the color entry count exceeds 256 colors, the remaining colors are ignored to prevent buffer overruns

Parameters
pInputPointer to the palette to copy
uStartIndexColor index of the 256 color internal palette to start modification
uPaletteSizeNumber of color entries in the palette (Maximum 256)
See also
SetPalette(const RGBWord8_t *,uint_t,uint_t)

◆ SetPalette() [2/2]

void Burger::FileBMP::SetPalette ( const RGBWord8_t * pInput,
uint_t uStartIndex = 0,
uint_t uPaletteSize = 256 )
inline

Set the file image's palette (RGB)


Given a pointer to a palette, copy the colors into this class for writing to an 8 bit BMP file. Since the Alpha is missing from the input, each entry set will have the alpha set to zero.

If the starting index is greater than 255, this function does nothing. If the color entry count exceeds 256 colors, the remaining colors are ignored to prevent buffer overruns

Parameters
pInputPointer to the palette to copy
uStartIndexColor index of the 256 color internal palette to start modification
uPaletteSizeNumber of color entries in the palette (Maximum 256)
See also
SetPalette(const RGBAWord8_t *,uint_t,uint_t)

◆ SetReserved1()

void Burger::FileBMP::SetReserved1 ( uint16_t uReserved1)
inline

Set the file image's first reserved value.


Sets the BMP file header's first reserved 16 bit value from native endian

Parameters
uReserved1New first reserved value
See also
Burger::FileBMP::GetReserved1(void) const or Burger::FileBMP::SetReserved2(uint16_t)

◆ SetReserved2()

void Burger::FileBMP::SetReserved2 ( uint16_t uReserved2)
inline

Set the file image's second reserved value.


Sets the BMP file header's second reserved 16 bit value from native endian

Parameters
uReserved2New second reserved value
See also
Burger::FileBMP::GetReserved2(void) const or Burger::FileBMP::SetReserved1(uint16_t)

◆ SetXPixelsPerMeter()

void Burger::FileBMP::SetXPixelsPerMeter ( int32_t iXPixelsPerMeter)
inline

Set the file image's pixels per meter for X.


Set the pixels per meter constant

Parameters
iXPixelsPerMeterNew pixels per meter constant
See also
Burger::FileBMP::DEFAULT_PIXELS_PER_METER, Burger::FileBMP::GetXPixelsPerMeter(void) const or Burger::FileBMP::SetYPixelsPerMeter(int32_t)

◆ SetYPixelsPerMeter()

void Burger::FileBMP::SetYPixelsPerMeter ( int32_t iYPixelsPerMeter)
inline

Set the file image's pixels per meter for Y.


Set the pixels per meter constant

Parameters
iYPixelsPerMeterNew pixels per meter constant
See also
Burger::FileBMP::DEFAULT_PIXELS_PER_METER, Burger::FileBMP::GetYPixelsPerMeter(void) const or Burger::FileBMP::SetXPixelsPerMeter(int32_t)

Member Data Documentation

◆ AUXTYPE

const uint32_t Burger::FileBMP::AUXTYPE = 0x6F676C65
static

'ogle' Mac creator code for BMP files (Byte swapped on little endian machines)

◆ DEFAULT_PIXELS_PER_METER

const int32_t Burger::FileBMP::DEFAULT_PIXELS_PER_METER = 2835
static

Default pixels per meter value for BMP files (2834.6472f)

◆ FILETYPE

const uint32_t Burger::FileBMP::FILETYPE = 0x424D5070
static

'BMPp' Mac File type for BMP files (Byte swapped on little endian machines)

◆ m_iXPixelsPerMeter

int32_t Burger::FileBMP::m_iXPixelsPerMeter
private

X Pixels per meter.

◆ m_iYPixelsPerMeter

int32_t Burger::FileBMP::m_iYPixelsPerMeter
private

Y Pixels per meter.

◆ m_Palette

RGBAWord8_t Burger::FileBMP::m_Palette[256]
private

Palette found in the image.

◆ m_uColorsImportant

uint32_t Burger::FileBMP::m_uColorsImportant
private

Number of important colors.

◆ m_uColorsUsed

uint32_t Burger::FileBMP::m_uColorsUsed
private

Number of colors used.

◆ m_uReserved1

uint16_t Burger::FileBMP::m_uReserved1
private

BMP Header reserved field #1.

◆ m_uReserved2

uint16_t Burger::FileBMP::m_uReserved2
private

BMP Header reserved field #2.