|
resonance 1.0.1
|
Description of a pixel rectangle, its layout, and its palette. More...
#include <abitmap.h>

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. | |
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.
| 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.
| pPixels | The pixel rectangle, or null to allocate one. |
| nFormat | The ABitmapFormat code. |
| bHasTransparentColor | Whether a later mTransparentColor applies. |
| nWidth | The width in pixels. |
| nHeight | The height in pixels. |
| nBytesPerRow | The row stride, or zero to derive it from the format. |
| 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.
| source | The bitmap whose pixels the rectangle lies in. |
| nX | The left column of the rectangle. |
| nY | The top row of the rectangle. |
| nWidth | The width in pixels. |
| nHeight | The height in pixels. |
| 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.
| pEntries | The entries to copy in. |
| nFirst | The first palette index to write. |
| nCount | The number of entries to write. |
|
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.
| nBitsPerPixel | The pixel width in bits. |
|
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.
| nFormat | The ABitmapFormat code. |
| nWidth | The width in pixels. |
| nHeight | The height in pixels. |
|
static |
Exchange the red and blue fields of a run of 1555 pixels in place.
| pPixels | The first pixel. |
| nCount | The number of pixels. |
|
static |
Exchange the first and third byte of a run of three byte pixels in place.
| pPixels | The first pixel. |
| nCount | The number of pixels. |
|
static |
Exchange the first and third byte of a run of four byte pixels in place.
| pPixels | The first pixel. |
| nCount | The number of pixels. |
| 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.
| nFlags | ABitmapColorKey bits. |
| 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.
| 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.
| bWhiten | Non-zero to set the colour bytes to white as well. |
| 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.
| source | The bitmap to copy. |
|
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.
| void* ABitmap::mPixels |
The pixel rectangle, null until allocated. +0x00
| unsigned short ABitmap::mHasTransparentColor |
Whether mTransparentColor applies. +0x04
| unsigned short ABitmap::mFormat |
The ABitmapFormat code. +0x05 bits 0 to 3
| unsigned short ABitmap::mOwnsPixels |
Set when the constructor allocated. bit 4
| unsigned short ABitmap::mOddNibbleStart |
Set when a four bit row starts high. bit 5
| unsigned short ABitmap::mUnused |
No reader or writer was located. bits 6 and 7
| short ABitmap::mWidth |
The width in pixels. +0x06
| short ABitmap::mHeight |
The height in pixels. +0x08
| short ABitmap::mBytesPerRow |
The distance between two rows in bytes. +0x0a
| unsigned int ABitmap::mTransparentColor |
The pixel value a copy skips. +0x0c
| int ABitmap::mByteCount |
The size of the pixel rectangle in bytes. +0x10
| APalette* ABitmap::mPalette |
The palette, null for a direct colour format. +0x14