diff

package
v0.0.0-...-03d6fc4 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2019 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PRIORITY_NOW is the highest priority intended for in request calls.
	PRIORITY_NOW = iota

	// PRIORITY_BACKGROUND is the priority to use for background tasks.
	// i.e. Use to calculate diffs of ignored digests.
	PRIORITY_BACKGROUND

	// PRIORITY_IDLE is the priority to use for background tasks that have
	// very low priority.
	PRIORITY_IDLE
)
View Source
const (
	METRIC_COMBINED = "combined"
	METRIC_PERCENT  = "percent"
	METRIC_PIXEL    = "pixel"
)

Variables

View Source
var (
	PixelMatchColor = color.Transparent

	// Orange gradient.
	//
	// These are non-premultiplied RGBA values.
	PixelDiffColor = [][]uint8{
		{0xfd, 0xd0, 0xa2, 0xff},
		{0xfd, 0xae, 0x6b, 0xff},
		{0xfd, 0x8d, 0x3c, 0xff},
		{0xf1, 0x69, 0x13, 0xff},
		{0xd9, 0x48, 0x01, 0xff},
		{0xa6, 0x36, 0x03, 0xff},
		{0x7f, 0x27, 0x04, 0xff},
	}

	// Blue gradient.
	//
	// These are non-premultiplied RGBA values.
	PixelAlphaDiffColor = [][]uint8{
		{0xc6, 0xdb, 0xef, 0xff},
		{0x9e, 0xca, 0xe1, 0xff},
		{0x6b, 0xae, 0xd6, 0xff},
		{0x42, 0x92, 0xc6, 0xff},
		{0x21, 0x71, 0xb5, 0xff},
		{0x08, 0x51, 0x9c, 0xff},
		{0x08, 0x30, 0x6b, 0xff},
	}
)

Functions

func DefaultDiffFn

func DefaultDiffFn(leftImg *image.NRGBA, rightImg *image.NRGBA) (interface{}, *image.NRGBA)

DefaultDiffFn implements the DiffFn function type. Calculates the basic image difference along with custom diff metrics.

func GetDiffMetricIDs

func GetDiffMetricIDs() []string

GetDiffMetricIDs returns the ids of the available diff metrics.

func GetNRGBA

func GetNRGBA(img image.Image) *image.NRGBA

GetNRGBA converts the image to an *image.NRGBA in an efficient manner.

func GetPixelDiffPercent

func GetPixelDiffPercent(numDiffPixels, totalPixels int) float32

Returns the percentage of pixels that differ, as a float between 0 and 100 (inclusive).

func OpenNRGBA

func OpenNRGBA(reader io.Reader) (*image.NRGBA, error)

OpenNRGBA reads an NRGBA image from the given reader. If the underlying image is not NRGBA it will be converted.

func OpenNRGBAFromFile

func OpenNRGBAFromFile(fileName string) (*image.NRGBA, error)

OpenNRGBAFromFile opens the given file path to a PNG file and returns the image as image.NRGBA.

func WritePNG

func WritePNG(w io.Writer, img *image.NRGBA) error

WritePNG is a utility function to write the given NRGBA image as a PNG to the given Writer.

Types

type DiffErr

type DiffErr string

Diff error to indicate different error conditions during diffing.

const (
	// Http related error occurred.
	HTTP DiffErr = "http_error"

	// Image is corrupted and cannot be decoded.
	CORRUPTED DiffErr = "corrupted"

	// Arbitrary error.
	OTHER DiffErr = "other"
)

type DiffMetrics

type DiffMetrics struct {
	// NumDiffPixels is the absolute number of pixels that are different.
	NumDiffPixels int `json:"numDiffPixels"`

	// PixelDiffPercent is the percentage of pixels that are different.
	PixelDiffPercent float32 `json:"pixelDiffPercent"`

	// MaxRGBADiffs contains the maximum difference of each channel.
	MaxRGBADiffs []int `json:"maxRGBADiffs"`

	// DimDiffer is true if the dimensions between the two images are different.
	DimDiffer bool `json:"dimDiffer"`

	// Diffs contains different diff metrics for the to images.
	Diffs map[string]float32 `json:"diffs"`
}

DiffMetrics contains the diff information between two images.

func PixelDiff

func PixelDiff(img1, img2 image.Image) (*DiffMetrics, *image.NRGBA)

PixelDiff is a utility function that calculates the DiffMetrics and the image of the difference for the provided images.

type DiffStore

type DiffStore interface {
	// Get returns the DiffMetrics of the provided dMain digest vs all digests
	// specified in dRest.
	Get(priority int64, mainDigest string, rightDigests []string) (map[string]interface{}, error)

	// ImageHandler returns a http.Handler for the given path prefix. The caller
	// can then serve images of the format:
	//        <urlPrefix>/images/<digests>.png
	//        <urlPrefix>/diffs/<digest1>-<digests2>.png
	ImageHandler(urlPrefix string) (http.Handler, error)

	// WarmDigest will fetch the given digests. If sync is true the call will
	// block until all digests have been fetched or failed to fetch.
	WarmDigests(priority int64, digests []string, sync bool)

	// WarmDiffs will calculate the difference between every digests in
	// leftDigests and every in digests in rightDigests.
	WarmDiffs(priority int64, leftDigests []string, rightDigests []string)

	// UnavailableDigests returns map[digest]*DigestFailure which can be used
	// to check whether a digest could not be processed and to provide details
	// about failures.
	UnavailableDigests() map[string]*DigestFailure

	// PurgeDigests removes all information related to the indicated digests
	// (image, diffmetric) from local caches. If purgeGCS is true it will also
	// purge the digests image from Google storage, forcing that the digest
	// be re-uploaded by the build bots.
	PurgeDigests(digests []string, purgeGCS bool) error
}

DiffStore defines an interface for a type that retrieves, stores and diffs images. How it retrieves the images is up to the implementation.

type DigestFailure

type DigestFailure struct {
	Digest string  `json:"digest"`
	Reason DiffErr `json:"reason"`
	TS     int64   `json:"ts"`
}

DigestFailure captures the details of a digest error that occurred.

func NewDigestFailure

func NewDigestFailure(digest string, reason DiffErr) *DigestFailure

NewDigestFailure is a convenience function to create an instance of DigestFailure. It sets the provided arguments in the correct fields and adds a timestamp with the current time in milliseconds.

type DigestFailureSlice

type DigestFailureSlice []*DigestFailure

Implement sort.Interface for a slice of DigestFailure

func (DigestFailureSlice) Len

func (d DigestFailureSlice) Len() int

func (DigestFailureSlice) Less

func (d DigestFailureSlice) Less(i, j int) bool

func (DigestFailureSlice) Swap

func (d DigestFailureSlice) Swap(i, j int)

type MetricFn

type MetricFn func(*DiffMetrics, *image.NRGBA, *image.NRGBA) float32

MetricsFn is the signature a custom diff metric has to implmente.

Jump to

Keyboard shortcuts

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