Draw an image
int PgDrawImage( void const *ptr,
int type,
PhPoint_t const *pos,
PhDim_t const *size,
int bpl,
long tag );
int PgDrawImagemx( void const *ptr,
int type,
PhPoint_t const *pos,
PhDim_t const *size,
int bpl,
long tag );
These functions build a command in the draw buffer to draw an image. The functions start the image at pos and extend it down and to the right according to size.
![]() |
Instead of using this function, we recommend using a PhImage_t structure and calling PgDrawPhImagemx(). To make one of the colors in the image transparent, call PhMakeTransBitmap(). |
The bpl argument indicates the number of bytes per line of image data (that is, the offset from one line of data to the next).
To calculate the size of the data transferred to the graphics driver, multiply bpl by size.y. You can determine the size and bpl arguments with the value returned by PxLoadImage().
The tag argument is used for data caching by programs such as phrelay. To calculate the tag, use PxCRC(). This argument is ignored if you set it to 0.
The type argument controls how the image data pointed to by ptr is interpreted by the graphics driver. You can set type to one of the following:
RRRR.RRRR.GGGG.GGGG.BBBB.BBBB
xRRR.RRGG.GGGB.BBBB
RRRR.RGGG.GGGB.BBBB
xxxx.RRRR.GGGG.BBBB
For convenience, the following masks can be applied to type to determine the image's class:
![]() |
If you call the "mx" form of this function, the data isn't
physically copied into the draw buffer. Instead, a pointer
to the array is stored until the draw buffer is flushed.
Make sure you call PgFlush()
before you modify the image.
If the data is in shared memory, the mx form of this function will automatically pass a shared memory reference instead of the image. |
The following example:
PhImage_t *pimage;
InitPalImage() {
if (pimage != NULL) return;
if ((pimage = PxLoadImage( "mackface.bmp", NULL )) == NULL) {
perror( "Unable to load image" );
return;
}
}
DrawPalImage() {
PhPoint_t p = { 0, 0 };
InitPalImage();
if (pimage == NULL) return;
if ((pimage->palette != NULL) && (pimage->colors > 0))
PgSetPalette( pimage->palette, 0, 0, pimage->colors,
Pg_PALSET_SOFT, 0 );
PgDrawImage( pimage->image, pimage->type, &p,
&pimage->size, pimage->bpl, 0 );
}
will draw:
Photon
| Safety: | |
|---|---|
| Interrupt handler | No |
| Signal handler | No |
| Thread | No |
PgDrawTImage(), PgFlush(), PgSetFillColor(), PgSetPalette(), PgShmemCreate(), PhMakeTransBitmap(), PxCRC(), PxLoadImage()