Documentation ¶
Index ¶
- Constants
- Variables
- func DefaultDiffFn(leftImg *image.NRGBA, rightImg *image.NRGBA) (interface{}, *image.NRGBA)
- func GetDiffMetricIDs() []string
- func GetNRGBA(img image.Image) *image.NRGBA
- func GetPixelDiffPercent(numDiffPixels, totalPixels int) float32
- func OpenNRGBA(reader io.Reader) (*image.NRGBA, error)
- func OpenNRGBAFromFile(fileName string) (*image.NRGBA, error)
- func WritePNG(w io.Writer, img *image.NRGBA) error
- type DiffErr
- type DiffMetrics
- type DiffStore
- type DigestFailure
- type DigestFailureSlice
- type MetricFn
Constants ¶
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 )
const ( METRIC_COMBINED = "combined" METRIC_PERCENT = "percent" METRIC_PIXEL = "pixel" )
Variables ¶
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 ¶
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 GetPixelDiffPercent ¶
Returns the percentage of pixels that differ, as a float between 0 and 100 (inclusive).
func OpenNRGBA ¶
OpenNRGBA reads an NRGBA image from the given reader. If the underlying image is not NRGBA it will be converted.
func OpenNRGBAFromFile ¶
OpenNRGBAFromFile opens the given file path to a PNG file and returns the image as image.NRGBA.
Types ¶
type DiffErr ¶
type DiffErr string
Diff error to indicate different error conditions during diffing.
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.
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) // 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)