PxLoadImage won't load under Photon 2.0 ???

We have compiled the example code from the Help files, and found it does not
work under Phab and Photon 2.0; It does work under QNX 4.25 and Photon 1.14.
The error messages reports “Couldn’t load image”. Not as much help as we
need…:slight_smile:

All of the Knowledge Base articles refer only to QNX 4.25. Is there some
trick for Photon 2.0?

Can anybody offer some suggestions to display a .bmp file from a disk in
a PtLabel widgit???

Thanks - Phil Olynyk

Phil Olynyk <phil.olynyk@eti-gaming.com> wrote:

We have compiled the example code from the Help files, and found it does not
work under Phab and Photon 2.0; It does work under QNX 4.25 and Photon 1.14.
The error messages reports “Couldn’t load image”. Not as much help as we
need…> :slight_smile:

All of the Knowledge Base articles refer only to QNX 4.25. Is there some
trick for Photon 2.0?

Can anybody offer some suggestions to display a .bmp file from a disk in
a PtLabel widgit???

Below is the code extracted from the Photon 2 course sample on
just this. It works - taught the section just yesterday,
including having the students compile and run this code… :slight_smile:

Norbert Black
QSSL Training Services

\


/* callbacks.c /
/
/
/
This application demonstrates how to load an image /
/
from a file. /
/
/
/
This file contains: /
/
/
/
loadImageCB() /
/
Callback type: Pt_CB_ACTIVATE /
/
Widget: Load button on the base window /
/
/
/
This function is called when the user chooses the /
/
Load button from the base window. /
/
This function demonstrates how to load images from /
/
a file. It also shows how to set up a progress /
/
function wherein you can give the user feedback /
/
during a long load as well as let Photon events /
/
be processed. /
/
/
/
Operation: /
/
The first step in writing code to load an image /
/
is to specify what image formats you will be /
/
supporting. This is done by inserting the /
/
#defines as is done in the section headed with /
/
“VERY IMPORTANT!” below. /
/
/
/
The next step is done in loadImageCB(). That is /
/
to set up a PxMethods_t structure. At minimum /
/
you must zero it out and set the flags member to /
/
PX_LOAD. After this you simply call /
/
PxLoadImage() to do the loading. /
/
/
/
This code also sets the px_progress memeber of /
/
the PxMethods_t structure to the address of a /
/
function to call during loading /
/
(progressFunction() below). /
/
/
/
PxLoadImage() returns a pointer to the loaded /
/
image. In this code we resize the window to fit /
/
the loaded image. /
/
/
/
The image is displayed by using it as the label /
/
data for a PtLabel widget. /
/
/
/
-------------------------------------------------------/
/
/
/
progressFunction() /
/
Function type: Progress Function called during /
/
image loading /
/
/
/
This function will be called during loading after /
/
every scan line is loaded/decoded. It is passed /
/
the percentage of the image that has been loaded so /
/
far. /
/
/
/
Operation: /
/
The percentage is displayed to the user using a /
/
PtProgress widget. /
/
/
/
PtBkgdHandlerProcess() is then called to let any /
/
Photon events be handled. /
/
/
/
-------------------------------------------------------*/

/* 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”
#include “globals.h”

/*=====================================================================

  • VERY IMPORTANT! see the following !!!
  • You must choose which image loading code will be linked into your
  • executable. Do this as shown below …
    */
    #define PX_IMAGE_MODULES
    #define PX_GIF_SUPPORT
    #define PX_PCX_SUPPORT
    #define PX_JPG_SUPPORT
    #define PX_BMP_SUPPORT
    #define PX_TGA_SUPPORT

#include <photon/PxImage.h> /* … and THEN do the include! /
/
VERY IMPORTANT! see the above !!!
=====================================================================/

PhImage_t image = NULL;
PtFileSelectionInfo_t info;



/
----------------------------------------------------------------------
*

  • baseSetup

---------------------------------------------------------------------/
int
baseSetup( PtWidget_t *link_instance, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo )
{
PtArg_t arg;

/* The Pt_FREE_MEMORY flag cannot be set from PhAB, so we do it here.
It tells the widget that when we give it a new image, if it already
has an old one, it can free the memory associated with that old one
before replacing it with the new one. Note that we also had to
set the Ph_RENDER_* flags in the image->flags below. */
PtSetArg (&arg, Pt_ARG_FLAGS, Pt_FREE_MEMORY, Pt_FREE_MEMORY);
PtSetResources (ABW_imageDestination, 1, &arg);

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

return( Pt_CONTINUE );
}

/*----------------------------------------------------------------------
*

  • loadImageCB

---------------------------------------------------------------------/
int
loadImageCB (PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo)
{
PhPoint_t dim, *posptr;
PtArg_t arg[1];
PxMethods_t methods;

/*------------------------------------------------------------------

  • get file to load using the dialog that PtFileSelection() displays
    -----------------------------------------------------------------/

if ( info.dim.w == 0 ) {
/* This will be done only once. info.dim.w is only 0 if you haven’t

  • brought up the file selection dialog yet. Once you’ve brought it
  • up, it will contain the width of the dialog.
    /
    info.pos.x = 0;
    info.pos.y = 30;
    strcpy (info.path, “/usr/help/product/photon/image-lib”);
    strcpy (info.fspec, "
    ");
    }

if ( PtFileSelection (ABW_base, &info.pos,
“Select file containing an image”,
info.path, info.fspec,
“&Load”, “&Cancel”,
“nsd”, &info, 0) == -1 ) {
ApError (ABW_base, 0, “PxloadImage”,
“Could not display file selection dialog”, NULL);
return( Pt_CONTINUE );
}

if ( info.ret == Pt_FSDIALOG_BTN2 )
return (Pt_CONTINUE);

/*------------------------------------------------------------------

  • Load the image from the file, ‘image’ will point to it.
  • The address of progressFunction() is also given so that it can
  • be called during loading.
  • progressFunction() will be called during loading after every
  • scan line is loaded/decoded. This is useful if the loading will
  • take long and you want the user to have some feedback that it
  • is actually working. In this case you may also want to
  • PtBkgdHandlerProcess() to let any Photon events be handled.
    -----------------------------------------------------------------/

memset (&methods, 0, sizeof (PxMethods_t));
methods.flags = PX_LOAD; // load file, convert to format photon understands
methods.px_progress = progressFunction;
image = PxLoadImage (info.path, &methods);
if ( image == NULL ) {
ApError (ABW_base, errno, “pxloadimage”, “PxLoadImage() failed”, NULL);
return (Pt_CONTINUE);
}
/* Since the PtLabel we will be using to display the image,
ABW_imageDestination, has the Pt_FREE_MEMORY flag set, and we’re
setting the flags below, the next time we dump a new image into the
PtLabel, it will free this one. */
image->flags = Ph_RELEASE_IMAGE | Ph_RELEASE_PALETTE |
Ph_RELEASE_TRANSPARENCY_MASK |
Ph_RELEASE_GHOST_BITMAP;

/*------------------------------------------------------------------

  • display the image using the label widget. Note that we figure
  • out what the new size of the window and of the label should be
  • using the information in the image structure.
    -----------------------------------------------------------------/

// get the position of the label widget (where the image goes)
PtSetArg (&arg[0], Pt_ARG_POS, &posptr, 0);
PtGetResources (ABW_imageDestination, 1, arg);

// calculate a new window size that accommodates the new image …
dim.x = posptr->x + image->size.w;
dim.y = posptr->y + image->size.h;
// … and set it
PtSetArg (&arg[0], Pt_ARG_DIM, &dim, 0);
PtSetResources (ABW_base, 1, arg);

// set up a work procedure to change the label. Why? If you care
// then read on but it’s not important for this example of pxloadimage().
// If you don’t care then see the code in the function called workProc()
// below for what we do next.
//
// For those who care… If the window is about to grow then we are
// going to do two things. One, we’ll draw the new image as a result of
// the code that changes the image. Two, we’ll get and expose event.
// The order in which we do these things is important.
//
// If we handle the expose event first then the drawing looks very smooth.
// If we handle the expose event second then it looks as though we are
// drawing the image twice. The first would be as a result of changing
// the image, the second is when we would draw the exposed parts of the
// window, first in grey and then with the image.
//
// Using a work proc to change the image data will cause the order to
// be: handle expose, followed by draw image. This is because work procs
// are called only after all pending events are handled.

PtAppAddWorkProc( NULL, workProc, NULL );

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

return (Pt_CONTINUE);
}

int
workProc( void *data )
{
PtArg_t arg[2];

// now set the new image and resize the label widget to fit it
PtSetArg (&arg[0], Pt_ARG_LABEL_DATA, image, sizeof (PhImage_t));
PtSetArg (&arg[1], Pt_ARG_DIM, &image->size, 0);
PtSetResources (ABW_imageDestination, 2, arg);

// return Pt_END to remove the work proc, we only want it done once per
// image load
return (Pt_END);
}

/*----------------------------------------------------------------------
*

  • progressFunction

---------------------------------------------------------------------/
void *progressFunction (int percentReadIn)
{
PtArg_t arg[1];

// percentReadIn >> 16, // whole portion is in upper 16-bites
// percentReadIn & 0x0000ffff // decimal portion is in lower 16-bites

PtSetArg (&arg[0], Pt_ARG_GAUGE_VALUE, (percentReadIn >> 16), 0);
PtSetResources (ABW_progress, 1, arg);

PtBkgdHandlerProcess(); // handle any Photon events

return NULL;
}
}

Can you make the actual image itself available for testing somehow?

Phil Olynyk <phil.olynyk@eti-gaming.com> wrote:

We have compiled the example code from the Help files, and found it does not
work under Phab and Photon 2.0; It does work under QNX 4.25 and Photon 1.14.
The error messages reports “Couldn’t load image”. Not as much help as we
need…> :slight_smile:

All of the Knowledge Base articles refer only to QNX 4.25. Is there some
trick for Photon 2.0?

Can anybody offer some suggestions to display a .bmp file from a disk in
a PtLabel widgit???

Thanks - Phil Olynyk

Norbert:
Below is the code extracted from the Photon 2 course sample on
just this. It works - taught the section just yesterday,
including having the students compile and run this code… > :slight_smile:

Norbert Black
QSSL Training Services

/*=====================================================================

  • VERY IMPORTANT! see the following !!!
  • You must choose which image loading code will be linked into your
  • executable. Do this as shown below …
    */
    #define PX_IMAGE_MODULES
    #define PX_GIF_SUPPORT
    #define PX_PCX_SUPPORT
    #define PX_JPG_SUPPORT
    #define PX_BMP_SUPPORT
    #define PX_TGA_SUPPORT

#include <photon/PxImage.h> /* … and THEN do the include! /
/
VERY IMPORTANT! see the above !!!
=====================================================================/

Hmm i notice that the standard and very popular amiga/Electronic Arts
IFF graphics support is missing from the above, i think i saw dan hint
at adding that option after it was pointed out that EA invented it and the
spec is free and widely documented.

its shame IFF cant be used in a standard way right now as MANY extreamly
good looking amiga freeware ICONS are in IFF gfx template format and Aminet
is lettered with potential to give RTP photon developers great ICONS/widgets ?
for Photon projects (check .

im wondering how people might currently convert gfx IFF`s to Photon widgets
at this time ? as im sure many people would prefer the amiga style to the
very windows/linux look or at least the option to use them if they wish.

take a look at Glow Icons, pix/gicon

Ohh on an unrelated subject while looking at the aminet mailinglist
for the above location i came across what seems the amigaE sources,
if true anyone fancy trying to port the AmigaE compiler and
related tools as found in aminets
(wuarchive.wustl.edu (128.252.135.4) being the main site)
/dev/E, there are many E sources that might be fun to port to RTP.