v1

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2018 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const DEFAULT_CONFIG_FILE = `screenshot-compare.json`
View Source
const WB = float64(0.114)

WB as defined by standard BT.601 by CCIR

View Source
const WG = float64(0.587)

WG as defined by standard BT.601 by CCIR

View Source
const WR = float64(0.299)

WR as defined by standard BT.601 by CCIR

Variables

This section is empty.

Functions

func Compare

func Compare(c *Config, r *Result) error

Compare applies the two images available in Config and compares them pixel-by-pixel. The result will be stored in the Result argument. If the score cannot be computed, then error will be non-nil and give a reason.

Types

type Config

type Config struct {
	// ColorSpace to use for comparison.
	// Currently supported: {Y'UV, RGB}
	ColorSpace string
	// Timeout defines a duration threshold. Timeout does not consider PreWait time.
	// If comparison exceeds this duration threshold, it will terminate prematurely.
	Timeout time.Duration
	// PreWait defines how long to wait before comparison starts
	PreWait time.Duration
	// AdmissibleDiffPixel is a fixed number N of pixels that are
	// allowed to be different. The comparison score will ignore the
	// the first N pixels yielding _any_ difference
	AdmissibleDiffPixel uint
	// NoDimensionError returns the maximum difference value as Score if
	// dimensions do not match instead of returning an error
	NoDimensionError bool
	// BaseImg is the image to compare in memory
	BaseImg TaggedImage
	// RefImg is the image to compare with ("expected image").
	// RImg is the parsed image to compare with in memory
	RefImg TaggedImage
}

Config defines the runtime configuration. Two runs of the executable with the same Config must yield the same result.

func NewConfig

func NewConfig() *Config

NewConfig creates a new configuration struct with default values

func (*Config) FromArgs

func (c *Config) FromArgs(args []string, usage string, mode int) (error, error)

FromArgs parses the given arguments and stores its data in its Config struct. If mode=1, all values must be set or an error is returned. Depending on the type, it might not be possible to distinguish between 'not set' and 'zero value'. If mode=2, values will be stored iff all required values are set. If mode=3, any non-zero value will be stored. The return values are warnings (value not set) and errors (value cannot be used/parsed). If the second return value is non-nil, Config will not be modified.

func (*Config) FromEnv

func (c *Config) FromEnv(mode int) (error, error)

FromEnv parses environment variables and stores its data in its Config struct If mode=1, all values must be set or an error is returned. Depending on the type, it might not be possible to distinguish between 'not set' and 'zero value'. If mode=2, values will be stored iff all required values are set. If mode=3, any non-zero value will be stored. The return values are warnings (value not set) and errors (value cannot be used/parsed). If the second return value is non-nil, Config will not be modified.

func (*Config) FromJSON

func (c *Config) FromJSON(filepath string, silentMissingError bool, mode int) (error, error)

FromJSON retrieves the configuration parameters from a JSON file and stores its data in its Config struct. If `filepath` is empty, the default filepath will be used. If `silentMissingError` is true, FromJSON does not modify Config and returns nil if the JSON file does not exist. If mode=1, all values must be set or an error is returned. Depending on the type, it might not be possible to distinguish between 'not set' and 'zero value'. If mode=2, values will be stored iff all required values are set. If mode=3, any non-zero value will be stored. The return values are warnings (value not set) and errors (value cannot be used/parsed). If the second return value is non-nil, Config will not be modified.

func (*Config) String

func (c *Config) String() string

func (*Config) Valid

func (c *Config) Valid() error

type Result

type Result struct {
	// Config provides a representation of the values used to run this program.
	// Useful for debugging
	Config string
	// Runtime gives the duration of the comparison algorithm plus waiting times
	Runtime time.Duration
	// Gives the number of pixels with _any_ difference between the two images.
	// If PixelsDifferent is smaller or equal to AdmissibleDiffPixel, the Score must be necessarily zero.
	PixelsDifferent uint
	// True, if the program did not finish within the timeframe given by Timeout
	Timeout bool
	// Score gives the percentage of pixels with difference (minus AdmissibleDiffPixel) between two images.
	// Is a value between 0 (inclusively) and 1 (inclusively)
	Score float64
	// contains filtered or unexported fields
}

Result is the result of an image comparison

type TaggedImage

type TaggedImage struct {
	// Image is an in-memory Go image.Image instance
	Image image.Image
	// Width gives the width of Image
	Width int
	// Height gives the height of Image
	Height int
	// MinX defines the smallest X coordinate to start comparison with
	MinX int
	// MinY defines the smallest Y coordinate to start comparison with
	MinY int
	// Format is the file format as returned by Go's image.Decode
	Format string
	// Source is a simple description for the source of this image (for example, its filepath)
	Source string
}

TaggedImage represents an image with explicit width, height, format and source values

func (*TaggedImage) FromFilepath

func (i *TaggedImage) FromFilepath(fp string) error

FromFilepath reads an image from the given filepath and fills TaggedImage with its data

func (*TaggedImage) String

func (i *TaggedImage) String() string

String returns the human-readable representation of TaggedImage

Jump to

Keyboard shortcuts

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