Documentation ¶
Index ¶
- Constants
- Variables
- func ColourMatch(c1, c2 color.Color) float64
- func ColoursAreEqual(c1 color.Color, c2 color.Color) bool
- func CopyRegion(dest *image.RGBA, destRegion *image.Rectangle, src image.Image, ...)
- func CountEachColourInImageInBounds(img image.Image, bounds image.Rectangle) [7]int
- func DetectColourTheme(c color.Color) int
- func DetectThemeOfEntireImage(img image.Image, description string) int
- func FindDominantColourInCounts(counts [7]int, description string) int
- func ImagesAreEqual(img1 image.Image, region1 *image.Rectangle, img2 image.Image, ...) bool
- func ImagesAreEqualVerbose(img1 image.Image, region1 *image.Rectangle, img2 image.Image, ...) bool
- func LoadImage(fileName string) (img image.Image, err error)
- func ProcessDirectory(globPattern string, directoryProcessor DirectoryProcessor, maxThreads int) error
- func RectsAreEqual(r1, r2 *image.Rectangle) bool
- func RectsAreSameSize(r1, r2 *image.Rectangle) bool
- func SavePNG(img image.Image, fileName string) error
- func SqByteDiff(a, b uint32) float64
- func SubImage(img image.Image, region *image.Rectangle) image.Image
- func VerifyBlackEdge(img image.Image, x, y, dx, dy int, black color.Color, grey color.Color) bool
- func VerifyPixelColour(img image.Image, x, y int, colour color.Color) bool
- type DirectoryProcessor
Constants ¶
const ( MATCH_WEIGHT_R = 0.299 MATCH_WEIGHT_G = 0.587 MATCH_WEIGHT_B = 0.114 GOOD_MATCH = 0.001 )
const ( KC_BLUE = iota KC_CYAN KC_GREEN KC_MAGENTA KC_ORANGE KC_RED KC_BLACK )
Key colours
Variables ¶
var ColourNames = [7]string{
"Blue", "Cyan", "Green", "Magenta", "Orange", "Red", "Black",
}
Colour names
Functions ¶
func ColourMatch ¶
ColourMatch compares two colours, returning a number between 0 and 1. 0 means a perfect match, 1 means complete mismatch. Alpha is ignored.
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 DetectColourTheme ¶
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 ¶
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 ImagesAreEqual ¶
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 ProcessDirectory ¶
func ProcessDirectory( globPattern string, directoryProcessor DirectoryProcessor, maxThreads int, ) error
ProcessDirectory uses a DirectoryProcessor to process the files matched by globPattern.
func RectsAreEqual ¶
func RectsAreSameSize ¶
func SqByteDiff ¶
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 VerifyBlackEdge ¶
VerifyBlackEdge checks that the pixel at (x, y) matches black and the pixel at (x + dx, y + dy) matches grey
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.