PxLoadImage()

Does function PxLoadImage() correctly recognize compressed bit map format
(BMP) files?
Please advice how to read compressed bit map files.

Janusz.

This depends on what you mean when you say compressed bitmap. If you mean .gif or .jpg then yes it will open them. One way to test the file you would like to open is to use the ‘pv’ utility.

Regards,
Dave B.


Janusz <ruszelj@baxter.com> wrote:

Does function PxLoadImage() correctly recognize compressed bit map format
(BMP) files?
Please advice how to read compressed bit map files.

Janusz.

I consider .bmp file RLE Encoded. Pv can read it without any problems but
PxLoadImage() can not. Simple program I have been using to test it is
attached below.

#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>

#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>

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;

struct timespec stop, start;

void 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;

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

case ‘f’: // filename
strncpy(fname, optarg, 200 );
break;

case ‘Q’: // query file
Query = 1;
break;

case ‘S’:
UseShmem^=1;
break;
}
}

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 = NULL; //progress;

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

clock_gettime(CLOCK_REALTIME, &start);

if( ( img = PxLoadImage( fname,
&methods ) ) == NULL ) {
fprintf( stderr, “Error loading/query %s\n”,
fname );
exit( EXIT_FAILURE );
}
clock_gettime(CLOCK_REALTIME, &stop);
double accum = (stop.tv_sec - start.tv_sec) +
(stop.tv_nsec - start.tv_nsec) * 1e-9;
printf("%s %lf [s]\n", fname, accum);

/* 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 );
exit( EXIT_SUCCESS );
}

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

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

clock_gettime(CLOCK_REALTIME, &start);

/* 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, NULL, 2, arg );

/* Create a label widget with the image. Remember that the
widget creates a copy of the PhImage_t structure (because
Pt_ARG_LABEL_DATA is an Alloc resource). 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_DATA,
img, sizeof( PhImage_t ) );
PtCreateWidget( PtLabel, window, 2, arg );

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

free( img );

PtRealizeWidget( window );
clock_gettime(CLOCK_REALTIME, &stop);
accum = (stop.tv_sec - start.tv_sec) +
(stop.tv_nsec - start.tv_nsec) * 1e-9;
printf(“Display time %lf [s]\n”, accum);

PtMainLoop();
}

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 );
}
}

void * warning( char *msg )
{
printf( “%s\n”, msg );
}

void * error( char *msg )
{
printf( “%s\n”, msg );
exit( EXIT_FAILURE );
}

void * progress( int percent )
{
printf( “Load Status: %d.%d percent\n”,
percent >> 16, percent & 0xffff );
}

----- Original Message -----
From: “Applications Mail Group” <apps@qnx.com>
Newsgroups: qdn.public.qnxrtp.photon
Sent: Thursday, August 02, 2001 9:30 AM
Subject: Re: PxLoadImage()


This depends on what you mean when you say compressed bitmap. If you mean
…gif or .jpg then yes it will open them. One way to test the file you would

like to open is to use the ‘pv’ utility.

Regards,
Dave B.


Janusz <> ruszelj@baxter.com> > wrote:
Does function PxLoadImage() correctly recognize compressed bit map
format
(BMP) files?
Please advice how to read compressed bit map files.

Janusz.

Hi,

Applications Mail Group <apps@qnx.com> wrote in article
<9kbo67$62n$1@nntp.qnx.com>…

This depends on what you mean when you say compressed bitmap. If you
mean .gif or .jpg then yes it will open them. One way to test the file you

would like to open is to use the ‘pv’ utility.

What about RLE compressed bitmap? Exactly *.bmp.

Thank you,
Eduard.

Regards,
Dave B.


Janusz <> ruszelj@baxter.com> > wrote:
Does function PxLoadImage() correctly recognize compressed bit map
format
(BMP) files?
Please advice how to read compressed bit map files.

Janusz.
\