BTIC5B - cr88192/bgbtech_misc GitHub Wiki

BTIC 5B

  • FOURCC: 'bt5b'
  • Will use a differential encoding for endpoints.
  • Will use an otherwise similar design to BT5A.
  • Focus primarily on 4x4 blocks within an RGB555 colorspace.

Table of Contents

TLV

Frame TLV:

  • 0x00..0x1F: 8K, TWOCC
    • LL-LL TT-TT
  • 0x20..0x3F: 8K, FOURCC
    • LL-LL TT-TT-TT-TT
  • 0x40..0x5F: 512M, TWOCC
    • LL-LL-LL-LL TT-TT
  • 0x60..0x7F: 512M, FOURCC
    • LL-LL-LL-LL TT-TT-TT-TT
  • 0x80..0x9F: 2M, TWOCC
    • LL-LL-LL TT-TT
  • 0xA0..0xBF: 2M, FOURCC
    • LL-LL-LL TT-TT-TT-TT
The length field for the TLV tags is effectively encoded in big-endian ordering.

TwoCC:

  • 'IX': Image Data (I-Frame), No LZ
  • 'PX': Image Data (P-Frame), No LZ
  • 'HX': Optional Header
  • 'Z3': Frame Encoded with RP2
  • 'Z4': Frame Encoded with LZ4
    • LZ Compressed frames will be preceded by a small 32-bit header:
      • (23: 0): Uncompressed Size
      • (31:24): Reserved / Zero
    • LZ may not be applied recursively.
Header:
  • u16 width; //image frame width
  • u16 height; //image frame height
  • u16 flags; //some control flags
    • 1: Uses simple skip rather than motion compensation.
      • This mode does not need a second block buffer or copying in the decoder.
The frame size will be internally padded up to a multiple of 4 pixels, though the width and height will represent the actual / non-padded resolution.

Image Data

The encoded stream will be byte-based.

  • The encoded stream will start with a command, and commands will continue until the end of the tag data.

Color Endpoints

When relevant, a pair of endpoint colors may be encoded.

This will nominally use 15-bit conjoined endpoint vectors:

  • ( 0): 0
  • ( 1): Dy0
  • ( 5: 2): Cb
  • ( 6): Dy1
  • (10: 7): Cg
  • ( 11): Dy2
  • (15:12): Cr
Conceptually, the conjoined endpoint will be decoded to RGB555 endpoints as:
  • Ar=(Cr*2)+Dy*2
  • Ag=(Cg*2)+Dy*2
  • Ab=(Cb*2)+Dy*2
  • Br=(Cr*2)-Dy*2
  • Bg=(Cg*2)-Dy*2
  • Bb=(Cb*2)-Dy*2
Note that these calculations will not saturate and carry may effect the LSB of the decoded 555 endpoints. In effect, the application of the delta will be via a 16-bit add operation.

Delta Endpoints:

  • ( 0): 1
  • (2:1): dDy
    • 0: dDy=-1 / A and B
    • 1: dDy= 0 / A only
    • 2: dDy=+1 / B only
    • 3: Escape (Endpoint Pair)
  • (7:3): Delta
    • Encoded as a 3*3*3 Blocks
      • Each delta is 0/1/2 -> -1/0/+1
      • Dv5=(dCr*9)+(dCg*3)+dCb;
      • Valid range is 00..1A
    • 1B : 15 / 30 bit Delta (3x 5-bit / 6x 5-bit)
    • 1C..1D: 17-bit Delta (2x 7^3, Mod 360^2)
    • 1E..1F: 9-bit Delta (7^3)
      • Each component encodes -3..+3
      • These deltas are only valid for Endpoint Pairs.
Endpoint Pair:
  • ( 2: 0): 111
  • ( 6: 3): Bb
  • (11: 7): Bg
  • (16:12): Br
  • (21:17): Ab
  • (26:22): Ag
  • (31:27): Ar
A delta endpoint may be used when the block endpoints are similar to the prior endpoint.

The interpretation of a delta endpoint will depend on the mode from the prior endpoint. If a conjoined endpoint, the delta will apply to the center value (with A and B being recalculated). If an endpoint pair, the delta may be applied to each color in the pair (Dy is ignored).

Pixel Blocks

Blocks may be encoded in several forms:

  • 2x2x1, 2x2 with 1 bit selectors.
  • 2x2x2, 2x2 with 2 bit selectors.
  • 4x4x1, 4x4 with 1 bit selectors.
  • 4x4x2, 4x4 with 2 bit selectors.
With a 1 bit selector:
  • 1: Color A (Max)
  • 0: Color B (Min)
With a 2 bit selector:
  • 3: Color A (Max)
  • 2: 2/3*ColorA + 1/3*ColorB
  • 1: 1/3*ColorA + 2/3*ColorB
  • 0: Color B (Min)
The 2-bit selector will be defined as an approximation:
  • 11/32 + 21/32
Within each block, pixels will be stored in raster order starting from the least significant bit. By convention, within an AVI or BMP container, the raster origin will be defined as the lower-left corner.

Pattern Table

The pattern table will consist of 64 patterns.

  • The low 3 bits will encode a horizontal sign and frequency.
  • The high 3 bits will encode a verical sign and frequency.
The frequency field:
  • 0: 2, 2, 2, 2,
  • 1: 4, 2, -2, -4,
  • 2: 4, -1, 1, -4,
  • 3: 4, -4, 4, -4,
  • 4: -2, -2, -2, -2,
  • 5: -4, -2, 2, 4,
  • 6: -4, 1, -1, 4,
  • 7: -4, 4, -4, 4
The pattern table will be generated by adding the horizontal and vertical fields (similar to a matrix multiply), and comparing each component result with zero.

Blocks and Commands

Commands start with a command byte, which is decoded to determine which action to perform. Each command is variable-length and bit packed.

Pattern Table Reference:

  • ( 0): 0
  • ( 1): p (Endpoint Present)
  • ( 7: 2): Pattern Table Index
  • ( 8+): (p==1): Endpoint.
Small Motion Vector / Skip (P-Frame Only):
  • ( 1: 0): 01
  • ( 4: 2): Dx (-3..+3), Dx!=7
  • ( 7: 5): Dy (-3..+3), Dy!=7
    • Copy block with the given motion vector delta.
    • Dx=7 (Dy=0..6): Copy Run of 1..7 blocks relative to last vector.
    • Dy=7 (Dx=0..6): Reset motion vector to Zero, do a Skip run.
  • Dx=7, Dy=7: Copy a longer run of blocks (Last Vector).
    • (15:8): Run of 4-258 Blocks (FF=Reserved)
Small 2x2 Block:
  • ( 2: 0): 011
  • ( 3): p (Endpoint Present)
  • ( 7: 4): 2x2x1
  • ( 8+): (p==1): Endpoint.
Small Run (4x4x1):
  • ( 4: 0): 00111
  • ( 5): p (Endpoint Present)
  • ( 7: 6): nn
  • ( 8+): (p==1): Endpoint
  • ( 8++): (nn+1) * 4x4x1
Small Run (2x2x1, No Endpoint):
  • ( 5: 0): 010111
  • ( 7: 6): nn
  • ( 8+): (nn+1) * (2 * 2x2x1)
Small Run (2x2x2, No Endpoint):
  • ( 5: 0): 110111
  • ( 7: 6): nn
  • ( 8+): (nn+1) * (2x2x2)
Small Run (Flat):
  • ( 4: 0): 01111
  • ( 7: 5): nnp
    • Run of 1-4 blocks, Flat Color (p: Color Bit)
Small Run, Flat Colors, Endpoint per Block:
  • ( 5: 0): 011111
  • ( 7: 6): nn
    • Run of 1-4 blocks, Endpoint Per Block
Bigger 4x4x2 Block:
  • ( 6: 0): 0111111
  • ( 7): p (Endpoint Present)
  • (39: 8): Pixel Bits, 4x4x2
  • ( 40+): (p!=0): Endpoint
  • ( 7: 0): 11111111
  • (10: 8): 011
  • ( 11): p (Color Selector)
  • (15:12): nnnn
    • Run of n*4+8 blocks (8..68), Flat Color
⚠️ **GitHub.com Fallback** ⚠️