Used for image buffers (8 bit)
More...
#include <Image.h>
|
void | applyPalette () |
| Applies palette changes.
|
|
unsigned char & | 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)
|
|
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 Image * | create () |
| Creates an empty image.
|
|
static Image * | create (int newWidth, int newHeight) |
| Creates an image with a certain width and height.
|
|
static Image * | create (Image *templateImage) |
| Creates a copy of an image.
|
|
static void | destroy (Image *&image) |
| Destroys an image.
|
|
|
unsigned char * | pixels |
| 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.
|
|
ColorControl * | colorControl1 |
| First color effect.
|
|
ColorControl * | colorControl2 |
| Second color effect.
|
|
int | appliedPaletteBrightness |
| Brightness for which the appliedPalette was calculated.
|
|
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
◆ clear()
void RPG::Image::clear |
( |
| ) |
|
Clears the image without resizing or freeing it.
- See also
- free
-
destroy
◆ copy()
void RPG::Image::copy |
( |
Image * | image | ) |
|
◆ create() [1/3]
static Image * RPG::Image::create |
( |
| ) |
|
|
static |
◆ create() [2/3]
static Image * RPG::Image::create |
( |
Image * | templateImage | ) |
|
|
static |
◆ create() [3/3]
static Image * RPG::Image::create |
( |
int | newWidth, |
|
|
int | newHeight ) |
|
static |
Creates an image with a certain width and height.
- Parameters
-
newWidth | Width of the new image |
newHeight | Height 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
-
image | Pointer 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
-
x | Upper-left X coordinate at the destination image |
y | Upper-left Y coordinate at the destination image |
image | Image to draw |
srcX | Upper-left X coordinate at the source image |
srcY | Upper-left Y coordinate at the source image |
srcWidth | Width of the area to copy (defaults to the whole image) |
srcHeight | Height of the area to copy (defaults to the whole image) |
maskColor | Color 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
-
x | X coordinate to start drawing to |
y | Y coordinate to start drawing to |
newPixels | Pointer to the pixel data to copy |
srcWidth | Width of area to copy |
srcHeight | Height of the area to copy |
srcLineWidth | Width of a pixel row in the source image |
maskColor | Color 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
-
x | Upper-left X position |
y | Upper-left Y position |
text | Text to draw |
color | Text 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 ) |
◆ free()
void RPG::Image::free |
( |
| ) |
|
◆ init()
void RPG::Image::init |
( |
int | newWidth, |
|
|
int | newHeight ) |
Clears the image and initializes it to a new size.
- Parameters
-
newWidth | New image width |
newHeight | New 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
-
filename | Path and filename of the file to load, including folder name and file extension. |
throwErrors | If true , an error will be shown when the image doesn't exist, otherwise the image will just be empty. |
autoResize | If 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
-
x | X coordinate of the pixel |
y | Y 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
-
newPalette | Pointer to the palette array to copy |
- See also
- setSystemPalette
-
copy
◆ setSystemPalette()
void RPG::Image::setSystemPalette |
( |
| ) |
|
The documentation for this class was generated from the following file: