Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
Image Class Reference

Public Types

enum  Format {
  FORMAT_GRAYSCALE, FORMAT_INTENSITY, FORMAT_GRAYSCALE_ALPHA, FORMAT_RGB,
  FORMAT_RGBA, FORMAT_INDEXED, FORMAT_INDEXED_ALPHA, FORMAT_YUV_422,
  FORMAT_YUV_444, FORMAT_BC1, FORMAT_BC2, FORMAT_BC3,
  FORMAT_BC4, FORMAT_BC5, FORMAT_PVRTC2, FORMAT_PVRTC2_ALPHA,
  FORMAT_PVRTC4, FORMAT_PVRTC4_ALPHA, FORMAT_ETC, FORMAT_ATC,
  FORMAT_ATC_ALPHA_EXPLICIT, FORMAT_ATC_ALPHA_INTERPOLATED, FORMAT_CUSTOM, FORMAT_MAX
}
 
enum  Interpolation { INTERPOLATE_NEAREST, INTERPOLATE_BILINEAR, INTERPOLATE_CUBIC }
 
enum  AlphaMode { ALPHA_NONE, ALPHA_BIT, ALPHA_BLEND }
 
enum  CompressMode { COMPRESS_BC, COMPRESS_PVRTC2, COMPRESS_PVRTC4, COMPRESS_ETC }
 

Public Member Functions

Error _decompress_bc ()
 
int get_width () const
 Get image width.
 
int get_height () const
 Get image height.
 
int get_mipmaps () const
 
Color get_pixel (int p_x, int p_y, int p_mipmap=0) const
 
void put_pixel (int p_x, int p_y, const Color &p_color, int p_mipmap=0)
 
void convert (Format p_new_format)
 
Image converted (int p_new_format)
 
Format get_format () const
 
int get_mipmap_offset (int p_mipmap) const
 
void get_mipmap_offset_and_size (int p_mipmap, int &r_ofs, int &r_size) const
 
void get_mipmap_offset_size_and_dimensions (int p_mipmap, int &r_ofs, int &r_size, int &w, int &h) const
 
void resize_to_po2 (bool p_square=false)
 
void resize (int p_width, int p_height, Interpolation p_interpolation=INTERPOLATE_BILINEAR)
 
Image resized (int p_width, int p_height, int p_interpolation=INTERPOLATE_BILINEAR)
 
void shrink_x2 ()
 
void crop (int p_width, int p_height)
 
void flip_x ()
 
void flip_y ()
 
Error generate_mipmaps (int p_amount=-1, bool p_keep_existing=false)
 
void clear_mipmaps ()
 
void make_normalmap (float p_height_scale=1.0)
 
void create (int p_width, int p_height, bool p_use_mipmaps, Format p_format)
 
void create (int p_width, int p_height, int p_mipmaps, Format p_format, const DVector< uint8_t > &p_data)
 
void create (const char **p_xpm)
 
bool empty () const
 
DVector< uint8_t > get_data () const
 
Error load (const String &p_path)
 
Error save_png (const String &p_path)
 
 Image ()
 
 Image (int p_width, int p_height, bool p_use_mipmaps, Format p_format)
 
 Image (int p_width, int p_height, int p_mipmaps, Format p_format, const DVector< uint8_t > &p_data)
 
AlphaMode detect_alpha () const
 
bool is_invisible () const
 
void put_indexed_pixel (int p_x, int p_y, uint8_t p_idx, int p_mipmap=0)
 
uint8_t get_indexed_pixel (int p_x, int p_y, int p_mipmap=0) const
 
void set_pallete (const DVector< uint8_t > &p_data)
 
bool operator== (const Image &p_image) const
 
void quantize ()
 
Error compress (CompressMode p_mode=COMPRESS_BC)
 
Image compressed (int p_mode)
 
Error decompress ()
 
Image decompressed () const
 
bool is_compressed () const
 
void fix_alpha_edges ()
 
void premultiply_alpha ()
 
void srgb_to_linear ()
 
void normalmap_to_xy ()
 
void blit_rect (const Image &p_src, const Rect2 &p_src_rect, const Point2 &p_dest)
 
void brush_transfer (const Image &p_src, const Image &p_brush, const Point2 &p_dest)
 
Image brushed (const Image &p_src, const Image &p_brush, const Point2 &p_dest) const
 
Rect2 get_used_rect () const
 
Image get_rect (const Rect2 &p_area) const
 
 Image (const uint8_t *p_mem_png, int p_len=-1)
 
 Image (const char **p_xpm)
 

Static Public Member Functions

static int get_format_pixel_size (Format p_format)
 
static int get_format_pixel_rshift (Format p_format)
 
static int get_format_pallete_size (Format p_format)
 
static int get_image_data_size (int p_width, int p_height, Format p_format, int p_mipmaps=0)
 
static int get_image_required_mipmaps (int p_width, int p_height, Format p_format)
 
static void set_compress_bc_func (void(*p_compress_func)(Image *))
 
static String get_format_name (Format p_format)
 

Static Public Attributes

static SavePNGFunc save_png_func = NULL
 
static const char * format_names [FORMAT_MAX]
 
static Image(* _png_mem_loader_func )(const uint8_t *p_png, int p_size) =NULL
 
static void(* _image_compress_bc_func )(Image *) =NULL
 
static void(* _image_compress_pvrtc2_func )(Image *) =NULL
 
static void(* _image_compress_pvrtc4_func )(Image *) =NULL
 
static void(* _image_compress_etc_func )(Image *) =NULL
 
static void(* _image_decompress_pvrtc )(Image *) =NULL
 
static void(* _image_decompress_bc )(Image *) =NULL
 
static void(* _image_decompress_etc )(Image *) =NULL
 
static DVector< uint8_t >(* lossy_packer )(const Image &p_image, float p_quality) =NULL
 
static Image(* lossy_unpacker )(const DVector< uint8_t > &p_buffer) =NULL
 
static DVector< uint8_t >(* lossless_packer )(const Image &p_image) =NULL
 
static Image(* lossless_unpacker )(const DVector< uint8_t > &p_buffer) =NULL
 

Member Enumeration Documentation

Enumerator
FORMAT_GRAYSCALE 

one byte per pixel, 0-255

FORMAT_INTENSITY 

one byte per pixel, 0-255

FORMAT_GRAYSCALE_ALPHA 

two bytes per pixel, 0-255. alpha 0-255

FORMAT_RGB 

one byte R, one byte G, one byte B

FORMAT_RGBA 

one byte R, one byte G, one byte B, one byte A

FORMAT_INDEXED 

index byte 0-256, and after image end, 256*3 bytes of palette

FORMAT_INDEXED_ALPHA 

index byte 0-256, and after image end, 256*4 bytes of palette (alpha)

Constructor & Destructor Documentation

Image::Image ( )

create an empty image

Image::Image ( int  p_width,
int  p_height,
bool  p_use_mipmaps,
Format  p_format 
)

create an empty image of a specific size and format

Image::Image ( int  p_width,
int  p_height,
int  p_mipmaps,
Format  p_format,
const DVector< uint8_t > &  p_data 
)

import an image of a specific size and format from a pointer

Member Function Documentation

void Image::convert ( Format  p_new_format)

Convert the image to another format, as close as it can be done.

void Image::create ( int  p_width,
int  p_height,
bool  p_use_mipmaps,
Format  p_format 
)

Create a new image of a given size and format. Current image will be lost

void Image::crop ( int  p_width,
int  p_height 
)

Crop the image to a specific size, if larger, then the image is filled by black

bool Image::empty ( ) const

returns true when the image is empty (0,0) in size

Error Image::generate_mipmaps ( int  p_amount = -1,
bool  p_keep_existing = false 
)

Generate a mipmap to an image (creates an image 1/4 the size, with averaging of 4->1)

Image::Format Image::get_format ( ) const

Get the current image format.

Color Image::get_pixel ( int  p_x,
int  p_y,
int  p_mipmap = 0 
) const

Get a pixel from the image. for grayscale or indexed formats, use Color::gray to obtain the actual value.

void Image::make_normalmap ( float  p_height_scale = 1.0)

Generate a normal map from a grayscale image

void Image::put_pixel ( int  p_x,
int  p_y,
const Color p_color,
int  p_mipmap = 0 
)

Set a pixel into the image. for grayscale or indexed formats, a suitable Color constructor.

void Image::resize_to_po2 ( bool  p_square = false)

Resize the image, using the prefered interpolation method. Indexed-Color images always use INTERPOLATE_NEAREST.

Member Data Documentation

const char * Image::format_names
static
Initial value:
={
"Grayscale",
"Intensity",
"GrayscaleAlpha",
"RGB",
"RGBA",
"Indexed",
"IndexedAlpha",
"YUV422",
"YUV444",
"BC1",
"BC2",
"BC3",
"BC4",
"BC5",
"PVRTC2",
"PVRTC2Alpha",
"PVRTC4",
"PVRTC4Alpha",
"ETC",
"ATC",
"ATCAlphaExp",
"ATCAlphaInterp",
}

The documentation for this class was generated from the following files: