compression

package
v1.10.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 22, 2024 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// TileSideLength is the number of pixel per side of a square frame tile.
	TileSideLength = 4
	// PixelPerTile is the number of pixel within one frame tile.
	PixelPerTile = TileSideLength * TileSideLength
)
View Source
const (
	CtrlColorTile2ColorsStatic  = ControlType(0)
	CtrlColorTile2ColorsMasked  = ControlType(1)
	CtrlColorTile4ColorsMasked  = ControlType(2)
	CtrlColorTile8ColorsMasked  = ControlType(3)
	CtrlColorTile16ColorsMasked = ControlType(4)

	CtrlSkip = ControlType(5)

	CtrlRepeatPrevious = ControlType(6)
	CtrlUnknown        = ControlType(7)
)

Control type constants are listed below.

View Source
const ControlWordParamLimit = 0x1FFFF

ControlWordParamLimit is the highest number the param property of a control word can take.

View Source
const (
	// ErrFormat indicates errors in the compression format.
	ErrFormat ss1.StringError = "format error"
)

Variables

This section is empty.

Functions

func PackControlWords

func PackControlWords(words []ControlWord) []byte

PackControlWords packs and encodes the given words into a byte stream.

Types

type BitstreamReader

type BitstreamReader struct {
	// contains filtered or unexported fields
}

BitstreamReader is a utility to read big-endian integer values of arbitrary bit size from a bitstream.

func NewBitstreamReader

func NewBitstreamReader(data []byte) *BitstreamReader

NewBitstreamReader returns a new instance of a bistream reader using the provided byte slice as source.

func (*BitstreamReader) Advance

func (reader *BitstreamReader) Advance(bits int)

Advance skips the provided amount of bits and puts the current position there. Successive read operations will return values from the new position. It is possible to advance beyond the available length.

This function panics when advancing with negative values.

func (*BitstreamReader) Exhausted

func (reader *BitstreamReader) Exhausted() bool

Exhausted returns true if the current position is at or beyond the possible length. Reading an exhausted stream yields only zeroes.

func (*BitstreamReader) Read

func (reader *BitstreamReader) Read(bits int) (result uint32)

Read returns a value with the requested bit size, right aligned, as a uint32. Reading does not advance the current position. A successful read of a certain size will return the same value when called repeatedly with the same parameter. Reading is possible beyond the available size. For the missing bits, a value of 0 is provided.

The function panics when reading more than 32 bits.

type BitstreamWriter

type BitstreamWriter struct {
	// contains filtered or unexported fields
}

BitstreamWriter is a utility to write big-endian integer values of arbitrary bit size to a bitstream.

func (BitstreamWriter) Buffer

func (w BitstreamWriter) Buffer() []byte

Buffer returns the currently stored buffer.

func (*BitstreamWriter) Write

func (w *BitstreamWriter) Write(bits uint, value uint32)

Write stores the given amount of bits from the provided value. Trying to write more than 32 bits will cause panic.

type ControlType

type ControlType byte

ControlType defines how to interpret a ControlWord.

type ControlWord

type ControlWord uint32

ControlWord describes the current compression action.

func ControlWordOf

func ControlWordOf(count int, controlType ControlType, param uint32) ControlWord

ControlWordOf returns a word with the given parameters.

func LongOffsetOf

func LongOffsetOf(offset uint32) ControlWord

LongOffsetOf returns a word that indicates a long offset with given value.

func UnpackControlWords

func UnpackControlWords(data []byte) (words []ControlWord, err error)

UnpackControlWords reads from an encoded string of bytes a series of packed control words. If all is OK, the control words are returned. If the function returns an error, something could not be read/decoded properly.

func (ControlWord) Count

func (word ControlWord) Count() int

Count returns the count value of the control.

func (ControlWord) IsLongOffset

func (word ControlWord) IsLongOffset() bool

IsLongOffset returns true if Count() returns 0.

func (ControlWord) LongOffset

func (word ControlWord) LongOffset() uint32

LongOffset returns the long offset value. Only relevant if IsLongOffset() returns true.

func (ControlWord) Packed

func (word ControlWord) Packed(times int) PackedControlWord

Packed returns the control word packed in a PackedControlWord with the given number of times.

func (ControlWord) Parameter

func (word ControlWord) Parameter() uint32

Parameter returns the type specific parameter value.

func (ControlWord) Type

func (word ControlWord) Type() ControlType

Type returns the type of the control. Only relevant if IsLongOffset() returns false.

type ControlWordSequence

type ControlWordSequence struct {
	// HTiles specifies the amount of horizontal tiles (= operations) a frame has.
	// This number is relevant for skip operations. If 0, then no compression of skip-operations is done.
	HTiles uint32
	// contains filtered or unexported fields
}

ControlWordSequence is a finalized set of control words to reproduce a list of tile coloring operations. Based on this sequence, a bitstream can be created based on a selection of such coloring operations (i.e., per frame).

func (ControlWordSequence) BitstreamFor

func (seq ControlWordSequence) BitstreamFor(ops []TileColorOp) ([]byte, error)

BitstreamFor returns the bitstream to reproduce the provided list of coloring operations from this sequence.

func (ControlWordSequence) ControlWords

func (seq ControlWordSequence) ControlWords() []ControlWord

ControlWords returns the list of low-level control words of the sequence.

type ControlWordSequencer

type ControlWordSequencer struct {
	// BitstreamIndexLimit specifies the highest value the sequencer may use to store offset values in the bitstream.
	// If this value is 0, then the default of 0xFFF (12 bits) is used.
	BitstreamIndexLimit uint32

	// DirectIndexLimit specifies the amount of direct pointers into the bitstream.
	// If this value is 0, then the default of BitstreamIndexLimit / 4 is used.
	DirectIndexLimit uint32
	// contains filtered or unexported fields
}

ControlWordSequencer receives a list of requested tile coloring operations and produces a sequence of low-level control words to reproduce the requested list.

func (*ControlWordSequencer) Add

func (seq *ControlWordSequencer) Add(op TileColorOp) error

Add extends the list of requested coloring operations with the given entry. The offset of the entry must be a value less than or equal ControlWordParamLimit, otherwise the function returns an error.

func (ControlWordSequencer) Sequence

Sequence packs the requested list of entries into a sequence of control words. An error is returned if the operations would exceed the possible storage space.

type EncodedFrame

type EncodedFrame struct {
	Bitstream  []byte
	Maskstream []byte
}

EncodedFrame contains the streams of one compressed frame.

type FrameDecoder

type FrameDecoder struct {
	// contains filtered or unexported fields
}

FrameDecoder is for decoding compressed frames with the help of data streams. A new instance of a decoder is created with a FrameDecoderBuilder.

func (*FrameDecoder) Decode

func (decoder *FrameDecoder) Decode(bitstreamData []byte, maskstreamData []byte) error

Decode reads the provided streams to paint a frame.

type FrameDecoderBuilder

type FrameDecoderBuilder struct {
	// contains filtered or unexported fields
}

FrameDecoderBuilder implements the builder pattern for creating new instances of FrameDecoder. This builder can be reused during the processing of a movie. Every Build() call creates a new instance.

func NewFrameDecoderBuilder

func NewFrameDecoderBuilder(width, height int) *FrameDecoderBuilder

NewFrameDecoderBuilder returns a new instance of a builder with given initial values.

func (*FrameDecoderBuilder) Build

func (builder *FrameDecoderBuilder) Build() *FrameDecoder

Build creates a new instance of a decoder with the most recent parameters.

func (*FrameDecoderBuilder) ForStandardFrame

func (builder *FrameDecoderBuilder) ForStandardFrame(frame []byte, stride int)

ForStandardFrame registers the frame buffer and sets the standard coloring method.

func (*FrameDecoderBuilder) WithControlWords

func (builder *FrameDecoderBuilder) WithControlWords(words []ControlWord)

WithControlWords registers the new word dictionary.

func (*FrameDecoderBuilder) WithPaletteLookupList

func (builder *FrameDecoderBuilder) WithPaletteLookupList(list []byte)

WithPaletteLookupList registers the new list.

type MaskstreamReader

type MaskstreamReader struct {
	// contains filtered or unexported fields
}

MaskstreamReader reads mask integers from a byte array.

func NewMaskstreamReader

func NewMaskstreamReader(source []byte) *MaskstreamReader

NewMaskstreamReader returns a new reader instance for given source.

func (*MaskstreamReader) Read

func (reader *MaskstreamReader) Read(bytes int) (value uint64)

Read returns a mask integer of given byte length from the current position. If the current position is at or beyond the available size, 0x00 is assumed for the missing bytes.

Reading more than 8, or less than 0, bytes panics.

type MaskstreamWriter

type MaskstreamWriter struct {
	Buffer []byte
}

MaskstreamWriter writes mask integers to a byte array.

func (*MaskstreamWriter) Write

func (w *MaskstreamWriter) Write(byteCount uint, mask uint64) error

Write adds the given amount of bytes from the mask to the buffer.

type PackedControlWord

type PackedControlWord uint32

PackedControlWord contains a ControlWord together with a count value of occurrences.

func (PackedControlWord) Times

func (packed PackedControlWord) Times() int

Times returns the amount of occurrences of the contained control word.

func (PackedControlWord) Value

func (packed PackedControlWord) Value() ControlWord

Value returns the control word value.

type PaletteLookup

type PaletteLookup struct {
	// contains filtered or unexported fields
}

PaletteLookup is a dictionary of tile delta data, found in a palette buffer.

func (*PaletteLookup) Buffer

func (lookup *PaletteLookup) Buffer() []byte

Buffer returns the underlying slice.

func (*PaletteLookup) Lookup

func (lookup *PaletteLookup) Lookup(tile tileDelta) (index int, pal []byte, mask uint64)

Lookup finds the given tile again and returns the properties where and how to reproduce it.

type PaletteLookupGenerator

type PaletteLookupGenerator struct {
	// contains filtered or unexported fields
}

PaletteLookupGenerator creates palette lookups based on a set of registered tiles.

func (*PaletteLookupGenerator) Add

func (gen *PaletteLookupGenerator) Add(delta tileDelta)

Add registers a further delta to the generator.

func (*PaletteLookupGenerator) Generate

Generate creates a lookup based on all currently registered tile deltas.

type SceneEncoder

type SceneEncoder struct {
	// contains filtered or unexported fields
}

SceneEncoder encodes an entire scene of bitmaps sharing the same palette.

func NewSceneEncoder

func NewSceneEncoder(width, height int) *SceneEncoder

NewSceneEncoder returns a new instance.

func (*SceneEncoder) AddFrame

func (e *SceneEncoder) AddFrame(frame []byte) error

AddFrame registers a further frame to the scene.

func (*SceneEncoder) Encode

func (e *SceneEncoder) Encode(ctx context.Context) (
	words []ControlWord, paletteLookupBuffer []byte, frames []EncodedFrame, err error)

Encode processes all the previously registered frames and creates the necessary components for decoding.

type TileColorFunction

type TileColorFunction func(hTile int, vTile int, lookupArray []byte, mask uint64, indexBitSize uint64)

TileColorFunction is one which shall color the pixel of a video frame tile using the provided values. mask is a packed field of 16 indices, each with a length of indexBitSize. These indices point into a value of lookupArray.

func StandardTileColorer

func StandardTileColorer(frame []byte, stride int) TileColorFunction

StandardTileColorer returns a TileColorFunction for given frame buffer.

This colorer iterates over all pixel of a tile. It sets the pixel value if the corresponding palette value is > 0x00.

type TileColorOp

type TileColorOp struct {
	Type   ControlType
	Offset uint32
}

TileColorOp describes one operation how a tile should be colored.

type TilePaletteKey added in v1.8.0

type TilePaletteKey struct {
	// contains filtered or unexported fields
}

TilePaletteKey marks use of colors of a 256 palette.

func TilePaletteKeyFrom added in v1.8.0

func TilePaletteKeyFrom(colors []byte) TilePaletteKey

TilePaletteKeyFrom returns a key for the given slice of colors.

func (*TilePaletteKey) Buffer added in v1.8.0

func (key *TilePaletteKey) Buffer() []byte

Buffer returns the color indices marked in use by this key.

func (*TilePaletteKey) Contains added in v1.8.0

func (key *TilePaletteKey) Contains(other *TilePaletteKey) bool

Contains returns true if this key is equal to, or a superset of, the given key.

func (*TilePaletteKey) HasColor added in v1.8.0

func (key *TilePaletteKey) HasColor(index byte) bool

HasColor returns true if the given color index is in use by this key.

func (*TilePaletteKey) LessThan added in v1.8.0

func (key *TilePaletteKey) LessThan(other *TilePaletteKey) bool

LessThan is a sorting function to order keys.

func (*TilePaletteKey) UseColor added in v1.8.0

func (key *TilePaletteKey) UseColor(index byte)

UseColor marks the given color index in use.

func (*TilePaletteKey) Without added in v1.8.0

func (key *TilePaletteKey) Without(other *TilePaletteKey) TilePaletteKey

Without returns a new key instance that has all remaining colors marked in use.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL