resonance 1.0.1
Loading...
Searching...
No Matches
ABitmap Class Reference

Description of a pixel rectangle, its layout, and its palette. More...

#include <abitmap.h>

Collaboration diagram for ABitmap:

Public Member Functions

 ABitmap (void *pPixels, int nFormat, bool bHasTransparentColor, int nWidth, int nHeight, int nBytesPerRow)
 Describe a pixel rectangle, allocating the pixels when the caller supplies none.
 ABitmap (const ABitmap &source, int nX, int nY, int nWidth, int nHeight)
 Describe a rectangle inside another bitmap, sharing its pixels.
void SetPaletteEntries (const unsigned int *pEntries, int nFirst, int nCount)
 Set or replace a run of palette entries, allocating the palette on first use.
void ApplyColorKey (int nFlags)
 Pick a colour key from the flags and rebuild the alpha of every pixel from it.
void SwapRedBlue ()
 Exchange red and blue throughout the bitmap, or throughout its palette.
void SetPaletteAlphaFromLowByte (int bWhiten)
 Copy the low byte of every palette entry into its alpha byte.
int Clone (ABitmap &source)
 Make this bitmap an owning copy of another.

Static Public Member Functions

static int Bpp2Format (int nBitsPerPixel)
 Return the ABitmapFormat code for a pixel width in bits.
static int ComputeByteCount (int nFormat, int nWidth, int nHeight)
 Return the size of a pixel rectangle in bytes, with rows packed at the format's own stride.
static void Reverse15 (unsigned short *pPixels, int nCount)
 Exchange the red and blue fields of a run of 1555 pixels in place.
static void Reverse24 (unsigned char *pPixels, int nCount)
 Exchange the first and third byte of a run of three byte pixels in place.
static void Reverse32 (unsigned char *pPixels, int nCount)
 Exchange the first and third byte of a run of four byte pixels in place.

Public Attributes

void * mPixels
unsigned short mHasTransparentColor: 8
unsigned short mFormat: 4
unsigned short mOwnsPixels: 1
unsigned short mOddNibbleStart: 1
unsigned short mUnused: 2
short mWidth
short mHeight
short mBytesPerRow
unsigned int mTransparentColor
int mByteCount
APalette * mPalette

Static Public Attributes

static const unsigned char bmPixelSize [kABitmapFormatCount]
 Bytes one pixel of each ABitmapFormat occupies.

Detailed Description

Description of a pixel rectangle, its layout, and its palette.

The record is not polymorphic and has no RTTI. Its allocations bill themselves to C:/FREQ/src/rndartt/abitmap.h, the only source path the shipped image retains. 165 copies of the tag pair ("APalette", "abitmap.h") appear in the data segment, one per translation unit that inlined a palette allocation.

ACanvas stores one of these at offset zero and reads mWidth and mHeight directly. The members are therefore public, although a friend declaration would fit the image equally well.

The record is 0x18 bytes. ACanvas::NewCompatibleCanvas() copies it whole, then fills in mBytesPerRow and mPixels for the copy. Every clipped copy slot of ACanvas copies exactly 0x18 bytes of its argument onto its stack, mutates the copy, and passes the copy on. The 0x18 byte copies confirm the size.

The constructor settles the five bit-fields, because it writes the low eight bits with a byte store and the four bit code and the two flag bits with read, modify, and write cycles over the enclosing halfword. Reading that halfword with a word load, as both the constructor and ACanvas::DrawBitmapLin4U() do, is a toolchain choice over a 16 bit container rather than evidence of a wider member. The neighbouring mWidth is intact after every such cycle because the read precedes the write.

A 0x420-byte form of this record, with an APalette inline at offset 0x18, does not fit the record ACanvas stores at offset zero. An ACanvas is 0x28 bytes and its offsets 0x18 through 0x1f are the clip rectangle. A base and derived pair reconciles the two, the 0x18 byte head described here being the base and the 0x420 byte form adding the inline palette.

One copy of the record does not fit the 0x18 byte size. ACanvas::DrawChar() copies 0x1c bytes of the glyph it is about to draw and then passes the copy where an ABitmap is expected. Either a font glyph is a derived record with one further word, or the description is 0x1c bytes with a member no canvas routine reads. The four bytes are unresolved.

Constructor & Destructor Documentation

◆ ABitmap() [1/2]

ABitmap::ABitmap ( void * pPixels,
int nFormat,
bool bHasTransparentColor,
int nWidth,
int nHeight,
int nBytesPerRow )

Describe a pixel rectangle, allocating the pixels when the caller supplies none.

Writes mFormat from the second argument, clears mOddNibbleStart, and writes mHasTransparentColor from the third. A row stride of zero is derived from the format instead, as (nWidth + 2) / 2 for kABitmapFormatLinear4 and as nWidth times the matching entry of ABitmap::bmPixelSize for every other code. mByteCount then becomes the stride times the height.

A null pixel pointer allocates mByteCount bytes, tagged with the source file and line, and sets mOwnsPixels. A supplied pointer clears the flag.

mTransparentColor and mPalette are both cleared, so a caller that wants either writes it afterwards. ACanvas::DrawBitmapRle8U() and its three relatives do exactly that.

Parameters
pPixelsThe pixel rectangle, or null to allocate one.
nFormatThe ABitmapFormat code.
bHasTransparentColorWhether a later mTransparentColor applies.
nWidthThe width in pixels.
nHeightThe height in pixels.
nBytesPerRowThe row stride, or zero to derive it from the format.
Ghidra address:
NTSC-U/C: 0x005593a0
Ghidra address:
PAL: 0x0059a4f8

◆ ABitmap() [2/2]

ABitmap::ABitmap ( const ABitmap & source,
int nX,
int nY,
int nWidth,
int nHeight )

Describe a rectangle inside another bitmap, sharing its pixels.

The format, the row stride, mHasTransparentColor, and the palette come from source, and mOwnsPixels is cleared. mPixels points at column nX of row nY of source. A kABitmapFormatLinear4 source addresses half bytes, so the column offset is nX / 2 bytes and an odd nX inverts mOddNibbleStart, taking one more byte when source starts high. mTransparentColor is never written. ACanvas::SubCanvas() is the only caller.

Parameters
sourceThe bitmap whose pixels the rectangle lies in.
nXThe left column of the rectangle.
nYThe top row of the rectangle.
nWidthThe width in pixels.
nHeightThe height in pixels.
Ghidra address:
NTSC-U/C: 0x00558dd8
Ghidra address:
PAL: 0x00599f30

Member Function Documentation

◆ SetPaletteEntries()

void ABitmap::SetPaletteEntries ( const unsigned int * pEntries,
int nFirst,
int nCount )

Set or replace a run of palette entries, allocating the palette on first use.

The palette is constructed before the allocation is tested against null, and the path where mPalette was already set calls SetEntries() with no test. The order is harmless in practice. AllocateTaggedMemory() treats a failure as fatal and never returns null.

Parameters
pEntriesThe entries to copy in.
nFirstThe first palette index to write.
nCountThe number of entries to write.
Ghidra address:
NTSC-U/C: 0x005eb290
Ghidra address:
PAL: 0x0062d3d8

◆ Bpp2Format()

int ABitmap::Bpp2Format ( int nBitsPerPixel)
static

Return the ABitmapFormat code for a pixel width in bits.

4, 8, 16, 24, and 32 give kABitmapFormatLinear4 through kABitmapFormatLinear32, and every other width gives kABitmapFormatLinear15.

Parameters
nBitsPerPixelThe pixel width in bits.
Returns
The format code.
Ghidra address:
NTSC-U/C: 0x00559310
Ghidra address:
PAL: 0x0059a468

◆ ComputeByteCount()

int ABitmap::ComputeByteCount ( int nFormat,
int nWidth,
int nHeight )
static

Return the size of a pixel rectangle in bytes, with rows packed at the format's own stride.

The stride matches the one the constructor derives, (nWidth + 2) / 2 for kABitmapFormatLinear4 and nWidth times the matching entry of ABitmap::bmPixelSize otherwise.

Parameters
nFormatThe ABitmapFormat code.
nWidthThe width in pixels.
nHeightThe height in pixels.
Returns
The size in bytes.
Ghidra address:
NTSC-U/C: 0x00559368
Ghidra address:
PAL: 0x0059a4c0

◆ Reverse15()

void ABitmap::Reverse15 ( unsigned short * pPixels,
int nCount )
static

Exchange the red and blue fields of a run of 1555 pixels in place.

Parameters
pPixelsThe first pixel.
nCountThe number of pixels.
Ghidra address:
NTSC-U/C: 0x00559568
Ghidra address:
PAL: 0x0059a6c0

◆ Reverse24()

void ABitmap::Reverse24 ( unsigned char * pPixels,
int nCount )
static

Exchange the first and third byte of a run of three byte pixels in place.

Parameters
pPixelsThe first pixel.
nCountThe number of pixels.
Ghidra address:
NTSC-U/C: 0x005595c8
Ghidra address:
PAL: 0x0059a720

◆ Reverse32()

void ABitmap::Reverse32 ( unsigned char * pPixels,
int nCount )
static

Exchange the first and third byte of a run of four byte pixels in place.

Parameters
pPixelsThe first pixel.
nCountThe number of pixels.
Ghidra address:
NTSC-U/C: 0x00559600
Ghidra address:
PAL: 0x0059a758

◆ ApplyColorKey()

void ABitmap::ApplyColorKey ( int nFlags)

Pick a colour key from the flags and rebuild the alpha of every pixel from it.

An indexed bitmap with a palette takes the index of the first palette entry among the first APalette::mEnd whose colour channels are white (kABitmapColorKeyWhite) or black (kABitmapColorKeyBlack). A 1555 bitmap takes 0x7fff or zero, and a 32 bit bitmap 0xffffff or zero, the white bit winning when both are set. Other formats pick nothing.

Whenever mHasTransparentColor is then set, whether by this call or before it, a canvas is built over the bitmap with ACanvas::NewCompatibleCanvas(), its ACanvas::SetAlphaValues() runs with mTransparentColor, and the canvas is deleted. The canvas is used before the null test that guards its deletion.

The one out-of-line copy sits inside the Rnd::Tex translation unit, and Rnd::Tex's slot 15 at 0x004e5928 is the one caller, passing the texture's flag word.

Parameters
nFlagsABitmapColorKey bits.
Ghidra address:
NTSC-U/C: 0x004e5b78
Ghidra address:
PAL: 0x005245c8

◆ SwapRedBlue()

void ABitmap::SwapRedBlue ( )

Exchange red and blue throughout the bitmap, or throughout its palette.

An indexed format swaps the first mPalette->mEnd palette entries, and does nothing without a palette. A direct colour format swaps every pixel of every row, stepping by mBytesPerRow. The four row loops inline Reverse15(), Reverse24(), and Reverse32(). Callers skip the call while g_nSkipColorSwap is non-zero.

Ghidra address:
NTSC-U/C: 0x00559140
Ghidra address:
PAL: 0x0059a298

◆ SetPaletteAlphaFromLowByte()

void ABitmap::SetPaletteAlphaFromLowByte ( int bWhiten)

Copy the low byte of every palette entry into its alpha byte.

The first mPalette->mEnd entries are rewritten, and a bitmap without a palette is not changed. With bWhiten set, the three colour bytes of each entry also become 0xff, leaving a white palette whose alpha carries the former low channel. Rnd::Tex::OnMipLoaded() is the one caller, passing zero for texture flag 0x10 and one for flag 0x20. The out-of-line copy sits in the Rnd::Tex translation unit. The name is inferred.

Parameters
bWhitenNon-zero to set the colour bytes to white as well.
Ghidra address:
NTSC-U/C: 0x004e7d48
Ghidra address:
PAL: 0x00526838

◆ Clone()

int ABitmap::Clone ( ABitmap & source)

Make this bitmap an owning copy of another.

Every descriptor field is taken from source, apart from mOwnsPixels, and mPalette is shared rather than copied. Unless the format is kABitmapFormatRle8, a stride that differs from the packed stride the constructor would derive is replaced by it, with mByteCount recomputed. mByteCount bytes are then allocated, tagged with the source file and line, and the pixels are copied in one block when both strides agree and row by row otherwise. No call site remains in the shipped program.

Parameters
sourceThe bitmap to copy.
Returns
0, or -1 when the allocation fails.
Ghidra address:
NTSC-U/C: 0x00558f28
Ghidra address:
PAL: 0x0059a080

Member Data Documentation

◆ bmPixelSize

const unsigned char ABitmap::bmPixelSize[kABitmapFormatCount]
static

Bytes one pixel of each ABitmapFormat occupies.

The entry for kABitmapFormatLinear4 is zero, because four-bit rows use a separate stride formula. Both ABitmap::ABitmap() and ACanvas::NewCompatibleCanvas() read the table.

Ghidra address:
NTSC-U/C: 0x00725cc0
Ghidra address:
PAL: 0x00769960

◆ mPixels

void* ABitmap::mPixels

The pixel rectangle, null until allocated. +0x00

◆ mHasTransparentColor

unsigned short ABitmap::mHasTransparentColor

Whether mTransparentColor applies. +0x04

◆ mFormat

unsigned short ABitmap::mFormat

The ABitmapFormat code. +0x05 bits 0 to 3

◆ mOwnsPixels

unsigned short ABitmap::mOwnsPixels

Set when the constructor allocated. bit 4

◆ mOddNibbleStart

unsigned short ABitmap::mOddNibbleStart

Set when a four bit row starts high. bit 5

◆ mUnused

unsigned short ABitmap::mUnused

No reader or writer was located. bits 6 and 7

◆ mWidth

short ABitmap::mWidth

The width in pixels. +0x06

◆ mHeight

short ABitmap::mHeight

The height in pixels. +0x08

◆ mBytesPerRow

short ABitmap::mBytesPerRow

The distance between two rows in bytes. +0x0a

◆ mTransparentColor

unsigned int ABitmap::mTransparentColor

The pixel value a copy skips. +0x0c

◆ mByteCount

int ABitmap::mByteCount

The size of the pixel rectangle in bytes. +0x10

◆ mPalette

APalette* ABitmap::mPalette

The palette, null for a direct colour format. +0x14


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