wavelength 1.0.0
Loading...
Searching...
No Matches
RndBitmap Class Reference

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.

Detailed Description

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.

Member Enumeration Documentation

◆ Order

The bits of mOrder.

Enumerator
kOrderRGBA 

Red in the lowest byte rather than blue.

kOrderGs 

Alpha from 0 to 128 and a palette in the GS entry order.

kOrderSwizzled 

Pixels in the GS block order.

Constructor & Destructor Documentation

◆ RndBitmap()

RndBitmap::RndBitmap ( )
inline

Construct an empty bitmap.

◆ ~RndBitmap()

RndBitmap::~RndBitmap ( )
inline

Release the pixels and the mipmaps.

Member Function Documentation

◆ NumMips()

int RndBitmap::NumMips ( ) const

Count the mipmaps that follow the bitmap.

Returns
The count.
Ghidra address:
NTSC-U/C: 0x0021c8e0
Ghidra address:
PAL: 0x002256f8

◆ PixelBytes()

int RndBitmap::PixelBytes ( ) const

Report the size of the pixels in bytes.

Returns
The size.
Ghidra address:
NTSC-U/C: 0x0021c918
Ghidra address:
PAL: 0x00225730

◆ PaletteBytes()

int RndBitmap::PaletteBytes ( ) const

Report the size of the palette in bytes, or 0 for a bitmap without one.

Returns
The size.
Ghidra address:
NTSC-U/C: 0x0021c928
Ghidra address:
PAL: 0x00225740

◆ NormalizeLayout()

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.

Ghidra address:
NTSC-U/C: 0x0021c950
Ghidra address:
PAL: 0x00225768

◆ NearestColor()

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.

Parameters
nRedThe red component.
nGreenThe green component.
nBlueThe blue component.
nAlphaThe alpha component.
Returns
The entry index.
Ghidra address:
NTSC-U/C: 0x0021ca10
Ghidra address:
PAL: 0x00225828

◆ ReadColor()

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.

Parameters
pDataThe stored colour.
nRedReceives the red component.
nGreenReceives the green component.
nBlueReceives the blue component.
nAlphaReceives the alpha component.
Ghidra address:
NTSC-U/C: 0x0021cb28
Ghidra address:
PAL: 0x00225940

◆ WriteColor()

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.

Parameters
nRedThe red component.
nGreenThe green component.
nBlueThe blue component.
nAlphaThe alpha component.
pDataReceives the stored colour.
Ghidra address:
NTSC-U/C: 0x0021cc80
Ghidra address:
PAL: 0x00225a98

◆ SetMip()

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.

Parameters
pMipThe mipmap, or null to change nothing.
Ghidra address:
NTSC-U/C: 0x0021cda8
Ghidra address:
PAL: 0x00225bc0

◆ Reset()

void RndBitmap::Reset ( )

Release the pixels and the mipmaps and empty the bitmap.

Ghidra address:
NTSC-U/C: 0x0021ce70
Ghidra address:
PAL: 0x00225c88

◆ Create() [1/4]

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.

Parameters
sourceThe bitmap to copy.
nBppThe bits per pixel.
nOrderThe Order bits.
Ghidra address:
NTSC-U/C: 0x0021cef0
Ghidra address:
PAL: 0x00225d08

◆ CheckDims()

bool RndBitmap::CheckDims ( int nWidth,
int nHeight,
int nBpp )
static

Report whether a size and a depth are valid, with a notice when they are not.

Parameters
nWidthThe width.
nHeightThe height.
nBppThe bits per pixel.
Returns
Whether they are valid.
Ghidra address:
NTSC-U/C: 0x0021d078
Ghidra address:
PAL: 0x00225e90

◆ Create() [2/4]

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.

Parameters
nWidthThe width.
nHeightThe height.
nRowBytesThe row size in bytes, or 0 to derive it.
nBppThe bits per pixel.
nOrderThe Order bits.
Ghidra address:
NTSC-U/C: 0x0021d0f0
Ghidra address:
PAL: 0x00225f08

◆ Create() [3/4]

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.

Parameters
nWidthThe width.
nHeightThe height.
nRowBytesThe row size in bytes, or 0 to derive it.
nBppThe bits per pixel.
nOrderThe Order bits.
pPaletteThe palette, or null.
pPixelsThe pixels.
pBufferThe block the bitmap releases with Reset(), or null.
Ghidra address:
NTSC-U/C: 0x0021d168
Ghidra address:
PAL: 0x00225f80

◆ Create() [4/4]

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.

Parameters
pBufferThe buffer.
Ghidra address:
NTSC-U/C: 0x0021d258
Ghidra address:
PAL: 0x00226070

◆ PixelOffset()

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.

Parameters
nXThe column.
nYThe row.
nHighNibbleReceives whether a 4-bit pixel is in the high half of the byte.
Returns
The byte offset.
Ghidra address:
NTSC-U/C: 0x0021d410
Ghidra address:
PAL: 0x00226228

◆ PixelIndex()

int RndBitmap::PixelIndex ( int nX,
int nY ) const

Report the palette index of a pixel.

Parameters
nXThe column.
nYThe row.
Returns
The index.
Ghidra address:
NTSC-U/C: 0x0021d6d0
Ghidra address:
PAL: 0x002264e8

◆ SetPixelIndex()

void RndBitmap::SetPixelIndex ( int nX,
int nY,
unsigned char nIndex )

Set the palette index of a pixel.

Parameters
nXThe column.
nYThe row.
nIndexThe index.
Ghidra address:
NTSC-U/C: 0x0021d730
Ghidra address:
PAL: 0x00226548

◆ MaxPixelIndex()

int RndBitmap::MaxPixelIndex ( ) const

Report the highest palette index any pixel uses.

Returns
The index, or -1 for a bitmap without a palette.
Ghidra address:
NTSC-U/C: 0x0021d7b0
Ghidra address:
PAL: 0x002265c8

◆ ConvertTo8Bpp()

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.

Ghidra address:
NTSC-U/C: 0x0021d868
Ghidra address:
PAL: 0x00226680

◆ LoadMip()

bool RndBitmap::LoadMip ( const char * pszPath)

Load a BMP file and add it as the last mipmap.

Parameters
pszPathThe file.
Returns
Whether the file loaded.
Ghidra address:
NTSC-U/C: 0x0021d9a0
Ghidra address:
PAL: 0x002267b8

◆ LoadAlpha()

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.

Parameters
pszPathThe file.
Ghidra address:
NTSC-U/C: 0x0021da58
Ghidra address:
PAL: 0x00226870

◆ LoadBmp()

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.

Parameters
pszPathThe file.
Returns
Whether the file loaded.
Ghidra address:
NTSC-U/C: 0x0021dd68
Ghidra address:
PAL: 0x00226b80

◆ SaveBmp()

void RndBitmap::SaveBmp ( const char * pszPath) const

Write the bitmap as a BMP file.

The bitmap has to be in the default byte order.

Parameters
pszPathThe file.
Ghidra address:
NTSC-U/C: 0x0021e398
Ghidra address:
PAL: 0x002271b0

◆ SamePalette()

bool RndBitmap::SamePalette ( const RndBitmap & other) const

Report whether another bitmap has the same palette entries.

Parameters
otherThe other bitmap.
Returns
Whether the palettes match.
Ghidra address:
NTSC-U/C: 0x0021e5e0
Ghidra address:
PAL: 0x002273f8

◆ SameFormat()

bool RndBitmap::SameFormat ( const RndBitmap & other) const

Report whether another bitmap stores pixels the same way, so rows copy unchanged.

Parameters
otherThe other bitmap.
Returns
Whether the formats match.
Ghidra address:
NTSC-U/C: 0x0021e6b0
Ghidra address:
PAL: 0x002274c8

◆ Blit()

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.

Parameters
sourceThe bitmap to copy from.
nDestXThe left column of the destination.
nDestYThe top row of the destination.
nSourceXThe left column of the source.
nSourceYThe top row of the source.
nWidthThe width.
nHeightThe height.
Ghidra address:
NTSC-U/C: 0x0021e710
Ghidra address:
PAL: 0x00227528

◆ PixelColor()

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.

Parameters
nXThe column.
nYThe row.
nRedReceives the red component.
nGreenReceives the green component.
nBlueReceives the blue component.
nAlphaReceives the alpha component.
Ghidra address:
NTSC-U/C: 0x0021e9a0
Ghidra address:
PAL: 0x002277b8

◆ SetPixelColor()

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.

Parameters
nXThe column.
nYThe row.
nRedThe red component.
nGreenThe green component.
nBlueThe blue component.
nAlphaThe alpha component.
Ghidra address:
NTSC-U/C: 0x0021ea70
Ghidra address:
PAL: 0x00227888

◆ PaletteOffset()

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.

Parameters
nIndexThe index.
Returns
The position.
Ghidra address:
NTSC-U/C: 0x0021eb10
Ghidra address:
PAL: 0x00227928

◆ PaletteColor()

void RndBitmap::PaletteColor ( int nIndex,
unsigned char & nRed,
unsigned char & nGreen,
unsigned char & nBlue,
unsigned char & nAlpha ) const

Report a palette entry.

Parameters
nIndexThe index.
nRedReceives the red component.
nGreenReceives the green component.
nBlueReceives the blue component.
nAlphaReceives the alpha component.
Ghidra address:
NTSC-U/C: 0x0021eb50
Ghidra address:
PAL: 0x00227968

◆ SetPaletteColor()

void RndBitmap::SetPaletteColor ( int nIndex,
unsigned char nRed,
unsigned char nGreen,
unsigned char nBlue,
unsigned char nAlpha )

Set a palette entry.

Parameters
nIndexThe index.
nRedThe red component.
nGreenThe green component.
nBlueThe blue component.
nAlphaThe alpha component.
Ghidra address:
NTSC-U/C: 0x0021ebc8
Ghidra address:
PAL: 0x002279e0

◆ Print()

void RndBitmap::Print ( PrnStream & stream) const

Write the size, the format, and the mipmap count of the bitmap.

Parameters
streamThe stream to write to.
Ghidra address:
NTSC-U/C: 0x0021ec40
Ghidra address:
PAL: 0x00227a58

◆ Save()

void RndBitmap::Save ( BinStream & stream) const

Write a 16-byte header, the palette, and the pixels of the bitmap and each mipmap.

Parameters
streamThe stream to write to.
Ghidra address:
NTSC-U/C: 0x0021ed20
Ghidra address:
PAL: 0x00227b38

◆ GetWidth()

unsigned short RndBitmap::GetWidth ( ) const
inline
Returns
The width in pixels.

◆ GetHeight()

unsigned short RndBitmap::GetHeight ( ) const
inline
Returns
The height in pixels.

◆ GetRowBytes()

unsigned short RndBitmap::GetRowBytes ( ) const
inline
Returns
The size of a row in bytes.

◆ GetBpp()

unsigned char RndBitmap::GetBpp ( ) const
inline
Returns
The bits per pixel.

◆ GetOrder()

unsigned char RndBitmap::GetOrder ( ) const
inline
Returns
The Order bits.

◆ GetPixels()

unsigned char * RndBitmap::GetPixels ( ) const
inline
Returns
The pixels.

◆ GetPalette()

unsigned char * RndBitmap::GetPalette ( ) const
inline
Returns
The palette, or null.

◆ GetMip() [1/2]

const RndBitmap * RndBitmap::GetMip ( ) const
inline
Returns
The next smaller mipmap, or null.

◆ GetMip() [2/2]

RndBitmap * RndBitmap::GetMip ( )
inline
Returns
The next smaller mipmap, or null.

Member Data Documentation

◆ sRev

unsigned char RndBitmap::sRev
static

The format version Save() writes.

Ghidra address:
NTSC-U/C: 0x003b0978

The documentation for this class was generated from the following file: