DynRPG  v0.14a
RM2k3 Plugin SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
Public Member Functions | Static Public Member Functions | Public Attributes
RPG::Image Class Reference

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

List of all members.

Public Member Functions

void applyPalette ()
 Applies palette changes.
unsigned char & pixel (int x, int y)
 Returns a reference to a certain pixel.
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 (RPG::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, RPG::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)
 Draws text onto the image.

Static Public Member Functions

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

Public Attributes

unsigned char * pixels
 Pointer to direct pixel data (stored from top to bottom)
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

Applies palette changes.

Clears the image without resizing or freeing it.

See also:
free
destroy
void RPG::Image::copy ( RPG::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 *)
static RPG::Image* RPG::Image::create ( ) [static]

Creates an empty image.

Returns:
Pointer to the image
See also:
create(int, int)
create(RPG::Image *)
destroy
static RPG::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
static RPG::Image* RPG::Image::create ( RPG::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
static void RPG::Image::destroy ( RPG::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
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)
void RPG::Image::draw ( int  x,
int  y,
RPG::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)
void RPG::Image::drawText ( 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
void RPG::Image::free ( )

Frees the image and sets its size to zero.

See also:
init
clear
destroy
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
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.
unsigned char& RPG::Image::pixel ( int  x,
int  y 
)

Returns a reference to a certain pixel.

Parameters:
xX coordinate of the pixel
yY coordinate of the pixel
Returns:
Reference to the pixel
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

Copies the palette from the system (necessary for drawText)

See also:
drawText
setPalette

Member Data Documentation

Alpha value (0 is invisible, 255 is fully visible)

Processed palette array (16 bit - do not use directly)

Brightness for which the appliedPalette was calculated.

If true, the image will automatically resize when loaded from a file.

First color effect.

Second color effect.

Height of the image.

Palette array (24 bit)

unsigned char* RPG::Image::pixels

Pointer to direct pixel data (stored from top to bottom)

If true, color 0 will be used as transparent color.

Width of the image.

 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator