Documentation
¶
Overview ¶
Package blocked provides a block encoder and decoder for bitmaps.
Example ¶
package main
import (
"bytes"
"fmt"
"math/rand"
"strings"
"github.com/kenshaw/blocked"
)
func main() {
for i, seed := range []int{
999,
4000,
12555,
} {
if i != 0 {
fmt.Println()
}
// create random data
r := rand.New(rand.NewSource(int64(seed)))
height := 1 + r.Intn(12)
data := make([]uint64, height)
for i := range height {
data[i] = r.Uint64()
}
// create bitmap from data, using 64 bits per line (the width of
// uint64)
img, err := blocked.New(data, 64)
if err != nil {
panic(err)
}
// note: to interpret data as 46 bits wide (or another bit width) do
// the following:
//
// img, err := blocked.New(data, 46)
// encode as blocks and display
for j, typ := range []blocked.Type{
blocked.Solids,
blocked.Halves,
blocked.Sextants,
blocked.Octants,
blocked.Braille,
} {
if j != 0 {
fmt.Println()
}
fmt.Printf("%d%c. %s:\n", i+1, 'a'+j, typ)
var buf bytes.Buffer
if err := img.Encode(&buf, typ); err != nil {
panic(err)
}
// usually this would suffice:
// fmt.Println(buf.String())
// to work around comment formatting issues in Go examples, add
// pipes to surround the output:
s := "|" + strings.ReplaceAll(buf.String(), "\n", "|\n|") + "|"
fmt.Println(s)
}
fmt.Println()
// block type's values (see: `go doc blocked.Auto`) can be used as
// formatting verbs in calls to fmt.Printf and other fmt.* funcs:
fmt.Printf("%df. Auto:\n%v\n", i+1, img)
}
}
Output: 1a. Solids: |██ ██████ ██ █ █ ██ ██ █ █ ██ █ █ ██ █ █ █ ███ █████| 1b. Halves: |▀▀ ▀▀▀▀▀▀ ▀▀ ▀ ▀ ▀▀ ▀▀ ▀ ▀ ▀▀ ▀ ▀ ▀▀ ▀ ▀ ▀ ▀▀▀ ▀▀▀▀▀| 1c. Sextants: |🬂 🬂🬂🬂 🬂🬁🬁🬁🬀🬁🬀🬀 🬁🬁🬀🬀🬁 🬂🬁🬁 🬀 🬁🬂🬁🬂🬂| 1d. Octants: |🮂 🮂🮂🮂 🮂 🮂 🮂🮂🮂| 1e. Braille: |⠉⠀⠉⠉⠉⠀⠉⠈⠈⠈⠁⠈⠁⠁⠀⠈⠈⠁⠁⠈⠀⠉⠈⠈⠀⠁⠀⠈⠉⠈⠉⠉| 1f. Auto: ██ ██████ ██ █ █ ██ ██ █ █ ██ █ █ ██ █ █ █ ███ █████ 2a. Solids: |█████ ████ █ █ █ █ █ █ █████ █ █ █ █ ███ ████ █ ███| | ██ ██ ██ ██ █ █ █ ███ █ █ █ ███ ██ ██ ██ █| |█ █ ███ ████ ██ █ █ ██ █ █ ██ █ ██ ██ ████ ██ █ █ █ | |███ █ ██ ████ ███ █ █ █ ███ ███ █ ███ █ ███ | | ████ ███ █ █ ██ █ █ █ ████ █ ███ █ █████ █ ████ ██ █| | █ █ █ ███ █ ██ █ █ ██ █████ █ ████ █ ██ | 2b. Halves: |▀██▀█▄ ██▀▀ █▄ █ ▀ ▀ ▄ ▀▄ ▀▄▄▄ ▀▀▀█▀ ▀▄ █ ▀▄█▄ ▄█▀█▄▀▀▀▀▄█ ▀▀█| |█▄▄▀ ▀▀█ ▀██▀▄██▄ ▀ ▄█▄▀█ ▀ ▀ ▄ ▄▀█▄█ ▄██ ▄ ▀▀ ▀▀██▄▀▀▄ ▀ ▀ ▄▄█ | | ▀█▀▀ ▀█▀▄ ▀ ▀▄▄█▀▄▀ ▄▄▀ ▀ █▀█▀▄█ ███▄█ ▀▀▀▀▀ ▄ ▄█▄█▀▀█ ██ ▀| 2c. Sextants: |🬙🬥🬪🬷🬥🬮🬛🬷🬁🬑🬦🬞🬗🬏🬗🬋🬠🬒🬕🬠🬓🬄🬶🬪🬵🬕🬺🬂🬒🬜🬁🬙| |🬊🬛🬃🬉🬚🬒🬅🬥🬶🬢🬆🬮🬄🬃🬦🬪🬣🬕🬺🬴▌🬌🬋🬃🬠🬂🬵🬶🬋🬓█🬈| 2d. Octants: |▟| |▝▘▀▘🮂🮂 🮂▘▀| 2e. Braille: |⣝⡫⠳⢼⠫⣥⢗⣼⡈⠌⣰⡠⡕⠄⠕⡒⡨⣍⡏⣨⡆⡃⠵⠳⢴⣏⠷⡉⠍⠞⣈⡝| |⠈⠋⠁⠈⠋⠂⠁⠑⠚⠑⠁⠒⠁⠁⠘⠙⠑⠃⠛⠓⠃⠉⠉⠁⠐⠀⠚⠚⠉⠃⠛⠈| 2f. Auto: 🬙🬥🬪🬷🬥🬮🬛🬷🬁🬑🬦🬞🬗🬏🬗🬋🬠🬒🬕🬠🬓🬄🬶🬪🬵🬕🬺🬂🬒🬜🬁🬙 🬊🬛🬃🬉🬚🬒🬅🬥🬶🬢🬆🬮🬄🬃🬦🬪🬣🬕🬺🬴▌🬌🬋🬃🬠🬂🬵🬶🬋🬓█🬈 3a. Solids: |█ █ ██ ██ █ ██ █ █ ██ █ █ ██ █ █ ██ █ █ ████ ██| |███ ██ █ █ ██ █ ███ █ █ ███ ████ ██ ███ ███ ██ | | █ █ █ █ █ ██ █ ███ █ █ █ █ █ ██ █ ████████ ██ ███ █| |█ ██ █ ███ ██ █ ████ ██ █ ███ █ ███ ██ ████ ███ | | ██ ██ ██ ██ █ ██ █ ██ ██ █ █ ██ █ ████ █ █ █ █ | |█ █ ██ █ ███ ██ █ ███ █ █ █ █ ████ ██ █ ██ █ ███ █ ███| | █ ████ █ ███ █ ██ ██ ██ ████ █ ██ █ █ ███ ██ █| | █ █████████ █ █ █ ██ █ █ █ ███ █ █ █ █ █ █ | |█ █ █ █ ████ ██ █ ███ █ ██ █ ████ ██ ████ ██ ██ | | █ ████ █ ████ █ ██ ███ █ █ █ ████ █ █ ██ ███ ███| | █ █ █ █ █ █ █ █ ███ █ █ █ █ █ █ ██ | |█ █ █ ██ █ ███ ███ █ ██ █ ████ █ █ ██ ███ ███ █ █| 3b. Halves: |█▄▄ █▄ █▀ ▄▀▀ ▄▄ █ ▀█▄█ ▀ █▀▄▀▄█▄ ██▄▄▀▄█ ██▄▀▄█▄ ▀██▀ ▀▀| |▄▀▄█ ▀ █ ▄█▄ ▀▀ █▄▀█▀ ▀ ▀▄▄▄█ █▄▀ ▄▀█▄█ ▄▀▀▀▀███▀ ▄▄ ▀█▄██▀▄▄▄▀| |▄▀█ ▄▄▀█ ██▄ ▀█▄▀▄ ██▄ █ ▄ ▄ ▄ ██▄█▀ ▀▄█ ▀▀ █ ▄▄▀█▀▀ █▄█ █ ▄█▄| | █ ▄████▄▄█▄ █▀▀ ▀▄▀▀▄ ▄█▀▄▀█ ▀▀▀▀ █ ▀▀▄▄█ ▄ ▀▄▀█▀ █▀▄ ▄▀| |▀▄▀▄█▄█ ▀█▀█▄██ ▄▀▄█▀█▄█ █▀ ▄ ▄ █▄▄▄ █▀▀▀ ▀█ ▄█▀▀▀ ██▄ ▀█▄▄| |▄▀ ▀▄ ▄ █▄▀ ▀▄▀▄▄█ ▄▄▄▀▄ ▄▄ ▀▀▀▄ ▀▄▄█▄ ▄ █ ▄▄▀▄▄█ ▄▄█ █▀▄| 3c. Sextants: |🬪🬢🬪▐🬀🬔🬟🬚🬘🬯🬛▌🬞🬀🬥🬤🬫🬃🬭▐🬌🬳🬻🬷🬺🬈🬌🬯🬬🬮 🬡| |🬗🬕🬭🬫▐🬴🬇🬱🬥▐🬱🬦🬞🬡🬡▐🬲🬜🬉🬸🬉🬃🬦🬡🬗🬜🬄🬳🬕🬧🬡🬲| |🬘🬏🬜🬝🬺🬻🬢🬕🬟🬧🬰🬢🬇🬴🬅🬄🬂🬒🬉 🬯🬶🬍🬦🬑🬤🬴🬘🬶 🬭🬅| |🬘🬁🬥🬟▐🬘🬂🬣🬣🬸🬠🬰🬢🬀🬠🬑 🬎🬥🬇🬮🬱🬞🬦🬀🬰🬢🬵🬡🬶▐🬥| 3d. Octants: |▐▟▂| |▘▞▝| | ▘| 3e. Braille: |⡳⣢⠳⢸⢁⣎⠡⠖⣜⢬⠗⠇⠠⣁⣫⢪⡺⢂⢤⣸⢓⠮⠾⣼⡷⢑⡓⢬⣻⡥⣀⡩| |⢪⠃⣲⣽⣜⣳⡈⡷⠕⢜⠷⡘⢐⡴⡰⡜⠷⠯⢨⠚⠨⢅⣸⢐⠪⡫⡥⢳⢇⠘⠐⡳| |⡱⠑⢗⢃⢹⡹⠚⢇⢎⣺⢙⣚⢄⠋⢐⡐⠀⠷⢖⠠⣋⣍⢀⢨⠃⣚⢍⣡⢛⣢⢹⢖| 3f. Auto: 🬪🬢🬪▐🬀🬔🬟🬚🬘🬯🬛▌🬞🬀🬥🬤🬫🬃🬭▐🬌🬳🬻🬷🬺🬈🬌🬯🬬🬮 🬡 🬗🬕🬭🬫▐🬴🬇🬱🬥▐🬱🬦🬞🬡🬡▐🬲🬜🬉🬸🬉🬃🬦🬡🬗🬜🬄🬳🬕🬧🬡🬲 🬘🬏🬜🬝🬺🬻🬢🬕🬟🬧🬰🬢🬇🬴🬅🬄🬂🬒🬉 🬯🬶🬍🬦🬑🬤🬴🬘🬶 🬭🬅 🬘🬁🬥🬟▐🬘🬂🬣🬣🬸🬠🬰🬢🬀🬠🬑 🬎🬥🬇🬮🬱🬞🬦🬀🬰🬢🬵🬡🬶▐🬥
Index ¶
- Variables
- func ASCIIsRunes() []rune
- func BinariesRunes() []rune
- func BrailleRunes() []rune
- func Dump(w io.Writer, syms map[uint8]rune)
- func HalvesRunes() []rune
- func OctantsRunes() []rune
- func QuadsRunes() []rune
- func QuadsSeparatedRunes() []rune
- func SextantsRunes() []rune
- func SextantsSeparatedRunes() []rune
- func SolidsRunes() []rune
- func XXsRunes() []rune
- type Bitmap
- func (img Bitmap) At(x, y int) color.Color
- func (img Bitmap) Best() Type
- func (img Bitmap) Bounds() image.Rectangle
- func (img Bitmap) Bytes() []byte
- func (img Bitmap) ColorModel() color.Model
- func (img Bitmap) Encode(w io.Writer, typ Type) error
- func (img Bitmap) Format(f fmt.State, verb rune)
- func (img Bitmap) Get(x, y int) bool
- func (img Bitmap) Height(typ Type) int
- func (img Bitmap) Scale() (int, int)
- func (img Bitmap) Set(x, y int, b bool)
- func (img Bitmap) Width(typ Type) int
- type Type
- func (typ Type) Contiguous() bool
- func (typ Type) Dump(w io.Writer)
- func (typ Type) Height() int
- func (typ Type) Rune() rune
- func (typ Type) RuneCount() int
- func (typ Type) RuneMap() map[uint8]rune
- func (typ Type) Runes() []rune
- func (typ Type) String() string
- func (typ Type) ToRune(b uint8) rune
- func (typ Type) Width() int
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultScaleWidth is the pixel width scale for bitmaps used as // [image.Image]. DefaultScaleWidth uint = 24 // DefaultScaleHeight is the pixel height scale for bitmaps used // as [image.Image]. DefaultScaleHeight uint = 24 // DefaultOpaque is the default opaque color. DefaultOpaque = color.Opaque // DefaultTransparent is the default transparent color. DefaultTransparent = color.Transparent )
Functions ¶
func ASCIIsRunes ¶
func ASCIIsRunes() []rune
ASCIIsRunes returns the runes for double block resolution bitmaps.
func BinariesRunes ¶
func BinariesRunes() []rune
BinariesRunes returns the runes for single block resolution bitmaps using '0', '1'.
func BrailleRunes ¶
func BrailleRunes() []rune
BrailleRunes returns the runes for octuple block resolution images using braille.
See: https://www.amp-what.com/unicode/search/braille
func Dump ¶
Dump dumps a ASCII drawing of the bitmask of the symbols to the writer.
Used to verify the symbols for different Type's.
func HalvesRunes ¶
func HalvesRunes() []rune
HalvesRunes returns the runes for double block resolution bitmaps.
See: https://www.amp-what.com/unicode/search/half%20block
func OctantsRunes ¶
func OctantsRunes() []rune
OctantsRunes returns the runes for octuple block resolution images.
See: https://www.amp-what.com/unicode/search/octants
func QuadsRunes ¶
func QuadsRunes() []rune
QuadsRunes returns the runes for quadruple block resolution bitmaps.
See: https://www.amp-what.com/unicode/search/quarter%20block
func QuadsSeparatedRunes ¶
func QuadsSeparatedRunes() []rune
QuadsSeparatedRunes returns the runes for quadruple block resolution images using separated quads.
See: https://www.amp-what.com/unicode/search/quad%20separated
func SextantsRunes ¶
func SextantsRunes() []rune
SextantsRunes returns the runes for sextuple block resolution images.
See: https://www.amp-what.com/unicode/search/sextants
func SextantsSeparatedRunes ¶
func SextantsSeparatedRunes() []rune
SextantsSeparatedRunes returns the runes for sextuple block resolution images using separated sextants.
See: https://www.amp-what.com/unicode/search/sextants%20separated
func SolidsRunes ¶
func SolidsRunes() []rune
SolidsRunes returns the runes for single block resolution bitmaps.
See: https://www.amp-what.com/unicode/search/full%20block
Types ¶
type Bitmap ¶
type Bitmap struct {
Pix []uint8
Stride int
Rect image.Rectangle
ScaleWidth uint
ScaleHeight uint
Opaque color.Alpha16
Transparent color.Alpha16
}
Bitmap is a monotone bitmap image.
func New ¶
New creates a new bitmap from data with width x. Data can be any type that works with binary.Write.
func NewBytes ¶ added in v0.2.0
NewBytes creates a new bitmap from for the unaligned bytes in data with width x, height y.
func (Bitmap) At ¶
At satisfies the image.Image interface.
func (Bitmap) Bounds ¶
Bounds satisfies the image.Image interface.
func (Bitmap) Bytes ¶ added in v0.2.1
Bytes returns the bitmap encoded using the Bitmap.Best block type.
func (Bitmap) ColorModel ¶
ColorModel satisfies the image.Image interface.
func (Bitmap) Format ¶ added in v0.1.4
Format satisfies the fmt.Formatter interface.
type Type ¶
type Type rune
Type is a block type.
const ( // Auto uses [Best] to determine the best, contiguous block type to use for // a provided height. Auto Type = 'v' // Solids are single, 1x1 blocks using [SolidsRunes]. Solids Type = 'l' // Binaries are single, 1x1 blocks using binary digits using [BinariesRunes]. Binaries Type = 'b' // XXs are single, 1x1 blocks using [XXsRunes]. XXs Type = 'L' // Doubles are single, 0.5x1 double wide blocks using [SolidsRunes]. Doubles Type = 'D' // Halves are 0.5x1 double wide blocks using [HalvesRunes]. Halves Type = 'e' // Halves are 1x2 double height blocks using ASCII-safe runes using // [ASCIIsRunes]. ASCIIs Type = 'E' // Quads are 3x2 quarter blocks using [QuadsRunes]. Quads Type = 'q' // QuadsSeparated are 2x2 quarter blocks using [QuadsSeparatedRunes]. QuadsSeparated Type = 'Q' // Sextants are 2x3 blocks using [SextantsRunes]. Sextants Type = 'x' // SextantsSeparated are 2x3 blocks using [SextantsSeparatedRunes]. SextantsSeparated Type = 'X' // Octants are 2x4 blocks using [OctantsRunes]. Octants Type = 'o' // Braille are 2x4 blocks using [BrailleRunes]. Braille Type = 'O' )
Block types.
func (Type) Contiguous ¶
Contiguous returns true when the type is a contiguous block type.
func (Type) Dump ¶
Dump dumps a ASCII drawing of the bitmask the block type's symbols to the writer.