mrcrowbar.lib.images.base module

class mrcrowbar.lib.images.base.CodecImage(parent, source, width=None, height=None, frame_count=1, format=None, mode=None)[source]

Bases: Image

Class for viewing image data encoded in a standard image file format.

ansi_format_iter(x_start=0, y_start=0, width=None, height=None, frame=0, columns=1, downsample=1)[source]

Return the ANSI escape sequence to render the image.

x_start

Offset from the left of the image data to render from. Defaults to 0.

y_start

Offset from the top of the image data to render from. Defaults to 0.

width

Width of the image data to render. Defaults to the image width.

height

Height of the image data to render. Defaults to the image height.

frame

Single frame number, or a list of frame numbers to render in sequence. Defaults to frame 0.

columns

Number of frames to render per line (useful for printing tilemaps!). Defaults to 1.

downsample

Shrink larger images by printing every nth pixel only. Defaults to 1.

property format
get_image()[source]
property mode
print(*args, **kwargs)[source]
class mrcrowbar.lib.images.base.Colour(source_data=None, parent=None, preload_attrs=None, endian=None, cache_bytes=False, path_hint=None)[source]

Bases: BaseColour, Block

Base class for Blocks.

source_data

Source data to construct Block with. Can be a byte string, dictionary of attribute: value pairs, or another Block object.

parent

Parent Block object where this Block is defined. Used for e.g. evaluating Refs.

preload_attrs

Attributes on the Block to set before importing the data. Used for linking in dependencies before loading.

endian

Platform endianness to use when interpreting the Block data. Useful for Blocks which have the same data layout but different endianness for stored numbers. Has no effect on fields with an predefined endianness.

cache_bytes

Cache the bytes equivalent of the Block. Useful for debugging the loading procedure. Defaults to False.

path_hint

Cache a string containing the path of the current Block, relative to the root.

class mrcrowbar.lib.images.base.Image(parent, source, width, height, frame_count=1)[source]

Bases: View

property frame_count
property height
property source
property width
class mrcrowbar.lib.images.base.IndexedImage(parent, source, width, height, frame_count=1, palette=[<mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>, <mrcrowbar.colour.BaseColour object>], mask=None)[source]

Bases: Image

Class for viewing indexed (palette-based) chunky image data.

ansi_format_iter(x_start=0, y_start=0, width=None, height=None, frame=0, columns=1, downsample=1, frame_index=None, frame_flip_v=0, frame_flip_h=0)[source]

Return the ANSI escape sequence to render the image.

x_start

Offset from the left of the image data to render from. Defaults to 0.

y_start

Offset from the top of the image data to render from. Defaults to 0.

width

Width of the image data to render. Defaults to the image width.

height

Height of the image data to render. Defaults to the image height.

frame

Single frame number/object, or a list of frames to render in sequence. Defaults to frame 0.

columns

Number of frames to render per line (useful for printing tilemaps!). Defaults to 1.

downsample

Shrink larger images by printing every nth pixel only. Defaults to 1.

frame_index

Constant or mrc.Ref for a frame object property denoting the index. Defaults to None (i.e. frame itself should be an index).

frame_flip_v

Constant or mrc.Ref for a frame object property for whether to mirror vertically. Defaults to 0.

frame_flip_h

Constant or mrc.Ref for a frame object property for whether to mirror horizontally. Defaults to 0.

get_image()[source]
property mask
property palette
print(*args, **kwargs)[source]
property repr
set_image(image, change_dims=True, change_palette=False)[source]
class mrcrowbar.lib.images.base.Palette(block_klass, offset, block_kwargs=None, count=None, fill=None, **kwargs)[source]

Bases: BlockField

Field for inserting another Block into the parent class.

block_klass

Block class to use, or a dict mapping between type and block class.

offset

Position of data, relative to the start of the parent block. Defaults to the end offset of the previous field.

block_kwargs

Arguments to be passed to the constructor of the block class.

count

Load multiple Blocks. None implies a single value, non-negative numbers will return a Python list.

fill

Exact byte sequence that denotes an empty entry in a list.

block_type

Key to use with the block_klass mapping. (Usually a Ref for a property on the parent block)

default_klass

Fallback Block class to use if there’s no match with the block_klass mapping.

length

Maximum size of the buffer to read in.

stream

Read Blocks continuously until a stop condition is met.

alignment

Number of bytes to align the start of each Block to.

transform

Transform class to use for preprocessing the data before importing or exporting each Block.

stream_end

Byte pattern to denote the end of the stream.

stop_check

A function that takes a data buffer and an offset; should return True if the end of the data stream has been reached and False otherwise.

scrub(value, parent=None)[source]

Return the value coerced to the correct type of the Field (if necessary).

value

Input Python object to process.

parent

Parent block object where this Field is defined. Used for e.g. evaluating Refs.

Throws FieldValidationError if value can’t be coerced.

class mrcrowbar.lib.images.base.Planarizer(bpp: int, width: int = None, height: int = None, plane_size: int = None, plane_padding: int = 0, frame_offset: int = 0, frame_stride: int = None, frame_count: int = 1, row_planar_size: int = None, plane_order=None)[source]

Bases: Transform

Create a Planarizer instance.

bpp

Bits per pixel (aka. number of bitplanes).

width

Width of destination image in pixels.

height

Height of destination image in pixels.

plane_size

Size of the image data for a single plane in bytes. Default is (width*height//8). Can’t be specified if width or height are defined.

plane_padding

Additional bytes per plane not used in the chunky data.

frame_offset

Start of the first frame of data. The frame controls are useful for storing multiple image frames sequentially with seperate sets of bitplanes per frame. They aren’t required for multiple frames stored in the same larger set of bitplanes.

frame_stride

Bytes between the start of each frame. Default is bpp*(plane_size+plane_padding).

frame_count

Number of frames.

row_planar_size

Number of bytes per row-plane in a row-planar image. Default is to process a graphic-planar image without rows.

plane_order

List of integers describing how to order the bitplanes in chunky output, from least significant to most significant. Defaults to all planes sequential.

export_data(buffer: bytes, parent=None)[source]

Perform a transform on a byte string.

buffer

Source byte string.

parent

Parent object of the source (to provide context for Refs).

import_data(buffer: bytes, parent=None)[source]

Perform a reverse-transform on a byte string.

buffer

Source byte string.

parent

Parent object of the source (to provide context for Refs).

class mrcrowbar.lib.images.base.RGBAColour(source_data=None, parent=None, preload_attrs=None, endian=None, cache_bytes=False, path_hint=None)[source]

Bases: Colour

Base class for Blocks.

source_data

Source data to construct Block with. Can be a byte string, dictionary of attribute: value pairs, or another Block object.

parent

Parent Block object where this Block is defined. Used for e.g. evaluating Refs.

preload_attrs

Attributes on the Block to set before importing the data. Used for linking in dependencies before loading.

endian

Platform endianness to use when interpreting the Block data. Useful for Blocks which have the same data layout but different endianness for stored numbers. Has no effect on fields with an predefined endianness.

cache_bytes

Cache the bytes equivalent of the Block. Useful for debugging the loading procedure. Defaults to False.

path_hint

Cache a string containing the path of the current Block, relative to the root.

a_8 = <UInt8: offset=0x3>
b_8 = <UInt8: offset=0x2>
g_8 = <UInt8: offset=0x1>
r_8 = <UInt8: offset=0x0>
class mrcrowbar.lib.images.base.RGBColour(source_data=None, parent=None, preload_attrs=None, endian=None, cache_bytes=False, path_hint=None)[source]

Bases: Colour

Base class for Blocks.

source_data

Source data to construct Block with. Can be a byte string, dictionary of attribute: value pairs, or another Block object.

parent

Parent Block object where this Block is defined. Used for e.g. evaluating Refs.

preload_attrs

Attributes on the Block to set before importing the data. Used for linking in dependencies before loading.

endian

Platform endianness to use when interpreting the Block data. Useful for Blocks which have the same data layout but different endianness for stored numbers. Has no effect on fields with an predefined endianness.

cache_bytes

Cache the bytes equivalent of the Block. Useful for debugging the loading procedure. Defaults to False.

path_hint

Cache a string containing the path of the current Block, relative to the root.

b_8 = <UInt8: offset=0x2>
g_8 = <UInt8: offset=0x1>
r_8 = <UInt8: offset=0x0>