Enumerationmigueldeicaza.swiftgodot 0.45.0SwiftGodot
ASTCFormat
Image.swift:303enum ASTCFormat
Cases
case astcFormat4x4
Hint to indicate that the high quality 4x4 ASTC compression format should be used.
case astcFormat8x8
Hint to indicate that the low quality 8x8 ASTC compression format should be used.
Other members in extension
View members
Hide members
This section is hidden by default because it contains too many (78) members.
Types
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 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
) 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 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 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 a 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.