Image

package
v0.0.0-...-80877a9 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2025 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package Image provides methods for working with Image object instances.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

func Create(width int, height int, use_mipmaps bool, format gdclass.ImageFormat) [1]gdclass.Image

Creates an empty image of given size and format. See [enum Format] constants. If [param use_mipmaps] is [code]true[/code], then generate mipmaps for this image. See the [method generate_mipmaps].

func CreateEmpty

func CreateEmpty(width int, height int, use_mipmaps bool, format gdclass.ImageFormat) [1]gdclass.Image

Creates an empty image of given size and format. See [enum Format] constants. If [param use_mipmaps] is [code]true[/code], then generate mipmaps for this image. See the [method generate_mipmaps].

func CreateFromData

func CreateFromData(width int, height int, use_mipmaps bool, format gdclass.ImageFormat, data []byte) [1]gdclass.Image

Creates a new image of given size and format. See [enum Format] constants. Fills the image with the given raw data. If [param use_mipmaps] is [code]true[/code] then loads mipmaps for this image from [param data]. See [method generate_mipmaps].

func LoadFromFile

func LoadFromFile(path string) [1]gdclass.Image

Creates a new [Image] and loads data from the specified file.

Types

type ASTCFormat

type ASTCFormat = gdclass.ImageASTCFormat //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 AlphaMode

type AlphaMode = gdclass.ImageAlphaMode //gd:Image.AlphaMode
const (
	/*Image does not have alpha.*/
	AlphaNone AlphaMode = 0
	/*Image stores alpha in a single bit.*/
	AlphaBit AlphaMode = 1
	/*Image uses alpha.*/
	AlphaBlend AlphaMode = 2
)

type Any

type Any interface {
	gd.IsClass
	AsImage() Instance
}

type ClockDirection

type ClockDirection int
const (
	/*Clockwise rotation. Used by some methods (e.g. [method Image.rotate_90]).*/
	Clockwise ClockDirection = 0
	/*Counter-clockwise rotation. Used by some methods (e.g. [method Image.rotate_90]).*/
	Counterclockwise ClockDirection = 1
)

type CompressMode

type CompressMode = gdclass.ImageCompressMode //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 [enum CompressMode] enum.*/
	CompressMax CompressMode = 5
)

type CompressSource

type CompressSource = gdclass.ImageCompressSource //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 Format

type Format = gdclass.ImageFormat //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 [code]RED[/code] with a single component and a bitdepth of 8.*/
	FormatR8 Format = 2
	/*OpenGL texture format [code]RG[/code] with two components and a bitdepth of 8 for each.*/
	FormatRg8 Format = 3
	/*OpenGL texture format [code]RGB[/code] with three components, each with a bitdepth of 8.
	  [b]Note:[/b] When creating an [ImageTexture], an sRGB to linear color space conversion is performed.*/
	FormatRgb8 Format = 4
	/*OpenGL texture format [code]RGBA[/code] with four components, each with a bitdepth of 8.
	  [b]Note:[/b] When creating an [ImageTexture], an sRGB to linear color space conversion is performed.*/
	FormatRgba8 Format = 5
	/*OpenGL texture format [code]RGBA[/code] with four components, each with a bitdepth of 4.*/
	FormatRgba4444 Format = 6
	/*OpenGL texture format [code]RGB[/code] with three components. Red and blue have a bitdepth of 5, and green has a bitdepth of 6.*/
	FormatRgb565 Format = 7
	/*OpenGL texture format [code]GL_R32F[/code] where there's one component, a 32-bit floating-point value.*/
	FormatRf Format = 8
	/*OpenGL texture format [code]GL_RG32F[/code] where there are two components, each a 32-bit floating-point values.*/
	FormatRgf Format = 9
	/*OpenGL texture format [code]GL_RGB32F[/code] where there are three components, each a 32-bit floating-point values.*/
	FormatRgbf Format = 10
	/*OpenGL texture format [code]GL_RGBA32F[/code] where there are four components, each a 32-bit floating-point values.*/
	FormatRgbaf Format = 11
	/*OpenGL texture format [code]GL_R16F[/code] where there's one component, a 16-bit "half-precision" floating-point value.*/
	FormatRh Format = 12
	/*OpenGL texture format [code]GL_RG16F[/code] where there are two components, each a 16-bit "half-precision" floating-point value.*/
	FormatRgh Format = 13
	/*OpenGL texture format [code]GL_RGB16F[/code] where there are three components, each a 16-bit "half-precision" floating-point value.*/
	FormatRgbh Format = 14
	/*OpenGL texture format [code]GL_RGBA16F[/code] 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 [url=https://en.wikipedia.org/wiki/S3_Texture_Compression]S3TC[/url] 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.
	  [b]Note:[/b] When creating an [ImageTexture], an sRGB to linear color space conversion is performed.*/
	FormatDxt1 Format = 17
	/*The [url=https://en.wikipedia.org/wiki/S3_Texture_Compression]S3TC[/url] 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.
	  [b]Note:[/b] When creating an [ImageTexture], an sRGB to linear color space conversion is performed.*/
	FormatDxt3 Format = 18
	/*The [url=https://en.wikipedia.org/wiki/S3_Texture_Compression]S3TC[/url] 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.
	  [b]Note:[/b] When creating an [ImageTexture], an sRGB to linear color space conversion is performed.*/
	FormatDxt5 Format = 19
	/*Texture format that uses [url=https://www.khronos.org/opengl/wiki/Red_Green_Texture_Compression]Red Green Texture Compression[/url], normalizing the red channel data using the same compression algorithm that DXT5 uses for the alpha channel.*/
	FormatRgtcR Format = 20
	/*Texture format that uses [url=https://www.khronos.org/opengl/wiki/Red_Green_Texture_Compression]Red Green Texture Compression[/url], normalizing the red and green channel data using the same compression algorithm that DXT5 uses for the alpha channel.*/
	FormatRgtcRg Format = 21
	/*Texture format that uses [url=https://www.khronos.org/opengl/wiki/BPTC_Texture_Compression]BPTC[/url] compression with unsigned normalized RGBA components.
	  [b]Note:[/b] When creating an [ImageTexture], an sRGB to linear color space conversion is performed.*/
	FormatBptcRgba Format = 22
	/*Texture format that uses [url=https://www.khronos.org/opengl/wiki/BPTC_Texture_Compression]BPTC[/url] compression with signed floating-point RGB components.*/
	FormatBptcRgbf Format = 23
	/*Texture format that uses [url=https://www.khronos.org/opengl/wiki/BPTC_Texture_Compression]BPTC[/url] compression with unsigned floating-point RGB components.*/
	FormatBptcRgbfu Format = 24
	/*[url=https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC1]Ericsson Texture Compression format 1[/url], also referred to as "ETC1", and is part of the OpenGL ES graphics standard. This format cannot store an alpha channel.*/
	FormatEtc Format = 25
	/*[url=https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC]Ericsson Texture Compression format 2[/url] ([code]R11_EAC[/code] variant), which provides one channel of unsigned data.*/
	FormatEtc2R11 Format = 26
	/*[url=https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC]Ericsson Texture Compression format 2[/url] ([code]SIGNED_R11_EAC[/code] variant), which provides one channel of signed data.*/
	FormatEtc2R11s Format = 27
	/*[url=https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC]Ericsson Texture Compression format 2[/url] ([code]RG11_EAC[/code] variant), which provides two channels of unsigned data.*/
	FormatEtc2Rg11 Format = 28
	/*[url=https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC]Ericsson Texture Compression format 2[/url] ([code]SIGNED_RG11_EAC[/code] variant), which provides two channels of signed data.*/
	FormatEtc2Rg11s Format = 29
	/*[url=https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC]Ericsson Texture Compression format 2[/url] ([code]RGB8[/code] variant), which is a follow-up of ETC1 and compresses RGB888 data.
	  [b]Note:[/b] When creating an [ImageTexture], an sRGB to linear color space conversion is performed.*/
	FormatEtc2Rgb8 Format = 30
	/*[url=https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC]Ericsson Texture Compression format 2[/url] ([code]RGBA8[/code]variant), which compresses RGBA8888 data with full alpha support.
	  [b]Note:[/b] When creating an [ImageTexture], an sRGB to linear color space conversion is performed.*/
	FormatEtc2Rgba8 Format = 31
	/*[url=https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC]Ericsson Texture Compression format 2[/url] ([code]RGB8_PUNCHTHROUGH_ALPHA1[/code] variant), which compresses RGBA data to make alpha either fully transparent or fully opaque.
	  [b]Note:[/b] When creating an [ImageTexture], an sRGB to linear color space conversion is performed.*/
	FormatEtc2Rgb8a1 Format = 32
	/*[url=https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC]Ericsson Texture Compression format 2[/url] ([code]RGBA8[/code] variant), which compresses RA data and interprets it as two channels (red and green). See also [constant FORMAT_ETC2_RGBA8].*/
	FormatEtc2RaAsRg Format = 33
	/*The [url=https://en.wikipedia.org/wiki/S3_Texture_Compression]S3TC[/url] 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 [constant FORMAT_DXT5].*/
	FormatDxt5RaAsRg Format = 34
	/*[url=https://en.wikipedia.org/wiki/Adaptive_scalable_texture_compression]Adaptive Scalable Texture Compression[/url]. This implements the 4×4 (high quality) mode.*/
	FormatAstc4x4 Format = 35
	/*Same format as [constant FORMAT_ASTC_4x4], but with the hint to let the GPU know it is used for HDR.*/
	FormatAstc4x4Hdr Format = 36
	/*[url=https://en.wikipedia.org/wiki/Adaptive_scalable_texture_compression]Adaptive Scalable Texture Compression[/url]. This implements the 8×8 (low quality) mode.*/
	FormatAstc8x8 Format = 37
	/*Same format as [constant FORMAT_ASTC_8x8], but with the hint to let the GPU know it is used for HDR.*/
	FormatAstc8x8Hdr Format = 38
	/*Represents the size of the [enum Format] enum.*/
	FormatMax Format = 39
)

type Instance

type Instance [1]gdclass.Image

Native image datatype. Contains image data which can be converted to an [ImageTexture] and provides commonly used [i]image processing[/i] methods. The maximum width and height for an [Image] are [constant MAX_WIDTH] and [constant MAX_HEIGHT]. An [Image] cannot be assigned to a texture property of an object directly (such as [member Sprite2D.texture]), and has to be converted manually to an [ImageTexture] first. [b]Note:[/b] The maximum image size is 16384×16384 pixels due to graphics hardware limitations. Larger images may fail to import.

var Nil Instance

Nil is a nil/null instance of the class. Equivalent to the zero value.

func New

func New() Instance

func (Instance) AdjustBcs

func (self Instance) AdjustBcs(brightness Float.X, contrast Float.X, saturation Float.X)

Adjusts this image's [param brightness], [param contrast], and [param saturation] by the given values. Does not work if the image is compressed (see [method is_compressed]).

func (Instance) AsImage

func (self Instance) AsImage() Instance

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) AsRefCounted

func (self Instance) AsRefCounted() [1]gd.RefCounted

func (Instance) AsResource

func (self Instance) AsResource() Resource.Instance

func (Instance) BlendRect

func (self Instance) BlendRect(src [1]gdclass.Image, src_rect Rect2i.PositionSize, dst Vector2i.XY)

Alpha-blends [param src_rect] from [param src] image to this image at coordinates [param dst], clipped accordingly to both image bounds. This image and [param src] image [b]must[/b] have the same format. [param src_rect] with non-positive size is treated as empty.

func (Instance) BlendRectMask

func (self Instance) BlendRectMask(src [1]gdclass.Image, mask [1]gdclass.Image, src_rect Rect2i.PositionSize, dst Vector2i.XY)

Alpha-blends [param src_rect] from [param src] image to this image using [param mask] image at coordinates [param dst], clipped accordingly to both image bounds. Alpha channels are required for both [param src] and [param mask]. [param dst] pixels and [param src] pixels will blend if the corresponding mask pixel's alpha value is not 0. This image and [param src] image [b]must[/b] have the same format. [param src] image and [param mask] image [b]must[/b] have the same size (width and height) but they can have different formats. [param src_rect] with non-positive size is treated as empty.

func (Instance) BlitRect

func (self Instance) BlitRect(src [1]gdclass.Image, src_rect Rect2i.PositionSize, dst Vector2i.XY)

Copies [param src_rect] from [param src] image to this image at coordinates [param dst], clipped accordingly to both image bounds. This image and [param src] image [b]must[/b] have the same format. [param src_rect] with non-positive size is treated as empty.

func (Instance) BlitRectMask

func (self Instance) BlitRectMask(src [1]gdclass.Image, mask [1]gdclass.Image, src_rect Rect2i.PositionSize, dst Vector2i.XY)

Blits [param src_rect] area from [param src] image to this image at the coordinates given by [param dst], clipped accordingly to both image bounds. [param src] pixel is copied onto [param dst] if the corresponding [param mask] pixel's alpha value is not 0. This image and [param src] image [b]must[/b] have the same format. [param src] image and [param mask] image [b]must[/b] have the same size (width and height) but they can have different formats. [param 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) ClearMipmaps

func (self Instance) ClearMipmaps()

Removes the image's mipmaps.

func (Instance) Compress

func (self Instance) Compress(mode gdclass.ImageCompressMode) 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 [param source] parameter helps to pick the best compression method for DXT and ETC2 formats. It is ignored for ASTC compression. For ASTC compression, the [param astc_format] parameter must be supplied.

func (Instance) CompressFromChannels

func (self Instance) CompressFromChannels(mode gdclass.ImageCompressMode, channels gdclass.ImageUsedChannels) 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 [method 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 [param astc_format] parameter must be supplied.

func (Instance) ComputeImageMetrics

func (self Instance) ComputeImageMetrics(compared_image [1]gdclass.Image, use_luma bool) Metrics

Compute image metrics on the current image and the compared image. The dictionary contains [code]max[/code], [code]mean[/code], [code]mean_squared[/code], [code]root_mean_squared[/code] and [code]peak_snr[/code].

func (Instance) Convert

func (self Instance) Convert(format gdclass.ImageFormat)

Converts the image's format. See [enum Format] constants.

func (Instance) CopyFrom

func (self Instance) CopyFrom(src [1]gdclass.Image)

Copies [param src] image to this image.

func (Instance) Crop

func (self Instance) Crop(width int, height int)

Crops the image to the given [param width] and [param height]. If the specified size is larger than the current size, the extra area is filled with black pixels.

func (Instance) Decompress

func (self Instance) Decompress() error

Decompresses the image if it is VRAM compressed in a supported format. Returns [constant OK] if the format is supported, otherwise [constant ERR_UNAVAILABLE]. [b]Note:[/b] The following formats can be decompressed: DXT, RGTC, BPTC. The formats ETC1 and ETC2 are not supported.

func (Instance) DetectAlpha

func (self Instance) DetectAlpha() gdclass.ImageAlphaMode

Returns [constant ALPHA_BLEND] if the image has data for alpha values. Returns [constant ALPHA_BIT] if all the alpha values are stored in a single bit. Returns [constant ALPHA_NONE] if no data for alpha values is found.

func (Instance) DetectUsedChannels

func (self Instance) DetectUsedChannels() gdclass.ImageUsedChannels

Returns the color channels used by this image, as one of the [enum UsedChannels] constants. If the image is compressed, the original [param source] must be specified.

func (Instance) Fill

func (self Instance) Fill(color Color.RGBA)

Fills the image with [param color].

func (Instance) FillRect

func (self Instance) FillRect(rect Rect2i.PositionSize, color Color.RGBA)

Fills [param rect] with [param color].

func (Instance) FixAlphaEdges

func (self Instance) FixAlphaEdges()

Blends low-alpha pixels with nearby pixels.

func (Instance) FlipX

func (self Instance) FlipX()

Flips the image horizontally.

func (Instance) FlipY

func (self Instance) FlipY()

Flips the image vertically.

func (Instance) GenerateMipmaps

func (self Instance) GenerateMipmaps() error

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 [code]0[/code]. Enabling [param 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 [method has_mipmaps] or [method get_mipmap_count]. Calling [method generate_mipmaps] on an image that already has mipmaps will replace existing mipmaps in the image.

func (Instance) GetData

func (self Instance) GetData() []byte

Returns a copy of the image's raw data.

func (Instance) GetDataSize

func (self Instance) GetDataSize() int

Returns size (in bytes) of the image's raw data.

func (Instance) GetFormat

func (self Instance) GetFormat() gdclass.ImageFormat

Returns the image's format. See [enum Format] constants.

func (Instance) GetHeight

func (self Instance) GetHeight() int

Returns the image's height.

func (Instance) GetMipmapCount

func (self Instance) GetMipmapCount() int

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

func (self Instance) GetMipmapOffset(mipmap int) int

Returns the offset where the image's mipmap with index [param mipmap] is stored in the [member data] dictionary.

func (Instance) GetPixel

func (self Instance) GetPixel(x int, y int) Color.RGBA

Returns the color of the pixel at [code](x, y)[/code]. This is the same as [method get_pixelv], but with two integer arguments instead of a [Vector2i] argument.

func (Instance) GetPixelv

func (self Instance) GetPixelv(point Vector2i.XY) Color.RGBA

Returns the color of the pixel at [param point]. This is the same as [method get_pixel], but with a [Vector2i] argument instead of two integer arguments.

func (Instance) GetRegion

func (self Instance) GetRegion(region Rect2i.PositionSize) [1]gdclass.Image

Returns a new [Image] that is a copy of this [Image]'s area specified with [param region].

func (Instance) GetSize

func (self Instance) GetSize() Vector2i.XY

Returns the image's size (width and height).

func (Instance) GetUsedRect

func (self Instance) GetUsedRect() Rect2i.PositionSize

Returns a [Rect2i] enclosing the visible portion of the image, considering each pixel with a non-zero alpha channel as visible.

func (Instance) GetWidth

func (self Instance) GetWidth() int

Returns the image's width.

func (Instance) HasMipmaps

func (self Instance) HasMipmaps() bool

Returns [code]true[/code] if the image has generated mipmaps.

func (Instance) IsCompressed

func (self Instance) IsCompressed() bool

Returns [code]true[/code] if the image is compressed.

func (Instance) IsEmpty

func (self Instance) IsEmpty() bool

Returns [code]true[/code] if the image has no data.

func (Instance) IsInvisible

func (self Instance) IsInvisible() bool

Returns [code]true[/code] if all the image's pixels have an alpha value of 0. Returns [code]false[/code] if any pixel has an alpha value higher than 0.

func (Instance) Load

func (self Instance) Load(path string) error

Loads an image from file [param path]. See [url=$DOCS_URL/tutorials/assets_pipeline/importing_images.html#supported-image-formats]Supported image formats[/url] for a list of supported image formats and limitations. [b]Warning:[/b] 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 [code]user://[/code] directory, and may not work in exported projects. See also [ImageTexture] description for usage examples.

func (Instance) LoadBmpFromBuffer

func (self Instance) LoadBmpFromBuffer(buffer []byte) error

Loads an image from the binary contents of a BMP file. [b]Note:[/b] 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. [b]Note:[/b] 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 [code]module_bmp_enabled=no[/code] SCons option.

func (Instance) LoadJpgFromBuffer

func (self Instance) LoadJpgFromBuffer(buffer []byte) error

Loads an image from the binary contents of a JPEG file.

func (Instance) LoadKtxFromBuffer

func (self Instance) LoadKtxFromBuffer(buffer []byte) error

Loads an image from the binary contents of a [url=https://github.com/KhronosGroup/KTX-Software]KTX[/url] file. Unlike most image formats, KTX can store VRAM-compressed data and embed mipmaps. [b]Note:[/b] Godot's libktx implementation only supports 2D images. Cubemaps, texture arrays, and de-padding are not supported. [b]Note:[/b] 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 [code]module_ktx_enabled=no[/code] SCons option.

func (Instance) LoadPngFromBuffer

func (self Instance) LoadPngFromBuffer(buffer []byte) error

Loads an image from the binary contents of a PNG file.

func (Instance) LoadSvgFromBuffer

func (self Instance) LoadSvgFromBuffer(buffer []byte) error

Loads an image from the UTF-8 binary contents of an [b]uncompressed[/b] SVG file ([b].svg[/b]). [b]Note:[/b] Beware when using compressed SVG files (like [b].svgz[/b]), they need to be [code]decompressed[/code] before loading. [b]Note:[/b] 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 [code]module_svg_enabled=no[/code] SCons option.

func (Instance) LoadSvgFromString

func (self Instance) LoadSvgFromString(svg_str string) error

Loads an image from the string contents of an SVG file ([b].svg[/b]). [b]Note:[/b] 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 [code]module_svg_enabled=no[/code] SCons option.

func (Instance) LoadTgaFromBuffer

func (self Instance) LoadTgaFromBuffer(buffer []byte) error

Loads an image from the binary contents of a TGA file. [b]Note:[/b] 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 [code]module_tga_enabled=no[/code] SCons option.

func (Instance) LoadWebpFromBuffer

func (self Instance) LoadWebpFromBuffer(buffer []byte) error

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 [code](color * alpha)/256[/code]. See also [member CanvasItemMaterial.blend_mode].

func (Instance) Resize

func (self Instance) Resize(width int, height int)

Resizes the image to the given [param width] and [param height]. New pixels are calculated using the [param interpolation] mode defined via [enum Interpolation] constants.

func (Instance) ResizeToPo2

func (self Instance) ResizeToPo2()

Resizes the image to the nearest power of 2 for the width and height. If [param square] is [code]true[/code] then set width and height to be the same. New pixels are calculated using the [param interpolation] mode defined via [enum Interpolation] constants.

func (Instance) RgbeToSrgb

func (self Instance) RgbeToSrgb() [1]gdclass.Image

Converts a standard RGBE (Red Green Blue Exponent) image to an sRGB image.

func (Instance) Rotate180

func (self Instance) Rotate180()

Rotates the image by [code]180[/code] degrees. The width and height of the image must be greater than [code]1[/code].

func (Instance) Rotate90

func (self Instance) Rotate90(direction ClockDirection)

Rotates the image in the specified [param direction] by [code]90[/code] degrees. The width and height of the image must be greater than [code]1[/code]. If the width and height are not equal, the image will be resized.

func (Instance) SaveExr

func (self Instance) SaveExr(path string) error

Saves the image as an EXR file to [param path]. If [param grayscale] is [code]true[/code] and the image has only one channel, it will be saved explicitly as monochrome rather than one red channel. This function will return [constant ERR_UNAVAILABLE] if Godot was compiled without the TinyEXR module. [b]Note:[/b] The TinyEXR module is disabled in non-editor builds, which means [method save_exr] will return [constant ERR_UNAVAILABLE] when it is called from an exported project.

func (Instance) SaveExrToBuffer

func (self Instance) SaveExrToBuffer() []byte

Saves the image as an EXR file to a byte array. If [param grayscale] is [code]true[/code] 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. [b]Note:[/b] The TinyEXR module is disabled in non-editor builds, which means [method save_exr] will return an empty byte array when it is called from an exported project.

func (Instance) SaveJpg

func (self Instance) SaveJpg(path string) error

Saves the image as a JPEG file to [param path] with the specified [param quality] between [code]0.01[/code] and [code]1.0[/code] (inclusive). Higher [param quality] values result in better-looking output at the cost of larger file sizes. Recommended [param quality] values are between [code]0.75[/code] and [code]0.90[/code]. Even at quality [code]1.00[/code], JPEG compression remains lossy. [b]Note:[/b] JPEG does not save an alpha channel. If the [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

func (self Instance) SaveJpgToBuffer() []byte

Saves the image as a JPEG file to a byte array with the specified [param quality] between [code]0.01[/code] and [code]1.0[/code] (inclusive). Higher [param quality] values result in better-looking output at the cost of larger byte array sizes (and therefore memory usage). Recommended [param quality] values are between [code]0.75[/code] and [code]0.90[/code]. Even at quality [code]1.00[/code], JPEG compression remains lossy. [b]Note:[/b] JPEG does not save an alpha channel. If the [Image] contains an alpha channel, the image will still be saved, but the resulting byte array won't contain the alpha channel.

func (Instance) SavePng

func (self Instance) SavePng(path string) error

Saves the image as a PNG file to the file at [param path].

func (Instance) SavePngToBuffer

func (self Instance) SavePngToBuffer() []byte

Saves the image as a PNG file to a byte array.

func (Instance) SaveWebp

func (self Instance) SaveWebp(path string) error

Saves the image as a WebP (Web Picture) file to the file at [param path]. By default it will save lossless. If [param lossy] is true, the image will be saved lossy, using the [param quality] setting between 0.0 and 1.0 (inclusive). Lossless WebP offers more efficient compression than PNG. [b]Note:[/b] The WebP format is limited to a size of 16383×16383 pixels, while PNG can save larger images.

func (Instance) SaveWebpToBuffer

func (self Instance) SaveWebpToBuffer() []byte

Saves the image as a WebP (Web Picture) file to a byte array. By default it will save lossless. If [param lossy] is true, the image will be saved lossy, using the [param quality] setting between 0.0 and 1.0 (inclusive). Lossless WebP offers more efficient compression than PNG. [b]Note:[/b] The WebP format is limited to a size of 16383×16383 pixels, while PNG can save larger images.

func (Instance) SetData

func (self Instance) SetData(width int, height int, use_mipmaps bool, format gdclass.ImageFormat, data []byte)

Overwrites data of an existing [Image]. Non-static equivalent of [method create_from_data].

func (Instance) SetPixel

func (self Instance) SetPixel(x int, y int, color Color.RGBA)

Sets the [Color] of the pixel at [code](x, y)[/code] to [param color]. [b]Example:[/b] [codeblocks] [gdscript] var img_width = 10 var img_height = 5 var img = Image.create(img_width, img_height, false, Image.FORMAT_RGBA8)

img.set_pixel(1, 2, Color.RED) # Sets the color at (1, 2) to red. [/gdscript] [csharp] int imgWidth = 10; int imgHeight = 5; var img = Image.Create(imgWidth, imgHeight, false, Image.Format.Rgba8);

img.SetPixel(1, 2, Colors.Red); // Sets the color at (1, 2) to red. [/csharp] [/codeblocks] This is the same as [method set_pixelv], but with a two integer arguments instead of a [Vector2i] argument.

func (Instance) SetPixelv

func (self Instance) SetPixelv(point Vector2i.XY, color Color.RGBA)

Sets the [Color] of the pixel at [param point] to [param color]. [b]Example:[/b] [codeblocks] [gdscript] var img_width = 10 var img_height = 5 var img = Image.create(img_width, img_height, false, Image.FORMAT_RGBA8)

img.set_pixelv(Vector2i(1, 2), Color.RED) # Sets the color at (1, 2) to red. [/gdscript] [csharp] int imgWidth = 10; int imgHeight = 5; var img = Image.Create(imgWidth, imgHeight, false, Image.Format.Rgba8);

img.SetPixelv(new Vector2I(1, 2), Colors.Red); // Sets the color at (1, 2) to red. [/csharp] [/codeblocks] This is the same as [method set_pixel], but with a [Vector2i] 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.

func (*Instance) UnsafePointer

func (self *Instance) UnsafePointer() unsafe.Pointer

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

type Interpolation

type Interpolation = gdclass.ImageInterpolation //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 [constant INTERPOLATE_CUBIC], 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 [constant INTERPOLATE_BILINEAR], 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 [constant INTERPOLATE_BILINEAR], 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.
	  [b]Note:[/b] If you intend to scale multiple copies of the original image, it's better to call [method generate_mipmaps]] 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 Metrics

type Metrics struct {
	Max             float32 `gd:"max"`
	Mean            float32 `gd:"mean"`
	MeanSquared     float32 `gd:"mean_squared"`
	RootMeanSquared float32 `gd:"root_mean_squared"`
	PeakSNR         float32 `gd:"peak_snr"`
}

type UsedChannels

type UsedChannels = gdclass.ImageUsedChannels //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
)

Jump to

Keyboard shortcuts

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