Bitmap Class Reference
[Graphics]

Public Types | |
| enum | Transformation { NoTransformation, Rotate_90, Rotate_180, Rotate_270, Mirror_X, Mirror_Y, Transformations_Count } |
Public Member Functions | |
| Bitmap () | |
| virtual StringId | GetType ()=0 |
| virtual | ~Bitmap () |
| virtual unsigned short * | GetColorData () const |
| virtual unsigned char * | GetAlphaData () const |
| virtual int | GetHPitch () const |
| virtual int | GetVPitch () const |
| virtual int | GetHOffset () const |
| virtual int | GetVOffset () const |
| virtual void | Clear () |
| virtual void | Fill (unsigned short color, unsigned char alpha=255) |
| virtual void | Fill (int x1, int y1, int x2, int y2, unsigned short color, unsigned char alpha=255) |
| virtual void | FillAlpha (unsigned char alpha) |
| virtual void | FillAlpha (int x1, int y1, int x2, int y2, unsigned char alpha) |
| virtual int | GetWidth (Transformation transformation=NoTransformation) const |
| virtual int | GetHeight (Transformation transformation=NoTransformation) const |
| virtual unsigned short | GetPixelColor (int x, int y, Transformation transformation=NoTransformation) const |
| virtual unsigned char | GetPixelAlpha (int x, int y, Transformation transformation=NoTransformation) const |
| virtual void | SetPixelColor (int x, int y, unsigned short color, Transformation transformation=NoTransformation) |
| virtual void | SetPixelAlpha (int x, int y, unsigned char alpha, Transformation transformation=NoTransformation) |
| virtual void | BlendPixel (int x, int y, unsigned short color, unsigned char alpha, Transformation transformation=NoTransformation) |
| virtual void | Blit (Bitmap &target, int x, int y, unsigned short modulate=0xffff, unsigned char alpha=255, Transformation transformation=NoTransformation) const |
| virtual void | Blit (int x1, int y1, int x2, int y2, Bitmap &target, int x, int y, unsigned short modulate=0xffff, unsigned char alpha=255, Transformation transformation=NoTransformation) const |
| virtual void | Copy (Bitmap &target, int x, int y, unsigned short modulate=0xffff, Transformation transformation=NoTransformation) const |
| virtual void | Copy (int x1, int y1, int x2, int y2, Bitmap &target, int x, int y, unsigned short modulate=0xffff, Transformation transformation=NoTransformation) const |
| virtual void | Save (Asset &asset) const =0 |
| virtual void | Load (const Asset &asset)=0 |
| virtual void | WriteToAsset (Asset *asset) const =0 |
| virtual void | ReadFromAsset (const Asset *asset)=0 |
Protected Member Functions | |
| void | TransformCoordinates (int &x, int &y, Transformation transformation) const |
| bool | Clip (int &sourceX, int &sourceY, int &sourceWidth, int &sourceHeight, int &targetX, int &targetY, int targetWidth, int targetHeight, Transformation transformation) const |
Protected Attributes | |
| unsigned short * | color_ |
| Pixel color data (hPitch*vPitch). | |
| unsigned char * | alpha_ |
| Pixel alpha data (width*height). | |
| int | width_ |
| Width of the bitmap. | |
| int | height_ |
| Height of the bitmap. | |
| int | hPitch_ |
| Horizontal pitch (dimension) of the bitmap. | |
| int | vPitch_ |
| Vertical pitch (dimension) of the bitmap. | |
| int | hOffset_ |
| Horizontal offset from bitmap origin to data. | |
| int | vOffset_ |
| Vertical offset from bitmap origin to data. | |
Detailed Description
A Bitmap is simply a collection of 16-bit color values with a width and a height. It is typically used as blit target, and is also what you pass on to the Present method of Platform_Screen to display stuff.Bitmaps can be blitted onto other bitmaps, but this is quite slow as the code is not yet optimized. It is recommended that you use just one bitmap (for your back buffer) and make all your other art of the type Bitmap_RLE8, as this can be blitted onto a Bitmap in the same way, but is much, much faster.
- Todo:
- Update Clip code to handle offset/pitch. Might be fixed, but needs cleaning up (transforms and such)
Additive blitting
Make TransformCoordinates non-inline
Definition at line 32 of file Bitmap.h.
Member Enumeration Documentation
Sometimes it is useful to rotate or flip bitmaps. The methods specified below all takes a Transformation parameter, which will cause the method to function as if the bitmap was transformed in the manner specified, without actually transforming any pixel data. This means you can blit an image upside down by just passing Mirror_Y as the transformation parameter to the blit method. All the transformation parameters default to untransformed, so just omit the parameter if you don't want to think about transformations...
- Enumerator:
Constructor & Destructor Documentation
| Bitmap::Bitmap | ( | ) |
Definition at line 11 of file Bitmap.cpp.
| virtual Bitmap::~Bitmap | ( | ) | [virtual] |
Member Function Documentation
| virtual StringId Bitmap::GetType | ( | ) | [pure virtual] |
The Bitmap class is an abstract interface, and is implemented by a number of different bitmap classes. The GetType method retrieves the name of the actual implementation for the Bitmap instance.
- Returns:
- A StringId containing the class name of this bitmaps implementation
Implemented in Bitmap_16bit, Bitmap_16bitAlpha, Bitmap_16bitAlphaCrop, Bitmap_Alpha, Bitmap_RLE16, and Bitmap_RLE8.
| unsigned short * Bitmap::GetColorData | ( | ) | const [virtual] |
Get the raw data pointer to the bitmap data. This should be used with care, as it can be quite easy to read outside the valid memory area. There might be Bitmap implementations which doesn't have color data, so this method can return 0.
- Returns:
- A pointer to the pixel data (each pixel is a 16 bit color value, on the form R5G6B5)
Definition at line 26 of file Bitmap.cpp.
| unsigned char * Bitmap::GetAlphaData | ( | ) | const [virtual] |
Get the raw data pointer to the bitmaps alpha channel data. This should be used with care, as it can be quite easy to read outside the valid memory area. There might be Bitmap implementations which doesn't have an alpha channel, so this method can return 0.
- Returns:
- A pointer to the alpha channel data (each pixel is a 8 bit transparency value, 0=Fully transparent, 255=Fully Opaque
Definition at line 34 of file Bitmap.cpp.
| int Bitmap::GetHPitch | ( | ) | const [virtual] |
Definition at line 43 of file Bitmap.cpp.
| int Bitmap::GetVPitch | ( | ) | const [virtual] |
Definition at line 51 of file Bitmap.cpp.
| int Bitmap::GetHOffset | ( | ) | const [virtual] |
Definition at line 59 of file Bitmap.cpp.
| int Bitmap::GetVOffset | ( | ) | const [virtual] |
Definition at line 67 of file Bitmap.cpp.
| void Bitmap::Clear | ( | ) | [virtual] |
Sets every pixel of the bitmap to black (0). Internally this just uses a memset for speed. If you want to clear to any other color, you need to use the Fill method, which is slightly slower. If the bitmap has an alpha channel, it will be cleared too.
Reimplemented in Bitmap_RLE16, and Bitmap_RLE8.
Definition at line 75 of file Bitmap.cpp.
| void Bitmap::Fill | ( | unsigned short | color, | |
| unsigned char | alpha = 255 | |||
| ) | [virtual] |
Fills the entire bitmap with the specified color. If an alpha value is specified, the fill will be semi-transparent, and what was already in the bitmap will show through. If the bitmap has an alpha channel, it won't be affected by Fill.
- Parameters:
-
color 16 bit color (R5G6B5) to fill the specified area with alpha Level of transparency for the fill. 0=Fully transparent, 255=Fully Opaque
Reimplemented in Bitmap_RLE16, and Bitmap_RLE8.
Definition at line 180 of file Bitmap.cpp.
| void Bitmap::Fill | ( | int | x1, | |
| int | y1, | |||
| int | x2, | |||
| int | y2, | |||
| unsigned short | color, | |||
| unsigned char | alpha = 255 | |||
| ) | [virtual] |
Fills the specified area of the bitmap with the specified color. If an alpha value is specified, the filled area will be semi-transparent, and what was already in the bitmap will show through. Note that the filled area will include the x2 and y2 pixels as well (it won't leave the last pixel blank as for instance DirectX dies).
If the specified area is outside of the bitmap, it will be clipped to the extents of the bitmap. If the bitmap has an alpha channel, it won't be affected by Fill.
- Parameters:
-
x1 X-coordinate of the top-left corner of the area to be filled y1 Y-coordinate of the top-left corner of the area to be filled x2 X-coordinate of the bottom-right corner of the area to be filled y2 Y-coordinate of the bottom-right corner of the area to be filled color 16 bit color (R5G6B5) to fill the specified area with alpha Level of transparency for the fill. 0=Fully transparent, 255=Fully Opaque
Reimplemented in Bitmap_RLE16, and Bitmap_RLE8.
Definition at line 91 of file Bitmap.cpp.
| void Bitmap::FillAlpha | ( | unsigned char | alpha | ) | [virtual] |
- Parameters:
-
alpha Level of transparency for the fill. 0=Fully transparent, 255=Fully Opaque
Definition at line 288 of file Bitmap.cpp.
| void Bitmap::FillAlpha | ( | int | x1, | |
| int | y1, | |||
| int | x2, | |||
| int | y2, | |||
| unsigned char | alpha | |||
| ) | [virtual] |
- Parameters:
-
x1 X-coordinate of the top-left corner of the area to be filled y1 Y-coordinate of the top-left corner of the area to be filled x2 X-coordinate of the bottom-right corner of the area to be filled y2 Y-coordinate of the bottom-right corner of the area to be filled alpha Level of transparency for the fill. 0=Fully transparent, 255=Fully Opaque
Definition at line 235 of file Bitmap.cpp.
| int Bitmap::GetWidth | ( | Transformation | transformation = NoTransformation |
) | const [virtual] |
Gets the width of the bitmap
- Returns:
- The width of the bitmap in pixels
- Parameters:
-
transformation Specifies the desired transformation to use for this operation
Reimplemented in Bitmap_RLE16, and Bitmap_RLE8.
Definition at line 311 of file Bitmap.cpp.
| int Bitmap::GetHeight | ( | Transformation | transformation = NoTransformation |
) | const [virtual] |
Gets the height of the bitmap
- Returns:
- The height of the bitmap in pixels
- Parameters:
-
transformation Specifies the desired transformation to use for this operation
Reimplemented in Bitmap_RLE16, and Bitmap_RLE8.
Definition at line 336 of file Bitmap.cpp.
| unsigned short Bitmap::GetPixelColor | ( | int | x, | |
| int | y, | |||
| Transformation | transformation = NoTransformation | |||
| ) | const [virtual] |
Gets the 16 bit (R5G6B5) pixel at the specified coordinate of the bitmap This version of GetPixel will take an Transformation parameters, so you can get pixels as if the bitmap was transformed.
- Returns:
- The pixel at the specified coordinate
- Parameters:
-
x X-coordinate of pixel to get y Y-coordinate of pixel to get transformation Specifies the desired transformation to use for this operation
Reimplemented in Bitmap_RLE16, and Bitmap_RLE8.
Definition at line 361 of file Bitmap.cpp.
| unsigned char Bitmap::GetPixelAlpha | ( | int | x, | |
| int | y, | |||
| Transformation | transformation = NoTransformation | |||
| ) | const [virtual] |
- Parameters:
-
x X-coordinate of pixel to get y Y-coordinate of pixel to get transformation Specifies the desired transformation to use for this operation
Reimplemented in Bitmap_RLE16, and Bitmap_RLE8.
Definition at line 379 of file Bitmap.cpp.
| void Bitmap::SetPixelColor | ( | int | x, | |
| int | y, | |||
| unsigned short | color, | |||
| Transformation | transformation = NoTransformation | |||
| ) | [virtual] |
Changes the pixel at the specified coordinate of the bitmap. This version of SetPixel will take an Transformation parameters, so you can set pixels as if the bitmap was transformed.
- Parameters:
-
x X-coordinate of pixel to set y Y-coordinate of pixel to set color 16 bit color (R5G6B5) to set the specified coordinate to transformation Specifies the desired transformation to use for this operation
Reimplemented in Bitmap_RLE16, and Bitmap_RLE8.
Definition at line 398 of file Bitmap.cpp.
| void Bitmap::SetPixelAlpha | ( | int | x, | |
| int | y, | |||
| unsigned char | alpha, | |||
| Transformation | transformation = NoTransformation | |||
| ) | [virtual] |
- Parameters:
-
x X-coordinate of pixel to set y Y-coordinate of pixel to set transformation Specifies the desired transformation to use for this operation
Reimplemented in Bitmap_RLE16, and Bitmap_RLE8.
Definition at line 415 of file Bitmap.cpp.
| void Bitmap::BlendPixel | ( | int | x, | |
| int | y, | |||
| unsigned short | color, | |||
| unsigned char | alpha, | |||
| Transformation | transformation = NoTransformation | |||
| ) | [virtual] |
Blends the pixel at the specified coordinate with the specified color, using the specified alpha value as a blend factor. This version of BlenPixel will take an Transformation parameters, so you can blend pixels as if the bitmap was transformed.
- Parameters:
-
x X-coordinate of pixel to change y Y-coordinate of pixel to change color 16 bit color (R5G6B5) to blend the existing pixel with alpha Blend factor. 0=Use the existing pixel color, 255=Use the specified color transformation Specifies the desired transformation to use for this operation
Reimplemented in Bitmap_RLE16, and Bitmap_RLE8.
Definition at line 432 of file Bitmap.cpp.
| void Bitmap::Blit | ( | Bitmap & | target, | |
| int | x, | |||
| int | y, | |||
| unsigned short | modulate = 0xffff, |
|||
| unsigned char | alpha = 255, |
|||
| Transformation | transformation = NoTransformation | |||
| ) | const [virtual] |
This method will blit this bitmap onto the target bitmap at the specified coordinate. It will blit the entire bitmap onto the target, but it will perform clipping on the parts which are outside of the target.
- Parameters:
-
target Target bitmap to blit this bitmap onto x X-coordinate in the target bitmap. The top left corner of this bitmap will be drawn at this coordinate on the target bitmap y Y-coordinate in the target bitmap. The top left corner of this bitmap will be drawn at this coordinate on the target bitmap modulate 16 bit color value (R5G6B5) to modulate the source pixels with before they are written. alpha Level of transparency the bitmap will be written with. 0=Fully transparent, 255=Fully Opaque transformation Specifies the desired transformation to use for this operation
Reimplemented in Bitmap_RLE16, and Bitmap_RLE8.
Definition at line 457 of file Bitmap.cpp.
| void Bitmap::Blit | ( | int | x1, | |
| int | y1, | |||
| int | x2, | |||
| int | y2, | |||
| Bitmap & | target, | |||
| int | x, | |||
| int | y, | |||
| unsigned short | modulate = 0xffff, |
|||
| unsigned char | alpha = 255, |
|||
| Transformation | transformation = NoTransformation | |||
| ) | const [virtual] |
This method will blit a section of this bitmap onto the target bitmap at the specified coordinate. You specify the top-left and bottom-right coordinates of a rectangle you want to blit onto the target. Clipping will be performed on the parts which are outside of the target.
- Todo:
- This test must take transformations into account
- Parameters:
-
x1 X-coordinate for the top-left corner of the section of this bitmap which is to be blitted onto the target y1 Y-coordinate for the top-left corner of the section of this bitmap which is to be blitted onto the target x2 X-coordinate for the bottom-right corner of the section of this bitmap which is to be blitted onto the target y2 Y-coordinate for the bottom-right corner of the section of this bitmap which is to be blitted onto the target target Target bitmap to blit this bitmap onto x X-coordinate in the target bitmap. The top left corner of the blitted section will be drawn at this coordinate on the target bitmap y Y-coordinate in the target bitmap. The top left corner of the blitted section will be drawn at this coordinate on the target bitmap modulate 16 bit color value (R5G6B5) to modulate the source pixels with before they are written. alpha Level of transparency the bitmap will be written with. 0=Fully transparent, 255=Fully Opaque transformation Specifies the desired transformation to use for this operation
Reimplemented in Bitmap_RLE16, and Bitmap_RLE8.
Definition at line 465 of file Bitmap.cpp.
| void Bitmap::Copy | ( | Bitmap & | target, | |
| int | x, | |||
| int | y, | |||
| unsigned short | modulate = 0xffff, |
|||
| Transformation | transformation = NoTransformation | |||
| ) | const [virtual] |
- Parameters:
-
target Target bitmap to blit this bitmap onto x X-coordinate in the target bitmap. The top left corner of this bitmap will be drawn at this coordinate on the target bitmap y Y-coordinate in the target bitmap. The top left corner of this bitmap will be drawn at this coordinate on the target bitmap modulate 16 bit color value (R5G6B5) to modulate the source pixels with before they are written. transformation Specifies the desired transformation to use for this operation
Reimplemented in Bitmap_RLE16, and Bitmap_RLE8.
Definition at line 1292 of file Bitmap.cpp.
| void Bitmap::Copy | ( | int | x1, | |
| int | y1, | |||
| int | x2, | |||
| int | y2, | |||
| Bitmap & | target, | |||
| int | x, | |||
| int | y, | |||
| unsigned short | modulate = 0xffff, |
|||
| Transformation | transformation = NoTransformation | |||
| ) | const [virtual] |
- Parameters:
-
x1 X-coordinate for the top-left corner of the section of this bitmap which is to be blitted onto the target y1 Y-coordinate for the top-left corner of the section of this bitmap which is to be blitted onto the target x2 X-coordinate for the bottom-right corner of the section of this bitmap which is to be blitted onto the target y2 Y-coordinate for the bottom-right corner of the section of this bitmap which is to be blitted onto the target target Target bitmap to blit this bitmap onto x X-coordinate in the target bitmap. The top left corner of the blitted section will be drawn at this coordinate on the target bitmap y Y-coordinate in the target bitmap. The top left corner of the blitted section will be drawn at this coordinate on the target bitmap modulate 16 bit color value (R5G6B5) to modulate the source pixels with before they are written. transformation Specifies the desired transformation to use for this operation
Reimplemented in Bitmap_RLE16, and Bitmap_RLE8.
Definition at line 1300 of file Bitmap.cpp.
| virtual void Bitmap::Save | ( | Asset & | asset | ) | const [pure virtual] |
Implemented in Bitmap_16bit, Bitmap_16bitAlpha, Bitmap_16bitAlphaCrop, Bitmap_Alpha, Bitmap_RLE16, and Bitmap_RLE8.
| virtual void Bitmap::Load | ( | const Asset & | asset | ) | [pure virtual] |
Implemented in Bitmap_16bit, Bitmap_16bitAlpha, Bitmap_16bitAlphaCrop, Bitmap_Alpha, Bitmap_RLE16, and Bitmap_RLE8.
| virtual void Bitmap::WriteToAsset | ( | Asset * | asset | ) | const [pure virtual] |
Implemented in Bitmap_16bit, Bitmap_16bitAlpha, Bitmap_16bitAlphaCrop, Bitmap_Alpha, Bitmap_RLE16, and Bitmap_RLE8.
| virtual void Bitmap::ReadFromAsset | ( | const Asset * | asset | ) | [pure virtual] |
Implemented in Bitmap_16bit, Bitmap_16bitAlpha, Bitmap_16bitAlphaCrop, Bitmap_Alpha, Bitmap_RLE16, and Bitmap_RLE8.
| void Bitmap::TransformCoordinates | ( | int & | x, | |
| int & | y, | |||
| Transformation | transformation | |||
| ) | const [protected] |
| bool Bitmap::Clip | ( | int & | sourceX, | |
| int & | sourceY, | |||
| int & | sourceWidth, | |||
| int & | sourceHeight, | |||
| int & | targetX, | |||
| int & | targetY, | |||
| int | targetWidth, | |||
| int | targetHeight, | |||
| Transformation | transformation | |||
| ) | const [protected] |
Member Data Documentation
unsigned short* Bitmap::color_ [protected] |
unsigned char* Bitmap::alpha_ [protected] |
int Bitmap::width_ [protected] |
int Bitmap::height_ [protected] |
int Bitmap::hPitch_ [protected] |
int Bitmap::vPitch_ [protected] |
int Bitmap::hOffset_ [protected] |
int Bitmap::vOffset_ [protected] |
Reproduction/republishing of any material on this site without permission is strictly prohibited.
