|
wavelength 1.0.0
|
Pixel rectangle with an optional palette and a chain of smaller mipmaps. More...
#include <rndbitmap.h>
Public Types | |
| enum | Order { kOrderRGBA = 1 , kOrderGs = 2 , kOrderSwizzled = 4 } |
| The bits of mOrder. More... | |
Public Member Functions | |
| RndBitmap () | |
| Construct an empty bitmap. | |
| ~RndBitmap () | |
| Release the pixels and the mipmaps. | |
| int | NumMips () const |
| Count the mipmaps that follow the bitmap. | |
| int | PixelBytes () const |
| Report the size of the pixels in bytes. | |
| int | PaletteBytes () const |
| Report the size of the palette in bytes, or 0 for a bitmap without one. | |
| void | NormalizeLayout () |
| Derive the row size when it is unset, and drop the swizzled order from a bitmap too small or too deep for it. | |
| unsigned char | NearestColor (unsigned char nRed, unsigned char nGreen, unsigned char nBlue, unsigned char nAlpha) const |
| Find the palette entry nearest to a colour, by the sum of the component differences. | |
| void | ReadColor (const unsigned char *pData, unsigned char &nRed, unsigned char &nGreen, unsigned char &nBlue, unsigned char &nAlpha) const |
| Decode one stored colour, a palette entry or a direct pixel, in the bitmap's format. | |
| void | WriteColor (unsigned char nRed, unsigned char nGreen, unsigned char nBlue, unsigned char nAlpha, unsigned char *pData) const |
| Encode one colour in the bitmap's format. | |
| void | SetMip (std::unique_ptr< RndBitmap > pMip) |
| Make a bitmap of half the size, with the same palette, the next mipmap. | |
| void | Reset () |
| Release the pixels and the mipmaps and empty the bitmap. | |
| void | Create (const RndBitmap &source, int nBpp, int nOrder) |
| Make a copy of another bitmap and its mipmaps in another format. | |
| void | Create (int nWidth, int nHeight, int nRowBytes, int nBpp, int nOrder) |
| Allocate a bitmap of a size and a format, with a palette when it has 8 bits per pixel or fewer. | |
| void | Create (int nWidth, int nHeight, int nRowBytes, int nBpp, int nOrder, unsigned char *pPalette, unsigned char *pPixels, unsigned char *pBuffer) |
| Describe pixels and a palette that already exist. | |
| void | Create (unsigned char *pBuffer) |
| Describe a bitmap that Save() wrote into a buffer, without copying it. | |
| int | PixelOffset (int nX, int nY, int &nHighNibble) const |
| Find the byte of the pixels with a pixel, in the GS block order for a swizzled bitmap. | |
| int | PixelIndex (int nX, int nY) const |
| Report the palette index of a pixel. | |
| void | SetPixelIndex (int nX, int nY, unsigned char nIndex) |
| Set the palette index of a pixel. | |
| int | MaxPixelIndex () const |
| Report the highest palette index any pixel uses. | |
| void | ConvertTo8Bpp () |
| Convert the pixels to 8 bits per pixel, keeping the palette entries. | |
| bool | LoadMip (const char *pszPath) |
| Load a BMP file and add it as the last mipmap. | |
| void | LoadAlpha (const char *pszPath) |
| Take the alpha of each pixel from the red of a BMP file of the same size and palette use. | |
| bool | LoadBmp (const char *pszPath) |
| Load an uncompressed BMP file of 4 or more bits per pixel. | |
| void | SaveBmp (const char *pszPath) const |
| Write the bitmap as a BMP file. | |
| bool | SamePalette (const RndBitmap &other) const |
| Report whether another bitmap has the same palette entries. | |
| bool | SameFormat (const RndBitmap &other) const |
| Report whether another bitmap stores pixels the same way, so rows copy unchanged. | |
| void | Blit (const RndBitmap &source, int nDestX, int nDestY, int nSourceX, int nSourceY, int nWidth, int nHeight) |
| Copy a rectangle of another bitmap into this one, converting the colours. | |
| void | PixelColor (int nX, int nY, unsigned char &nRed, unsigned char &nGreen, unsigned char &nBlue, unsigned char &nAlpha) const |
| Report the colour of a pixel. | |
| void | SetPixelColor (int nX, int nY, unsigned char nRed, unsigned char nGreen, unsigned char nBlue, unsigned char nAlpha) |
| Set the colour of a pixel, or its nearest palette entry. | |
| int | PaletteOffset (int nIndex) const |
| Map a palette index to its position in the palette, which the GS order of an 8-bit palette permutes. | |
| void | PaletteColor (int nIndex, unsigned char &nRed, unsigned char &nGreen, unsigned char &nBlue, unsigned char &nAlpha) const |
| Report a palette entry. | |
| void | SetPaletteColor (int nIndex, unsigned char nRed, unsigned char nGreen, unsigned char nBlue, unsigned char nAlpha) |
| Set a palette entry. | |
| void | Print (PrnStream &stream) const |
| Write the size, the format, and the mipmap count of the bitmap. | |
| void | Save (BinStream &stream) const |
| Write a 16-byte header, the palette, and the pixels of the bitmap and each mipmap. | |
| unsigned short | GetWidth () const |
| unsigned short | GetHeight () const |
| unsigned short | GetRowBytes () const |
| unsigned char | GetBpp () const |
| unsigned char | GetOrder () const |
| unsigned char * | GetPixels () const |
| unsigned char * | GetPalette () const |
| const RndBitmap * | GetMip () const |
| RndBitmap * | GetMip () |
Static Public Member Functions | |
| static bool | CheckDims (int nWidth, int nHeight, int nBpp) |
| Report whether a size and a depth are valid, with a notice when they are not. | |
Static Public Attributes | |
| static unsigned char | sRev |
| The format version Save() writes. | |
Pixel rectangle with an optional palette and a chain of smaller mipmaps.
The class is not polymorphic and emits no RTTI descriptor, so the name and the member titles are inferred, the titles from the labels of its text dump. RndTex has one. A palette entry and a 32-bit pixel are four bytes in the byte order mOrder selects. A bitmap of 4 or 8 bits per pixel indexes its palette, and one of 16, 24, or 32 bits stores its colours directly.
| enum RndBitmap::Order |
|
inline |
Construct an empty bitmap.
|
inline |
Release the pixels and the mipmaps.
| int RndBitmap::NumMips | ( | ) | const |
Count the mipmaps that follow the bitmap.
| int RndBitmap::PixelBytes | ( | ) | const |
Report the size of the pixels in bytes.
| int RndBitmap::PaletteBytes | ( | ) | const |
Report the size of the palette in bytes, or 0 for a bitmap without one.
| void RndBitmap::NormalizeLayout | ( | ) |
Derive the row size when it is unset, and drop the swizzled order from a bitmap too small or too deep for it.
The name is inferred.
| unsigned char RndBitmap::NearestColor | ( | unsigned char | nRed, |
| unsigned char | nGreen, | ||
| unsigned char | nBlue, | ||
| unsigned char | nAlpha ) const |
Find the palette entry nearest to a colour, by the sum of the component differences.
| nRed | The red component. |
| nGreen | The green component. |
| nBlue | The blue component. |
| nAlpha | The alpha component. |
| void RndBitmap::ReadColor | ( | const unsigned char * | pData, |
| unsigned char & | nRed, | ||
| unsigned char & | nGreen, | ||
| unsigned char & | nBlue, | ||
| unsigned char & | nAlpha ) const |
Decode one stored colour, a palette entry or a direct pixel, in the bitmap's format.
The name is inferred.
| pData | The stored colour. |
| nRed | Receives the red component. |
| nGreen | Receives the green component. |
| nBlue | Receives the blue component. |
| nAlpha | Receives the alpha component. |
| void RndBitmap::WriteColor | ( | unsigned char | nRed, |
| unsigned char | nGreen, | ||
| unsigned char | nBlue, | ||
| unsigned char | nAlpha, | ||
| unsigned char * | pData ) const |
Encode one colour in the bitmap's format.
The name is inferred.
| nRed | The red component. |
| nGreen | The green component. |
| nBlue | The blue component. |
| nAlpha | The alpha component. |
| pData | Receives the stored colour. |
| void RndBitmap::SetMip | ( | std::unique_ptr< RndBitmap > | pMip | ) |
Make a bitmap of half the size, with the same palette, the next mipmap.
A bitmap of the wrong size or palette is refused with a notice.
| pMip | The mipmap, or null to change nothing. |
| void RndBitmap::Reset | ( | ) |
Release the pixels and the mipmaps and empty the bitmap.
| void RndBitmap::Create | ( | const RndBitmap & | source, |
| int | nBpp, | ||
| int | nOrder ) |
Make a copy of another bitmap and its mipmaps in another format.
The mipmaps share this bitmap's palette.
| source | The bitmap to copy. |
| nBpp | The bits per pixel. |
| nOrder | The Order bits. |
|
static |
Report whether a size and a depth are valid, with a notice when they are not.
| nWidth | The width. |
| nHeight | The height. |
| nBpp | The bits per pixel. |
| void RndBitmap::Create | ( | int | nWidth, |
| int | nHeight, | ||
| int | nRowBytes, | ||
| int | nBpp, | ||
| int | nOrder ) |
Allocate a bitmap of a size and a format, with a palette when it has 8 bits per pixel or fewer.
| nWidth | The width. |
| nHeight | The height. |
| nRowBytes | The row size in bytes, or 0 to derive it. |
| nBpp | The bits per pixel. |
| nOrder | The Order bits. |
| void RndBitmap::Create | ( | int | nWidth, |
| int | nHeight, | ||
| int | nRowBytes, | ||
| int | nBpp, | ||
| int | nOrder, | ||
| unsigned char * | pPalette, | ||
| unsigned char * | pPixels, | ||
| unsigned char * | pBuffer ) |
Describe pixels and a palette that already exist.
An invalid size or depth changes nothing. A palette on a bitmap of more than 8 bits per pixel is dropped with a notice.
| nWidth | The width. |
| nHeight | The height. |
| nRowBytes | The row size in bytes, or 0 to derive it. |
| nBpp | The bits per pixel. |
| nOrder | The Order bits. |
| pPalette | The palette, or null. |
| pPixels | The pixels. |
| pBuffer | The block the bitmap releases with Reset(), or null. |
| void RndBitmap::Create | ( | unsigned char * | pBuffer | ) |
Describe a bitmap that Save() wrote into a buffer, without copying it.
The bitmap takes the buffer. The data after the 16-byte header has to be aligned to 16 bytes. The name is inferred.
| pBuffer | The buffer. |
| int RndBitmap::PixelOffset | ( | int | nX, |
| int | nY, | ||
| int & | nHighNibble ) const |
Find the byte of the pixels with a pixel, in the GS block order for a swizzled bitmap.
The name is inferred.
| nX | The column. |
| nY | The row. |
| nHighNibble | Receives whether a 4-bit pixel is in the high half of the byte. |
| int RndBitmap::PixelIndex | ( | int | nX, |
| int | nY ) const |
Report the palette index of a pixel.
| nX | The column. |
| nY | The row. |
| void RndBitmap::SetPixelIndex | ( | int | nX, |
| int | nY, | ||
| unsigned char | nIndex ) |
Set the palette index of a pixel.
| nX | The column. |
| nY | The row. |
| nIndex | The index. |
| int RndBitmap::MaxPixelIndex | ( | ) | const |
Report the highest palette index any pixel uses.
| void RndBitmap::ConvertTo8Bpp | ( | ) |
Convert the pixels to 8 bits per pixel, keeping the palette entries.
Only as many palette bytes as the old depth has are copied. The name is inferred.
| bool RndBitmap::LoadMip | ( | const char * | pszPath | ) |
Load a BMP file and add it as the last mipmap.
| pszPath | The file. |
| void RndBitmap::LoadAlpha | ( | const char * | pszPath | ) |
Take the alpha of each pixel from the red of a BMP file of the same size and palette use.
Palette bitmaps combine the two palettes, growing to 8 bits per pixel when the combination needs it.
| pszPath | The file. |
| bool RndBitmap::LoadBmp | ( | const char * | pszPath | ) |
Load an uncompressed BMP file of 4 or more bits per pixel.
A file whose path includes _tb makes black transparent, _gw takes the alpha from the red and turns the colour white, and _ga takes the alpha from the red.
| pszPath | The file. |
| void RndBitmap::SaveBmp | ( | const char * | pszPath | ) | const |
Write the bitmap as a BMP file.
The bitmap has to be in the default byte order.
| pszPath | The file. |
| bool RndBitmap::SamePalette | ( | const RndBitmap & | other | ) | const |
Report whether another bitmap has the same palette entries.
| other | The other bitmap. |
| bool RndBitmap::SameFormat | ( | const RndBitmap & | other | ) | const |
Report whether another bitmap stores pixels the same way, so rows copy unchanged.
| other | The other bitmap. |
| void RndBitmap::Blit | ( | const RndBitmap & | source, |
| int | nDestX, | ||
| int | nDestY, | ||
| int | nSourceX, | ||
| int | nSourceY, | ||
| int | nWidth, | ||
| int | nHeight ) |
Copy a rectangle of another bitmap into this one, converting the colours.
| source | The bitmap to copy from. |
| nDestX | The left column of the destination. |
| nDestY | The top row of the destination. |
| nSourceX | The left column of the source. |
| nSourceY | The top row of the source. |
| nWidth | The width. |
| nHeight | The height. |
| void RndBitmap::PixelColor | ( | int | nX, |
| int | nY, | ||
| unsigned char & | nRed, | ||
| unsigned char & | nGreen, | ||
| unsigned char & | nBlue, | ||
| unsigned char & | nAlpha ) const |
Report the colour of a pixel.
| nX | The column. |
| nY | The row. |
| nRed | Receives the red component. |
| nGreen | Receives the green component. |
| nBlue | Receives the blue component. |
| nAlpha | Receives the alpha component. |
| void RndBitmap::SetPixelColor | ( | int | nX, |
| int | nY, | ||
| unsigned char | nRed, | ||
| unsigned char | nGreen, | ||
| unsigned char | nBlue, | ||
| unsigned char | nAlpha ) |
Set the colour of a pixel, or its nearest palette entry.
| nX | The column. |
| nY | The row. |
| nRed | The red component. |
| nGreen | The green component. |
| nBlue | The blue component. |
| nAlpha | The alpha component. |
| int RndBitmap::PaletteOffset | ( | int | nIndex | ) | const |
Map a palette index to its position in the palette, which the GS order of an 8-bit palette permutes.
The name is inferred.
| nIndex | The index. |
| void RndBitmap::PaletteColor | ( | int | nIndex, |
| unsigned char & | nRed, | ||
| unsigned char & | nGreen, | ||
| unsigned char & | nBlue, | ||
| unsigned char & | nAlpha ) const |
Report a palette entry.
| nIndex | The index. |
| nRed | Receives the red component. |
| nGreen | Receives the green component. |
| nBlue | Receives the blue component. |
| nAlpha | Receives the alpha component. |
| void RndBitmap::SetPaletteColor | ( | int | nIndex, |
| unsigned char | nRed, | ||
| unsigned char | nGreen, | ||
| unsigned char | nBlue, | ||
| unsigned char | nAlpha ) |
Set a palette entry.
| nIndex | The index. |
| nRed | The red component. |
| nGreen | The green component. |
| nBlue | The blue component. |
| nAlpha | The alpha component. |
| void RndBitmap::Print | ( | PrnStream & | stream | ) | const |
Write the size, the format, and the mipmap count of the bitmap.
| stream | The stream to write to. |
| void RndBitmap::Save | ( | BinStream & | stream | ) | const |
Write a 16-byte header, the palette, and the pixels of the bitmap and each mipmap.
| stream | The stream to write to. |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
static |
The format version Save() writes.