Polycode
|
An image in memory. More...
Inherited by Polycode::Label.
Public Member Functions | |
Image (const String &fileName) | |
Create image from file name. | |
Image (int width, int height, int type=IMAGE_RGBA) | |
Create a blank image of specified size and type. | |
Image (char *data, int width, int height, int type=IMAGE_RGBA) | |
Create an image of specified size and type and set its contents from the specified buffer. | |
Image (Image *copyImage) | |
Create an image from another image. | |
bool | loadImage (const String &fileName) |
Load an image from a file. | |
bool | saveImage (const String &fileName) |
Saves the image to a file. | |
void | createEmpty (unsigned int width, unsigned int height) |
Recreate the image as an empty image of specified size. | |
void | fill (Number r, Number g, Number b, Number a) |
Fills the image with the specified color values. | |
void | setPixel (int x, int y, Number r, Number g, Number b, Number a) |
Sets a pixel at specified coordinates to specified color. | |
void | setPixel (int x, int y, Color col) |
Sets a pixel at specified coordinates to specified color. | |
Color | getPixel (int x, int y) |
Returns the pixel color at specified position. | |
void | line (int x0, int y0, int x1, int y1, Color col) |
Draws a line with specified color. | |
void | moveTo (int x, int y) |
Moves brush to specified position. | |
void | move (int x, int y) |
Translates brush a specified amount relative to its current position. | |
void | lineTo (int x, int y, Color col) |
Draws a line to specified position. | |
void | drawRect (int x, int y, int w, int h, Color col) |
Draws a rectangle with specified color. | |
void | perlinNoise (int seed, bool alpha) |
Draws perlin noise in the image. | |
void | fastBlur (int blurSize) |
Blurs the image using box blur. | |
void | gaussianBlur (float radius, float deviation) |
Blurs the image using gaussian blur. | |
char * | getPixelsInRect (unsigned int x, unsigned int y, unsigned int width, unsigned int height) |
Returns an area of the image buffer. | |
int | getBrushX () const |
Returns the x position of the brush. | |
int | getBrushY () const |
Returns the y position of the brush. | |
unsigned int | getWidth () const |
Returns the width of the image. | |
unsigned int | getHeight () const |
Returns the height of the image. | |
char * | getPixels () |
Returns the raw image data. |
An image in memory.
Basic RGB or RGBA images stored in memory. Can be loaded from PNG files, created into textures and written to file.
Image::Image | ( | const String & | fileName | ) |
Create image from file name.
fileName | Path to image file to load. |
Image::Image | ( | int | width, |
int | height, | ||
int | type = IMAGE_RGBA |
||
) |
Create a blank image of specified size and type.
width | Width of the image to create. |
height | Height of the image to create. |
type | Type of image to create. Can be IMAGE_RGBA or IMAGE_RGB. |
Image::Image | ( | char * | data, |
int | width, | ||
int | height, | ||
int | type = IMAGE_RGBA |
||
) |
Create an image of specified size and type and set its contents from the specified buffer.
data | Data buffer to set contents from. |
width | Width of the image to create. |
height | Height of the image to create. |
type | Type of image to create. Can be IMAGE_RGBA or IMAGE_RGB. |
Image::Image | ( | Image * | copyImage | ) |
Create an image from another image.
copyImage | The image to copy. |
void Image::createEmpty | ( | unsigned int | width, |
unsigned int | height | ||
) |
Recreate the image as an empty image of specified size.
The image type stays the same.
width | Width of the image to create. |
height | Height of the image to create. |
void Image::drawRect | ( | int | x, |
int | y, | ||
int | w, | ||
int | h, | ||
Color | col | ||
) |
void Image::fastBlur | ( | int | blurSize | ) |
Blurs the image using box blur.
blurSize | Size of the blur in pixels. |
void Image::fill | ( | Number | r, |
Number | g, | ||
Number | b, | ||
Number | a | ||
) |
Fills the image with the specified color values.
r | Red value 0-1. |
g | Green value 0-1 |
b | Blue value 0-1 |
a | Alpha value 0-1 |
void Image::gaussianBlur | ( | float | radius, |
float | deviation | ||
) |
Blurs the image using gaussian blur.
radius | Radius of the blur |
deviation | Standard deviation of the gaussian distribution |
Color Image::getPixel | ( | int | x, |
int | y | ||
) |
Returns the pixel color at specified position.
x | X position of pixel. |
y | Y position of pixel. |
char * Image::getPixels | ( | ) |
Returns the raw image data.
char * Image::getPixelsInRect | ( | unsigned int | x, |
unsigned int | y, | ||
unsigned int | width, | ||
unsigned int | height | ||
) |
Returns an area of the image buffer.
The area can go outside of image bounds, in which case the pixels not within the image are zeroed out. This method allocates new memory for the returned buffer and you must free it manually.
x | X position of the area to return. |
y | Y position of the area to return. |
width | Width of the area to return. |
height | Height of the area to return. |
void Image::line | ( | int | x0, |
int | y0, | ||
int | x1, | ||
int | y1, | ||
Color | col | ||
) |
Draws a line with specified color.
x0 | Starting x position. |
y0 | Starting y position. |
x1 | Ending x position. |
y1 | Ending y position. |
col | Color to use. |
void Image::lineTo | ( | int | x, |
int | y, | ||
Color | col | ||
) |
Draws a line to specified position.
x | Ending x position. |
y | Ending y position. |
col | Color to use. |
bool Image::loadImage | ( | const String & | fileName | ) |
Load an image from a file.
fileName | Path to image file to load. |
void Image::move | ( | int | x, |
int | y | ||
) |
Translates brush a specified amount relative to its current position.
x | Amount to translate on X axis |
y | Amount to translate on Y axis |
void Image::moveTo | ( | int | x, |
int | y | ||
) |
Moves brush to specified position.
x | New brush position X |
y | New brush position Y |
void Image::perlinNoise | ( | int | seed, |
bool | alpha | ||
) |
Draws perlin noise in the image.
seed | Seed for the noise |
alpha | If true, affects alpha, if false only affects the color. |
bool Image::saveImage | ( | const String & | fileName | ) |
Saves the image to a file.
Currently only PNG files are supported.
fileName | Path to image file to load. |
void Image::setPixel | ( | int | x, |
int | y, | ||
Number | r, | ||
Number | g, | ||
Number | b, | ||
Number | a | ||
) |
Sets a pixel at specified coordinates to specified color.
x | X position of pixel. |
y | Y position of pixel. |
r | Red value 0-1. |
g | Green value 0-1 |
b | Blue value 0-1 |
a | Alpha value 0-1 |