repton

package
v0.0.0-...-de71bd2 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: ISC Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MATCH_WEIGHT_R = 0.299
	MATCH_WEIGHT_G = 0.587
	MATCH_WEIGHT_B = 0.114

	GOOD_MATCH = 0.001
)
View Source
const (
	KC_BLUE = iota
	KC_CYAN
	KC_GREEN
	KC_MAGENTA
	KC_ORANGE
	KC_RED
	KC_BLACK
)

Key colours

Variables

View Source
var ColourNames = [7]string{
	"Blue", "Cyan", "Green", "Magenta", "Orange", "Red", "Black",
}

Colour names

Functions

func ColourMatch

func ColourMatch(c1, c2 color.Color) float64

ColourMatch compares two colours, returning a number between 0 and 1. 0 means a perfect match, 1 means complete mismatch. Alpha is ignored.

func ColoursAreEqual

func ColoursAreEqual(c1 color.Color, c2 color.Color) bool

func CopyRegion

func CopyRegion(dest *image.RGBA, destRegion *image.Rectangle,
	src image.Image, srcRegion *image.Rectangle,
)

CopyRegion copies a region from src into dest. If either region is null the entire source is used. If destRegion is nil, it is set to the same size as srcRegion but at origin (0, 0).

func CountEachColourInImageInBounds

func CountEachColourInImageInBounds(
	img image.Image,
	bounds image.Rectangle,
) [7]int

func DetectColourTheme

func DetectColourTheme(c color.Color) int

DetectColourTheme detects which of the above colours is the closest match for the input, returning an index into ColourNames, or -1 for no (close) match.

func DetectThemeOfEntireImage

func DetectThemeOfEntireImage(img image.Image, description string) int

DetectThemeOfEntireImage looks at all the pixels in an image, sorting them into whichever of the above colours they match best. It returns the index of the colour with the most matches.

func FindDominantColourInCounts

func FindDominantColourInCounts(
	counts [7]int,
	description string,
) int

func ImagesAreEqual

func ImagesAreEqual(img1 image.Image, region1 *image.Rectangle,
	img2 image.Image, region2 *image.Rectangle,
) bool

func ImagesAreEqualVerbose

func ImagesAreEqualVerbose(img1 image.Image, region1 *image.Rectangle,
	img2 image.Image, region2 *image.Rectangle, verbose bool,
) bool

ImageCompare returns true if the content of both regions is the same. Either or both regions may be nil to compare the entire image. Returns true if both images are the same.

func LoadImage

func LoadImage(fileName string) (img image.Image, err error)

LoadImage loads a PNG, which a DirectoryProcessor will typically find useful.

func ProcessDirectory

func ProcessDirectory(
	globPattern string,
	directoryProcessor DirectoryProcessor,
	maxThreads int,
) error

ProcessDirectory uses a DirectoryProcessor to process the files matched by globPattern.

func RectsAreEqual

func RectsAreEqual(r1, r2 *image.Rectangle) bool

func RectsAreSameSize

func RectsAreSameSize(r1, r2 *image.Rectangle) bool

func SavePNG

func SavePNG(img image.Image, fileName string) error

func SqByteDiff

func SqByteDiff(a, b uint32) float64

SqByteDiff returns the square of the difference between two colour words normalised from range (0-65535) to (0.0-1.0). The bytes are actually uint32 with 16-bits of precision because that's what Color.RGBA returns.

func SubImage

func SubImage(img image.Image, region *image.Rectangle) image.Image

func VerifyBlackEdge

func VerifyBlackEdge(img image.Image, x, y, dx, dy int,
	black color.Color, grey color.Color,
) bool

VerifyBlackEdge checks that the pixel at (x, y) matches black and the pixel at (x + dx, y + dy) matches grey

func VerifyPixelColour

func VerifyPixelColour(img image.Image, x, y int, colour color.Color) bool

VerifyPixelColour checks that the pixel at (x, y) matches colour

Types

type DirectoryProcessor

type DirectoryProcessor interface {
	// ProcessFile is called for each file. It's called in batches, each
	// invocation in a goroutine running concurrently with others in the
	// same batch. fileName is a full pathname.
	ProcessFile(fileName string)

	// MinimumFilesNeededForCompletion allows the number of files in each
	// batch to be optimised. For example, extractatlases needs to process
	// at least 6 files to start with, to complete each colour, but after
	// that it may only need to complete a couple more, and should be able
	// to achieve completion without needing to load the entire set.
	MinimumFilesNeededForCompletion() int

	// Finish is called after MinimumFilesNeededForCompletion returns 0.
	Finish()

	// StartBatch is called just before the beginning of each batch
	StartBatch()

	// FinishBatch is called just after the end of each batch
	FinishBatch()
}

DirectoryProcessor encapsulates a set of functions to process all or some of the files in a directory.

Jump to

Keyboard shortcuts

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