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:
valueis a BigInt literal containing the bitmap contents.
cardinalityis the number of distinct colors in the bitmap.
paletteis an optional array of integers, each representing a color.