![]() |
![]() |
![]() |
![]() |
![]() |
This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs. |
Create a transparency mask for an image
int PhMakeTransBitmap( PhImage_t *image,
PgColor_t trans_color );
ph
This function creates a transparent bitmap or transparency mask for the given image, provided there isn't one already.
![]() |
PhMakeTransparent() is similar to PhMakeTransBitmap(), but PhMakeTransparent() uses chroma when possible; chroma is accelerated by most hardware, whereas transparency bitmaps are always implemented in software. |
The meaning of the trans_color argument depends on the type of the image:
if ( PhMakeTransBitmap( my_image,
n | Pg_INDEX_COLOR ) == 0 )
{
...
}
The resulting bitmap is stored in the mask_bm member of the PhImage_t structure. This function sets the image's Ph_RELEASE_TRANSPARENCY_MASK flag.
To draw the image using the transparency mask, use PgDrawPhImage() or PgDrawPhImagemx().
/*
* This is code for a PhAB application that demonstrates
* how to make a transparency mask for an image. This
* also shows how to take that image and to put it into
* a label widget and to draw it into a PtRaw's canvas.
*/
/* Standard headers */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
/* Toolkit headers */
#include <Ph.h>
#include <Pt.h>
#include <Ap.h>
/* Local headers */
#include "abimport.h"
#include "proto.h"
ApDBase_t *database;
PhImage_t trans_image;
/*
* Setup function for the base window
*/
int
base_window_setup( PtWidget_t *link_instance,
ApInfo_t *apinfo,
PtCallbackInfo_t *cbinfo )
{
PhImage_t *imgptr;
// Get the original image from an image-type
// label widget that we've put in a PhAB picture
// module - don't close the database since we'll
// still be using its image and palette data
database = ApOpenDBase( ABM_our_picture_module );
imgptr = ApGetImageRes( database, "image_label" );
// Copy it so that we don't change the original
// PhImage_t; we'll still be using the same image
// and palette data though
memcpy( &trans_image, imgptr, sizeof(PhImage_t) );
// all white pixels will be transparent
PhMakeTransBitmap( &trans_image, Pg_WHITE );
// Put the image that contains the transparency mask
// into another image-type label
PtSetResource( ABW_destination_label,
Pt_ARG_LABEL_IMAGE, &trans_image, 0 );
/* eliminate 'unreferenced' warnings */
link_instance = link_instance, apinfo = apinfo;
cbinfo = cbinfo;
return( Pt_CONTINUE );
}
/*
* Draw function (Pt_ARG_RAW_DRAW_F) for a PtRaw widget
*/
void
raw_draw_f( PtWidget_t *widget, PhTile_t *damage )
{
PhPoint_t pos = {0, 0};
PhRect_t rect;
damage = damage;
PtSuperClassDraw( PtBasic, widget, damage );
// Find our canvas
PtCalcCanvas( widget, &rect );
// Set translation so that drawing is relative to
// the PtRaw widget, not its parent.
PgSetTranslation( &rect.ul, Pg_RELATIVE );
// Clip to our basic canvas (it's only polite).
PtClipAdd( widget, &rect );
// Do our drawing...
PgDrawPhImagemx( &pos, &trans_image, 0 );
// Remove our translation and clipping
rect.ul.x *= -1; // subtract what we added above
rect.ul.y *= -1;
PgSetTranslation( &rect.ul, Pg_RELATIVE );
PtClipRemove();
}
Photon
| Safety: | |
|---|---|
| Interrupt handler | No |
| Signal handler | No |
| Thread | No |
PgColor_t, PgDrawPhImage*(), PgDrawPhImageRect*(), PgDrawRepPhImage*(), PhCreateImage(), PhImage_t, PhMakeTransparent()
"Images" in the Raw Drawing and Animation chapter of the Photon Programmer's Guide
![]() |
![]() |
![]() |
![]() |