Bitmap Class Reference
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Public Types | |
| enum | Orientation { Rotate_0, Rotate_90, Rotate_180, Rotate_270, Mirror_X, Mirror_Y, Orientations_Count } |
Public Member Functions | |
| Bitmap () | |
| Bitmap (const Asset &asset) | |
| Bitmap (int width, int height) | |
| Bitmap (const Image &image) | |
| ~Bitmap () | |
| unsigned short * | GetData () |
| void | Clear () |
| void | Fill (int x1, int y1, int x2, int y2, unsigned short color, unsigned char alpha=255) |
| void | Fill (unsigned short color, unsigned char alpha=255) |
| int | GetWidth (Orientation orientation=Rotate_0) const |
| int | GetHeight (Orientation orientation=Rotate_0) const |
| unsigned short | GetPixel (int x, int y) const |
| unsigned short | GetPixel (int x, int y, Orientation orientation) const |
| void | SetPixel (int x, int y, unsigned short color, Orientation orientation) |
| void | SetPixel (int x, int y, unsigned short color) |
| void | BlendPixel (int x, int y, unsigned short color, unsigned char alpha, Orientation orientation) |
| void | BlendPixel (int x, int y, unsigned short color, unsigned char alpha) |
| void | Blit (Bitmap *target, int x, int y, unsigned short modulate=0xffff, unsigned char alpha=255, Orientation orientation=Rotate_0) const |
| void | Blit (int x1, int y1, int x2, int y2, Bitmap *target, int x, int y, unsigned short modulate=0xffff, unsigned char alpha=255, Orientation orientation=Rotate_0) const |
| void | Save (Asset &asset) const |
| void | Load (const Asset &asset) |
| void | WriteToAsset (Asset *asset) const |
| void | ReadFromAsset (const Asset *asset) |
Public Attributes | |
| unsigned short * | data_ |
| Pixel data (width*height). | |
| int | width_ |
| Width of the bitmap. | |
| int | height_ |
| Height of the bitmap. | |
Member Enumeration Documentation
| enum Bitmap::Orientation |
Sometimes it is useful to rotate or flip bitmaps. The methods specified below all take an Orientation 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 orientation parameter to the blit method. All the orientation parameters default to 0 degree rotation, which means untransformed, so just omit the parameter if you don't want to think about orientations...
- Enumerator:
Constructor & Destructor Documentation
| Bitmap::Bitmap | ( | ) |
Definition at line 13 of file Bitmap.cpp.
| Bitmap::Bitmap | ( | const Asset & | asset | ) |
Definition at line 23 of file Bitmap.cpp.
| Bitmap::Bitmap | ( | int | width, | |
| int | height | |||
| ) |
Creates an empty bitmap with the specified dimensions. All pixels will be set to black (0) at creation.
- Parameters:
-
width The width of the bitmap, in pixels height The height of the bitmap, in pixels
Definition at line 34 of file Bitmap.cpp.
| Bitmap::Bitmap | ( | const Image & | image | ) |
Creates a bitmap from an Image. The width and the height of the bitmap will be taken from the image, the colors reduced from 32 to 16 bits, and the alpha channel is dropped.
- Parameters:
-
image Image to create bitmap from
Definition at line 46 of file Bitmap.cpp.
| Bitmap::~Bitmap | ( | ) |
Definition at line 68 of file Bitmap.cpp.
Member Function Documentation
| unsigned short * Bitmap::GetData | ( | ) |
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.
- Returns:
- A pointer to the pixel data (each pixel is a 16 bit color value, on the form R5G6B5)
Definition at line 129 of file Bitmap.cpp.
| void Bitmap::Clear | ( | ) |
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.
Definition at line 137 of file Bitmap.cpp.
| void Bitmap::Fill | ( | int | x1, | |
| int | y1, | |||
| int | x2, | |||
| int | y2, | |||
| unsigned short | color, | |||
| unsigned char | alpha = 255 | |||
| ) |
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).
If the specified area us outside of the bitmap, it will be clipped to the extents of the bitmap.
- 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
Definition at line 145 of file Bitmap.cpp.
| void Bitmap::Fill | ( | unsigned short | color, | |
| unsigned char | alpha = 255 | |||
| ) |
- 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
Definition at line 202 of file Bitmap.cpp.
| int Bitmap::GetWidth | ( | Orientation | orientation = Rotate_0 |
) | const |
Gets the width of the bitmap
- Returns:
- The width of the bitmap in pixels
- Parameters:
-
orientation Specifies the desired transformation to use for this operation
Definition at line 79 of file Bitmap.cpp.
| int Bitmap::GetHeight | ( | Orientation | orientation = Rotate_0 |
) | const |
Gets the height of the bitmap
- Returns:
- The height of the bitmap in pixels
- Parameters:
-
orientation Specifies the desired transformation to use for this operation
Definition at line 104 of file Bitmap.cpp.
| unsigned short Bitmap::GetPixel | ( | int | x, | |
| int | y | |||
| ) | const |
Gets the 16 bit (R5G6B5) pixel at the specified coordinate of the bitmap
- Returns:
- The pixel at the specified coordinate
- Parameters:
-
x X-coordinate of pixel to get y Y-coordinate of pixel to get
Definition at line 259 of file Bitmap.cpp.
| unsigned short Bitmap::GetPixel | ( | int | x, | |
| int | y, | |||
| Orientation | orientation | |||
| ) | const |
Gets the 16 bit (R5G6B5) pixel at the specified coordinate of the bitmap This version of GetPixel will take an Orientation 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 orientation Specifies the desired transformation to use for this operation
Definition at line 271 of file Bitmap.cpp.
| void Bitmap::SetPixel | ( | int | x, | |
| int | y, | |||
| unsigned short | color, | |||
| Orientation | orientation | |||
| ) |
Changes the pixel at the specified coordinate of the bitmap. This version of SetPixel will take an Orientation 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 orientation Specifies the desired transformation to use for this operation
Definition at line 247 of file Bitmap.cpp.
| void Bitmap::SetPixel | ( | int | x, | |
| int | y, | |||
| unsigned short | color | |||
| ) |
Changes the pixel at the specified coordinate of the bitmap.
- 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
Definition at line 236 of file Bitmap.cpp.
| void Bitmap::BlendPixel | ( | int | x, | |
| int | y, | |||
| unsigned short | color, | |||
| unsigned char | alpha, | |||
| Orientation | orientation | |||
| ) |
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 Orientation 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 orientation Specifies the desired transformation to use for this operation
Definition at line 303 of file Bitmap.cpp.
| void Bitmap::BlendPixel | ( | int | x, | |
| int | y, | |||
| unsigned short | color, | |||
| unsigned char | alpha | |||
| ) |
Blends the pixel at the specified coordinate with the specified color, using the specified alpha value as a blend factor.
- 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
Definition at line 284 of file Bitmap.cpp.
| void Bitmap::Blit | ( | Bitmap * | target, | |
| int | x, | |||
| int | y, | |||
| unsigned short | modulate = 0xffff, |
|||
| unsigned char | alpha = 255, |
|||
| Orientation | orientation = Rotate_0 | |||
| ) | const |
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 orientation Specifies the desired transformation to use for this operation
Definition at line 370 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, |
|||
| Orientation | orientation = Rotate_0 | |||
| ) | const |
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.
- 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 orientation Specifies the desired transformation to use for this operation
Definition at line 378 of file Bitmap.cpp.
| void Bitmap::Save | ( | Asset & | asset | ) | const |
Definition at line 1151 of file Bitmap.cpp.
| void Bitmap::Load | ( | const Asset & | asset | ) |
Definition at line 1166 of file Bitmap.cpp.
| void Bitmap::WriteToAsset | ( | Asset * | asset | ) | const |
Definition at line 1199 of file Bitmap.cpp.
| void Bitmap::ReadFromAsset | ( | const Asset * | asset | ) |
Definition at line 1185 of file Bitmap.cpp.
Member Data Documentation
| unsigned short* Bitmap::data_ |
| int Bitmap::width_ |
| int Bitmap::height_ |





