Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes

Romulus.Nes.Blitter Class Reference

Specialized drawing class used to render NES screen images. More...

List of all members.

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.

Detailed Description

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.


Member Enumeration Documentation

Specifies flipping to be used when blitting a tile.

These values can be combined.

Enumerator:
None 

Specifies no flipping.

Horizontal 

Specifies horizontal flipping.

Vertical 

Specifies vertical flipping.

HorizontalVertial 

Specifies both horizontal and vertical flipping.


Constructor & Destructor Documentation

Romulus.Nes.Blitter.Blitter (  ) 

Creates a new blitter.


Member Function Documentation

IDisposable Romulus.Nes.Blitter.Begin ( Bitmap  source,
Bitmap  dest 
)

Prepares for write-only blitting operations.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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).

Parameters:
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.

Parameters:
r 
color 
void Romulus.Nes.Blitter.FillTile ( int  x,
int  y,
byte  color 
)

Fills an 8x8 tile with solid color.

Parameters:
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]

Returns a boolean indicating whethe the specified Bitmap can be used as a pattern source with a Blitter.

Parameters:
source The Bitmap to test.
Returns:
Boolean indicating whethe the specified Bitmap can be used as a pattern source with a Blitter.
static bool Romulus.Nes.Blitter.IsTargetValid ( Bitmap  target  )  [static]

Returns a boolean indicating whether the specified Bitmap can be drawn to using a Blitter.

Parameters:
target The Bitmap to test.
Returns:
Boolean indicating whether the specified Bitmap can be drawn to using a Blitter.

Member Data Documentation

readonly Rectangle Romulus.Nes.Blitter.DestBounds = new Rectangle(0, 0, DestWidth, DestHeight) [static]

The expected bounds of a render target.

The expected height of a render target.

The expected width of a render target.

const PixelFormat Romulus.Nes.Blitter.ImageFormat = PixelFormat.Format8bppIndexed

The pixel format used by the Blitter.

The expected height of the pattern source image.

The expected width of the pattern source image.


The documentation for this class was generated from the following file:
 All Classes Namespaces Functions Variables Enumerations Properties Events