位图操作是WindML 2D图形库里一个非常重要的功能。要想绘制位图,需要先了解两个名词
顾名思义,DIB主要是给人用的,DDB主要是给显卡用的。与之相关的函数主要有这几个:
typedef struct ugl_dib
{
UGL_SIZE width; /* width of bitmap image in pixels */
UGL_SIZE height; /* height of bitmap image in pixels */
UGL_SIZE stride; /* distance between adjacent scan lines */
UGL_INT32 imageFormat; /* format of the index in bitmap image */
UGL_COLOR_FORMAT colorFormat; /* format of the image */
UGL_SIZE clutSize; /* size of clut in number of elements */
void *pClut; /* Pointer to CLUT */
void *pImage; /* Pointer to image */
UGL_UINT32 transColorKey; /* Reserved field */
} UGL_DIB;
typedef struct ugl_bmap_header
{
UGL_UINT16 type; /* type of bitmap */
UGL_UINT16 width; /* width of bitmap */
UGL_UINT16 height; /* height of bitmap */
UGL_UINT16 maxWidth; /* maximum width of bitmap */
UGL_UINT16 maxHeight; /* maximum height of bitmap */
void *extension; /* device specific extensions */
} UGL_BMAP_HEADER;
typedef UGL_BMAP_HEADER *UGL_BITMAP_ID;
typedef UGL_BMAP_HEADER UGL_DDB;
typedef UGL_DDB *UGL_DDB_ID;
UGL_DDB_ID uglBitmapCreate
(
UGL_DEVICE_ID devId,
UGL_DIB *pDib,
UGL_DIB_CREATE_MODE createMode,
UGL_UINT32 initValue,
UGL_DEVICE_MEM_POOL_ID poolId
);
UGL_STATUS uglBitmapDestroy
(
UGL_DEVICE_ID devId,
UGL_DDB_ID ddbId
);
UGL_STATUS uglBitmapBlt
(
UGL_GC_ID gc,
UGL_BITMAP_ID srcBitmapId,
UGL_POS srcLeft,
UGL_POS srcTop,
UGL_POS srcRight,
UGL_POS srcBottom,
UGL_DDB_ID dstBitmapId,
UGL_POS dstX,
UGL_POS dstY
);
UGL_STATUS uglBitmapStretchBlt
(
UGL_GC_ID gc,
UGL_BITMAP_ID srcBitmapId,
UGL_POS srcLeft,
UGL_POS srcTop,
UGL_POS srcRight,
UGL_POS srcBottom,
UGL_DDB_ID dstBitmapId,
UGL_POS dstLeft,
UGL_POS dstTop,
UGL_POS dstRight,
UGL_POS dstBottom
);
UGL_STATUS uglBitmapWrite
(
UGL_DEVICE_ID devId,
UGL_DIB *pDib,
UGL_POS srcLeft,
UGL_POS srcTop,
UGL_POS srcRight,
UGL_POS srcBottom,
UGL_DDB_ID ddbId,
UGL_POS dstX,
UGL_POS dstY
);
UGL_STATUS uglBitmapRead
(
UGL_DEVICE_ID devId,
UGL_DDB_ID ddbId,
UGL_POS srcLeft,
UGL_POS srcTop,
UGL_POS srcRight,
UGL_POS srcBottom,
UGL_DIB *pDib,
UGL_POS dstX,
UGL_POS dstY
);
UGL_STATUS uglBitmapInfoGet
(
UGL_DEVICE_ID devId,
UGL_DDB_ID bitmapId,
UGL_BITMAP_INFO *pBitmapInfo
);
UGL_STATUS uglBitmapSizeGet
(
UGL_DDB_ID ddbId,
UGL_SIZE *pWidth,
UGL_SIZE *pHeight
);
UGL_STATUS uglBitmapResize
(
UGL_DEVICE_ID devId,
UGL_DDB_ID bitmapId,
int width,
int height
);
首先,需要先创建一个DIB对象。而将这个DIB绘制到屏幕,大致有两种方案:uglBitmapWrite()和uglBitmapBlt()。
uglBitmapWrite()的作用是将DIB直接搬移到一个DDB设备,当这个设备就是Display时,那就是绘制到屏幕了。第二种方案是,先用uglBitmapCreate()将DIB转换为DDB,然后使用uglBitmapBlt()将这个DDB位图搬移到DDB设备;如果需要拉伸,可以使用uglBitmapStretchBlt()。uglBitmapCreate()的另一个优势是,通过第三个参数UGL_DIB_CREATE_MODE createMode,可以轻松创建纯色的位图。