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.
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.
Find below an example of resizing a source texture with filtering enabled.
Please not that the texel-to-pixel mapping implementation has changed for the magnification case since D2 Driver version 3.10.
Blit Functions | BLock Image Transfer operations |
BLIT Attributes Writes | |
d2_setblitsrc | Specify the source for blit operation. |
BLIT Rendering Functions | |
d2_blitcopy | Copy rectangle part of the source into destination. |
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.
handle | device pointer (see: d2_opendevice) |
ptr | address of the top left texel (coordinate 0,0) |
pitch | number of pixels (not bytes) per scanline |
width | width of bitmap in pixels (equal or less than pitch) |
height | height of bitmap in pixels |
format | pixel encoding type (bitmap format) |
d2_mode_alpha8 | monochrome 8bit per pixel |
d2_mode_alpha4 | monochrome 4bit per pixel |
d2_mode_alpha2 | monochrome 2bit per pixel |
d2_mode_alpha1 | monochrome 1bit per pixel |
d2_mode_rgb565 | colored 16bit per pixel (alpha is blue) |
d2_mode_argb8888 | colored 32bit per pixel |
d2_mode_rgba8888 | colored 32bit per pixel |
d2_mode_rgb888 | (same as d2_mode_argb8888, in case of RLE textures 24bit pixel are decoded to 32bit) |
d2_mode_argb4444 | colored 16bit per pixel |
d2_mode_rgba4444 | colored 16bit per pixel |
d2_mode_rgb444 | (same as d2_mode_argb4444) |
d2_mode_argb1555 | colored 16bit per pixel |
d2_mode_rgba5551 | colored 16bit per pixel |
d2_mode_rgb555 | (same as d2_mode_argb1555) |
d2_mode_ai44 | colored, palletized 8bit per pixel, (4 bit alpha, 4 bit indexed RGB: see d2_settexclut) |
d2_mode_i8 | colored, palletized 8bit per pixel (palette is used if d2_mode_clut is also set) |
d2_mode_i4 | colored, palletized 4bit per pixel (palette is used if d2_mode_clut is also set) |
d2_mode_i2 | colored, palletized 2bit per pixel (palette is used if d2_mode_clut is also set) |
d2_mode_i1 | colored, 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_rle | Enables the RLE unit (available if the feature bit D2FB_RLEUNIT is set (see d2_getrevisionhw)). |
d2_mode_clut | Enables 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.
errorcode (D2_OK if successful) see list of Errorcodes for details
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.
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.
handle | device pointer (see: d2_opendevice) |
srcwidth, srcheight | size of source rectangle in pixels (integer) |
srcx,srcy | position in source bitmap (integer) |
dstwidth, dstheight | size of destination rectangle in pixels (fixedpoint) |
dstx,dsty | position in destination bitmap (fixedpoint) |
flags | any combination of blit flag bits (see below) |
d2_bf_filteru | apply linear filter on U axis (x-direction) |
d2_bf_filterv | apply linear filter in V axis (y-direction) |
d2_bf_filter | apply bilinear filter (both axis) |
d2_bf_wrapu | wrap bitmap on U axis (x-direction) |
d2_bf_wrapv | wrap bitmap on V axis (y-direction) |
d2_bf_wrap | wrap bitmap on U and V axis (x/y-direction) |
d2_bf_mirroru | mirror bitmap in U axis (x-direction) |
d2_bf_mirrorv | mirror bitmap in V axis (y-direction) |
d2_bf_colorize | bitmap colors are multiplied by color register index 0 (see: d2_setcolor) |
d2_bf_colorize2 | bitmap colors are interpolated between color register index 0 and 1 (see: d2_setcolor) |
d2_bf_usealpha | alpha value from bitmap is used |
d2_bf_invertalpha | alpha value from bitmap is inverted before use (requires usealpha) |
d2_bf_no_blitctxbackup | for 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.
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
errorcode (D2_OK if successfull) see list of Errorcodes for details
Specify the source for blit operation.
d2_s32 d2_setblitsrc( d2_device * handle, void * ptr, d2_s32 pitch, d2_s32 width, d2_s32 height, d2_u32 format )
Copy rectangle part of the source into destination.
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 )
Create a new device handle.
d2_device * d2_opendevice( d2_u32 flags )
Set texture colour palette pointer.
d2_s32 d2_settexclut( d2_device * handle, d2_color * clut )
Query hw revisionID.
d2_u32 d2_getrevisionhw( const d2_device * handle )
Set index offset for indexed texture formats.
d2_s32 d2_settexclut_offset( d2_device * handle, d2_u32 offset )
Specify the rendering target.
d2_s32 d2_framebuffer( d2_device * handle, void * ptr, d2_s32 pitch, d2_u32 width, d2_u32 height, d2_s32 format )
Set color registers.
d2_s32 d2_setcolor( d2_device * handle, d2_s32 index, d2_color color )