avifilelib.bmp module

Decoders for Microsoft BMP formats.

This package provides decoders capable of decoding frames encoded using the Microsoft Bitmap formats.

class avifilelib.bmp.BMP16Decoder(width, height, colors=None)

Bases: avifilelib.bmp.BMPDecoderBase

Decoder for 16-bit bitmaps.

This class implements a decoder for the 16-bit bitmaps.

BIT_COUNT = 16
BLUE_MASK = 31
BLUE_SHIFT = 0
COMPRESSION = 0
GREEN_MASK = 992
GREEN_SHIFT = 5
RED_MASK = 31744
RED_SHIFT = 10
decode_frame_buffer(buffer, size, keyframe=True)

Decode a frame from a bytes object.

Decodes a single frame from the data contained in buffer.

Parameters:
  • buffer (bytes) – A bytes object containing the frame data.
  • size (int) – Size of the data in the buffer.
  • keyframe (bool) – Indicates to the decoder that this chunk contains a key frame.
Returns:

A two dimensional array of dimensions height by width containing the resulting image.

Return type:

numpy.ndarray

class avifilelib.bmp.BMP24Decoder(width, height, colors=None)

Bases: avifilelib.bmp.BMPDecoderBase

Decoder for 24-bit bitmaps.

This class implements a decoder for the 24-bit bitmaps.

BIT_COUNT = 24
COMPRESSION = 0
decode_frame_buffer(buffer, size, keyframe=True)

Decode a frame from a bytes object.

Decodes a single frame from the data contained in buffer.

Parameters:
  • buffer (bytes) – A bytes object containing the frame data.
  • size (int) – Size of the data in the buffer.
  • keyframe (bool) – Indicates to the decoder that this chunk contains a key frame.
Returns:

A two dimensional array of dimensions height by width containing the resulting image.

Return type:

numpy.ndarray

class avifilelib.bmp.BMP32Decoder(width, height, colors=None)

Bases: avifilelib.bmp.BMPDecoderBase

Decoder for 32-bit bitmaps.

This class implements a decoder for the 32-bit bitmaps.

BIT_COUNT = 32
COMPRESSION = 0
decode_frame_buffer(buffer, size, keyframe=True)

Decode a frame from a bytes object.

Decodes a single frame from the data contained in buffer.

Parameters:
  • buffer (bytes) – A bytes object containing the frame data.
  • size (int) – Size of the data in the buffer.
  • keyframe (bool) – Indicates to the decoder that this chunk contains a key frame.
Returns:

A two dimensional array of dimensions height by width containing the resulting image.

Return type:

numpy.ndarray

class avifilelib.bmp.BMP8Decoder(width, height, colors=None)

Bases: avifilelib.bmp.BMPDecoderBase

Decoder for 8-bit bitmaps.

This class implements a decoder for the 8-bit bitmaps.

BIT_COUNT = 8
COMPRESSION = 0
decode_frame_buffer(buffer, size, keyframe=True)

Decode a frame from a bytes object.

Decodes a single frame from the data contained in buffer.

Parameters:
  • buffer (bytes) – A bytes object containing the frame data.
  • size (int) – Size of the data in the buffer.
  • keyframe (bool) – Indicates to the decoder that this chunk contains a key frame.
Returns:

A two dimensional array of dimensions height by width containing the resulting image.

Return type:

numpy.ndarray

class avifilelib.bmp.BMPDecoderBase(width, height, colors=None)

Bases: avifilelib.decoder.DecoderBase

Base class for bitmap decoders.

Parameters:
  • width (int) – Width of the image to be decoded.
  • height (int) – Height of the image to be decoded.
  • colors (numpy.ndarray, dtype=uint8) – N x 3 of red, green, and blue values, where N is 2^4 or 2^8 depending on the type of RLE compression.
COMPRESSION = (<BI_COMPRESSION.BI_RGB: 0>,)
classmethod for_avi_stream(stream_definition)

Attempts to find a decoder implementation for a stream.

Subclasses of BMPDecoderBase are selected by matching the value of BIT_COUNT.

Returns:A subclass of BMPDecoderBase.
Return type:object
image

Gets a copy of the image.

class avifilelib.bmp.BMPFileHeader(type, size, reserved1, reserved2, offbits)

Bases: object

BITMAPFILEHEADER structure.

Parameters:
  • type (bytes) – must be b’BM’
  • size (int) – Size of the bitmap data
  • reserved1 (int) – Reserved value, must be zero (but not checked here)
  • reserved2 (int) – Reserved value, must be zero (but not checked here)
  • offbits (int) – offset from the beginning of the header to start of the bitmap data
classmethod from_buffer(buffer)
classmethod from_file(file)
class avifilelib.bmp.BMP_DRAW_ORDER

Bases: enum.Enum

Bitmap drawing orders.

BOTTOM_UP = 1
TOP_DOWN = 2