Documentation
¶
Index ¶
- Variables
- func AsRGBA(src image.Image) *image.RGBA
- func Assert(t TestingT, img image.Image, filename string, tols ...int)
- func Base64SplitLines(b []byte) []byte
- func CloneAsRGBA(src image.Image) *image.RGBA
- func ColorsEqual(cc, ic color.RGBA, tol int) bool
- func Crop(src image.Image, rect image.Rectangle) image.Image
- func DiffImage(a, b image.Image) image.Image
- func ImagesEqual(a, b image.Image, tol int) (bounds, content bool, ac, bc color.RGBA, x, y int)
- func Resize(src image.Image, size image.Point) image.Image
- func Save(im image.Image, filename string) error
- func ToBase64(img image.Image, f Formats) ([]byte, string)
- func Uint8Equal(cc, ic uint8, tol int) bool
- func Unwrap(src image.Image) image.Image
- func Update(src image.Image)
- func WrapJS(src image.Image) image.Image
- func Write(im image.Image, w io.Writer, f Formats) error
- type Formats
- func ExtToFormat(ext string) (Formats, error)
- func FormatsValues() []Formats
- func FromBase64(eb []byte) (image.Image, Formats, error)
- func Open(filename string) (image.Image, Formats, error)
- func OpenFS(fsys fs.FS, filename string) (image.Image, Formats, error)
- func Read(r io.Reader) (image.Image, Formats, error)
- func (i Formats) Desc() string
- func (i Formats) Int64() int64
- func (i Formats) MarshalText() ([]byte, error)
- func (i *Formats) SetInt64(in int64)
- func (i *Formats) SetString(s string) error
- func (i Formats) String() string
- func (i *Formats) UnmarshalText(text []byte) error
- func (i Formats) Values() []enums.Enum
- type JSON
- type JSONEncoded
- type JSRGBA
- type TestingT
- type Wrapped
Constants ¶
This section is empty.
Variables ¶
var UpdateTestImages = updateTestImages
UpdateTestImages indicates whether to update currently saved test images in [AssertImage] instead of comparing against them. It is automatically set if the build tag "update" is specified, or if the environment variable "CORE_UPDATE_TESTDATA" is set to "true". It should typically only be set through those methods. It should only be set when behavior has been updated that causes test images to change, and it should only be set once and then turned back off.
Functions ¶
func AsRGBA ¶ added in v0.3.11
AsRGBA returns the image as an *image.RGBA. If it already is one, it returns that image directly. Otherwise it returns a clone. It calls Unwrap first. See also CloneAsRGBA.
func Assert ¶
Assert asserts that the given image is equivalent to the image stored at the given filename in the testdata directory, with ".png" added to the filename if there is no extension (eg: "button" becomes "testdata/button.png"). Forward slashes are automatically replaced with backslashes on Windows. If it is not, it fails the test with an error, but continues its execution. If there is no image at the given filename in the testdata directory, it creates the image. optional tolerance argument specifies the maximum color difference, which defaults to 10.
func Base64SplitLines ¶
Base64SplitLines splits the encoded Base64 bytes into standard lines of 76 chars each. The last line also ends in a newline
func CloneAsRGBA ¶
CloneAsRGBA returns an *image.RGBA copy of the supplied image. It calls Unwrap first. See also AsRGBA.
func ColorsEqual ¶ added in v0.3.13
ColorsEqual returns true if two colors equal within tol
func Crop ¶ added in v0.3.12
Crop returns a cropped region of the source image (which can be Wrapped), returning a WrapJS image handle on web and using web-native optimized code.
func DiffImage ¶ added in v0.3.8
DiffImage returns the difference between two images, with pixels having the abs of the difference between pixels. Images must have the same bounds.
func ImagesEqual ¶ added in v0.3.13
ImagesEqual compares two images, returns false if not equal, based on bounds or content. If a content difference, then the colors and pixel where they first differ are returned. The first image is considered the reference, correct one. Tol is the color tolerance.
func Resize ¶ added in v0.3.12
Resize returns a resized version of the source image (which can be Wrapped), returning a WrapJS image handle on web and using web-native optimized code. Otherwise, uses medium quality Linear resize.
func Save ¶
Save saves the image to the given filename, with the format inferred from the filename. png, jpeg, gif, tiff, and bmp are supported.
func ToBase64 ¶ added in v0.3.13
ToBase64 returns bytes of image encoded in given format, in Base64 encoding with "image/format" mimetype returned
func Uint8Equal ¶ added in v0.3.13
Uint8Equal returns true if two numbers are within tol
func Unwrap ¶ added in v0.3.11
Unwrap calls [Wrapped.Underlying] on a Wrapped if it is one. It returns the original image otherwise.
func Update ¶ added in v0.3.11
Update calls [Wrapped.Update] on a Wrapped if it is one. It does nothing otherwise.
func WrapJS ¶ added in v0.3.11
WrapJS returns a JavaScript optimized wrapper around the given image.Image on web, and just returns the image on other platforms.
Types ¶
type Formats ¶
type Formats int32 //enums:enum
Formats are the supported image encoding / decoding formats
const FormatsN Formats = 7
FormatsN is the highest valid value for type Formats, plus one.
func ExtToFormat ¶
ExtToFormat returns a Format based on a filename extension, which can start with a . or not
func FormatsValues ¶
func FormatsValues() []Formats
FormatsValues returns all possible values for the type Formats.
func FromBase64 ¶
FromBase64 returns image from Base64-encoded bytes
func Open ¶
Open opens an image from the given filename. The format is inferred automatically, and is returned using the Formats enum. png, jpeg, gif, tiff, bmp, and webp are supported.
func OpenFS ¶
OpenFS opens an image from the given filename using the given fs.FS filesystem (e.g., for embed files). The format is inferred automatically, and is returned using the Formats enum. png, jpeg, gif, tiff, bmp, and webp are supported.
func Read ¶
Read reads an image to the given reader, The format is inferred automatically, and is returned using the Formats enum. png, jpeg, gif, tiff, bmp, and webp are supported.
func (Formats) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*Formats) SetString ¶
SetString sets the Formats value from its string representation, and returns an error if the string is invalid.
func (*Formats) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type JSON ¶ added in v0.3.13
JSON is a wrapper around an image.Image that defines JSON Marshal and Unmarshal methods, so that the image will automatically be properly saved / loaded when used as a struct field, for example. Must be a pointer type to support custom unmarshal function. The original image is not anonymously embedded so that you have to extract it, otherwise it will be processed inefficiently.
func NewJSON ¶ added in v0.3.13
NewJSON returns a new JSON wrapper around given image, to support automatic wrapping and unwrapping.
func (*JSON) MarshalJSON ¶ added in v0.3.13
func (*JSON) UnmarshalJSON ¶ added in v0.3.13
type JSONEncoded ¶ added in v0.3.13
type JSONEncoded struct {
Width int
Height int
// Image is the encoded byte stream, which will be encoded in JSON
// using Base64
Image []byte
}
JSONEncoded is a representation of an image encoded into a byte stream, using the PNG encoder. This can be Marshal and Unmarshal'd directly.
type JSRGBA ¶ added in v0.3.13
JSRGBA is a dummy version of this type so code does not have to be conditionalized.
type Wrapped ¶ added in v0.3.11
type Wrapped interface {
image.Image
// Update is called whenever the image data has been updated,
// to update any additional data based on the new image.
// This may copy an image to the GPU or update JavaScript pointers.
Update()
// Underlying returns the underlying image.Image, which should
// be called whenever passing the image to some other Go-based
// function that is likely to be optimized for different image types,
// such as [draw.Draw]. Do NOT use this for functions that will
// directly handle the wrapped image!
Underlying() image.Image
}
Wrapped extends the image.Image interface with two methods that manage the wrapping of an underlying Go image.Image. This can be used for images that are actually GPU textures, and to manage JavaScript pointers on the js platform.