Polycode
Polycode::Image Class Reference

An image in memory. More...

Inherited by Polycode::Label.

List of all members.

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.

Detailed Description

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.


Constructor & Destructor Documentation

Image::Image ( const String fileName)

Create image from file name.

Parameters:
fileNamePath to image file to load.
Image::Image ( int  width,
int  height,
int  type = IMAGE_RGBA 
)

Create a blank image of specified size and type.

Parameters:
widthWidth of the image to create.
heightHeight of the image to create.
typeType 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.

Parameters:
dataData buffer to set contents from.
widthWidth of the image to create.
heightHeight of the image to create.
typeType of image to create. Can be IMAGE_RGBA or IMAGE_RGB.
Image::Image ( Image copyImage)

Create an image from another image.

Parameters:
copyImageThe image to copy.

Member Function Documentation

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.

Parameters:
widthWidth of the image to create.
heightHeight of the image to create.
void Image::drawRect ( int  x,
int  y,
int  w,
int  h,
Color  col 
)

Draws a rectangle with specified color.

Parameters:
xRectangle x position.
yRectangle y position.
wRectangle width.
hRectangle height.
colColor to use.
void Image::fastBlur ( int  blurSize)

Blurs the image using box blur.

Parameters:
blurSizeSize of the blur in pixels.
void Image::fill ( Number  r,
Number  g,
Number  b,
Number  a 
)

Fills the image with the specified color values.

Parameters:
rRed value 0-1.
gGreen value 0-1
bBlue value 0-1
aAlpha value 0-1
void Image::gaussianBlur ( float  radius,
float  deviation 
)

Blurs the image using gaussian blur.

Parameters:
radiusRadius of the blur
deviationStandard deviation of the gaussian distribution
Color Image::getPixel ( int  x,
int  y 
)

Returns the pixel color at specified position.

Parameters:
xX position of pixel.
yY position of pixel.
Returns:
Pixel color at specified position.
char * Image::getPixels ( )

Returns the raw image data.

Returns:
Pointer to 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.

Parameters:
xX position of the area to return.
yY position of the area to return.
widthWidth of the area to return.
heightHeight of the area to return.
void Image::line ( int  x0,
int  y0,
int  x1,
int  y1,
Color  col 
)

Draws a line with specified color.

Parameters:
x0Starting x position.
y0Starting y position.
x1Ending x position.
y1Ending y position.
colColor to use.
void Image::lineTo ( int  x,
int  y,
Color  col 
)

Draws a line to specified position.

Parameters:
xEnding x position.
yEnding y position.
colColor to use.
bool Image::loadImage ( const String fileName)

Load an image from a file.

Parameters:
fileNamePath to image file to load.
Returns:
True if successfully loaded, false otherwise.
void Image::move ( int  x,
int  y 
)

Translates brush a specified amount relative to its current position.

Parameters:
xAmount to translate on X axis
yAmount to translate on Y axis
void Image::moveTo ( int  x,
int  y 
)

Moves brush to specified position.

Parameters:
xNew brush position X
yNew brush position Y
void Image::perlinNoise ( int  seed,
bool  alpha 
)

Draws perlin noise in the image.

Parameters:
seedSeed for the noise
alphaIf 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.

Parameters:
fileNamePath to image file to load.
Returns:
True if successfully loaded, false otherwise.
void Image::setPixel ( int  x,
int  y,
Number  r,
Number  g,
Number  b,
Number  a 
)

Sets a pixel at specified coordinates to specified color.

Parameters:
xX position of pixel.
yY position of pixel.
rRed value 0-1.
gGreen value 0-1
bBlue value 0-1
aAlpha value 0-1
void Image::setPixel ( int  x,
int  y,
Color  col 
)

Sets a pixel at specified coordinates to specified color.

Parameters:
xX position of pixel.
yY position of pixel.
colColor to set.