PxLoadImage and PhAB Animation

Hi all,
Has anyone successfully got the sample PxLoadImage function to work for them? If yes can you please help me? I always get the “Can not load image” error with this sample function.

Basically, I have a few jpeg images that I want to put in a PhAB app. that would display them one after another, sort a like a slide show.

I tried following help instruction on how to do animation, the instructions themselves are an endless loop! It says I have to create a database in PhAB, but I cannot create one following the instructions in QNX help. The instructions go into a forever loop without really showing you how to do anything.

If someone can help me with this i would really appreciate it!

Thank you in advance.


Can you post the code that is not working?
What version of QNX are you on?

I think for a simple slideshow app, then I would not bother with any fancy PhAb stuff, you really only need PxLoadImage and PtTimer to do automatic transistions between pictures.

I am using QNX 6.2.1. I tried to get the following code to work.
I just wanted to do a simple program that would display a few images, but when I couldn’t get the sample program to work I got kinda discourage.
If you can give me some pointers I would be very greatful to you.
Thanks again for your help.

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <malloc.h>
#include <assert.h>
#include <ctype.h>
#include <signal.h>

#include <Ph.h>
#include <Pt.h>

#include <photon/PxImage.h>

void *memory_allocate( long nbytes, int type );
void *memory_free( void *memory, int type );
void *warning( char *msg );
void *error( char *msg );
void *progress( int percent );

int         UseShmem = 1;

int main( int argc, char *argv[] )
    int         c;
    PtArg_t     arg[5];
    PtWidget_t  *window;
    char        fname[255] = { 0 };
    int         Query = 0;
    PhImage_t   *img;
    PxMethods_t methods;

    /* initialize widget library and attach to Photon */
    if( PtInit( NULL ) )
        PtExit( EXIT_FAILURE );

    while( ( c = getopt( argc, argv,
                         "f:QS" ) ) != -1 ) {
        switch( c ) {

            case 'f':         // filename
                strncpy(fname, optarg, 200 );

            case 'Q':         // query file
                Query = 1;

            case 'S':

    memset( &methods, 0, sizeof( PxMethods_t ) );
    methods.px_alloc    = memory_allocate;
    methods.px_free     = memory_free;
    methods.px_warning  = warning;
    methods.px_error    = error;
    methods.px_progress = progress;

    if( Query )
        methods.flags |= PX_QUERY;
        methods.flags |= PX_LOAD;

    if( ( img = PxLoadImage( fname,
                             &methods ) ) == NULL ) {
        fprintf( stderr, "Error loading/query %s\n",
                 fname );
        PtExit( EXIT_FAILURE );

    /* Make sure PhReleaseImage() releases any allocated
       members of the PhImage_t structure. */

    img->flags |= Ph_RELEASE_IMAGE_ALL;

    if( Query ) {
      printf( "Image width:   %d\n", img->size.w );
      printf( "Image height:  %d\n", img->size.h );
      printf( "Image BPL:     %d\n", img->bpl );
      printf( "Image colors:  %d\n", img->colors );
      printf( "Image type:    %d\n", img->type );
    PtExit( EXIT_SUCCESS );

    /* increase the draw buffer */
    PgSetDrawBufferSize( 0x8000 );

    /* create a window */
    PtSetArg( &arg[0], Pt_ARG_DIM, &img->size, 0 );
    PtSetArg( &arg[1], Pt_ARG_WINDOW_TITLE,
              "Photon Image Viewer", 0 );
    window = PtCreateWidget( PtWindow, Pt_NO_PARENT, 2, arg );

    /* Create a label widget with the image. Remember that
       the widget creates a copy of the PhImage_t structure.
       The widget doesn't copy data pointed to by the
       PhImage_t members. */

    PtSetArg( &arg[0], Pt_ARG_LABEL_TYPE, Pt_IMAGE, 0 );
    PtSetArg( &arg[1], Pt_ARG_LABEL_IMAGE, img, 0 );
    PtCreateWidget( PtLabel, window, 2, arg );

    /* Free the PhImage_t structure (but not its contents). */

    free( img );

    PtRealizeWidget( window );

    return EXIT_SUCCESS;

void *memory_allocate( long nbytes, int type )
    if( type == PX_IMAGE && UseShmem ) {
        return( PgShmemCreate( nbytes, NULL ) );
    else {
        return( calloc( 1, nbytes ) );

void *memory_free( void *memory, int type )
    if( type == PX_IMAGE && UseShmem ) {
        PgShmemDestroy( memory );
    else {
        free( memory );
    return NULL;

void *warning( char *msg )
    printf( "%s\n", msg );
    return NULL;

void *error( char *msg )
    printf( "%s\n", msg );
    PtExit( EXIT_FAILURE );
    return NULL;

void *progress( int percent )
    printf( "Load Status:  %d.%d percent\n",
             percent >> 16, percent & 0xffff );
    return NULL;

I copied your code into image.c, then did the following:

qcc -g -o image image.c -lph -lphexlib

./image -f logo.jpg

Worked as expected - I got the status messages on stdout and it displayed the logo from the jpeg.

So, you need to supply more info. I admit I tried it on 6.3, but that shouldn’t be the issue (since I have used code like this in many other versions of QNX).


I am using QNX 6.2.1 IDE. I copied the code and compiled it. I got a bin file which I ftp to my target board. Then I run the bin file and the following is what I got:
[/tmp]# ./image -f auto_navi.jpg
Could not load image

I made sure the photo is in the same directory and gave the path for it also. For some reason I can not get this to work!
Any idea? Thanks,

Sure, make sure you have all the shared objects which are required on your target. In particular, the pi_io_*.so from /lib/dll. When PxLoadImage determines the type of the file you are trying to decode, it loads the appropriate dll. If you try this:

DL_DEBUG=1 ./image -f auto_navi.jpg

you should see the attempt and failure to load a shared object.

As an aside, one of the advantages of selfhosted development is seeing the application run on a full up system, them if it fails on the target, you know it is an embedding problem, not an application problem. ;-)


You are a godsend! Thank you very much!!! That command helped a great deal.
You made my day! that command gave me so much info and I was able to correct the problem.
The proram works :laughing:

No problem. Glad to be a help. ;-)