Project Home
Project Home
Trackers
Trackers
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - PgAlpha_t Help: (4 Items)
   
PgAlpha_t Help  
First, I'd like to thank everyone who has helped my on all my photon questions. It has really helped speed up the 
development on my project.

Second, my question. We store images in a jar file which I then have to decode into Photon images. Due to a bug in 
PxLoadImage (which doesn't handle 8-bit pngs correctly, ignores transparency) and the fact that I can only load images 
from a file, I decided to try libpng instead. Long story short, I was able to get everything working. However, there is 
a small part that isn't clear. When I create my PhImage object, there is a property called alpha that is NULL when you 
call PhCreateImage.  In order to get the alpha portion of my 24bit png to draw correctly, I had to create an alpha 
object, memset it to zeros and set alpha_op = Pg_BLEND_SRC_As | Pg_BLEND_DST_1mAs. I'm looking for a explanation of what
 all the different pieces of PgAlpha_t mean so that I handle different png formats correctly. 

Third, my understanding of PhImage memory management is poor. There is the flags property which instructs PhReleaseImage
 which properties to release. A flag for the alpha property isn't documented but I did find it in the header. When it 
frees, is it using free() and assumes all the pieces are allocated with malloc()? It also mention that it doesn't free 
the image itself. Since PhCreateImage allocates the image block, how do I free that? Do I simply call free() on the 
image property?

Thx,
Bill
Re: PgAlpha_t Help  
void PhReleaseImage(PhImage_t *img)
{

    PhDrawContext_t *cur_dc=NULL;

    if (_Ph_)
        cur_dc = _Ph_->draw_context;

    if(img)
    {
        if(img->flags & Ph_RELEASE_IMAGE)
        {
            FREE(img->image);
            img->image = NULL;
        }

        if(img->flags & Ph_RELEASE_PALETTE)
        {
            if (cur_dc)
            {
                if ((CUR_GC->palette.palette == img->palette) || (BUF_GC->palette.palette == img->palette))
                    PgSetPalette(NULL, 0, 0, -1, Pg_PALSET_SOFT, 0);
            }
            free(img->palette);
            img->palette = NULL;
        }

        if(img->flags & Ph_RELEASE_TRANSPARENCY_MASK)
        {
            FREE(img->mask_bm);
            img->mask_bm = NULL;
        }

        if(img->flags & Ph_RELEASE_GHOST_BITMAP)
        {
            FREE(img->ghost_bitmap);
            img->ghost_bitmap = NULL;
        }

        if((img->flags & Ph_RELEASE_ALPHA) && img->alpha)
        {
            if (cur_dc)
            {
                if ((CUR_GC->alpha.src_alpha_map.map == img->alpha->src_alpha_map.map) ||
                    (BUF_GC->alpha.src_alpha_map.map == img->alpha->src_alpha_map.map))
                    PgSetAlpha(0, NULL, NULL, 0, 0);
            }

            FREE(img->alpha->src_alpha_map.map);
/*          free(img->alpha->dest_alpha_map.map); */
            free(img->alpha);
            img->alpha = NULL;
        }
    }
}

It does release the "image data", it doesn't release the PhImage_t structure.  From the docs:

This function doesn't release the image structure itself.

You will notice the FREE() macro, it is defined as:

#define FREE(p) \
    {           \
        if((p) && PgShmemDestroy(p))    \
            free(p);                    \
    }

So if shared memory was used for the image data, via the parameter to PhCreateImage(), it will be released properly.

Regarding PgAlpha_t, you should not have to be responsible for this, 
what version of QNX are you using?  I have heard rumblings about lack of PNG palettized image support, but no one has 
returns answers to me.  If you are using QNX SDP 6.4.0, the libpng is used by the codec.  Can you post one of these 
images?

FYI:  There is an actual Foundry27 Graphics project with forums you can post to for Photon, Advanced Graphics, and GLES 
among other things.

Regards,
-Derek
Re: PgAlpha_t Help  
[snip]
> Regarding PgAlpha_t, you should not have to be responsible for this, 
> what version of QNX are you using?  I have heard rumblings about lack of PNG 
> palettized image support, but no one has returns answers to me.  If you are 
> using QNX SDP 6.4.0, the libpng is used by the codec.  Can you post one of 
> these images?
[snip]

As a follow up to this statement, one can use libimg for palettized PNG images:

img_t img;

memset(&img, 0x00, sizeof(img));
img.format = IMG_FMT_BGRA8888;
img.flags |= IMG_FORMAT;

img_load_file( ................);

One can then access the pixels via:

img.access.direct.data
Re: PgAlpha_t Help  
PNGs with alpha-bits in the palette entries will be supported in QNX SDP 642.  This will apply to Photon and Advanced 
Graphic APIs.  See PR37475 in the _642_ release notes when it is released.

Regards,
-Derek