Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/photon/lib_ref/ph/phmaketransparent.html on line 1

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/photon/lib_ref/ph/phmaketransparent.html on line 1

Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/photon/lib_ref/ph/phmaketransparent.html on line 8

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/photon/lib_ref/ph/phmaketransparent.html on line 8

PhMakeTransparent()

Make a given color transparent in an image, using chroma if possible

Synopsis:

int PhMakeTransparent( PhImage_t *image,
                       PgColor_t trans_color );

Library:

ph

Description:

PhMakeTransparent() makes the given trans_color transparent in the given image. This function is similar to PhMakeTransBitmap(), but PhMakeTransparent() uses chroma when possible; chroma is accelerated by most hardware, whereas transparency bitmaps are always implemented in software.


Note: If the image is palette-based, and the specified color appears more than once in the palette, both become transparent if chroma is used. In this case, PhMakeTransparent() calls PhMakeTransBitmap() to create a transparency mask.

The trans_color argument is the RGB color in the image's palette to be made transparent. You can pass an index into the palette as trans_color by ORing it with Pg_INDEX_COLOR. For example:

if ( PhMakeTransparent( my_image,
                        n | Pg_INDEX_COLOR ) == 0 )
{
    …
}

To draw the image, use PgDrawPhImage() or PgDrawPhImagemx().

Returns:

0
Success.
-1
An error occurred.

Examples:

/*
 * This is code for a PhAB application that demonstrates
 * how to make an image transparent.  It also shows how
 * to take that image, put it into a label widget, and
 * draw it on 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) );

    /* Make all the white pixels transparent. */

    PhMakeTransparent( &trans_image, Pg_WHITE );

    /* Put the transparent image 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 by
       subtracting what we added above. */
    rect.ul.x *= -1;
    rect.ul.y *= -1;
    PgSetTranslation( &rect.ul, Pg_RELATIVE );
    PtClipRemove();
}

Classification:

Photon

Safety:
Interrupt handler No
Signal handler No
Thread No

See also:

PgColor_t, PgDrawPhImage*(), PgDrawPhImageRect*(), PgDrawRepPhImage*(), PhCreateImage(), PhImage_t, PhMakeTransBitmap()

Images in the Raw Drawing and Animation chapter of the Photon Programmer's Guide


Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/photon/lib_ref/ph/phmaketransparent.html on line 250

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/photon/lib_ref/ph/phmaketransparent.html on line 250