DynRPG v0.32 Unofficial
Plugin SDK
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
RPG::Image Class Reference

Used for image buffers (8 bit) More...

#include <Image.h>

Public Member Functions

void applyPalette ()
 Applies palette changes.
 
unsigned charpixel (int x, int y)
 Returns a reference to a certain pixel. Each pixel contains the palette ID (so one could do image->palette[image->pixel(x,y)] to get the color of a pixel at a certain x/y coordinate in GGBBRR order)
 
void free ()
 Frees the image and sets its size to zero.
 
void init (int newWidth, int newHeight)
 Clears the image and initializes it to a new size.
 
void setPalette (int *newPalette)
 Copies a palette to the image and applies it.
 
void copy (Image *image)
 Copies an RPG::Image with all its attributes to another.
 
void loadFromFile (std::string filename, bool throwErrors=true, bool autoResize=true)
 Loads an image from a file.
 
void draw (int x, int y, unsigned char *newPixels, int srcWidth, int srcHeight, int srcLineWidth, int maskColor=0)
 Copies pixels into the image.
 
void draw (int x, int y, Image *image, int srcX=0, int srcY=0, int srcWidth=-1, int srcHeight=-1, int maskColor=0)
 Draws another image (or a part of it) onto the image.
 
void clear ()
 Clears the image without resizing or freeing it.
 
void setSystemPalette ()
 Copies the palette from the system (necessary for drawText)
 
void drawText (int x, int y, std::string text, int color)
 Broken as of v 0.20. Use RPG::Image::drawString instead as it is using the same rm2k3 function, but references it in memory correctly.
 
void drawString (int x, int y, std::string text, int color)
 Draws text onto the image.
 

Static Public Member Functions

static Imagecreate ()
 Creates an empty image.
 
static Imagecreate (int newWidth, int newHeight)
 Creates an image with a certain width and height.
 
static Imagecreate (Image *templateImage)
 Creates a copy of an image.
 
static void destroy (Image *&image)
 Destroys an image.
 

Public Attributes

unsigned charpixels
 Pointer to direct pixel data (stored from top to bottom). Each pixel contains the palette ID (so one could reference it as image->palette[image->pixels[i]] to get the color of a pixel at the location in GGBBRR order)
 
int palette [256]
 Palette array (24 bit)
 
short appliedPalette [256]
 Processed palette array (16 bit - do not use directly)
 
int width
 Width of the image.
 
int height
 Height of the image.
 
bool useMaskColor
 If true, color 0 will be used as transparent color.
 
int alpha
 Alpha value (0 is invisible, 255 is fully visible)
 
bool autoResize
 If true, the image will automatically resize when loaded from a file.
 
ColorControlcolorControl1
 First color effect.
 
ColorControlcolorControl2
 Second color effect.
 
int appliedPaletteBrightness
 Brightness for which the appliedPalette was calculated.
 

Detailed Description

Used for image buffers (8 bit)

This class is the only class of which instances may be created by the plugin developer, using the create and destroy methods. It is used for all kinds of images (8 bit). There are two palette arrays: The palette array is used to store the actual 24-bit colors, and the appliedPalette array is used to store special calculated values corresponding to the current screen brightness. It uses 16-bit colors. The applyPalette method is used to recalculate the appliedPalette values. The appliedPaletteBrightness member stores the brightness value for which the appliedPalette was created. If it doesn't equal to the current screen brightness, the RPG Maker will automatically call applyPalette when the image is drawn.

I know that this is overkill and it would have been easier to draw the images to the screen first and then reduce the brightness of the pixels on the screen, but the RPG Maker decided to do it this way.

Note
Drawing images to a RPG::Canvas is very slow, as well as the drawText method. Please see the Optimization section!
See also
RPG::ColorControl
RPG::Canvas
RPG::Canvas::brightness

Member Function Documentation

◆ clear()

void RPG::Image::clear ( )

Clears the image without resizing or freeing it.

See also
free
destroy

◆ copy()

void RPG::Image::copy ( Image * image)

Copies an RPG::Image with all its attributes to another.

Instead of *image2 = *image1;, you must use image2->copy(image1);.

Parameters
imageThe image to copy (source)
See also
draw(int, int, Image *, int, int, int, int, int)
create(RPG::Image *)

◆ create() [1/3]

static Image * RPG::Image::create ( )
static

Creates an empty image.

Returns
Pointer to the image
See also
create(int, int)
create(RPG::Image *)
destroy

◆ create() [2/3]

static Image * RPG::Image::create ( Image * templateImage)
static

Creates a copy of an image.

Parameters
templateImageImage to copy
Returns
Pointer to the new image
See also
create()
create(int, int)
destroy
copy

◆ create() [3/3]

static Image * RPG::Image::create ( int newWidth,
int newHeight )
static

Creates an image with a certain width and height.

Parameters
newWidthWidth of the new image
newHeightHeight of the new image
Returns
Pointer to the image
See also
create()
create(RPG::Image *)
destroy
init

◆ destroy()

static void RPG::Image::destroy ( Image *& image)
static

Destroys an image.

Parameters
imagePointer to the image which should be destroyed
Note
This function automatically sets the pointer to zero after destroying the image.
See also
create
free
clear

◆ draw() [1/2]

void RPG::Image::draw ( int x,
int y,
Image * image,
int srcX = 0,
int srcY = 0,
int srcWidth = -1,
int srcHeight = -1,
int maskColor = 0 )

Draws another image (or a part of it) onto the image.

This part can be used to blit another image, or a certain part of it. Please keep in mind that this will produce strange results if the other image has a different palette.

Parameters
xUpper-left X coordinate at the destination image
yUpper-left Y coordinate at the destination image
imageImage to draw
srcXUpper-left X coordinate at the source image
srcYUpper-left Y coordinate at the source image
srcWidthWidth of the area to copy (defaults to the whole image)
srcHeightHeight of the area to copy (defaults to the whole image)
maskColorColor which should be transparent (can also be RPG::MASK_NONE)
Note
Please also see the Optimization section!
See also
draw(int, int, unsigned char *, int, int, int, int)

◆ draw() [2/2]

void RPG::Image::draw ( int x,
int y,
unsigned char * newPixels,
int srcWidth,
int srcHeight,
int srcLineWidth,
int maskColor = 0 )

Copies pixels into the image.

Parameters
xX coordinate to start drawing to
yY coordinate to start drawing to
newPixelsPointer to the pixel data to copy
srcWidthWidth of area to copy
srcHeightHeight of the area to copy
srcLineWidthWidth of a pixel row in the source image
maskColorColor which should be transparent (can also be RPG::MASK_NONE)
Note
Please also see the Optimization section!
See also
draw(int, int, RPG::Image *, int, int, int, int, int)

◆ drawString()

void RPG::Image::drawString ( int x,
int y,
std::string text,
int color )

Draws text onto the image.

This method will draw text onto the image, using the current system font and system graphic. Glyphs (like $A) work too.

Parameters
xUpper-left X position
yUpper-left Y position
textText to draw
colorText color to use (0 to 19)
Precondition
The image should have the same palette as the system graphic (use setSystemPalette).
Warning
This method is quite slow. Do not use it too often. Please also read the Optimization section!

In the image, there must be at least 8 pixels of extra space to the right, otherwise it will corrupt memory! The text itself needs 16 pixels vertically and 6 pixels horizontally (per character).
See also
setSystemPalette
drawText

◆ drawText()

void RPG::Image::drawText ( int x,
int y,
std::string text,
int color )

Broken as of v 0.20. Use RPG::Image::drawString instead as it is using the same rm2k3 function, but references it in memory correctly.

See also
drawString

◆ free()

void RPG::Image::free ( )

Frees the image and sets its size to zero.

See also
init
clear
destroy

◆ init()

void RPG::Image::init ( int newWidth,
int newHeight )

Clears the image and initializes it to a new size.

Parameters
newWidthNew image width
newHeightNew image height
See also
free

◆ loadFromFile()

void RPG::Image::loadFromFile ( std::string filename,
bool throwErrors = true,
bool autoResize = true )

Loads an image from a file.

This function will load an image from a BMP, PNG or XYZ file.

Parameters
filenamePath and filename of the file to load, including folder name and file extension.
throwErrorsIf true, an error will be shown when the image doesn't exist, otherwise the image will just be empty.
autoResizeIf true, the image will automatically resize to the size of the image in the file.

◆ pixel()

unsigned char & RPG::Image::pixel ( int x,
int y )

Returns a reference to a certain pixel. Each pixel contains the palette ID (so one could do image->palette[image->pixel(x,y)] to get the color of a pixel at a certain x/y coordinate in GGBBRR order)

Parameters
xX coordinate of the pixel
yY coordinate of the pixel
Returns
Reference to the pixel

◆ setPalette()

void RPG::Image::setPalette ( int * newPalette)

Copies a palette to the image and applies it.

Parameters
newPalettePointer to the palette array to copy
See also
setSystemPalette
copy

◆ setSystemPalette()

void RPG::Image::setSystemPalette ( )

Copies the palette from the system (necessary for drawText)

See also
drawText
setPalette

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