Example:
/* * The following code loads a BITMAP object from a file and then * fills a box in a DC. * * You should note that the code assigns 'bmType' field of the BITMAP object directly. */ { int tox = 800, toy = 800; int count; BITMAP bitmap; unsigned int start_tick, end_tick; /* Load the bitmap from the file. */ if (LoadBitmap (hdc, &bitmap, "res/icon.bmp")) return; bitmap.bmType = BMP_TYPE_ALPHACHANNEL; /* Fill a box with the bitmap with alpha channel. */ start_tick = GetTickCount (); count = 1000; while (count--) { tox = rand() % 800; toy = rand() % 800; /* Set a random alpha channel. */ bitmap.bmAlpha = rand() % 256; /* Fill the box. */ FillBoxWithBitmap (hdc, tox, toy, 0, 0, &bitmap); } end_tick = GetTickCount (); TellSpeed (hwnd, start_tick, end_tick, "Alpha Blended Bitmap", 1000); bitmap.bmType = BMP_TYPE_ALPHACHANNEL | BMP_TYPE_COLORKEY; /* Set the color key (the transparent pixel) of the bitmap. */ bitmap.bmColorKey = GetPixelInBitmap (&bitmap, 0, 0); /* Fill a box with the bitmap with alpha channel and color key. */ start_tick = GetTickCount (); count = 1000; while (count--) { tox = rand() % 800; toy = rand() % 800; /* Set a random alpha channel. */ bitmap.bmAlpha = rand() % 256; /* Fill the box. */ FillBoxWithBitmap (hdc, tox, toy, 0, 0, &bitmap); } end_tick = GetTickCount (); TellSpeed (hwnd, start_tick, end_tick, "Alpha Blended Transparent Bitmap", 1000); UnloadBitmap (&bitmap); }
#define LoadBitmap LoadBitmapFromFile |
#define LoadMyBitmap LoadMyBitmapFromFile |
#define MLS_BLENDMODE_NONE 0x00 |
This function is used to set attributes of MLShadow slave screen. After creating a slave screen by InitSlaveScreen successfully, you should call this function to set its attributes. When blend_flags is MLS_INFOMASK_ALL, it will set all attributes of slave screen.
dc_mls | The handle to the slave screen. | |
mask | The attributes mask, can be or'ed values of the following mask: |
offset_x | The x offset value of slave screen relative to masterscreen. | |
offset_y | The y offset value of slave screen relative to masterscreen. | |
blend_flags | The blend flags, can be one of the following values: |
color_key | The colorkey value of MLShadow slave screen. | |
alpha | The alpha value of MLShadow slave screen. | |
z_order | The zorder of MLShadow slave screen. |
typedef void(* CB_ONE_SCANLINE)(void *context, MYBITMAP *my_bmp, int y) |
const char *GUIAPI CheckBitmapType | ( | MG_RWops * | fp | ) |
Checks the type of the bitmap in a data source.
This function checks the type of the bitmap in the data source fp, and returns the extension of this type of bitmap file.
fp | The pointer to the data source. |
int GUIAPI CleanupMyBitmapSL | ( | MYBITMAP * | my_bmp, | |
void * | load_info | |||
) |
Cleanups the scanline loader.
This function cleanups the scanline loader.
my_bmp | The pointer to the MYBITMAP object. | |
load_info | The initialized information retured by InitMyBitmapSL function. |
void GUIAPI CompileRGBABitmap | ( | HDC | hdc, | |
BYTE * | bits, | |||
Uint32 | pitch, | |||
const BYTE * | my_bits, | |||
Uint32 | my_pitch, | |||
Uint32 | w, | |||
Uint32 | h, | |||
DWORD | flags, | |||
void * | pixel_format, | |||
CB_DRAW_PIXEL | cb_draw, | |||
MYBITMAP_CONTXT * | mybmp | |||
) |
Convert a MYBITMAP pixel data to a BITMAP pixel data.
This function Convert a MYBITMAP pixel data to a BITMAP pixel data.
hdc | The device context. | |
bits | The BITMAP pixel data(RGBA etc.). | |
pitch | The pitch of the BITMAP object. | |
my_bits | The MYBITMAP pixel data to be compile. | |
my_pitch | The pitch of the MYBITMAP object. | |
w | The width of the MYBITMAP object. | |
h | The height of the MYBITMAP object. | |
flags | The flags of the MYBITMAP object. | |
pixel_format | The pixel format of the MYBITMAP object. | |
cb_draw | The draw callback function. | |
mybmp | The context of cb_draw. |
void GUIAPI CompileRGBABitmapEx | ( | HDC | hdc, | |
BYTE * | bits, | |||
Uint32 | pitch, | |||
const BYTE * | my_bits, | |||
Uint32 | my_pitch, | |||
Uint32 | w, | |||
Uint32 | h, | |||
DWORD | flags, | |||
void * | pixel_format, | |||
CB_DRAW_PIXEL | cb_draw, | |||
MYBITMAP_CONTXT * | mybmp, | |||
BYTE * | alpha_mask | |||
) |
Compile a MYBITMAP pixel data to a BITMAP pixel data.
This function compile a MYBITMAP pixel data to a BITMAP pixel data.
void GUIAPI DeleteBitmapAlphaPixel | ( | PBITMAP | bmp | ) |
Deletes the bitmap alpha pixel format information of a BITMAP object.
This function deletes the bitmap alpha pixel format information of the BITMAP object bmp.
void GUIAPI Expand16CBitmap | ( | HDC | hdc, | |
BYTE * | bits, | |||
Uint32 | pitch, | |||
const BYTE * | my_bits, | |||
Uint32 | my_pitch, | |||
Uint32 | w, | |||
Uint32 | h, | |||
DWORD | flags, | |||
const RGB * | pal | |||
) |
Convert a 16 color MYBITMAP pixel data to a BITMAP pixel data.
This function compile a 16 color MYBITMAP pixel data to a BITMAP pixel data.
hdc | The device context. | |
bits | The BITMAP pixel data(RGBA etc.). | |
pitch | The pitch of the BITMAP object. | |
my_bits | The MYBITMAP pixel data to be compile. | |
my_pitch | The pitch of the MYBITMAP object. | |
w | The width of the MYBITMAP object. | |
h | The height of the MYBITMAP object. | |
flags | The flags of the MYBITMAP object. | |
pal | The Palette of the MYBITMAP object. |
void GUIAPI ExpandMonoBitmap | ( | HDC | hdc, | |
BYTE * | bits, | |||
Uint32 | pitch, | |||
const BYTE * | my_bits, | |||
Uint32 | my_pitch, | |||
Uint32 | w, | |||
Uint32 | h, | |||
DWORD | flags, | |||
Uint32 | bg, | |||
Uint32 | fg | |||
) |
Convert a mono color MYBITMAP pixel data to a BITMAP pixel data.
This function compile a MYBITMAP pixel data to a BITMAP pixel data.
hdc | The device context. | |
bits | The BITMAP pixel data(RGBA etc.). | |
pitch | The pitch of the BITMAP object. | |
my_bits | The MYBITMAP pixel data to be compile. | |
my_pitch | The pitch of the MYBITMAP object. | |
w | The width of the MYBITMAP object. | |
h | The height of the MYBITMAP object. | |
flags | The flags of the MYBITMAP object. | |
bg | The foreground color of the BITMAP object. | |
fg | The foreground color of the BITMAP object. |
int GUIAPI ExpandMyBitmap | ( | HDC | hdc, | |
PBITMAP | bmp, | |||
const MYBITMAP * | my_bmp, | |||
const RGB * | pal, | |||
int | frame | |||
) |
Expands a MYBITMAP object to a BITMAP object.
This function expands the MYBITMAP object pointed to by my_bmp to a BITMAP object (bmp).
hdc | The device context. | |
bmp | The expanded BITMAP object. | |
my_bmp | The MYBITMAP object to be expanded. | |
pal | The palette of the MYBITMAP object. | |
frame | The frame of the MYBITMAP object. |
void void GUIAPI HFlipBitmap | ( | BITMAP * | bmp, | |
unsigned char * | inter_buff | |||
) |
Horizontal Flip the special Bitmap object.
bmp | The BITMAP object. | |
inter_buff | The one scan line pre-alloc buffer of bitmap. |
Initializes a BITMAP object as a normal bitmap.
This function initializes the bitmap pointed to by bmp as a normal bitmap. It sets the bitmap structure fields, and allocates the bits if bits is NULL.
hdc | The device context. | |
w | The width of the bitmap. | |
h | The height of the bitmap. | |
pitch | The pitch of the bitmap. | |
bits | The bits of the bitmap. | |
bmp | The BITMAP object to be initialized. |
Initializes the bitmap pixel format information of a BITMAP object.
This function initializes the bitmap pixel format information of the BITMAP object pointed to by bmp. This includes bmBitsPerPixel and bmBytesPerPixel fields, and the private pixel format if the bitmap is a bitmap with alpha.
hdc | The device context. | |
bmp | The BITMAP object to be initialized. |
Initializes scanline loader of the MYBITMAP object from a data source.
This function initializes scanline loader of the MYBITMAP object from a data source.
area | The data source. | |
ext | The extension of the type of this bitmap. | |
my_bmp | The pointer to the MYBITMAP object. | |
pal | The palette will be returned. |
HDC GUIAPI InitSlaveScreen | ( | const char * | name, | |
const char * | mode | |||
) |
Initializes slave screen.
name | The gal engine name. | |
mode | The display mode. For example : 640x480-16bpp. |
Loads a device-dependent bitmap from a general data source.
This function loads a device-dependent bitmap from the data source area.
hdc | The device context. | |
pBitmap | The pointer to the BITMAP object. | |
area | The data source. | |
ext | The extension of the type of this bitmap. |
ERR_BMP_OK | Loading successfully | |
ERR_BMP_IMAGE_TYPE | Not a valid bitmap. | |
ERR_BMP_UNKNOWN_TYPE | Not recongnized bitmap type. | |
ERR_BMP_CANT_READ | Read error. | |
ERR_BMP_CANT_SAVE | Save error. | |
ERR_BMP_NOT_SUPPORTED | Not supported bitmap type. | |
ERR_BMP_MEM | Memory allocation error. | |
ERR_BMP_LOAD | Loading error. | |
ERR_BMP_FILEIO | I/O failed. | |
ERR_BMP_OTHER | Other error. | |
ERR_BMP_ERROR_SOURCE | A error data source. |
Loads a device-dependent bitmap from a file.
int GUIAPI LoadBitmapFromMem | ( | HDC | hdc, | |
PBITMAP | pBitmap, | |||
const void * | mem, | |||
int | size, | |||
const char * | ext | |||
) |
Loads a device-dependent bitmap from memory.
Loads a MYBITMAP object from a data source.
This function loads a MYBITMAP object from the data source area.
my_bmp | The pointer to the MYBITMAP object. | |
area | The data source. | |
pal | The palette will be returned. | |
ext | The extension of the type of this bitmap. |
Loads a MYBITMAP object from a file.
int GUIAPI LoadMyBitmapFromMem | ( | PMYBITMAP | my_bmp, | |
RGB * | pal, | |||
const void * | mem, | |||
int | size, | |||
const char * | ext | |||
) |
Loads a MYBITMAP object from memory.
This function loads a MYBITMAP object from memory.
my_bmp | The pointer to the MYBITMAP object. | |
pal | The palette will be retruned through this pointer. | |
mem | The pointer to the memory area. | |
size | The size of the memory area. | |
ext | The extension name used to determine the type of the bitmap. |
int GUIAPI LoadMyBitmapSL | ( | MG_RWops * | area, | |
void * | load_info, | |||
MYBITMAP * | my_bmp, | |||
CB_ONE_SCANLINE | cb, | |||
void * | context | |||
) |
Loads MYBITMAP scanlines from a data source one by one.
This function loads MYBITMAP scanlines from the data source area one by one.
area | The data source. | |
load_info | The initialized information retured by InitMyBitmapSL function. | |
my_bmp | The pointer to the MYBITMAP object. | |
cb | The callback to inform one scanline loaded. It can be NULL. | |
context | The context information passed to the callback. |
Enable or Disable a MLShadow slave screen.
This function is used to enable or diable a MLShadow slave screen. After creating a slave screen by InitSlaveScreen successfully, its default status is diabled.
dc_mls | The handle of MLShadow slave screen. | |
enable | Whether to enable the MLShadow slave screen. |
Paints an image from data source on device directly.
This function paints an image from data source onto device directly.
hdc | The device context. | |
x | (x,y), the paint position on device. | |
y | (x,y), the paint position on device. | |
area | The data source. | |
ext | The extension of the type of this bitmap. |
ERR_BMP_OK | Painted successfully | |
ERR_BMP_IMAGE_TYPE | Not a valid image type. | |
ERR_BMP_UNKNOWN_TYPE | Not recongnized bitmap type. | |
ERR_BMP_CANT_READ | Read error. | |
ERR_BMP_NOT_SUPPORTED | Not supported bitmap type. | |
ERR_BMP_MEM | Memory allocation error. | |
ERR_BMP_LOAD | Loading error. | |
ERR_BMP_FILEIO | I/O failed. | |
ERR_BMP_OTHER | Other error. | |
ERR_BMP_ERROR_SOURCE | A error data source. |
int GUIAPI PaintImageFromFile | ( | HDC | hdc, | |
int | x, | |||
int | y, | |||
const char * | spFileName | |||
) |
Paints an image from file on device directly.
hdc | The device context. | |
x | (x,y), the paint position on device. | |
y | (x,y), the paint position on device. | |
spFileName | The file name of the image file. |
int GUIAPI PaintImageFromMem | ( | HDC | hdc, | |
int | x, | |||
int | y, | |||
const void * | mem, | |||
int | size, | |||
const char * | ext | |||
) |
Paints an image from memory on device directly.
hdc | The device context. | |
x | (x,y), the paint position on device. | |
y | (x,y), the paint position on device. | |
mem | The pointer to memory containing image data. | |
size | The size of the image data. | |
ext | The name of the image which indicates the type of the image. |
Pivot a bitmap object.
This function aligns the point in the bitmap given by (cx, cy) to (x, y) in device context, then rotates around this point.
void GUIAPI PivotScaledBitmapFlip | ( | HDC | hdc, | |
const BITMAP * | bmp, | |||
fixed | x, | |||
fixed | y, | |||
fixed | cx, | |||
fixed | cy, | |||
int | angle, | |||
fixed | scale_x, | |||
fixed | scale_y, | |||
BOOL | h_flip, | |||
BOOL | v_flip | |||
) |
Rotates, stretches or shrinks, flips a bitmap object.
This function flips the bitmap vertically if v_flip is TRUE, flips the bitmap horizontally if h_flip is TRUE first. Then stretches or shrinks the bitmap according to scale and aligns the point in the bitmap given by (cx, cy) to (x, y) in device context, Finally rotates specified angle pointed to angle in 1/64ths of a degree around this point (cx, cy).
hdc | The device context. | |
bmp | The pointer of BITMAP object. | |
x | (x,y) The x coordinate of a point in fixed point on dc. | |
y | (x,y) The y coordinate of a point in fixed point on dc. | |
cx | (cx,cy) The x coordinate of a point in fixed point on the bitmap. | |
cy | (cx,cy) The y coordinate of a point in fixed point on the bitmap. | |
angle | The specified rotated angle around its center. | |
scale_x | The ratio of width of stretching or shrinking the bitmap in fixed point. | |
scale_y | The ratio of height of stretching or shrinking the bitmap in fixed point. | |
h_flip | The flags of fliping horizontally. | |
v_flip | The flags of fliping vertically. |
BOOL GUIAPI RegisterBitmapFileType | ( | const char * | ext, | |
void *(*)(MG_RWops *fp, MYBITMAP *my_bmp, RGB *pal) | init, | |||
int(*)(MG_RWops *fp, void *init_info, MYBITMAP *my_bmp, CB_ONE_SCANLINE cb, void *context) | load, | |||
void(*)(void *init_info) | cleanup, | |||
int(*)(MG_RWops *fp, MYBITMAP *my_bmp, RGB *pal) | save, | |||
BOOL(*)(MG_RWops *fp) | check | |||
) |
Registers a bitmap file loader, saver, and checker.
This function registers a new bitmap file loader, saver, and checker. You should pass the extension of the bitmap files, the functions to init, load, and cleanup this type of bitmap file, the function to save, and the function to check the type.
ext | The extension name of the type of bitmap file, like "jpg" or "gif". | |
init | The routine to init the MYBITMAP object (bmp). This routine fills the MYBITMAP structure and get the pallete if needed. It will return the init_info for the following load routine. | |
load | The routine to load the scanlines of the bitmap file. This routine will load the initialized MYBITMAP object (bmp) from the data source (fp). It will call the scanline loaded callback (cb) by passing through the context (context), the MYBITMAP object (bmp), and the index of the scanline. | |
cleanup | The cleanup routine. | |
save | The saver of the bitmap file, can be NULL. | |
check | The checker of the bitmap file. |
Replaces a specific pixels in a bitmap with another pixel.
This function replaces the specific pixels with value iOColor with the other pixel value iNcolor in the bitmap pBitmap.
hdc | The device context. | |
pBitmap | The BITMAP object. | |
iOColor | The pixel value of the color will be replaced. | |
iNColor | The pixel value of the new color. |
Rotate a bitmap object.
hdc | The device context. | |
bmp | The pointer of Bitmap object. | |
lx | (lx,ty), the x coordinate of top left corner. | |
ty | (lx,ty), the y coordinate of top left corner. | |
angle | The specified rotated angle around its center. It must be in 1/64ths of a degree. |
Flips horizontally and rotates a bitmap object.
Flips vertically and rotates a bitmap object.
This function flips vertically before rotating the bitmap pointed to bmp.
void GUIAPI RotateScaledBitmap | ( | HDC | hdc, | |
const BITMAP * | bmp, | |||
int | lx, | |||
int | ty, | |||
int | angle, | |||
int | w, | |||
int | h | |||
) |
Stretches or shrinks a bitmap object at the same as rotating it.
void GUIAPI RotateScaledBitmapHFlip | ( | HDC | hdc, | |
const BITMAP * | bmp, | |||
int | lx, | |||
int | ty, | |||
int | angle, | |||
int | w, | |||
int | h | |||
) |
Flip horizontaly, rotates, stretch or shrinks a bitmap object.
This function is similar to RotateScaledBitmap() expect that it flips the bitmap horizontally first.
void GUIAPI RotateScaledBitmapVFlip | ( | HDC | hdc, | |
const BITMAP * | bmp, | |||
int | lx, | |||
int | ty, | |||
int | angle, | |||
int | w, | |||
int | h | |||
) |
Flip vertically, rotates, stretch or shrinks a bitmap object.
This function is similar to RotateScaledBitmap() expect that it flips the bitmap vertically first.
Saves a BITMAP object to a bitmap file.
This function saves the BITMAP object pBitmap to the bitmap file named spFileName.
hdc | The device context. | |
pBitmap | The BITMAP object. | |
spFileName | The file name. |
Saves a MYBITMAP object to a bitmap file.
This function saves the MYBITMAP object my_bmp to the bitmap file named spFileName.
my_bmp | The MYBITMAP object. | |
pal | The palette. | |
spFileName | The file name. |
int GUIAPI StretchPaintImageEx | ( | HDC | hdc, | |
int | x, | |||
int | y, | |||
int | w, | |||
int | h, | |||
MG_RWops * | area, | |||
const char * | ext | |||
) |
Paints an image from data source on device directly.
This function paints an image from data source onto device directly with stretch.
hdc | The device context. | |
x | (x,y), the paint position on device. | |
y | (x,y), the paint position on device. | |
w | the width of the stretched bitmap. | |
h | the height of the stretched bitmap. | |
area | The data source. | |
ext | The extension of the type of this bitmap. |
ERR_BMP_OK | Painted successfully | |
ERR_BMP_IMAGE_TYPE | Not a valid image type. | |
ERR_BMP_UNKNOWN_TYPE | Not recongnized bitmap type. | |
ERR_BMP_CANT_READ | Read error. | |
ERR_BMP_NOT_SUPPORTED | Not supported bitmap type. | |
ERR_BMP_MEM | Memory allocation error. | |
ERR_BMP_LOAD | Loading error. | |
ERR_BMP_FILEIO | I/O failed. | |
ERR_BMP_OTHER | Other error. | |
ERR_BMP_ERROR_SOURCE | A error data source. |
int GUIAPI StretchPaintImageFromFile | ( | HDC | hdc, | |
int | x, | |||
int | y, | |||
int | w, | |||
int | h, | |||
const char * | spFileName | |||
) |
Paints an image from file on device directly.
hdc | The device context. | |
x | (x,y), the paint position on device. | |
y | (x,y), the paint position on device. | |
w | The width of the stretched bitmap. | |
h | The height of the stretched bitmap. | |
spFileName | the file name of the image file. |
int GUIAPI StretchPaintImageFromMem | ( | HDC | hdc, | |
int | x, | |||
int | y, | |||
int | w, | |||
int | h, | |||
const void * | mem, | |||
int | size, | |||
const char * | ext | |||
) |
Paints an image from memory on device directly.
hdc | The device context. | |
x | (x,y) the paint position on device. | |
y | (x,y) the paint position on device. | |
w | The width of the stretched bitmap. | |
h | The height of the stretched bitmap. | |
mem | The pointer to memory containing image data. | |
size | The size of the image data. | |
ext | The name of the image which indicates the type of the image. |
void TerminateSlaveScreen | ( | HDC | hdc | ) |
Terminates slave screen.
hdc | The slave device context. |
void GUIAPI UnloadBitmap | ( | PBITMAP | pBitmap | ) |
Unloads a bitmap.
This function unloads the specified bitmap pBitmap. It will free the private pixel format and the bits of the bitmap.
pBitmap | The BITMAP object. |
void GUIAPI UnloadMyBitmap | ( | PMYBITMAP | my_bmp | ) |
Unloads a bitmap.
This function unloads the specified MYBITMAP object my_bmp. It will free the bits of the bitmap.
my_bmp | The pointer to the MYBITMAP object. |
void GUIAPI VFlipBitmap | ( | BITMAP * | bmp, | |
unsigned char * | inter_buff | |||
) |
Vertical Flip the special Bitmap object.
bmp | The BITMAP object. | |
inter_buff | The one scan line pre-alloc buffer of bitmap. |