BigInt Embedded Bitmap Encoding

BigInt Embedded Bitmap Encoding

This is the second post in the series. See the previous post, ECMAScript Embedded Bitmap Encoding for context.


My friend Roman pointed out that I was, in fact, doing things suboptimally in the EEBE post:

  • The array of scanlines can be replaced with a single BigInt literal, bringing substantially less syntactic overhead.
  • The use of integer bpp for color depth can be wasteful if the number of colors isn't a power of two, and we're not seeing any performance gains from it either. More compact results can be achieved by using the number of distinct colors directly.

The updated example is as follows:

// ECMAScript Embedded Bitmap Encoding (EEBE)
// Required fields:
export const value = 0x61e3c70891a1c08n
export const width = 7
export const height = 9
export const cardinality = 2
// Optional fields:
export const palette = [
  0x000000,
  0xffffff,
]

The following fields are exported:

  • value is a BigInt literal containing the bitmap contents.
  • width and height are self-explanatory.
  • cardinality is the number of distinct colors in the bitmap.
  • palette is an optional array of integers, each representing a color.

The updated playground for this version is here.