Skip to content

Bmp object

bmp_object

Module for reading and parsing bitmap graphics files.

BmpColorMap

An object representing a BMP_COLOR_MAP.

Attributes:

Name Type Description
Blue int

blue

Green int

green

Red int

red

typedef struct {
    UINT8   Blue;
    UINT8   Green;
    UINT8   Red;
    UINT8   Reserved;
} BMP_COLOR_MAP;

__init__

__init__(filestream: Optional[IO] = None) -> BmpColorMap

Inits an empty object or loads from an fs.

PopulateFromFileStream

PopulateFromFileStream(fs: IO) -> None

Loads a bmp from a filestream.

Parameters:

Name Type Description Default
fs obj

A loaded filestream.

required

Raises:

Type Description
Exception

Invalid filestream

Print

Print() -> None

Logs the object.

Write

Write(fs: IO) -> None

Writes the object to a fs.

BmpObject

An object representing a BMP_IMAGE_HEADER.

typedef struct {
    CHAR8         CharB;  < -- Start of FileHeader
    CHAR8         CharM;
    UINT32        Size;
    UINT16        Reserved[2];
    UINT32        ImageOffset;  <-- Start of pixel data relative to start of FileHeader
    UINT32        HeaderSize;  < -- Start of BmpHeader
    UINT32        PixelWidth;
    UINT32        PixelHeight;
    UINT16        Planes;          ///< Must be 1
    UINT16        BitPerPixel;     ///< 1, 4, 8, or 24
    UINT32        CompressionType;
    UINT32        ImageSize;       ///< Compressed image size in bytes
    UINT32        XPixelsPerMeter;
    UINT32        YPixelsPerMeter;
    UINT32        NumberOfColors;
    UINT32        ImportantColors;
} BMP_IMAGE_HEADER;

__init__

__init__(filestream: Optional[IO] = None) -> BmpObject

Inits an empty object or loads from filestream.

ExpectedColorMapEntires

ExpectedColorMapEntires() -> int

Returns expected entries depending on BitPerPixel.

PopulateFromFileStream

PopulateFromFileStream(fs: IO) -> None

Method to un-serialize from a filestream.

Parameters:

Name Type Description Default
fs obj

filestream

required

Raises:

Type Description
Exception

Invalid filestream

Exception

Invalid size

Exception

Invalid Color map

Exception

Data remaining in buffer

Print

Print(
    PrintImageData: bool = False,
    PrintColorMapData: bool = False,
) -> None

Prints to logger.

Parameters:

Name Type Description Default
PrintImageData bool

Whether to print the ColorImage Data

False
PrintColorMapData bool

Whether to print the ColorMap List

False

Write

Write(fs: IO) -> bytes

Serializes the Bmp object.

Returns:

Type Description
bytes

string representing packed data as bytes (i.e. b'\x01\x00\x03')