Enumerationmigueldeicaza.swiftgodot 0.46.0SwiftGodot
Format
Image.swift:24enum Format
Cases
case l8
Texture format with a single 8-bit depth representing luminance.
case la8
OpenGL texture format with two values, luminance and alpha each stored with 8 bits.
case r8
OpenGL texture format
RED
with a single component and a bitdepth of 8.case rg8
OpenGL texture format
RG
with two components and a bitdepth of 8 for each.case rgb8
OpenGL texture format
RGB
with three components, each with a bitdepth of 8.case rgba8
OpenGL texture format
RGBA
with four components, each with a bitdepth of 8.case rgba4444
OpenGL texture format
RGBA
with four components, each with a bitdepth of 4.case rgb565
OpenGL texture format
RGB
with three components. Red and blue have a bitdepth of 5, and green has a bitdepth of 6.case rf
OpenGL texture format
GL_R32F
where there’s one component, a 32-bit floating-point value.case rgf
OpenGL texture format
GL_RG32F
where there are two components, each a 32-bit floating-point values.case rgbf
OpenGL texture format
GL_RGB32F
where there are three components, each a 32-bit floating-point values.case rgbaf
OpenGL texture format
GL_RGBA32F
where there are four components, each a 32-bit floating-point values.case rh
OpenGL texture format
GL_R16F
where there’s one component, a 16-bit “half-precision” floating-point value.case rgh
OpenGL texture format
GL_RG16F
where there are two components, each a 16-bit “half-precision” floating-point value.case rgbh
OpenGL texture format
GL_RGB16F
where there are three components, each a 16-bit “half-precision” floating-point value.case rgbah
OpenGL texture format
GL_RGBA16F
where there are four components, each a 16-bit “half-precision” floating-point value.case rgbe9995
A special OpenGL texture format where the three color components have 9 bits of precision and all three share a single 5-bit exponent.
case dxt1
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.
case dxt3
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.
case dxt5
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.
case rgtcR
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.
case rgtcRg
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.
case bptcRgba
Texture format that uses BPTC compression with unsigned normalized RGBA components.
case bptcRgbf
Texture format that uses BPTC compression with signed floating-point RGB components.
case bptcRgbfu
Texture format that uses BPTC compression with unsigned floating-point RGB components.
case etc
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.
case etc2R11
Ericsson Texture Compression format 2 (
R11_EAC
variant), which provides one channel of unsigned data.case etc2R11s
Ericsson Texture Compression format 2 (
SIGNED_R11_EAC
variant), which provides one channel of signed data.case etc2Rg11
Ericsson Texture Compression format 2 (
RG11_EAC
variant), which provides two channels of unsigned data.case etc2Rg11s
Ericsson Texture Compression format 2 (
SIGNED_RG11_EAC
variant), which provides two channels of signed data.case etc2Rgb8
Ericsson Texture Compression format 2 (
RGB8
variant), which is a follow-up of ETC1 and compresses RGB888 data.case etc2Rgba8
Ericsson Texture Compression format 2 (
RGBA8
variant), which compresses RGBA8888 data with full alpha support.case etc2Rgb8a1
Ericsson Texture Compression format 2 (
RGB8_PUNCHTHROUGH_ALPHA1
variant), which compresses RGBA data to make alpha either fully transparent or fully opaque.case etc2RaAsRg
Ericsson Texture Compression format 2 (
RGBA8
variant), which compresses RA data and interprets it as two channels (red and green). See also .etc2Rgba8.case dxt5RaAsRg
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 .dxt5.
case astc4x4
Adaptive Scalable Texture Compression. This implements the 4×4 (high quality) mode.
case astc4x4Hdr
Same format as .astc4x4, but with the hint to let the GPU know it is used for HDR.
case astc8x8
Adaptive Scalable Texture Compression. This implements the 8×8 (low quality) mode.
case astc8x8Hdr
Same format as .astc8x8, but with the hint to let the GPU know it is used for HDR.
case max
Represents the size of the
Format
enum.
Other members in extension
View members
Hide members
This section is hidden by default because it contains too many (80) members.
Types
enum ASTCFormat
enum AlphaMode
enum CompressMode
enum CompressSource
enum Interpolation
enum UsedChannels
Type members
static let maxHeight: Int
The maximal height allowed for
Image
resources.static let maxWidth: Int
The maximal width allowed for
Image
resources.static func create(width: Int32, height: Int32, useMipmaps: Bool, format: Image.Format
) -> Image? Creates an empty image of given size and format. See
Format
constants. IfuseMipmaps
istrue
, then generate mipmaps for this image. See thegenerateMipmaps(renormalize:)
.static func createEmpty(width: Int32, height: Int32, useMipmaps: Bool, format: Image.Format
) -> Image? Creates an empty image of given size and format. See
Format
constants. IfuseMipmaps
istrue
, then generate mipmaps for this image. See thegenerateMipmaps(renormalize:)
.static func createFromData(width: Int32, height: Int32, useMipmaps: Bool, format: Image.Format, data: PackedByteArray
) -> Image? Creates a new image of given size and format. See
Format
constants. Fills the image with the given raw data. IfuseMipmaps
istrue
then loads mipmaps for this image fromdata
. SeegenerateMipmaps(renormalize:)
.static func loadFromFile(path: String
) -> Image? Creates a new
Image
and loads data from the specified file.class var godotClassName: StringName
Instance members
func adjustBcs(brightness: Double, contrast: Double, saturation: Double
) Adjusts this image’s
brightness
,contrast
, andsaturation
by the given values. Does not work if the image is compressed (seeisCompressed
).func blendRect(src: Image?, srcRect: Rect2i, dst: Vector2i
) Alpha-blends
srcRect
fromsrc
image to this image at coordinatesdst
, clipped accordingly to both image bounds. This image andsrc
image must have the same format.srcRect
with non-positive size is treated as empty.func blendRectMask(src: Image?, mask: Image?, srcRect: Rect2i, dst: Vector2i
) Alpha-blends
srcRect
fromsrc
image to this image usingmask
image at coordinatesdst
, clipped accordingly to both image bounds. Alpha channels are required for bothsrc
andmask
.dst
pixels andsrc
pixels will blend if the corresponding mask pixel’s alpha value is not 0. This image andsrc
image must have the same format.src
image andmask
image must have the same size (width and height) but they can have different formats.srcRect
with non-positive size is treated as empty.func blitRect(src: Image, srcRect: Rect2i, dst: Vector2i
) Copies
srcRect
fromsrc
image to this image at coordinatesdst
, clipped accordingly to both image bounds. This image andsrc
image must have the same format.srcRect
with non-positive size is treated as empty.func blitRectMask(src: Image?, mask: Image?, srcRect: Rect2i, dst: Vector2i
) Blits
srcRect
area fromsrc
image to this image at the coordinates given bydst
, clipped accordingly to both image bounds.src
pixel is copied ontodst
if the correspondingmask
pixel’s alpha value is not 0. This image andsrc
image must have the same format.src
image andmask
image must have the same size (width and height) but they can have different formats.srcRect
with non-positive size is treated as empty.func bumpMapToNormalMap(bumpScale: Double
) 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 clearMipmaps(
) Removes the image’s mipmaps.
func compress(mode: Image.CompressMode, source: Image.CompressSource, astcFormat: Image.ASTCFormat
) -> GodotError 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.
func compressFromChannels(mode: Image.CompressMode, channels: Image.UsedChannels, astcFormat: Image.ASTCFormat
) -> GodotError 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.
func computeImageMetrics(comparedImage: Image?, useLuma: Bool
) -> GDictionary Compute image metrics on the current image and the compared image.
func convert(format: Image.Format
) Converts the image’s format. See
Format
constants.func copyFrom(src: Image?
) Copies
src
image to this image.func crop(width: Int32, height: Int32
) Crops the image to the given
width
andheight
. If the specified size is larger than the current size, the extra area is filled with black pixels.func decompress(
) -> GodotError Decompresses the image if it is VRAM compressed in a supported format. Returns
ok
if the format is supported, otherwiseerrUnavailable
.func detectAlpha(
) -> Image.AlphaMode 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 detectUsedChannels(source: Image.CompressSource
) -> Image.UsedChannels Returns the color channels used by this image, as one of the
UsedChannels
constants. If the image is compressed, the originalsource
must be specified.func fill(color: Color
) Fills the image with
color
.func fillRect(Rect2i, color: Color
) Fills
rect
withcolor
.func fixAlphaEdges(
) Blends low-alpha pixels with nearby pixels.
func flipX(
) Flips the image horizontally.
func flipY(
) Flips the image vertically.
func generateMipmaps(renormalize: Bool
) -> GodotError 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
. Enablingrenormalize
when generating mipmaps for normal map textures will make sure all resulting vector values are normalized.func getData(
) -> PackedByteArray Returns a copy of the image’s raw data.
func getDataSize(
) -> Int Returns size (in bytes) of the image’s raw data.
func getFormat(
) -> Image.Format Returns the image’s format. See
Format
constants.func getHeight(
) -> Int32 Returns the image’s height.
func getMipmapCount(
) -> Int32 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 getMipmapOffset(mipmap: Int32
) -> Int32 Returns the offset where the image’s mipmap with index
mipmap
is stored in thedata
dictionary.func getPixel(x: Int32, y: Int32
) -> Color Returns the color of the pixel at
(x, y)
.func getPixelv(point: Vector2i
) -> Color Returns the color of the pixel at
point
.func getRegion(Rect2i
) -> Image? Returns a new
Image
that is a copy of thisImage
’s area specified withregion
.func getSize(
) -> Vector2i Returns the image’s size (width and height).
func getUsedRect(
) -> Rect2i Returns a
Rect2i
enclosing the visible portion of the image, considering each pixel with a non-zero alpha channel as visible.func getWidth(
) -> Int32 Returns the image’s width.
func hasMipmaps(
) -> Bool Returns
true
if the image has generated mipmaps.func isCompressed(
) -> Bool Returns
true
if the image is compressed.func isEmpty(
) -> Bool Returns
true
if the image has no data.func isInvisible(
) -> Bool Returns
true
if all the image’s pixels have an alpha value of 0. Returnsfalse
if any pixel has an alpha value higher than 0.func load(path: String
) -> GodotError Loads an image from file
path
. See Supported image formats for a list of supported image formats and limitations.func loadBmpFromBuffer(PackedByteArray
) -> GodotError Loads an image from the binary contents of a BMP file.
func loadJpgFromBuffer(PackedByteArray
) -> GodotError Loads an image from the binary contents of a JPEG file.
func loadKtxFromBuffer(PackedByteArray
) -> GodotError Loads an image from the binary contents of a KTX file. Unlike most image formats, KTX can store VRAM-compressed data and embed mipmaps.
func loadPngFromBuffer(PackedByteArray
) -> GodotError Loads an image from the binary contents of a PNG file.
func loadSvgFromBuffer(PackedByteArray, scale: Double
) -> GodotError Loads an image from the UTF-8 binary contents of an uncompressed SVG file (.svg).
func loadSvgFromString(svgStr: String, scale: Double
) -> GodotError Loads an image from the string contents of an SVG file (.svg).
func loadTgaFromBuffer(PackedByteArray
) -> GodotError Loads an image from the binary contents of a TGA file.
func loadWebpFromBuffer(PackedByteArray
) -> GodotError Loads an image from the binary contents of a WebP file.
func 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 premultiplyAlpha(
) Multiplies color values with alpha values. Resulting color values for a pixel are
(color * alpha)/256
. See alsoblendMode
.func resize(width: Int32, height: Int32, interpolation: Image.Interpolation
) Resizes the image to the given
width
andheight
. New pixels are calculated using theinterpolation
mode defined viaInterpolation
constants.func resizeToPo2(square: Bool, interpolation: Image.Interpolation
) Resizes the image to the nearest power of 2 for the width and height. If
square
istrue
then set width and height to be the same. New pixels are calculated using theinterpolation
mode defined viaInterpolation
constants.func rgbeToSrgb(
) -> Image? Converts a standard RGBE (Red Green Blue Exponent) image to an sRGB image.
func rotate180(
) Rotates the image by
180
degrees. The width and height of the image must be greater than1
.func rotate90(direction: ClockDirection
) Rotates the image in the specified
direction
by90
degrees. The width and height of the image must be greater than1
. If the width and height are not equal, the image will be resized.func saveExr(path: String, grayscale: Bool
) -> GodotError Saves the image as an EXR file to
path
. Ifgrayscale
istrue
and the image has only one channel, it will be saved explicitly as monochrome rather than one red channel. This function will returnerrUnavailable
if Godot was compiled without the TinyEXR module.func saveExrToBuffer(grayscale: Bool
) -> PackedByteArray Saves the image as an EXR file to a byte array. If
grayscale
istrue
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.func saveJpg(path: String, quality: Double
) -> GodotError Saves the image as a JPEG file to
path
with the specifiedquality
between0.01
and1.0
(inclusive). Higherquality
values result in better-looking output at the cost of larger file sizes. Recommendedquality
values are between0.75
and0.90
. Even at quality1.00
, JPEG compression remains lossy.func saveJpgToBuffer(quality: Double
) -> PackedByteArray Saves the image as a JPEG file to a byte array with the specified
quality
between0.01
and1.0
(inclusive). Higherquality
values result in better-looking output at the cost of larger byte array sizes (and therefore memory usage). Recommendedquality
values are between0.75
and0.90
. Even at quality1.00
, JPEG compression remains lossy.func savePng(path: String
) -> GodotError Saves the image as a PNG file to the file at
path
.func savePngToBuffer(
) -> PackedByteArray Saves the image as a PNG file to a byte array.
func saveWebp(path: String, lossy: Bool, quality: Double
) -> GodotError Saves the image as a WebP (Web Picture) file to the file at
path
. By default it will save lossless. Iflossy
is true, the image will be saved lossy, using thequality
setting between 0.0 and 1.0 (inclusive). Lossless WebP offers more efficient compression than PNG.func saveWebpToBuffer(lossy: Bool, quality: Double
) -> PackedByteArray 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 thequality
setting between 0.0 and 1.0 (inclusive). Lossless WebP offers more efficient compression than PNG.func setData(width: Int32, height: Int32, useMipmaps: Bool, format: Image.Format, data: PackedByteArray
) Overwrites data of an existing
Image
. Non-static equivalent ofcreateFromData(width:height:useMipmaps:format:data:)
.func setPixel(x: Int32, y: Int32, color: Color
) Sets the
Color
of the pixel at(x, y)
tocolor
.func setPixelv(point: Vector2i, color: Color
) Sets the
Color
of the pixel atpoint
tocolor
.func shrinkX2(
) Shrinks the image by a factor of 2 on each axis (this divides the pixel count by 4).
func srgbToLinear(
) Converts the raw data from the sRGB colorspace to a linear scale.
Citizens in SwiftGodot
Conformances
protocol CaseIterable
A type that provides a collection of all of its values.
protocol CustomDebugStringConvertible
A type with a customized textual representation suitable for debugging purposes.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol RawRepresentable<RawValue>
A type that can be converted to and from an associated raw value.
Type members
Instance members
var debugDescription: String
A textual representation of this instance, suitable for debugging
Type features
static func != (lhs: Self, rhs: Self
) -> Bool Returns a Boolean value indicating whether two values are not equal.