bm_compress: Compress bitmaps using a "block elements" scheme

View source: R/bm_compress.R

bm_compressR Documentation

Compress bitmaps using a "block elements" scheme

Description

Compress bitmaps by a factor of two by re-mapping to a “block elements” scheme.

Usage

bm_compress(bm_object, direction = "vertical")

Arguments

bm_object

Either a bm_bitmap(), bm_list(), or bm_font() object.

direction

Either "vertical" or "v", "horizontal" or "h", OR "both" or "b".

Details

Depending on direction we shrink the bitmaps height and/or width by a factor of two and re-encode pairs/quartets of pixels to a “block elements” scheme. If necessary we pad the right/bottom of the bitmap(s) by a pixel. For each pair/quartet we determine the most-common non-zero element and map them to a length twenty set of integers representing the “block elements” scheme. For integers greater than zero we map it to higher twenty character sets i.e. 1's get mapped to 0:19, 2's get mapped to 20:39, 3's get mapped to 40:59, etc. Using the default px_unicode will give you the exact matching “Block Elements” glyphs while px_ascii gives the closest ASCII approximation. Hence print.bm_bitmap() should produce reasonable results for compressed bitmaps if either of them are used as the px argument.

Value

Either a bm_bitmap(), bm_list(), or bm_font() object.

See Also

See https://en.wikipedia.org/wiki/Block_Elements for more info on the Unicode Block Elements block.

Examples

  font_file <- system.file("fonts/spleen/spleen-8x16.hex.gz", package = "bittermelon")
  font <- read_hex(font_file)
  r <- font[[str2ucp("R")]]
  print(r, px = px_ascii)
  print(bm_compress(r, "vertical"), px = px_ascii)
  print(bm_compress(r, "horizontal"), px = px_ascii)
  print(bm_compress(r, "both"), px = px_ascii)

bittermelon documentation built on Feb. 16, 2023, 8:08 p.m.