Image

Inherits: Resource < Reference < Object

Category: Core

Brief Description

Image datatype.

Member Functions

void blend_rect ( Image src, Rect2 src_rect, Vector2 dst )
void blend_rect_mask ( Image src, Image mask, Rect2 src_rect, Vector2 dst )
void blit_rect ( Image src, Rect2 src_rect, Vector2 dst )
void blit_rect_mask ( Image src, Image mask, Rect2 src_rect, Vector2 dst )
void clear_mipmaps ( )
int compress ( int mode, int source, float lossy_quality )
void convert ( int format )
void copy_from ( Image src )
void create ( int width, int height, bool use_mipmaps, int format )
void create_from_data ( int width, int height, bool use_mipmaps, int format, PoolByteArray data )
void crop ( int width, int height )
int decompress ( )
int detect_alpha ( ) const
void expand_x2_hq2x ( )
void fill ( Color color )
void fix_alpha_edges ( )
void flip_x ( )
void flip_y ( )
int generate_mipmaps ( )
PoolByteArray get_data ( ) const
int get_format ( ) const
int get_height ( ) const
int get_mipmap_offset ( int mipmap ) const
Color get_pixel ( int x, int y ) const
Image get_rect ( Rect2 rect ) const
Vector2 get_size ( ) const
Rect2 get_used_rect ( ) const
int get_width ( ) const
bool has_mipmaps ( ) const
bool is_compressed ( ) const
bool is_empty ( ) const
bool is_invisible ( ) const
int load ( String path )
void lock ( )
void normalmap_to_xy ( )
void premultiply_alpha ( )
void resize ( int width, int height, int interpolation=1 )
void resize_to_po2 ( bool square=false )
int save_png ( String path ) const
void set_pixel ( int x, int y, Color color )
void shrink_x2 ( )
void srgb_to_linear ( )
void unlock ( )

Member Variables

  • Dictionary data - Holds all of the image’s color data in a given format. See FORMAT\_\* constants.

Numeric Constants

  • FORMAT_L8 = 0
  • FORMAT_LA8 = 1
  • FORMAT_R8 = 2
  • FORMAT_RG8 = 3
  • FORMAT_RGB8 = 4
  • FORMAT_RGBA8 = 5
  • FORMAT_RGBA4444 = 6
  • FORMAT_RGBA5551 = 7
  • FORMAT_RF = 8
  • FORMAT_RGF = 9
  • FORMAT_RGBF = 10
  • FORMAT_RGBAF = 11
  • FORMAT_RH = 12
  • FORMAT_RGH = 13
  • FORMAT_RGBH = 14
  • FORMAT_RGBAH = 15
  • FORMAT_RGBE9995 = 16
  • FORMAT_DXT1 = 17
  • FORMAT_DXT3 = 18
  • FORMAT_DXT5 = 19
  • FORMAT_RGTC_R = 20
  • FORMAT_RGTC_RG = 21
  • FORMAT_BPTC_RGBA = 22
  • FORMAT_BPTC_RGBF = 23
  • FORMAT_BPTC_RGBFU = 24
  • FORMAT_PVRTC2 = 25
  • FORMAT_PVRTC2A = 26
  • FORMAT_PVRTC4 = 27
  • FORMAT_PVRTC4A = 28
  • FORMAT_ETC = 29
  • FORMAT_ETC2_R11 = 30
  • FORMAT_ETC2_R11S = 31
  • FORMAT_ETC2_RG11 = 32
  • FORMAT_ETC2_RG11S = 33
  • FORMAT_ETC2_RGB8 = 34
  • FORMAT_ETC2_RGBA8 = 35
  • FORMAT_ETC2_RGB8A1 = 36
  • FORMAT_MAX = 37
  • INTERPOLATE_NEAREST = 0
  • INTERPOLATE_BILINEAR = 1
  • INTERPOLATE_CUBIC = 2
  • ALPHA_NONE = 0
  • ALPHA_BIT = 1
  • ALPHA_BLEND = 2
  • COMPRESS_S3TC = 0
  • COMPRESS_PVRTC2 = 1
  • COMPRESS_PVRTC4 = 2
  • COMPRESS_ETC = 3
  • COMPRESS_ETC2 = 4
  • COMPRESS_SOURCE_GENERIC = 0
  • COMPRESS_SOURCE_SRGB = 1
  • COMPRESS_SOURCE_NORMAL = 2

Description

Native image datatype. Contains image data, which can be converted to a Texture, and several functions to interact with it. The maximum width and height for an Image is 16384 pixels.

Member Function Description

Alpha-blends src_rect from src image to this image at coordinates dest.

Alpha-blends src_rect from src image to this image using mask image at coordinates dst. 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. src image and mask image must have the same size (width and height) but they can have different formats.

Copies src_rect from src image to this image at coordinates dst.

Blits src_rect area from src image to this image at the coordinates given by dst. src pixel is copied onto dst if the corresponding mask pixel’s alpha value is not 0. src image and mask image must have the same size (width and height) but they can have different formats.

  • void clear_mipmaps ( )

Removes the image’s mipmaps.

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. See COMPRESS\_\* constants.

  • void convert ( int format )

Converts the image’s format. See FORMAT\_\* constants.

  • void copy_from ( Image src )

Copies src image to this image.

  • void create ( int width, int height, bool use_mipmaps, int format )

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 generate_mipmaps method.

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 generate mipmaps for this image. See the generate_mipmaps method.

  • void crop ( int width, int height )

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.

  • int decompress ( )

Decompresses the image if it is compressed. Returns an error if decompress function is not available.

  • int detect_alpha ( ) const

Returns ALPHA_BLEND if the image has data for alpha values. Returns ALPHA_BIT if all the alpha values are below a certain threshold or the maximum value. Returns ALPHA_NONE if no data for alpha values is found.

  • void expand_x2_hq2x ( )

Stretches the image and enlarges it by a factor of 2. No interpolation is done.

  • void fill ( Color color )

Fills the image with a given Color.

  • void fix_alpha_edges ( )

Blends low-alpha pixels with nearby pixels.

  • void flip_x ( )

Flips the image horizontally.

  • void flip_y ( )

Flips the image vertically.

  • int generate_mipmaps ( )

Generates mipmaps for the image. Mipmaps are pre-calculated and lower resolution copies of the image. Mipmaps are automatically used if the image needs to be scaled down when rendered. This improves image quality and the performance of the rendering. Returns an error if the image is compressed, in a custom format or if the image’s width/height is 0.

Returns the image’s raw data.

  • int get_format ( ) const

Returns the image’s raw data.

  • int get_height ( ) const

Returns the image’s height.

  • int get_mipmap_offset ( int mipmap ) const

Returns the offset where the image’s mipmap with index mipmap is stored in the data dictionary.

Returns the color of the pixel at (x, y) if the image is locked. If the image is unlocked it always returns a Color with the value (0, 0, 0, 1.0).

Returns a new image that is a copy of the image’s area specified with rect.

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

  • Rect2 get_used_rect ( ) const

Returns a Rect2 enclosing the visible portion of the image.

  • int get_width ( ) const

Returns the image’s width.

  • bool has_mipmaps ( ) const

Returns true if the image has generated mipmaps.

  • bool is_compressed ( ) const

Returns true if the image is compressed.

  • bool is_empty ( ) const

Returns true if the image has no data.

  • bool is_invisible ( ) const

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.

Loads an image from file path.

  • void lock ( )

Locks the data for writing access.

  • void normalmap_to_xy ( )

Converts the image’s data to represent coordinates on a 3D plane. This is used when the image represents a normalmap. A normalmap can add lots of detail to a 3D surface without increasing the polygon count.

  • void premultiply_alpha ( )

Multiplies color values with alpha values. Resulting color values for a pixel are (color \* alpha)/256.

  • void resize ( int width, int height, int interpolation=1 )

Resizes the image to the given width and height. New pixels are calculated using interpolation. See interpolation constants.

  • void resize_to_po2 ( bool square=false )

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.

Saves the image as a PNG file to path.

Sets the Color of the pixel at (x, y) if the image is locked. Example:

var img = Image.new()
img.lock()
img.set_pixel(x, y, color) # Works
img.unlock()
img.set_pixel(x, y, color) # Does not have an effect
  • void shrink_x2 ( )

Shrinks the image by a factor of 2.

  • void srgb_to_linear ( )

Converts the raw data from the sRGB colorspace to a linear scale.

  • void unlock ( )

Unlocks the data and prevents changes.