gomonochromebitmap

package module
v0.1.0-beta.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2022 License: MIT Imports: 5 Imported by: 5

README

gomonochromebitmap

Golang library for monochrome image operations

I developed this library for my personal "retrocomputing"/emulator project. This library is only for black-white images.

At the moment some basic functions are implemented in very naive way. I just need this library for getting things running I will provide more optimized versions after I complete my other project using this library.

##example Please check further examples from gomonochromebitmap_test.go

Documentation

Overview

Some fonts for gomonochromebitmap

Package provides functions for operating monochrome images

Index

Constants

View Source
const (
	ANSI_NO    = ""
	ANSI_RESET = "\033[0m"
)
View Source
const (
	FGANSI_BLACK  = "\033[30m"
	FGANSI_RED    = "\033[31m"
	FGANSI_GREEN  = "\033[32m"
	FGANSI_YELLOW = "\033[33m"
	FGANSI_BLUE   = "\033[34m"
	FGANSI_PURPLE = "\033[35m"
	FGANSI_CYAN   = "\033[36m"
	FGANSI_WHITE  = "\033[37m"

	FGANSI_BRIGHT_BLACK  = "\033[30;1m"
	FGANSI_BRIGHT_RED    = "\033[31;1m"
	FGANSI_BRIGHT_GREEN  = "\033[32;1m"
	FGANSI_BRIGHT_YELLOW = "\033[33;1m"
	FGANSI_BRIGHT_BLUE   = "\033[34;1m"
	FGANSI_BRIGHT_PURPLE = "\033[35;1m"
	FGANSI_BRIGHT_CYAN   = "\033[36;1m"
	FGANSI_BRIGHT_WHITE  = "\033[37;1m"
)
View Source
const (
	BGANSI_BLACK  = "\033[40m"
	BGANSI_RED    = "\033[41m"
	BGANSI_GREEN  = "\033[42m"
	BGANSI_YELLOW = "\033[43m"
	BGANSI_BLUE   = "\033[44m"
	BGANSI_PURPLE = "\033[45m"
	BGANSI_CYAN   = "\033[46m"
	BGANSI_WHITE  = "\033[47m"

	BGANSI_BRIGHT_BLACK  = "\033[40;1m"
	BGANSI_BRIGHT_RED    = "\033[41;1m"
	BGANSI_BRIGHT_GREEN  = "\033[42;1m"
	BGANSI_BRIGHT_YELLOW = "\033[43;1m"
	BGANSI_BRIGHT_BLUE   = "\033[44;1m"
	BGANSI_BRIGHT_PURPLE = "\033[45;1m"
	BGANSI_BRIGHT_CYAN   = "\033[46;1m"
	BGANSI_BRIGHT_WHITE  = "\033[47;1m"
)
View Source
const (
	CLEARDISPLAY = "\033c"
)

Variables

This section is empty.

Functions

func CreatePlanarColorImage

func CreatePlanarColorImage(planes []MonoBitmap, palette []color.Color) (image.Image, error)

Use each monochrome bitmap as bit in color palette index. https://en.wikipedia.org/wiki/Planar_(computer_graphics)

func GetFont_11x16

func GetFont_11x16() map[rune]MonoBitmap

func GetFont_3x6

func GetFont_3x6() map[rune]MonoBitmap

func GetFont_4x5

func GetFont_4x5() map[rune]MonoBitmap

func GetFont_5x7

func GetFont_5x7() map[rune]MonoBitmap

func GetFont_6x10

func GetFont_6x10() map[rune]MonoBitmap

func GetFont_8x12

func GetFont_8x12() map[rune]MonoBitmap

func GetFont_8x8

func GetFont_8x8() map[rune]MonoBitmap

Types

type AnsiColorString

type AnsiColorString string

type BlockGraphics

type BlockGraphics struct {
	Clear       bool
	HaveBorder  bool
	BorderColor AnsiColorString
	TextColor   AnsiColorString
}

func (*BlockGraphics) ToFullBlockChars

func (p *BlockGraphics) ToFullBlockChars(bitmap *MonoBitmap) string

ToFullBlockChars creates console printable version of image ' ','█'

func (*BlockGraphics) ToHalfBlockChars

func (p *BlockGraphics) ToHalfBlockChars(bitmap *MonoBitmap) string

ToHalfBlockChars ' ', '▀', '▄', '█'

func (*BlockGraphics) ToQuadBlockChars

func (p *BlockGraphics) ToQuadBlockChars(bitmap *MonoBitmap) string

ToQuadBlockChars ' ', '▘', '▝', '▀','▖', '▌', '▞', '▛','▗', '▚', '▐', '▜','▄', '▙', '▟', '█'

type MonoBitmap

type MonoBitmap struct {
	Pix []uint32 //using byte vs uint16 vs uint32 vs uint64...  32bit shoud suit well for raspi1/2
	W   int
	H   int
}

func NewMonoBitmap

func NewMonoBitmap(w int, h int, fill bool) MonoBitmap

NewMonoBitmap initializes empty bitmap fill is default value

func NewMonoBitmapFromImage

func NewMonoBitmapFromImage(img image.Image, area image.Rectangle, threshold byte, invert bool) MonoBitmap

NewMonoBitmapFromImage initializes bitmap from image. Color conversion: if any Red,Green or Blue value is over threshold then pixel is true

func (*MonoBitmap) Bounds

func (p *MonoBitmap) Bounds() image.Rectangle

Bounds returns W,H in Rect struct

func (*MonoBitmap) Circle

func (p *MonoBitmap) Circle(p0 image.Point, r int, value bool)

Modified from C++ source https://en.wikipedia.org/wiki/Midpoint_circle_algorithm

func (*MonoBitmap) CircleFill

func (p *MonoBitmap) CircleFill(p0 image.Point, r int, value bool)

Modified from C++ source https://en.wikipedia.org/wiki/Midpoint_circle_algorithm

func (*MonoBitmap) DrawBitmap

func (p *MonoBitmap) DrawBitmap(source MonoBitmap, sourceArea image.Rectangle, targetCorner image.Point, drawTrue bool, drawFalse bool, invert bool)

Draws source bitmap on bitmap drawTrue, draw when point value is true drawFalse, draw when point value is true

func (*MonoBitmap) Fill

func (p *MonoBitmap) Fill(area image.Rectangle, fillValue bool)

Fills rectangle area from map. Used for clearing image

func (*MonoBitmap) FlipH

func (p *MonoBitmap) FlipH()

func (*MonoBitmap) FlipV

func (p *MonoBitmap) FlipV()

Flip with axis in vertical

func (*MonoBitmap) GetDisplayImage

func (p *MonoBitmap) GetDisplayImage(trueColorUpper color.Color, trueColorDowner color.Color, upperRows int, falseColor color.Color, pixelW int, pixelH int, gapW int, gapH int) image.Image

Generates image that is rendered like it was LCD. Space in between segments is transparent upper vs lower color allows to render two color LCD's (like cyan and yellow strip)

func (*MonoBitmap) GetImage

func (p *MonoBitmap) GetImage(trueColor color.Color, falseColor color.Color) image.Image

GetImage Creates RGBA image from bitmap

func (*MonoBitmap) GetPix

func (p *MonoBitmap) GetPix(x int, y int) bool

Gets pixel. Returns false if out of range

func (*MonoBitmap) GetView

func (p *MonoBitmap) GetView(w int, h int, p0 image.Point, pxStep int, edges bool) MonoBitmap

Get view (size w,h) for display. Starting from corner p0. Result is centered. If p0 goes outside, function clamps view This is meant only for producing scrollable output picture for display. Better scaling functions elsewhere pxStep=0, autoscale, so bitmap will fit pxStep=1 is 1:1 pxStep=2 is 2:1 (50% scale) pxStep=3 is 3:1 (25% scale) pxStep is limited to point where whole bitmap is visible Returns: image, actual cornerpoint and zoom used. Useful if UI includes

func (*MonoBitmap) Hline

func (p *MonoBitmap) Hline(x0 int, x1 int, y int, value bool)

Horizontal line for filling

func (*MonoBitmap) Invert

func (p *MonoBitmap) Invert(area image.Rectangle)

Inverts pixel values

func (*MonoBitmap) Line

func (p *MonoBitmap) Line(p0 image.Point, p1 image.Point, value bool)

Bresenham's line, copied from http://41j.com/blog/2012/09/bresenhams-line-drawing-algorithm-implemetations-in-go-and-c/

func (*MonoBitmap) Print

func (p *MonoBitmap) Print(text string, font map[rune]MonoBitmap, lineSpacing int, gap int, area image.Rectangle, drawTrue bool, drawFalse bool, invert bool, wrap bool) image.Rectangle

Prints message on screen.Creates new lines on \n Returns rectangle where text was printed

func (*MonoBitmap) RLEdecode

func (p *MonoBitmap) RLEdecode(activeFirst bool, data []byte) error

RLEdecode decodes run length compressed bitmap data

func (*MonoBitmap) RLEencode

func (p *MonoBitmap) RLEencode(activeFirst bool) []byte

RLEencodes bitmap in runlength compressed format

func (*MonoBitmap) Rotate90

func (p *MonoBitmap) Rotate90(turn90 int)

Rotates in 90 decree steps +1=90 clockwise -1=90 anticlockwise +2=180 clockwise etc...

func (*MonoBitmap) SetPix

func (p *MonoBitmap) SetPix(x int, y int, value bool)

TODO BUG: does not work if not div by 8

func (*MonoBitmap) Vline

func (p *MonoBitmap) Vline(x int, y0 int, y1 int, value bool)

Directories

Path Synopsis
This sub library is for simulating gadgets on desktop Supports keys and monochrome display.
This sub library is for simulating gadgets on desktop Supports keys and monochrome display.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL