Blit Functions

BLock Image Transfer operations

Blit’s are special Rendering Functions to copy one rectangle part of the video memory into another part of the video memory.  The operation could be performed using texturemapping and boxrendering as well, but the blit interface avoids setting and restoring all necessary context states.

Texel-to-pixel mapping

Conceptually textures are seen the same way as a raster display: Each texel is defined at the exact center of a grid cell.  The driver maps the left border of the left-most texel to the left border of the left-most destination pixel and the right border of the right-most texel to the right border of the right-most destination pixel.

Example

Find below an example of resizing a source texture with filtering enabled.

  • A source image (3x1) is stretched to a destination rectangle (5x1).
  • A source image (5x1) is downsized to a destination rectangle (3x1).

Please not that the texel-to-pixel mapping implementation has changed for the magnification case since D2 Driver version 3.10.

Summary
Blit FunctionsBLock Image Transfer operations
BLIT Attributes Writes
d2_setblitsrcSpecify the source for blit operation.
BLIT Rendering Functions
d2_blitcopyCopy rectangle part of the source into destination.

BLIT Attributes Writes

d2_setblitsrc

d2_s32 d2_setblitsrc(d2_device *handle,
void *ptr,
d2_s32 pitch,
d2_s32 width,
d2_s32 height,
d2_u32 format)

Specify the source for blit operation.

parameters

handledevice pointer (see: d2_opendevice)
ptraddress of the top left texel (coordinate 0,0)
pitchnumber of pixels (not bytes) per scanline
widthwidth of bitmap in pixels (equal or less than pitch)
heightheight of bitmap in pixels
formatpixel encoding type (bitmap format)

bitmap formats

d2_mode_alpha8monochrome 8bit per pixel
d2_mode_alpha4monochrome 4bit per pixel
d2_mode_alpha2monochrome 2bit per pixel
d2_mode_alpha1monochrome 1bit per pixel
d2_mode_rgb565colored 16bit per pixel (alpha is blue)
d2_mode_argb8888colored 32bit per pixel
d2_mode_rgba8888colored 32bit per pixel
d2_mode_rgb888(same as d2_mode_argb8888, in case of RLE textures 24bit pixel are decoded to 32bit)
d2_mode_argb4444colored 16bit per pixel
d2_mode_rgba4444colored 16bit per pixel
d2_mode_rgb444(same as d2_mode_argb4444)
d2_mode_argb1555colored 16bit per pixel
d2_mode_rgba5551colored 16bit per pixel
d2_mode_rgb555(same as d2_mode_argb1555)
d2_mode_ai44colored, palletized 8bit per pixel, (4 bit alpha, 4 bit indexed RGB: see d2_settexclut)
d2_mode_i8colored, palletized 8bit per pixel (palette is used if d2_mode_clut is also set)
d2_mode_i4colored, palletized 4bit per pixel (palette is used if d2_mode_clut is also set)
d2_mode_i2colored, palletized 2bit per pixel (palette is used if d2_mode_clut is also set)
d2_mode_i1colored, palletized 1bit per pixel (palette is used if d2_mode_clut is also set)

additional flags (can be combined with all above formats) :

d2_mode_rleEnables the RLE unit (available if the feature bit D2FB_RLEUNIT is set (see d2_getrevisionhw)).
d2_mode_clutEnables the color look up table (for d2_mode_i8 through d2_mode_i1) (see d2_settexclut).

Modes d2_mode_rgb888, d2_mode_rgb444 and d2_mode_rgb555 can be used as well.  Alpha information has to be ignored by not selecting the flag d2_bf_usealpha when calling d2_blitcopy.

If the CLUT is not enabled with an indexed color format (d2_mode_i8 to d2_mode_i1), the index is written directly to the framebuffer.  The index can be combined with the offset, see d2_settexclut_offset.

In case of d2_mode_alpha4 to d2_mode_alpha1 bits are MSB aligned and replicated to the lower bits of the 8 bit format of the internal A, R, G and B channels.

returns

errorcode (D2_OK if successful) see list of Errorcodes for details

note

width can be max 2048 pixel, height can be max 1024 pixel.

Please notice that a cache flush using ‘d1_cacheblockflush’ might be necessary if memory contents were changed before!  To avoid problems you can use the d1 driver memory management functions ‘d1_copytovidmem’ or ‘d1_copyfromvidmem’, which implicitly do a cache flush.

BLIT Rendering Functions

d2_blitcopy

d2_s32 d2_blitcopy(d2_device *handle,
d2_s32 srcwidth,
d2_s32 srcheight,
d2_blitpos srcx,
d2_blitpos srcy,
d2_width dstwidth,
d2_width dstheight,
d2_point dstx,
d2_point dsty,
d2_u32 flags)

Copy rectangle part of the source into destination.

The source is set prior to the blit using d2_setblitsrc and the destination will be part of the framebuffer (see: d2_framebuffer) just as with any normal rendering function.

parameters

handledevice pointer (see: d2_opendevice)
srcwidth, srcheightsize of source rectangle in pixels (integer)
srcx,srcyposition in source bitmap (integer)
dstwidth, dstheightsize of destination rectangle in pixels (fixedpoint)
dstx,dstyposition in destination bitmap (fixedpoint)
flagsany combination of blit flag bits (see below)

blit flag bits

d2_bf_filteruapply linear filter on U axis (x-direction)
d2_bf_filtervapply linear filter in V axis (y-direction)
d2_bf_filterapply bilinear filter (both axis)
d2_bf_wrapuwrap bitmap on U axis (x-direction)
d2_bf_wrapvwrap bitmap on V axis (y-direction)
d2_bf_wrapwrap bitmap on U and V axis (x/y-direction)
d2_bf_mirrorumirror bitmap in U axis (x-direction)
d2_bf_mirrorvmirror bitmap in V axis (y-direction)
d2_bf_colorizebitmap colors are multiplied by color register index 0 (see: d2_setcolor)
d2_bf_colorize2bitmap colors are interpolated between color register index 0 and 1 (see: d2_setcolor)
d2_bf_usealphaalpha value from bitmap is used
d2_bf_invertalphaalpha value from bitmap is inverted before use (requires usealpha)
d2_bf_no_blitctxbackupfor this blit don’t backup context data for better performance; previous texture modes get lost and must be set again
blitsrc.src:+-------------------------------------+
            |           blitsrc.width             |
            |<----------blitsrc.pitch------------>|
            |                                     |
            |    srcx/y:+-----------------+  ^
            |           |                 |  |
            |           |<---srcwidth---->|  |
            |           |                 |  | srcheight
            |           |                 |  |
            |           +-------\\--------+  v
            |                    \\
                                  \\
    Display:  +--------------------\\----------------------+
              |                     \\                     |
              |         dstx/y:+-----\\-------------+  ^
              |                |                    |  |
              |                |<------dstwidth---->|  |
              |                |                    |  | dstheight
              |                |                    |  |
              |                |                    |  |
              |                +--------------------+  v

d2_setblitsrc sets parameters for the texture buffer.  d2_blitcopy sets parameters for an area of the texture buffer and an area of the framebuffer where the texture area will be mapped to.  Both areas don’t need to be the same size.

note

Wrapping will work with source bitmap dimensions that are integer powers of two only (2,4,8,16,32,..)!

texture pitch can be >= 2048 if (srcheight-1) * pitch < 2048*1024 and if srcheight is multiple of dstheight

d2_bf_filterv cannot be used if the pitch of the texture is >= 2048

returns

errorcode (D2_OK if successfull) see list of Errorcodes for details

d2_s32 d2_setblitsrc(d2_device *handle,
void *ptr,
d2_s32 pitch,
d2_s32 width,
d2_s32 height,
d2_u32 format)
Specify the source for blit operation.
d2_s32 d2_blitcopy(d2_device *handle,
d2_s32 srcwidth,
d2_s32 srcheight,
d2_blitpos srcx,
d2_blitpos srcy,
d2_width dstwidth,
d2_width dstheight,
d2_point dstx,
d2_point dsty,
d2_u32 flags)
Copy rectangle part of the source into destination.
There is a rendering function for each supported geometric shape.
d2_device * d2_opendevice(d2_u32 flags)
Create a new device handle.
d2_s32 d2_settexclut(d2_device *handle,
d2_color *clut)
Set texture colour palette pointer.
d2_u32 d2_getrevisionhw(const d2_device *handle)
Query hw revisionID.
d2_s32 d2_settexclut_offset(d2_device *handle,
d2_u32 offset)
Set index offset for indexed texture formats.
List of all dave driver errorcodes.
d2_s32 d2_framebuffer(d2_device *handle,
void *ptr,
d2_s32 pitch,
d2_u32 width,
d2_u32 height,
d2_s32 format)
Specify the rendering target.
d2_s32 d2_setcolor(d2_device *handle,
d2_s32 index,
d2_color color)
Set color registers.
Close