markup

package
v0.3.15 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 12 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package markup is the screenshot markup editor: annotations drawn over a captured image (crop, arrow, rectangle, ellipse, freehand, text, highlighter, numbered markers and pixelation) with undo and redo, painted live on screen and flattened into the pixels that are saved.

Index

Constants

This section is empty.

Variables

Tools lists every tool in toolbar order.

Functions

func Flatten

func Flatten(d *Doc, font render.Font) *image.RGBA

Flatten renders the document as it is saved: the marks burned into a copy of the captured pixels, cropped. Pixelated cells replace the pixels under them, so nothing of the original survives there.

func MarkerPx

func MarkerPx(size int) int

MarkerPx is a marker's diameter at stroke size, in image pixels.

func Paint

func Paint(cv *render.Canvas, marks []Mark, v View, font render.Font)

Paint draws marks over the image placed by v.

func PaintMark

func PaintMark(cv *render.Canvas, m Mark, v View, font render.Font)

PaintMark draws one mark over the image placed by v. A crop draws nothing: it decides what is kept, not what is drawn.

func TextPx

func TextPx(size int) float64

TextPx is the font size a text mark of stroke size draws at, in image pixels.

Types

type Deps

type Deps struct {
	App *app.Application
	// Font draws the toolbar, text marks and marker numbers; Px is the
	// toolbar's size.
	Font render.Font
	Px   float64
	// Palette is the colors the toolbar offers, the first one picked.
	Palette []render.Color
	// Save writes the flattened image over path, atomically, and copies it.
	Save func(img *image.RGBA, path string) error
	// SaveAs writes the flattened image to a path the user picked.
	SaveAs func(img *image.RGBA, path string) error
	// Closed runs once the window is gone, whatever closed it.
	Closed func()
}

Deps are what the editor needs from the shell.

type Doc

type Doc struct {
	// contains filtered or unexported fields
}

Doc is an image under edit: the captured pixels, never changed, and the marks over them with an undo cursor.

func NewDoc

func NewDoc(base render.StillImage) *Doc

NewDoc starts editing base, which it never writes.

func (*Doc) Base

func (d *Doc) Base() render.StillImage

Base is the captured image.

func (*Doc) Crop

func (d *Doc) Crop() image.Rectangle

Crop is the part of the image that is kept: the newest crop, else all of it.

func (*Doc) Marks

func (d *Doc) Marks() []Mark

Marks are the marks in effect, oldest first.

func (*Doc) Prepare

func (d *Doc) Prepare(m Mark) Mark

Prepare is m as Push would apply it: numbered and sampled.

func (*Doc) Push

func (d *Doc) Push(m Mark) bool

Push applies m on top, discarding what undo had taken back. A pixelation samples its cells now, a marker takes the next number, and a mark with nothing to show is dropped; it reports whether m was applied.

func (*Doc) Redo

func (d *Doc) Redo() bool

Redo reapplies the mark undo took back last, reporting whether there was one.

func (*Doc) Undo

func (d *Doc) Undo() bool

Undo takes the newest mark back, reporting whether there was one.

type Editor

type Editor struct {
	// contains filtered or unexported fields
}

Editor is one open markup window. Its methods run on the loop goroutine.

func Open

func Open(d Deps, base render.StillImage, path string) (*Editor, error)

Open shows the editor over base, the captured image saved at path. It draws base as it is in memory: the file is never read.

func (*Editor) Close

func (e *Editor) Close()

Close closes the window without saving.

func (*Editor) Doc

func (e *Editor) Doc() *Doc

Doc is the document under edit.

func (*Editor) Redo

func (e *Editor) Redo()

Redo reapplies the last mark undo took back.

func (*Editor) Save

func (e *Editor) Save() error

Save flattens the marks into the image, writes it over the capture and closes the editor; a failed write keeps it open and is returned.

func (*Editor) SaveAs

func (e *Editor) SaveAs()

SaveAs asks where to save a copy and writes it there.

func (*Editor) SetTool

func (e *Editor) SetTool(t Tool)

SetTool picks what the next drag draws.

func (*Editor) Undo

func (e *Editor) Undo()

Undo takes the newest mark back.

type Mark

type Mark struct {
	Tool   Tool
	Points []image.Point
	Color  render.Color
	Size   int
	Text   string
	Number int
	// contains filtered or unexported fields
}

Mark is one annotation in image pixels. Points holds the drag's endpoints (every sampled point for freehand); Size is the stroke width; Text is a text mark's string; Number is a marker's ordinal.

func (Mark) Rect

func (m Mark) Rect() image.Rectangle

Rect is the rectangle the mark's first and last points span.

type Tool

type Tool uint8

Tool is what a drag on the image draws.

const (
	ToolArrow Tool = iota
	ToolRect
	ToolEllipse
	ToolFreehand
	ToolText
	ToolHighlight
	ToolMarker
	ToolPixelate
	ToolCrop
)

The editor's tools.

type View

type View struct {
	X, Y, Scale float64
}

View places image pixels on a canvas: a pixel p lands at (X + p.X*Scale, Y + p.Y*Scale) in the canvas's logical pixels.

func (View) Image

func (v View) Image(x, y float64) image.Point

Image maps a canvas point back to the image pixel under it.

Jump to

Keyboard shortcuts

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