Documentation
¶
Overview ¶
Native image datatype. Contains image data which can be converted to an graphics.gd/classdb/ImageTexture and provides commonly used image processing methods. The maximum width and height for an graphics.gd/classdb/Image are MaxWidth and MaxHeight.
An graphics.gd/classdb/Image cannot be assigned to a texture property of an object directly (such as graphics.gd/classdb/Sprite2D.Instance.Texture), and has to be converted manually to an graphics.gd/classdb/ImageTexture first.
Note: The maximum image size is 16384×16384 pixels due to graphics hardware limitations. Larger images may fail to import.
Index ¶
- Constants
- type ASTCFormat
- type Advanced
- type AlphaMode
- type Any
- type CompressMode
- type CompressSource
- type Expanded
- func (self Expanded) BumpMapToNormalMap(bump_scale Float.X)
- func (self Expanded) Compress(mode CompressMode, source CompressSource, astc_format ASTCFormat) error
- func (self Expanded) CompressFromChannels(mode CompressMode, channels UsedChannels, astc_format ASTCFormat) error
- func (self Expanded) DetectUsedChannels(source CompressSource) UsedChannels
- func (self Expanded) GenerateMipmaps(renormalize bool) error
- func (self Expanded) LoadSvgFromBuffer(buffer []byte, scale Float.X) error
- func (self Expanded) LoadSvgFromString(svg_str string, scale Float.X) error
- func (self Expanded) Resize(width int, height int, interpolation Interpolation)
- func (self Expanded) ResizeToPo2(square bool, interpolation Interpolation)
- func (self Expanded) SaveExr(path string, grayscale bool) error
- func (self Expanded) SaveExrToBuffer(grayscale bool) []byte
- func (self Expanded) SaveJpg(path string, quality Float.X) error
- func (self Expanded) SaveJpgToBuffer(quality Float.X) []byte
- func (self Expanded) SaveWebp(path string, lossy bool, quality Float.X) error
- func (self Expanded) SaveWebpToBuffer(lossy bool, quality Float.X) []byte
- type Extension
- type Format
- type ID
- type Instance
- func Create(width int, height int, use_mipmaps bool, format Format) Instance
- func CreateEmpty(width int, height int, use_mipmaps bool, format Format) Instance
- func CreateFromData(width int, height int, use_mipmaps bool, format Format, data []byte) Instance
- func LoadFromFile(path string) Instance
- func New() Instance
- func (self Instance) AdjustBcs(brightness Float.X, contrast Float.X, saturation Float.X)
- func (self Instance) AsImage() Instance
- func (self Instance) AsObject() [1]gd.Object
- func (self Instance) AsRefCounted() [1]gd.RefCounted
- func (self Instance) AsResource() Resource.Instance
- func (self Instance) BlendRect(src Instance, src_rect Rect2i.PositionSize, dst Vector2i.XY)
- func (self Instance) BlendRectMask(src Instance, mask Instance, src_rect Rect2i.PositionSize, dst Vector2i.XY)
- func (self Instance) BlitRect(src Instance, src_rect Rect2i.PositionSize, dst Vector2i.XY)
- func (self Instance) BlitRectMask(src Instance, mask Instance, src_rect Rect2i.PositionSize, dst Vector2i.XY)
- func (self Instance) BumpMapToNormalMap()
- func (self Instance) ClearMipmaps()
- func (self Instance) Compress(mode CompressMode) error
- func (self Instance) CompressFromChannels(mode CompressMode, channels UsedChannels) error
- func (self Instance) ComputeImageMetrics(compared_image Instance, use_luma bool) Metrics
- func (self Instance) Convert(format Format)
- func (self Instance) CopyFrom(src Instance)
- func (self Instance) Crop(width int, height int)
- func (self Instance) Decompress() error
- func (self Instance) DetectAlpha() AlphaMode
- func (self Instance) DetectUsedChannels() UsedChannels
- func (self Instance) Fill(color Color.RGBA)
- func (self Instance) FillRect(rect Rect2i.PositionSize, color Color.RGBA)
- func (self Instance) FixAlphaEdges()
- func (self Instance) FlipX()
- func (self Instance) FlipY()
- func (self Instance) GenerateMipmaps() error
- func (self Instance) GetData() []byte
- func (self Instance) GetDataSize() int
- func (self Instance) GetFormat() Format
- func (self Instance) GetHeight() int
- func (self Instance) GetMipmapCount() int
- func (self Instance) GetMipmapOffset(mipmap int) int
- func (self Instance) GetPixel(x int, y int) Color.RGBA
- func (self Instance) GetPixelv(point Vector2i.XY) Color.RGBA
- func (self Instance) GetRegion(region Rect2i.PositionSize) Instance
- func (self Instance) GetSize() Vector2i.XY
- func (self Instance) GetUsedRect() Rect2i.PositionSize
- func (self Instance) GetWidth() int
- func (self Instance) HasMipmaps() bool
- func (self Instance) ID() ID
- func (self Instance) IsCompressed() bool
- func (self Instance) IsEmpty() bool
- func (self Instance) IsInvisible() bool
- func (self Instance) LinearToSrgb()
- func (self Instance) Load(path string) error
- func (self Instance) LoadBmpFromBuffer(buffer []byte) error
- func (self Instance) LoadJpgFromBuffer(buffer []byte) error
- func (self Instance) LoadKtxFromBuffer(buffer []byte) error
- func (self Instance) LoadPngFromBuffer(buffer []byte) error
- func (self Instance) LoadSvgFromBuffer(buffer []byte) error
- func (self Instance) LoadSvgFromString(svg_str string) error
- func (self Instance) LoadTgaFromBuffer(buffer []byte) error
- func (self Instance) LoadWebpFromBuffer(buffer []byte) error
- func (self Instance) NormalMapToXy()
- func (self Instance) PremultiplyAlpha()
- func (self Instance) Resize(width int, height int)
- func (self Instance) ResizeToPo2()
- func (self Instance) RgbeToSrgb() Instance
- func (self Instance) Rotate180()
- func (self Instance) Rotate90(direction Angle.Direction)
- func (self Instance) SaveExr(path string) error
- func (self Instance) SaveExrToBuffer() []byte
- func (self Instance) SaveJpg(path string) error
- func (self Instance) SaveJpgToBuffer() []byte
- func (self Instance) SavePng(path string) error
- func (self Instance) SavePngToBuffer() []byte
- func (self Instance) SaveWebp(path string) error
- func (self Instance) SaveWebpToBuffer() []byte
- func (self Instance) SetData(width int, height int, use_mipmaps bool, format Format, data []byte)
- func (self *Instance) SetObject(obj [1]gd.Object) bool
- func (self Instance) SetPixel(x int, y int, color Color.RGBA)
- func (self Instance) SetPixelv(point Vector2i.XY, color Color.RGBA)
- func (self Instance) ShrinkX2()
- func (self Instance) SrgbToLinear()
- func (self Instance) Virtual(name string) reflect.Value
- type Interpolation
- type Metrics
- type UsedChannels
Constants ¶
const MaxHeight = 1.6777216e+07 //gd:Image.MAX_HEIGHT
const MaxWidth = 1.6777216e+07 //gd:Image.MAX_WIDTH
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ASTCFormat ¶
type ASTCFormat int //gd:Image.ASTCFormat
const ( // Hint to indicate that the high quality 4×4 ASTC compression format should be used. AstcFormat4x4 ASTCFormat = 0 // Hint to indicate that the low quality 8×8 ASTC compression format should be used. AstcFormat8x8 ASTCFormat = 1 )
type Advanced ¶
type Advanced = class
Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.
type CompressMode ¶
type CompressMode int //gd:Image.CompressMode
const ( // Use S3TC compression. CompressS3tc CompressMode = 0 // Use ETC compression. CompressEtc CompressMode = 1 // Use ETC2 compression. CompressEtc2 CompressMode = 2 // Use BPTC compression. CompressBptc CompressMode = 3 // Use ASTC compression. CompressAstc CompressMode = 4 // Represents the size of the [CompressMode] enum. CompressMax CompressMode = 5 )
type CompressSource ¶
type CompressSource int //gd:Image.CompressSource
const ( // Source texture (before compression) is a regular texture. Default for all textures. CompressSourceGeneric CompressSource = 0 // Source texture (before compression) is in sRGB space. CompressSourceSrgb CompressSource = 1 // Source texture (before compression) is a normal texture (e.g. it can be compressed into two channels). CompressSourceNormal CompressSource = 2 )
type Expanded ¶
func (Expanded) BumpMapToNormalMap ¶
Converts a bump map to a normal map. A bump map provides a height offset per-pixel, while a normal map provides a normal direction per pixel.
func (Expanded) Compress ¶
func (self Expanded) Compress(mode CompressMode, source CompressSource, astc_format ASTCFormat) error
Compresses the image to use less memory. Can not directly access pixel data while the image is compressed. Returns error if the chosen compression mode is not available.
The 'source' parameter helps to pick the best compression method for DXT and ETC2 formats. It is ignored for ASTC compression.
For ASTC compression, the 'astc_format' parameter must be supplied.
func (Expanded) CompressFromChannels ¶
func (self Expanded) CompressFromChannels(mode CompressMode, channels UsedChannels, astc_format ASTCFormat) error
Compresses the image to use less memory. Can not directly access pixel data while the image is compressed. Returns error if the chosen compression mode is not available.
This is an alternative to Instance.Compress that lets the user supply the channels used in order for the compressor to pick the best DXT and ETC2 formats. For other formats (non DXT or ETC2), this argument is ignored.
For ASTC compression, the 'astc_format' parameter must be supplied.
func (Expanded) DetectUsedChannels ¶
func (self Expanded) DetectUsedChannels(source CompressSource) UsedChannels
Returns the color channels used by this image, as one of the UsedChannels constants. If the image is compressed, the original 'source' must be specified.
func (Expanded) GenerateMipmaps ¶
Generates mipmaps for the image. Mipmaps are precalculated lower-resolution copies of the image that are automatically used if the image needs to be scaled down when rendered. They help improve image quality and performance when rendering. This method returns an error if the image is compressed, in a custom format, or if the image's width/height is 0. Enabling 'renormalize' when generating mipmaps for normal map textures will make sure all resulting vector values are normalized.
It is possible to check if the image has mipmaps by calling Instance.HasMipmaps or Instance.GetMipmapCount. Calling Instance.GenerateMipmaps on an image that already has mipmaps will replace existing mipmaps in the image.
func (Expanded) LoadSvgFromBuffer ¶
Loads an image from the UTF-8 binary contents of an uncompressed SVG file (.svg).
Note: Beware when using compressed SVG files (like .svgz), they need to be decompressed before loading.
Note: This method is only available in engine builds with the SVG module enabled. By default, the SVG module is enabled, but it can be disabled at build-time using the module_svg_enabled=no SCons option.
func (Expanded) LoadSvgFromString ¶
Loads an image from the string contents of an SVG file (.svg).
Note: This method is only available in engine builds with the SVG module enabled. By default, the SVG module is enabled, but it can be disabled at build-time using the module_svg_enabled=no SCons option.
func (Expanded) Resize ¶
func (self Expanded) Resize(width int, height int, interpolation Interpolation)
Resizes the image to the given 'width' and 'height'. New pixels are calculated using the 'interpolation' mode defined via Interpolation constants.
func (Expanded) ResizeToPo2 ¶
func (self Expanded) ResizeToPo2(square bool, interpolation Interpolation)
Resizes the image to the nearest power of 2 for the width and height. If 'square' is true then set width and height to be the same. New pixels are calculated using the 'interpolation' mode defined via Interpolation constants.
func (Expanded) SaveExr ¶
Saves the image as an EXR file to 'path'. If 'grayscale' is true and the image has only one channel, it will be saved explicitly as monochrome rather than one red channel. This function will return [ErrUnavailable] if Godot was compiled without the TinyEXR module.
Note: The TinyEXR module is disabled in non-editor builds, which means Instance.SaveExr will return [ErrUnavailable] when it is called from an exported project.
func (Expanded) SaveExrToBuffer ¶
Saves the image as an EXR file to a byte array. If 'grayscale' is true and the image has only one channel, it will be saved explicitly as monochrome rather than one red channel. This function will return an empty byte array if Godot was compiled without the TinyEXR module.
Note: The TinyEXR module is disabled in non-editor builds, which means Instance.SaveExr will return an empty byte array when it is called from an exported project.
func (Expanded) SaveJpg ¶
Saves the image as a JPEG file to 'path' with the specified 'quality' between 0.01 and 1.0 (inclusive). Higher 'quality' values result in better-looking output at the cost of larger file sizes. Recommended 'quality' values are between 0.75 and 0.90. Even at quality 1.00, JPEG compression remains lossy.
Note: JPEG does not save an alpha channel. If the graphics.gd/classdb/Image contains an alpha channel, the image will still be saved, but the resulting JPEG file won't contain the alpha channel.
func (Expanded) SaveJpgToBuffer ¶
Saves the image as a JPEG file to a byte array with the specified 'quality' between 0.01 and 1.0 (inclusive). Higher 'quality' values result in better-looking output at the cost of larger byte array sizes (and therefore memory usage). Recommended 'quality' values are between 0.75 and 0.90. Even at quality 1.00, JPEG compression remains lossy.
Note: JPEG does not save an alpha channel. If the graphics.gd/classdb/Image contains an alpha channel, the image will still be saved, but the resulting byte array won't contain the alpha channel.
func (Expanded) SaveWebp ¶
Saves the image as a WebP (Web Picture) file to the file at 'path'. By default it will save lossless. If 'lossy' is true, the image will be saved lossy, using the 'quality' setting between 0.0 and 1.0 (inclusive). Lossless WebP offers more efficient compression than PNG.
Note: The WebP format is limited to a size of 16383×16383 pixels, while PNG can save larger images.
func (Expanded) SaveWebpToBuffer ¶
Saves the image as a WebP (Web Picture) file to a byte array. By default it will save lossless. If 'lossy' is true, the image will be saved lossy, using the 'quality' setting between 0.0 and 1.0 (inclusive). Lossless WebP offers more efficient compression than PNG.
Note: The WebP format is limited to a size of 16383×16383 pixels, while PNG can save larger images.
type Extension ¶
Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension
func (*Extension[T]) AsRefCounted ¶
func (self *Extension[T]) AsRefCounted() [1]gd.RefCounted
func (*Extension[T]) AsResource ¶
type Format ¶
type Format int //gd:Image.Format
const ( // Texture format with a single 8-bit depth representing luminance. FormatL8 Format = 0 // OpenGL texture format with two values, luminance and alpha each stored with 8 bits. FormatLa8 Format = 1 // OpenGL texture format RED with a single component and a bitdepth of 8. FormatR8 Format = 2 // OpenGL texture format RG with two components and a bitdepth of 8 for each. FormatRg8 Format = 3 // OpenGL texture format RGB with three components, each with a bitdepth of 8. // // Note: When creating an [graphics.gd/classdb/ImageTexture], an sRGB to linear color space conversion is performed. FormatRgb8 Format = 4 // OpenGL texture format RGBA with four components, each with a bitdepth of 8. // // Note: When creating an [graphics.gd/classdb/ImageTexture], an sRGB to linear color space conversion is performed. FormatRgba8 Format = 5 // OpenGL texture format RGBA with four components, each with a bitdepth of 4. FormatRgba4444 Format = 6 // OpenGL texture format RGB with three components. Red and blue have a bitdepth of 5, and green has a bitdepth of 6. FormatRgb565 Format = 7 // OpenGL texture format GL_R32F where there's one component, a 32-bit floating-point value. FormatRf Format = 8 // OpenGL texture format GL_RG32F where there are two components, each a 32-bit floating-point values. FormatRgf Format = 9 // OpenGL texture format GL_RGB32F where there are three components, each a 32-bit floating-point values. FormatRgbf Format = 10 // OpenGL texture format GL_RGBA32F where there are four components, each a 32-bit floating-point values. FormatRgbaf Format = 11 // OpenGL texture format GL_R16F where there's one component, a 16-bit "half-precision" floating-point value. FormatRh Format = 12 // OpenGL texture format GL_RG16F where there are two components, each a 16-bit "half-precision" floating-point value. FormatRgh Format = 13 // OpenGL texture format GL_RGB16F where there are three components, each a 16-bit "half-precision" floating-point value. FormatRgbh Format = 14 // OpenGL texture format GL_RGBA16F where there are four components, each a 16-bit "half-precision" floating-point value. FormatRgbah Format = 15 // A special OpenGL texture format where the three color components have 9 bits of precision and all three share a single 5-bit exponent. FormatRgbe9995 Format = 16 // The [S3TC] texture format that uses Block Compression 1, and is the smallest variation of S3TC, only providing 1 bit of alpha and color data being premultiplied with alpha. // // Note: When creating an [graphics.gd/classdb/ImageTexture], an sRGB to linear color space conversion is performed. // // [S3TC]: https://en.wikipedia.org/wiki/S3_Texture_Compression FormatDxt1 Format = 17 // The [S3TC] texture format that uses Block Compression 2, and color data is interpreted as not having been premultiplied by alpha. Well suited for images with sharp alpha transitions between translucent and opaque areas. // // Note: When creating an [graphics.gd/classdb/ImageTexture], an sRGB to linear color space conversion is performed. // // [S3TC]: https://en.wikipedia.org/wiki/S3_Texture_Compression FormatDxt3 Format = 18 // The [S3TC] texture format also known as Block Compression 3 or BC3 that contains 64 bits of alpha channel data followed by 64 bits of DXT1-encoded color data. Color data is not premultiplied by alpha, same as DXT3. DXT5 generally produces superior results for transparent gradients compared to DXT3. // // Note: When creating an [graphics.gd/classdb/ImageTexture], an sRGB to linear color space conversion is performed. // // [S3TC]: https://en.wikipedia.org/wiki/S3_Texture_Compression FormatDxt5 Format = 19 // Texture format that uses [Red Green Texture Compression], normalizing the red channel data using the same compression algorithm that DXT5 uses for the alpha channel. // // [Red Green Texture Compression]: https://www.khronos.org/opengl/wiki/Red_Green_Texture_Compression FormatRgtcR Format = 20 // Texture format that uses [Red Green Texture Compression], normalizing the red and green channel data using the same compression algorithm that DXT5 uses for the alpha channel. // // [Red Green Texture Compression]: https://www.khronos.org/opengl/wiki/Red_Green_Texture_Compression FormatRgtcRg Format = 21 // Texture format that uses [BPTC] compression with unsigned normalized RGBA components. // // Note: When creating an [graphics.gd/classdb/ImageTexture], an sRGB to linear color space conversion is performed. // // [BPTC]: https://www.khronos.org/opengl/wiki/BPTC_Texture_Compression FormatBptcRgba Format = 22 // Texture format that uses [BPTC] compression with signed floating-point RGB components. // // [BPTC]: https://www.khronos.org/opengl/wiki/BPTC_Texture_Compression FormatBptcRgbf Format = 23 // Texture format that uses [BPTC] compression with unsigned floating-point RGB components. // // [BPTC]: https://www.khronos.org/opengl/wiki/BPTC_Texture_Compression FormatBptcRgbfu Format = 24 // [Ericsson Texture Compression format 1], also referred to as "ETC1", and is part of the OpenGL ES graphics standard. This format cannot store an alpha channel. // // [Ericsson Texture Compression format 1]: https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC1 FormatEtc Format = 25 // [Ericsson Texture Compression format 2] (R11_EAC variant), which provides one channel of unsigned data. // // [Ericsson Texture Compression format 2]: https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC FormatEtc2R11 Format = 26 // [Ericsson Texture Compression format 2] (SIGNED_R11_EAC variant), which provides one channel of signed data. // // [Ericsson Texture Compression format 2]: https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC FormatEtc2R11s Format = 27 // [Ericsson Texture Compression format 2] (RG11_EAC variant), which provides two channels of unsigned data. // // [Ericsson Texture Compression format 2]: https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC FormatEtc2Rg11 Format = 28 // [Ericsson Texture Compression format 2] (SIGNED_RG11_EAC variant), which provides two channels of signed data. // // [Ericsson Texture Compression format 2]: https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC FormatEtc2Rg11s Format = 29 // [Ericsson Texture Compression format 2] (RGB8 variant), which is a follow-up of ETC1 and compresses RGB888 data. // // Note: When creating an [graphics.gd/classdb/ImageTexture], an sRGB to linear color space conversion is performed. // // [Ericsson Texture Compression format 2]: https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC FormatEtc2Rgb8 Format = 30 // [Ericsson Texture Compression format 2] (RGBA8variant), which compresses RGBA8888 data with full alpha support. // // Note: When creating an [graphics.gd/classdb/ImageTexture], an sRGB to linear color space conversion is performed. // // [Ericsson Texture Compression format 2]: https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC FormatEtc2Rgba8 Format = 31 // [Ericsson Texture Compression format 2] (RGB8_PUNCHTHROUGH_ALPHA1 variant), which compresses RGBA data to make alpha either fully transparent or fully opaque. // // Note: When creating an [graphics.gd/classdb/ImageTexture], an sRGB to linear color space conversion is performed. // // [Ericsson Texture Compression format 2]: https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC FormatEtc2Rgb8a1 Format = 32 // [Ericsson Texture Compression format 2] (RGBA8 variant), which compresses RA data and interprets it as two channels (red and green). See also [FormatEtc2Rgba8]. // // [Ericsson Texture Compression format 2]: https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC FormatEtc2RaAsRg Format = 33 // The [S3TC] texture format also known as Block Compression 3 or BC3, which compresses RA data and interprets it as two channels (red and green). See also [FormatDxt5]. // // [S3TC]: https://en.wikipedia.org/wiki/S3_Texture_Compression FormatDxt5RaAsRg Format = 34 // [Adaptive Scalable Texture Compression]. This implements the 4×4 (high quality) mode. // // [Adaptive Scalable Texture Compression]: https://en.wikipedia.org/wiki/Adaptive_scalable_texture_compression FormatAstc4x4 Format = 35 // Same format as [FormatAstc4x4], but with the hint to let the GPU know it is used for HDR. FormatAstc4x4Hdr Format = 36 // [Adaptive Scalable Texture Compression]. This implements the 8×8 (low quality) mode. // // [Adaptive Scalable Texture Compression]: https://en.wikipedia.org/wiki/Adaptive_scalable_texture_compression FormatAstc8x8 Format = 37 // Same format as [FormatAstc8x8], but with the hint to let the GPU know it is used for HDR. FormatAstc8x8Hdr Format = 38 // Represents the size of the [Format] enum. FormatMax Format = 39 )
type ID ¶
ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.
type Instance ¶
Instance of the class with convieniently typed arguments and results.
var Nil Instance
Nil is a nil/null instance of the class. Equivalent to the zero value.
func Create ¶
Creates an empty image of given size and format. See Format constants. If 'use_mipmaps' is true, then generate mipmaps for this image. See the Instance.GenerateMipmaps.
func CreateEmpty ¶
Creates an empty image of given size and format. See Format constants. If 'use_mipmaps' is true, then generate mipmaps for this image. See the Instance.GenerateMipmaps.
func CreateFromData ¶
Creates a new image of given size and format. See Format constants. Fills the image with the given raw data. If 'use_mipmaps' is true then loads mipmaps for this image from 'data'. See Instance.GenerateMipmaps.
func LoadFromFile ¶
Creates a new graphics.gd/classdb/Image and loads data from the specified file.
func (Instance) AdjustBcs ¶
Adjusts this image's 'brightness', 'contrast', and 'saturation' by the given values. Does not work if the image is compressed (see Instance.IsCompressed).
func (Instance) AsRefCounted ¶
func (self Instance) AsRefCounted() [1]gd.RefCounted
func (Instance) AsResource ¶
func (Instance) BlendRect ¶
Alpha-blends 'src_rect' from 'src' image to this image at coordinates 'dst', clipped accordingly to both image bounds. This image and 'src' image must have the same format. 'src_rect' with non-positive size is treated as empty.
func (Instance) BlendRectMask ¶
func (self Instance) BlendRectMask(src Instance, mask Instance, src_rect Rect2i.PositionSize, dst Vector2i.XY)
Alpha-blends 'src_rect' from 'src' image to this image using 'mask' image at coordinates 'dst', clipped accordingly to both image bounds. Alpha channels are required for both 'src' and 'mask'. 'dst' pixels and 'src' pixels will blend if the corresponding mask pixel's alpha value is not 0. This image and 'src' image must have the same format. 'src' image and 'mask' image must have the same size (width and height) but they can have different formats. 'src_rect' with non-positive size is treated as empty.
func (Instance) BlitRect ¶
Copies 'src_rect' from 'src' image to this image at coordinates 'dst', clipped accordingly to both image bounds. This image and 'src' image must have the same format. 'src_rect' with non-positive size is treated as empty.
Note: The alpha channel data in 'src' will overwrite the corresponding data in this image at the target position. To blend alpha channels, use Instance.BlendRect instead.
func (Instance) BlitRectMask ¶
func (self Instance) BlitRectMask(src Instance, mask Instance, src_rect Rect2i.PositionSize, dst Vector2i.XY)
Blits 'src_rect' area from 'src' image to this image at the coordinates given by 'dst', clipped accordingly to both image bounds. 'src' pixel is copied onto 'dst' if the corresponding 'mask' pixel's alpha value is not 0. This image and 'src' image must have the same format. 'src' image and 'mask' image must have the same size (width and height) but they can have different formats. 'src_rect' with non-positive size is treated as empty.
func (Instance) BumpMapToNormalMap ¶
func (self Instance) BumpMapToNormalMap()
Converts a bump map to a normal map. A bump map provides a height offset per-pixel, while a normal map provides a normal direction per pixel.
func (Instance) Compress ¶
func (self Instance) Compress(mode CompressMode) error
Compresses the image to use less memory. Can not directly access pixel data while the image is compressed. Returns error if the chosen compression mode is not available.
The 'source' parameter helps to pick the best compression method for DXT and ETC2 formats. It is ignored for ASTC compression.
For ASTC compression, the 'astc_format' parameter must be supplied.
func (Instance) CompressFromChannels ¶
func (self Instance) CompressFromChannels(mode CompressMode, channels UsedChannels) error
Compresses the image to use less memory. Can not directly access pixel data while the image is compressed. Returns error if the chosen compression mode is not available.
This is an alternative to Instance.Compress that lets the user supply the channels used in order for the compressor to pick the best DXT and ETC2 formats. For other formats (non DXT or ETC2), this argument is ignored.
For ASTC compression, the 'astc_format' parameter must be supplied.
func (Instance) ComputeImageMetrics ¶
Compute image metrics on the current image and the compared image.
The dictionary contains max, mean, mean_squared, root_mean_squared and peak_snr.
func (Instance) Crop ¶
Crops the image to the given 'width' and 'height'. If the specified size is larger than the current size, the extra area is filled with black pixels.
func (Instance) Decompress ¶
Decompresses the image if it is VRAM compressed in a supported format. Returns [Ok] if the format is supported, otherwise [ErrUnavailable].
Note: The following formats can be decompressed: DXT, RGTC, BPTC. The formats ETC1 and ETC2 are not supported.
func (Instance) DetectAlpha ¶
Returns AlphaBlend if the image has data for alpha values. Returns AlphaBit if all the alpha values are stored in a single bit. Returns AlphaNone if no data for alpha values is found.
func (Instance) DetectUsedChannels ¶
func (self Instance) DetectUsedChannels() UsedChannels
Returns the color channels used by this image, as one of the UsedChannels constants. If the image is compressed, the original 'source' must be specified.
func (Instance) FillRect ¶
func (self Instance) FillRect(rect Rect2i.PositionSize, color Color.RGBA)
Fills 'rect' with 'color'.
func (Instance) FixAlphaEdges ¶
func (self Instance) FixAlphaEdges()
Blends low-alpha pixels with nearby pixels.
func (Instance) GenerateMipmaps ¶
Generates mipmaps for the image. Mipmaps are precalculated lower-resolution copies of the image that are automatically used if the image needs to be scaled down when rendered. They help improve image quality and performance when rendering. This method returns an error if the image is compressed, in a custom format, or if the image's width/height is 0. Enabling 'renormalize' when generating mipmaps for normal map textures will make sure all resulting vector values are normalized.
It is possible to check if the image has mipmaps by calling Instance.HasMipmaps or Instance.GetMipmapCount. Calling Instance.GenerateMipmaps on an image that already has mipmaps will replace existing mipmaps in the image.
func (Instance) GetDataSize ¶
Returns size (in bytes) of the image's raw data.
func (Instance) GetMipmapCount ¶
Returns the number of mipmap levels or 0 if the image has no mipmaps. The largest main level image is not counted as a mipmap level by this method, so if you want to include it you can add 1 to this count.
func (Instance) GetMipmapOffset ¶
Returns the offset where the image's mipmap with index 'mipmap' is stored in the [Instance.Data] dictionary.
func (Instance) GetPixel ¶
Returns the color of the pixel at (x, y).
This is the same as Instance.GetPixelv, but with two integer arguments instead of a [Vector2i.XY] argument.
func (Instance) GetPixelv ¶
Returns the color of the pixel at 'point'.
This is the same as Instance.GetPixel, but with a [Vector2i.XY] argument instead of two integer arguments.
func (Instance) GetRegion ¶
func (self Instance) GetRegion(region Rect2i.PositionSize) Instance
Returns a new graphics.gd/classdb/Image that is a copy of this graphics.gd/classdb/Image's area specified with 'region'.
func (Instance) GetUsedRect ¶
func (self Instance) GetUsedRect() Rect2i.PositionSize
Returns a [Rect2i.PositionSize] enclosing the visible portion of the image, considering each pixel with a non-zero alpha channel as visible.
func (Instance) HasMipmaps ¶
Returns true if the image has generated mipmaps.
func (Instance) IsCompressed ¶
Returns true if the image is compressed.
func (Instance) IsInvisible ¶
Returns true if all the image's pixels have an alpha value of 0. Returns false if any pixel has an alpha value higher than 0.
func (Instance) LinearToSrgb ¶
func (self Instance) LinearToSrgb()
Converts the entire image from the linear colorspace to the sRGB colorspace. Only works on images with FormatRgb8 or FormatRgba8 formats.
func (Instance) Load ¶
Loads an image from file 'path'. See Supported image formats for a list of supported image formats and limitations.
Warning: This method should only be used in the editor or in cases when you need to load external images at run-time, such as images located at the user:// directory, and may not work in exported projects.
See also graphics.gd/classdb/ImageTexture description for usage examples.
func (Instance) LoadBmpFromBuffer ¶
Loads an image from the binary contents of a BMP file.
Note: Godot's BMP module doesn't support 16-bit per pixel images. Only 1-bit, 4-bit, 8-bit, 24-bit, and 32-bit per pixel images are supported.
Note: This method is only available in engine builds with the BMP module enabled. By default, the BMP module is enabled, but it can be disabled at build-time using the module_bmp_enabled=no SCons option.
func (Instance) LoadJpgFromBuffer ¶
Loads an image from the binary contents of a JPEG file.
func (Instance) LoadKtxFromBuffer ¶
Loads an image from the binary contents of a KTX file. Unlike most image formats, KTX can store VRAM-compressed data and embed mipmaps.
Note: Godot's libktx implementation only supports 2D images. Cubemaps, texture arrays, and de-padding are not supported.
Note: This method is only available in engine builds with the KTX module enabled. By default, the KTX module is enabled, but it can be disabled at build-time using the module_ktx_enabled=no SCons option.
func (Instance) LoadPngFromBuffer ¶
Loads an image from the binary contents of a PNG file.
func (Instance) LoadSvgFromBuffer ¶
Loads an image from the UTF-8 binary contents of an uncompressed SVG file (.svg).
Note: Beware when using compressed SVG files (like .svgz), they need to be decompressed before loading.
Note: This method is only available in engine builds with the SVG module enabled. By default, the SVG module is enabled, but it can be disabled at build-time using the module_svg_enabled=no SCons option.
func (Instance) LoadSvgFromString ¶
Loads an image from the string contents of an SVG file (.svg).
Note: This method is only available in engine builds with the SVG module enabled. By default, the SVG module is enabled, but it can be disabled at build-time using the module_svg_enabled=no SCons option.
func (Instance) LoadTgaFromBuffer ¶
Loads an image from the binary contents of a TGA file.
Note: This method is only available in engine builds with the TGA module enabled. By default, the TGA module is enabled, but it can be disabled at build-time using the module_tga_enabled=no SCons option.
func (Instance) LoadWebpFromBuffer ¶
Loads an image from the binary contents of a WebP file.
func (Instance) NormalMapToXy ¶
func (self Instance) NormalMapToXy()
Converts the image's data to represent coordinates on a 3D plane. This is used when the image represents a normal map. A normal map can add lots of detail to a 3D surface without increasing the polygon count.
func (Instance) PremultiplyAlpha ¶
func (self Instance) PremultiplyAlpha()
Multiplies color values with alpha values. Resulting color values for a pixel are (color * alpha)/256. See also graphics.gd/classdb/CanvasItemMaterial.Instance.BlendMode.
func (Instance) Resize ¶
Resizes the image to the given 'width' and 'height'. New pixels are calculated using the 'interpolation' mode defined via Interpolation constants.
func (Instance) ResizeToPo2 ¶
func (self Instance) ResizeToPo2()
Resizes the image to the nearest power of 2 for the width and height. If 'square' is true then set width and height to be the same. New pixels are calculated using the 'interpolation' mode defined via Interpolation constants.
func (Instance) RgbeToSrgb ¶
Converts a standard RGBE (Red Green Blue Exponent) image to an sRGB image.
func (Instance) Rotate180 ¶
func (self Instance) Rotate180()
Rotates the image by 180 degrees. The width and height of the image must be greater than 1.
func (Instance) Rotate90 ¶
Rotates the image in the specified 'direction' by 90 degrees. The width and height of the image must be greater than 1. If the width and height are not equal, the image will be resized.
func (Instance) SaveExr ¶
Saves the image as an EXR file to 'path'. If 'grayscale' is true and the image has only one channel, it will be saved explicitly as monochrome rather than one red channel. This function will return [ErrUnavailable] if Godot was compiled without the TinyEXR module.
Note: The TinyEXR module is disabled in non-editor builds, which means Instance.SaveExr will return [ErrUnavailable] when it is called from an exported project.
func (Instance) SaveExrToBuffer ¶
Saves the image as an EXR file to a byte array. If 'grayscale' is true and the image has only one channel, it will be saved explicitly as monochrome rather than one red channel. This function will return an empty byte array if Godot was compiled without the TinyEXR module.
Note: The TinyEXR module is disabled in non-editor builds, which means Instance.SaveExr will return an empty byte array when it is called from an exported project.
func (Instance) SaveJpg ¶
Saves the image as a JPEG file to 'path' with the specified 'quality' between 0.01 and 1.0 (inclusive). Higher 'quality' values result in better-looking output at the cost of larger file sizes. Recommended 'quality' values are between 0.75 and 0.90. Even at quality 1.00, JPEG compression remains lossy.
Note: JPEG does not save an alpha channel. If the graphics.gd/classdb/Image contains an alpha channel, the image will still be saved, but the resulting JPEG file won't contain the alpha channel.
func (Instance) SaveJpgToBuffer ¶
Saves the image as a JPEG file to a byte array with the specified 'quality' between 0.01 and 1.0 (inclusive). Higher 'quality' values result in better-looking output at the cost of larger byte array sizes (and therefore memory usage). Recommended 'quality' values are between 0.75 and 0.90. Even at quality 1.00, JPEG compression remains lossy.
Note: JPEG does not save an alpha channel. If the graphics.gd/classdb/Image contains an alpha channel, the image will still be saved, but the resulting byte array won't contain the alpha channel.
func (Instance) SavePngToBuffer ¶
Saves the image as a PNG file to a byte array.
func (Instance) SaveWebp ¶
Saves the image as a WebP (Web Picture) file to the file at 'path'. By default it will save lossless. If 'lossy' is true, the image will be saved lossy, using the 'quality' setting between 0.0 and 1.0 (inclusive). Lossless WebP offers more efficient compression than PNG.
Note: The WebP format is limited to a size of 16383×16383 pixels, while PNG can save larger images.
func (Instance) SaveWebpToBuffer ¶
Saves the image as a WebP (Web Picture) file to a byte array. By default it will save lossless. If 'lossy' is true, the image will be saved lossy, using the 'quality' setting between 0.0 and 1.0 (inclusive). Lossless WebP offers more efficient compression than PNG.
Note: The WebP format is limited to a size of 16383×16383 pixels, while PNG can save larger images.
func (Instance) SetData ¶
Overwrites data of an existing graphics.gd/classdb/Image. Non-static equivalent of CreateFromData.
func (Instance) SetPixel ¶
Sets the [Color.RGBA] of the pixel at (x, y) to 'color'.
This is the same as Instance.SetPixelv, but with a two integer arguments instead of a [Vector2i.XY] argument.
func (Instance) SetPixelv ¶
Sets the [Color.RGBA] of the pixel at 'point' to 'color'.
This is the same as Instance.SetPixel, but with a [Vector2i.XY] argument instead of two integer arguments.
func (Instance) ShrinkX2 ¶
func (self Instance) ShrinkX2()
Shrinks the image by a factor of 2 on each axis (this divides the pixel count by 4).
func (Instance) SrgbToLinear ¶
func (self Instance) SrgbToLinear()
Converts the raw data from the sRGB colorspace to a linear scale. Only works on images with FormatRgb8 or FormatRgba8 formats.
type Interpolation ¶
type Interpolation int //gd:Image.Interpolation
const ( // Performs nearest-neighbor interpolation. If the image is resized, it will be pixelated. InterpolateNearest Interpolation = 0 // Performs bilinear interpolation. If the image is resized, it will be blurry. This mode is faster than [InterpolateCubic], but it results in lower quality. InterpolateBilinear Interpolation = 1 // Performs cubic interpolation. If the image is resized, it will be blurry. This mode often gives better results compared to [InterpolateBilinear], at the cost of being slower. InterpolateCubic Interpolation = 2 // Performs bilinear separately on the two most-suited mipmap levels, then linearly interpolates between them. // // It's slower than [InterpolateBilinear], but produces higher-quality results with far fewer aliasing artifacts. // // If the image does not have mipmaps, they will be generated and used internally, but no mipmaps will be generated on the resulting image. // // Note: If you intend to scale multiple copies of the original image, it's better to call [Instance.GenerateMipmaps]] on it in advance, to avoid wasting processing power in generating them again and again. // // On the other hand, if the image already has mipmaps, they will be used, and a new set will be generated for the resulting image. InterpolateTrilinear Interpolation = 3 // Performs Lanczos interpolation. This is the slowest image resizing mode, but it typically gives the best results, especially when downscaling images. InterpolateLanczos Interpolation = 4 )
type UsedChannels ¶
type UsedChannels int //gd:Image.UsedChannels
const ( // The image only uses one channel for luminance (grayscale). UsedChannelsL UsedChannels = 0 // The image uses two channels for luminance and alpha, respectively. UsedChannelsLa UsedChannels = 1 // The image only uses the red channel. UsedChannelsR UsedChannels = 2 // The image uses two channels for red and green. UsedChannelsRg UsedChannels = 3 // The image uses three channels for red, green, and blue. UsedChannelsRgb UsedChannels = 4 // The image uses four channels for red, green, blue, and alpha. UsedChannelsRgba UsedChannels = 5 )