Specialized drawing class used to render NES screen images. More...
Public Types | |
enum | FlipFlags { None = 0, Horizontal = 1, Vertical = 2, HorizontalVertial = Horizontal | Vertical } |
Specifies flipping to be used when blitting a tile. More... | |
Public Member Functions | |
Blitter () | |
Creates a new blitter. | |
IDisposable | Begin (Bitmap source, Bitmap dest) |
IDisposable | Begin (Bitmap dest) |
Prepares for blitting operations that do not involve a source image. When the blitter is opened for blitting using this method, the behavior of operations that require a source image are undefined. Supports read/write operations. | |
void | End () |
Finalizes the blitting operation. | |
void | ChangeSource (Bitmap newSource) |
void | DrawDitherTile (int tileX, int tileY, byte color, int parity) |
Draws a 50% dither of the specified color on a 8x8 tile. | |
void | DrawDitherTile (int x, int y, byte color) |
Draws a 50% dither of the specified color on an 8x8 tile. | |
void | DrawDither (Rectangle r, byte color) |
Fills a rectangle with a 50% dither. | |
void | DrawDither (Rectangle r, byte color, int parity) |
Fills a rectangle with a 50% dither. | |
void | FillTile (int x, int y, byte color) |
Fills an 8x8 tile with solid color. | |
void | FillRect (Rectangle r, byte color) |
Fills the specified rectangle with the specified color. | |
void | DrawRect (Rectangle rect, byte color) |
Draws a rectangle to the destination. | |
void | DrawRectHalf (Rectangle rect, byte color) |
Draws the top and left lines of a rectangle to the destination (good for grids). | |
void | BlitTile (int tile, int destTileX, int destTileY, byte pal) |
Draws a tile to the destination. | |
void | BlitTileTransparent (int tile, int destTileX, int destTileY, byte pal) |
void | BlitTileTransparent (int tile, int destTileX, int destTileY, byte pal, int transparentColor) |
Performs a bit-block-transfer from the source brush to the destination brush, applying the specified paletteIndex. Any pixels with a value of zero will be rendered transparently. | |
void | BlitTileTransparent (int tile, int destX, int destY, byte pal, FlipFlags flip, int transparentColor) |
void | BlitTileTransparent (int tile, int destX, int destY, byte pal, FlipFlags flip) |
Performs a bit-block-transfer from the source brush to the destination brush, applying the specified paletteIndex. Any pixels with a value of zero will be rendered transparently. | |
void | BlitTransparent (int tile, int destX, int destY, byte pal, FlipFlags flip) |
Performs a bit-block-transfer from the source brush to the destination brush, applying the specified paletteIndex. Any pixels with a value of zero will be rendered transparently. This overload specifies a pixel location instead of a tile location. | |
void | BlitTransparent (int tile, int destX, int destY, byte pal, FlipFlags flip, int transparentColor) |
Performs a bit-block-transfer from the source brush to the destination brush, applying the specified paletteIndex. Any pixels with a value of zero will be rendered transparently. This overload specifies a pixel location instead of a tile location. | |
Static Public Member Functions | |
static Bitmap | CreateCompatibleTargetBitmap () |
Creates a bitmap with the correct dimensions and format for a blitter to render to. | |
static bool | IsTargetValid (Bitmap target) |
Returns a boolean indicating whether the specified Bitmap can be drawn to using a Blitter. | |
static bool | IsSourceValid (Bitmap source) |
Returns a boolean indicating whethe the specified Bitmap can be used as a pattern source with a Blitter. | |
Public Attributes | |
const int | DestWidth = 256 |
The expected width of a render target. | |
const int | DestHeight = 256 |
The expected height of a render target. | |
const int | SourceWidth = 2048 |
The expected width of the pattern source image. | |
const int | SourceHeight = 8 |
The expected height of the pattern source image. | |
const PixelFormat | ImageFormat = PixelFormat.Format8bppIndexed |
The pixel format used by the Blitter. | |
Static Public Attributes | |
static readonly Rectangle | DestBounds = new Rectangle(0, 0, DestWidth, DestHeight) |
The expected bounds of a render target. |
Specialized drawing class used to render NES screen images.
This class is meant to be used for rendering from a pattern table to an NES screen image. Both images must be 8-bit. The source image should only use the first four colors of the palette.
This class is designed to be highly optimized and does not perform many safety checks. Invalid or out of bounds values as well as incorrect image sizes and formats will produce irregular results or likely cause exceptions to be thrown.
Romulus.Nes.Blitter.Blitter | ( | ) |
Creates a new blitter.
IDisposable Romulus.Nes.Blitter.Begin | ( | Bitmap | source, | |
Bitmap | dest | |||
) |
Prepares for write-only blitting operations.
source | The source image. This should be 2048 pixels wide and eight pixels tall. | |
dest | The destination image. This should be 256 pixels wide and tall. |
Calling Dispose on the returned object is equivalent to calling the End method. This allows a blitting operation's scope to be defined by a using block.
using (blitterObject.Begin(source, target)) { // Blitting operations go here. // No need to call blitterObject.End. }
IDisposable Romulus.Nes.Blitter.Begin | ( | Bitmap | dest | ) |
Prepares for blitting operations that do not involve a source image. When the blitter is opened for blitting using this method, the behavior of operations that require a source image are undefined. Supports read/write operations.
dest | The destination image. This should be 256 pixels wide and tall. |
Calling Dispose on the returned object is equivalent to calling the End method. This allows a blitting operation's scope to be defined by a using block.
using (blitterObject.Begin(target)) { // Blitting operations go here. // No need to call blitterObject.End. }
void Romulus.Nes.Blitter.BlitTile | ( | int | tile, | |
int | destTileX, | |||
int | destTileY, | |||
byte | pal | |||
) |
Draws a tile to the destination.
tile | The count of the tile to be used from the source brush | |
destTileX | The x-coordinate of the tile to be drawn to in the destination | |
destTileY | The y-coordinate of the tile to be drawn to in the destination | |
pal | The paletteIndex to use. |
The paletteIndex specified will work for the range 0 through 31 if the source brush is formatted correctly, but for NES screen rendering typically only the first four palettes will be used.
void Romulus.Nes.Blitter.BlitTileTransparent | ( | int | tile, | |
int | destTileX, | |||
int | destTileY, | |||
byte | pal | |||
) |
Draws a tile to the destination.
tile | The count of the tile to be used from the source brush | |
destTileX | The x-coordinate of the tile to be drawn to in the destination | |
destTileY | The y-coordinate of the tile to be drawn to in the destination | |
pal | The paletteIndex to use. |
The paletteIndex specified will work for the range 0 through 31 if the source brush is formatted correctly, but for NES screen rendering typically only the first four palettes will be used.
void Romulus.Nes.Blitter.BlitTileTransparent | ( | int | tile, | |
int | destTileX, | |||
int | destTileY, | |||
byte | pal, | |||
int | transparentColor | |||
) |
Performs a bit-block-transfer from the source brush to the destination brush, applying the specified paletteIndex. Any pixels with a value of zero will be rendered transparently.
tile | The count of the tile to be used from the source brush | |
destTileX | The x-coordinate of the tile to be drawn to in the destination | |
destTileY | The y-coordinate of the tile to be drawn to in the destination | |
pal | The paletteIndex to use. |
The paletteIndex specified will work for the range 0 through 31 if the source brush is formatted correctly, but for NES screen rendering typically only the first four palettes will be used.
transparentColor | The color to use for transparent. This is typically zero. Specify a negative value for no transparency. |
void Romulus.Nes.Blitter.BlitTileTransparent | ( | int | tile, | |
int | destX, | |||
int | destY, | |||
byte | pal, | |||
FlipFlags | flip, | |||
int | transparentColor | |||
) |
Performs a bit-block-transfer from the source brush to the destination brush, applying the specified paletteIndex. Any pixels with a value of zero will be rendered transparently.
tile | The count of the tile to be used from the source brush | |
destX | The x-coordinate of the tile to be drawn to in the destination | |
destY | The y-coordinate of the tile to be drawn to in the destination | |
pal | The paletteIndex to use. |
The paletteIndex specified will work for the range 0 through 31 if the source brush is formatted correctly, but for NES screen rendering typically only the first four palettes will be used.
flip | T FlipFlags value indicating how to flip the tile. | |
transparentColor | The color to use as transparent. |
void Romulus.Nes.Blitter.BlitTileTransparent | ( | int | tile, | |
int | destX, | |||
int | destY, | |||
byte | pal, | |||
FlipFlags | flip | |||
) |
Performs a bit-block-transfer from the source brush to the destination brush, applying the specified paletteIndex. Any pixels with a value of zero will be rendered transparently.
tile | The count of the tile to be used from the source brush | |
destX | The x-coordinate of the tile to be drawn to in the destination | |
destY | The y-coordinate of the tile to be drawn to in the destination | |
pal | The paletteIndex to use. |
The paletteIndex specified will work for the range 0 through 31 if the source brush is formatted correctly, but for NES screen rendering typically only the first four palettes will be used.
flip | T FlipFlags value indicating how to flip the tile. |
void Romulus.Nes.Blitter.BlitTransparent | ( | int | tile, | |
int | destX, | |||
int | destY, | |||
byte | pal, | |||
FlipFlags | flip | |||
) |
Performs a bit-block-transfer from the source brush to the destination brush, applying the specified paletteIndex. Any pixels with a value of zero will be rendered transparently. This overload specifies a pixel location instead of a tile location.
tile | The count of the tile to be used from the source brush | |
destX | The x-coordinate to draw to. | |
destY | The y-coordinate to draw to. | |
pal | The paletteIndex to use. |
The paletteIndex specified will work for the range 0 through 31 if the source brush is formatted correctly, but for NES screen rendering typically only the first four palettes will be used.
flip | T FlipFlags value indicating how to flip the tile. |
void Romulus.Nes.Blitter.BlitTransparent | ( | int | tile, | |
int | destX, | |||
int | destY, | |||
byte | pal, | |||
FlipFlags | flip, | |||
int | transparentColor | |||
) |
Performs a bit-block-transfer from the source brush to the destination brush, applying the specified paletteIndex. Any pixels with a value of zero will be rendered transparently. This overload specifies a pixel location instead of a tile location.
tile | The count of the tile to be used from the source brush | |
destX | The x-coordinate to draw to. | |
destY | The y-coordinate to draw to. | |
pal | The paletteIndex to use. |
The paletteIndex specified will work for the range 0 through 31 if the source brush is formatted correctly, but for NES screen rendering typically only the first four palettes will be used.
transparentColor | The color to render as transparent. Zero by default. | |
flip | T FlipFlags value indicating how to flip the tile. |
void Romulus.Nes.Blitter.ChangeSource | ( | Bitmap | newSource | ) |
Selectes a different source for blitting without closing and opening the lock on the destination brush.
newSource | The new source brush. |
static Bitmap Romulus.Nes.Blitter.CreateCompatibleTargetBitmap | ( | ) | [static] |
Creates a bitmap with the correct dimensions and format for a blitter to render to.
void Romulus.Nes.Blitter.DrawDither | ( | Rectangle | r, | |
byte | color, | |||
int | parity | |||
) |
Fills a rectangle with a 50% dither.
r | The rectangle to fill. | |
color | The color to apply the dither with. | |
parity | The parity, default is zero (even). Odd parity reverses which pixels are filled and which are not modified. |
void Romulus.Nes.Blitter.DrawDither | ( | Rectangle | r, | |
byte | color | |||
) |
Fills a rectangle with a 50% dither.
r | The rectangle to fill. | |
color | The color to apply the dither with. |
void Romulus.Nes.Blitter.DrawDitherTile | ( | int | tileX, | |
int | tileY, | |||
byte | color, | |||
int | parity | |||
) |
Draws a 50% dither of the specified color on a 8x8 tile.
tileX | The x-coordinate of a 16x16 tile. | |
tileY | The y-coordinate of a 16x16 tile. | |
color | The count of the color to draw with | |
parity | T value of 0 or 1 to indicate the parity of the dither. |
void Romulus.Nes.Blitter.DrawDitherTile | ( | int | x, | |
int | y, | |||
byte | color | |||
) |
Draws a 50% dither of the specified color on an 8x8 tile.
x | The x-coordinate of an 8x8 tile. | |
y | The y-coordinate of an 8x8 tile. | |
color | The count of the color to draw with |
void Romulus.Nes.Blitter.DrawRect | ( | Rectangle | rect, | |
byte | color | |||
) |
Draws a rectangle to the destination.
rect | The bounds of the rectangle. | |
color | The count of the color to use. |
void Romulus.Nes.Blitter.DrawRectHalf | ( | Rectangle | rect, | |
byte | color | |||
) |
Draws the top and left lines of a rectangle to the destination (good for grids).
rect | The bounds of the rectangle. | |
color | The count of the color to use. |
void Romulus.Nes.Blitter.End | ( | ) |
Finalizes the blitting operation.
void Romulus.Nes.Blitter.FillRect | ( | Rectangle | r, | |
byte | color | |||
) |
Fills the specified rectangle with the specified color.
r | ||
color |
void Romulus.Nes.Blitter.FillTile | ( | int | x, | |
int | y, | |||
byte | color | |||
) |
Fills an 8x8 tile with solid color.
x | The x-coordinate of the tile. | |
y | The y-coordinate of the tile. | |
color | The count of the color to fill with. |
static bool Romulus.Nes.Blitter.IsSourceValid | ( | Bitmap | source | ) | [static] |
static bool Romulus.Nes.Blitter.IsTargetValid | ( | Bitmap | target | ) | [static] |
readonly Rectangle Romulus.Nes.Blitter.DestBounds = new Rectangle(0, 0, DestWidth, DestHeight) [static] |
The expected bounds of a render target.
const int Romulus.Nes.Blitter.DestHeight = 256 |
The expected height of a render target.
const int Romulus.Nes.Blitter.DestWidth = 256 |
The expected width of a render target.
const PixelFormat Romulus.Nes.Blitter.ImageFormat = PixelFormat.Format8bppIndexed |
The pixel format used by the Blitter.
const int Romulus.Nes.Blitter.SourceHeight = 8 |
The expected height of the pattern source image.
const int Romulus.Nes.Blitter.SourceWidth = 2048 |
The expected width of the pattern source image.