PxLoadImage

HI,

I tried the function PxLoadImage, it works well on QNX 4.23-25 but the same
little PhAB app. does not work on Nutrino. Obviously, I converted and
recompiled it on the Nutrino plateform. But in all case, it’s almost the
same code shown in the exemple from the help.

The result is :
“Could not load image”

Rick

Hi Rick,

Could you post a snippet of code for the problem you are having??

Regards
Brenda


Rick <eric.dionne@eti-gaming.com> wrote:

HI,

I tried the function PxLoadImage, it works well on QNX 4.23-25 but the same
little PhAB app. does not work on Nutrino. Obviously, I converted and
recompiled it on the Nutrino plateform. But in all case, it’s almost the
same code shown in the exemple from the help.

The result is :
“Could not load image”

Rick

OK,

First, I use this function in a callback, it’s when I press on a button to
change the image of a PtBkgd.

Here’s the source of this callback:

/* Standard headers */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

#define PX_IMAGE_MODULES // define the modules we want
#define PX_GIF_SUPPORT
#define PX_JPG_SUPPORT
#define PX_PCX_SUPPORT
#define PX_BMP_SUPPORT

#include <photon/PxImage.h>

/* Local headers */
#include “ablibs.h”
#include “abimport.h”
#include “proto.h”

// These functions are the same from help
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;
PhImage_t *img=NULL;

char fname[200] = {“button_off.bmp”}; // or jpeg give the same result

int ChangeImage( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t
*cbinfo )
{
PtArg_t arg[2];
PxMethods_t methods;
int fd=-1;

/* eliminate ‘unreferenced’ warnings */
widget = widget, apinfo = apinfo, cbinfo = cbinfo;

/////
/* Open file just to be sure if exists /
/

if ( (fd = open( fname, O_RDONLY )) == -1)
{
fprintf( stderr, “File %s not found”, fname );
PtExit( EXIT_FAILURE );
}
close( fd );
*/
//////////

memset( &methods, 0, sizeof( PxMethods_t ) );
methods.px_alloc = memory_allocate;
methods.px_free = (void )&memory_free;
methods.px_warning = (void
)&warning;
methods.px_error = (void*)&error;
methods.px_progress = (void*)&progress;
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;

fprintf( stderr, “Image width: %d\n”, img->size.w );
fprintf( stderr, “Image height: %d\n”, img->size.h );
fprintf( stderr, “Image BPL: %d\n”, img->bpl );
fprintf( stderr, “Image colors: %d\n”, img->colors );
fprintf( stderr, “Image type: %d\n”, img->type );

/* 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 );
PtSetResources( ABW_PtBkgd1, 2, arg );

free( img );

return( Pt_CONTINUE );
}

“Gui Group” <gui@qnx.com> wrote in message news:9j1cv0$j66$1@nntp.qnx.com

Hi Rick,

Could you post a snippet of code for the problem you are having??

Regards
Brenda


Rick <> eric.dionne@eti-gaming.com> > wrote:
HI,

I tried the function PxLoadImage, it works well on QNX 4.23-25 but the
same
little PhAB app. does not work on Nutrino. Obviously, I converted and
recompiled it on the Nutrino plateform. But in all case, it’s almost the
same code shown in the exemple from the help.

The result is :
“Could not load image”

Rick


\

We found the “problem” !!!.

It’s not working on plateform 6.0 patch C but it’s working on 6.1.

By the way in the code, from the previous post, there is a little error for
setting the resources, we should read:

// PtSetArg( &arg[0], Pt_ARG_LABEL_TYPE, Pt_IMAGE, 0 );
PtSetArg( &arg[0], Pt_ARG_BKGD_IMAGE, img, 0 );
PtSetResources( ABW_PtBkgd1, 1, arg );



“Rick” <eric.dionne@eti-gaming.com> wrote in message
news:9j1h0v$5mr$1@inn.qnx.com

OK,

First, I use this function in a callback, it’s when I press on a button to
change the image of a PtBkgd.

Here’s the source of this callback:

/* Standard headers */
#include <stdio.h
#include <stdlib.h
#include <unistd.h
#include <string.h

#define PX_IMAGE_MODULES // define the modules we want
#define PX_GIF_SUPPORT
#define PX_JPG_SUPPORT
#define PX_PCX_SUPPORT
#define PX_BMP_SUPPORT

#include <photon/PxImage.h

/* Local headers */
#include “ablibs.h”
#include “abimport.h”
#include “proto.h”

// These functions are the same from help
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;
PhImage_t *img=NULL;

char fname[200] = {“button_off.bmp”}; // or jpeg give the same result

int ChangeImage( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t
*cbinfo )
{
PtArg_t arg[2];
PxMethods_t methods;
int fd=-1;

/* eliminate ‘unreferenced’ warnings */
widget = widget, apinfo = apinfo, cbinfo = cbinfo;

/////
/* Open file just to be sure if exists /
/

if ( (fd = open( fname, O_RDONLY )) == -1)
{
fprintf( stderr, “File %s not found”, fname );
PtExit( EXIT_FAILURE );
}
close( fd );
*/
//////////

memset( &methods, 0, sizeof( PxMethods_t ) );
methods.px_alloc = memory_allocate;
methods.px_free = (void )&memory_free;
methods.px_warning = (void
)&warning;
methods.px_error = (void*)&error;
methods.px_progress = (void*)&progress;
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;

fprintf( stderr, “Image width: %d\n”, img->size.w );
fprintf( stderr, “Image height: %d\n”, img->size.h );
fprintf( stderr, “Image BPL: %d\n”, img->bpl );
fprintf( stderr, “Image colors: %d\n”, img->colors );
fprintf( stderr, “Image type: %d\n”, img->type );

/* 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 );
PtSetResources( ABW_PtBkgd1, 2, arg );

free( img );

return( Pt_CONTINUE );
}

“Gui Group” <> gui@qnx.com> > wrote in message
news:9j1cv0$j66$> 1@nntp.qnx.com> …
Hi Rick,

Could you post a snippet of code for the problem you are having??

Regards
Brenda


Rick <> eric.dionne@eti-gaming.com> > wrote:
HI,

I tried the function PxLoadImage, it works well on QNX 4.23-25 but the
same
little PhAB app. does not work on Nutrino. Obviously, I converted and
recompiled it on the Nutrino plateform. But in all case, it’s almost
the
same code shown in the exemple from the help.

The result is :
“Could not load image”

Rick




\