Sending a screengrab straight to the printer

I’m trying to streamline my screengrabber so that it generates a .phs
file directly from the PhImage_t structure created by PgReadScreen().
For some reason, it does not seem to work. The only way I can get it to
work is to write the image to disk as a bitmap, then load the image from
disk. This results in a delay of several seconds, and just seems like an
unnecessary kluge to me. Is there any way to make the following code work?

The error code it returns indicates that “the draw buffer couldn’t be
resized enough to fit a single scan line of the image,” according to the
help docs. However, what the help docs don’t tell you is HOW TO REMEDY
THE SITUATION… Most frustrating, and happens all too often with QNX.

//qcc octopus.c -o octopus -lph -lphexlib

#include <iostream.h>
#include <stdio.h>
#include <Pt.h>

// make sure we include BMP support!
#define PX_IMAGE_MODULES
#define PX_PHIMAGE_SUPPORT
#define PX_BMP_SUPPORT
#include <photon/PxImage.h>

int snap(char *fname,PhRect_t rect)
{
int len;
char *mem;
PhImage_t *image;

int iErrCode = 0;
PhDrawContext_t pdc = 0;
PpPrintContext_t
mpPC;
PhPoint_t p = { 0, 0 };


// get the size of the shared memory you need for the image
if ((len=PgReadScreenSize(&rect))<=0) return -1;

// allocate shared memory to contain the image
if (!(mem=(char*)PgShmemCreate(len,NULL))) return -1;

// read the portion of the screen you’re interested in
if (image=PgReadScreen(&rect,mem))
{

mpPC = PpCreatePC();

if (mpPC)
{
// set up my context
if(!iErrCode)
{
PpSetPC(mpPC, Pp_PC_DRIVER, “/usr/bin/phs-to-ps”, 0);
PpSetPC(mpPC, Pp_PC_FILENAME, “grabscreen.phs”, 0);

Ph_rect xPrintArea;
xPrintArea.ul.x = 750;
xPrintArea.ul.y = 500;
xPrintArea.lr.x = 500;
xPrintArea.lr.y = 400;
PpSetPC(mpPC, Pp_PC_MARGINS, &xPrintArea, 0);

PhDim_t xPaperSize;
xPaperSize.w = 8500;
xPaperSize.h = 11000;
PpSetPC(mpPC, Pp_PC_PAPER_SIZE, &xPaperSize, 0);

PhDim_t xSourceSize;
xSourceSize.w = 1024;
xSourceSize.h = 768;
PpSetPC(mpPC, Pp_PC_SOURCE_SIZE, &xSourceSize, 0);

}

// initialize the print job
if(!iErrCode)
{
if(PpStartJob(mpPC))
iErrCode = 2;
}

// make the print context active
if(!iErrCode)
{
pdc = PpContinueJob(mpPC);
if(!pdc)
iErrCode = 3;
}

if (image == NULL)
{
cout << “ERROR: NULL image” << endl;
exit(1);
}

cout << "image size: " << image->size.w << “x” << image->size.h << endl;

iErrCode = PgDrawPhImage(&p, image, 0);

cout << "iErrCode = " << iErrCode << endl;

PpEndJob(mpPC);
PpReleasePC(mpPC);
}

}

// destroy the shared memory you used
PgShmemDestroy(mem);

return 0;
}

int main(int argc,char *argv[])
{
int i;

int iPtInit = PtInit("/dev/photon");

cout << "PtInit returned: " << iPtInit << endl;

// get a connection to Photon
if (iPtInit!=0)
{
perror(“Error: Could not connect to Photon.”);
exit(-1);
}

PhRect_t rect;
char fname[120];

//windows_rect(r,&rect);
rect.ul.x = 0;
rect.ul.y = 0;
rect.lr.x = 1023;
rect.lr.y = 767;
sprintf(fname,“grabscreen.bmp”,i);
snap(fname,rect);

return 0;
}

One of the first things it says on the PgReadScreenSize() help page is “you
must target this function at a specific card by calling
PdSetTargetDevice()”. This note is accompanied by a helpful little picture
of a hand with a finger on it suggesting that this is important. I don’t
know much about this stuff, but your program doesn’t call that function.
Perhaps it should?

dB

“Mathew Kirsch” <mkirsch@ocdus.jnj.com> wrote in message
news:b3lrbr$3ke$1@inn.qnx.com

I’m trying to streamline my screengrabber so that it generates a .phs
file directly from the PhImage_t structure created by PgReadScreen().
For some reason, it does not seem to work. The only way I can get it to
work is to write the image to disk as a bitmap, then load the image from
disk. This results in a delay of several seconds, and just seems like an
unnecessary kluge to me. Is there any way to make the following code work?

The error code it returns indicates that “the draw buffer couldn’t be
resized enough to fit a single scan line of the image,” according to the
help docs. However, what the help docs don’t tell you is HOW TO REMEDY
THE SITUATION… Most frustrating, and happens all too often with QNX.

file://qcc octopus.c -o octopus -lph -lphexlib

#include <iostream.h
#include <stdio.h
#include <Pt.h

// make sure we include BMP support!
#define PX_IMAGE_MODULES
#define PX_PHIMAGE_SUPPORT
#define PX_BMP_SUPPORT
#include <photon/PxImage.h

int snap(char *fname,PhRect_t rect)
{
int len;
char *mem;
PhImage_t *image;

int iErrCode = 0;
PhDrawContext_t pdc = 0;
PpPrintContext_t
mpPC;
PhPoint_t p = { 0, 0 };


// get the size of the shared memory you need for the image
if ((len=PgReadScreenSize(&rect))<=0) return -1;

// allocate shared memory to contain the image
if (!(mem=(char*)PgShmemCreate(len,NULL))) return -1;

// read the portion of the screen you’re interested in
if (image=PgReadScreen(&rect,mem))
{

mpPC = PpCreatePC();

if (mpPC)
{
// set up my context
if(!iErrCode)
{
PpSetPC(mpPC, Pp_PC_DRIVER, “/usr/bin/phs-to-ps”, 0);
PpSetPC(mpPC, Pp_PC_FILENAME, “grabscreen.phs”, 0);

Ph_rect xPrintArea;
xPrintArea.ul.x = 750;
xPrintArea.ul.y = 500;
xPrintArea.lr.x = 500;
xPrintArea.lr.y = 400;
PpSetPC(mpPC, Pp_PC_MARGINS, &xPrintArea, 0);

PhDim_t xPaperSize;
xPaperSize.w = 8500;
xPaperSize.h = 11000;
PpSetPC(mpPC, Pp_PC_PAPER_SIZE, &xPaperSize, 0);

PhDim_t xSourceSize;
xSourceSize.w = 1024;
xSourceSize.h = 768;
PpSetPC(mpPC, Pp_PC_SOURCE_SIZE, &xSourceSize, 0);

}

// initialize the print job
if(!iErrCode)
{
if(PpStartJob(mpPC))
iErrCode = 2;
}

// make the print context active
if(!iErrCode)
{
pdc = PpContinueJob(mpPC);
if(!pdc)
iErrCode = 3;
}

if (image == NULL)
{
cout << “ERROR: NULL image” << endl;
exit(1);
}

cout << "image size: " << image->size.w << “x” << image->size.h
endl;

iErrCode = PgDrawPhImage(&p, image, 0);

cout << "iErrCode = " << iErrCode << endl;

PpEndJob(mpPC);
PpReleasePC(mpPC);
}

}

// destroy the shared memory you used
PgShmemDestroy(mem);

return 0;
}

int main(int argc,char *argv[])
{
int i;

int iPtInit = PtInit("/dev/photon");

cout << "PtInit returned: " << iPtInit << endl;

// get a connection to Photon
if (iPtInit!=0)
{
perror(“Error: Could not connect to Photon.”);
exit(-1);
}

PhRect_t rect;
char fname[120];

file://windows_rect(r,&rect);
rect.ul.x = 0;
rect.ul.y = 0;
rect.lr.x = 1023;
rect.lr.y = 767;
sprintf(fname,“grabscreen.bmp”,i);
snap(fname,rect);

return 0;
}

Mathew Kirsch wrote:

I’m trying to streamline my screengrabber so that it generates a .phs
file directly from the PhImage_t structure created by PgReadScreen().
For some reason, it does not seem to work. The only way I can get it to
work is to write the image to disk as a bitmap, then load the image from
disk. This results in a delay of several seconds, and just seems like an
unnecessary kluge to me. Is there any way to make the following code work?

The error code it returns indicates that “the draw buffer couldn’t be
resized enough to fit a single scan line of the image,” according to the
help docs. However, what the help docs don’t tell you is HOW TO REMEDY
THE SITUATION… Most frustrating, and happens all too often with QNX.

//qcc octopus.c -o octopus -lph -lphexlib

#include <iostream.h
#include <stdio.h
#include <Pt.h

// make sure we include BMP support!
#define PX_IMAGE_MODULES
#define PX_PHIMAGE_SUPPORT
#define PX_BMP_SUPPORT
#include <photon/PxImage.h

int snap(char *fname,PhRect_t rect)
{
int len;
char *mem;
PhImage_t *image;

int iErrCode = 0;
PhDrawContext_t pdc = 0;
PpPrintContext_t
mpPC;
PhPoint_t p = { 0, 0 };


// get the size of the shared memory you need for the image
if ((len=PgReadScreenSize(&rect))<=0) return -1;

// allocate shared memory to contain the image
if (!(mem=(char*)PgShmemCreate(len,NULL))) return -1;

// read the portion of the screen you’re interested in
if (image=PgReadScreen(&rect,mem))
{

mpPC = PpCreatePC();

if (mpPC)
{
// set up my context
if(!iErrCode)
{
PpSetPC(mpPC, Pp_PC_DRIVER, “/usr/bin/phs-to-ps”, 0);
PpSetPC(mpPC, Pp_PC_FILENAME, “grabscreen.phs”, 0);

Ph_rect xPrintArea;
xPrintArea.ul.x = 750;
xPrintArea.ul.y = 500;
xPrintArea.lr.x = 500;
xPrintArea.lr.y = 400;
PpSetPC(mpPC, Pp_PC_MARGINS, &xPrintArea, 0);

PhDim_t xPaperSize;
xPaperSize.w = 8500;
xPaperSize.h = 11000;
PpSetPC(mpPC, Pp_PC_PAPER_SIZE, &xPaperSize, 0);

PhDim_t xSourceSize;
xSourceSize.w = 1024;
xSourceSize.h = 768;
PpSetPC(mpPC, Pp_PC_SOURCE_SIZE, &xSourceSize, 0);

}

// initialize the print job
if(!iErrCode)
{
if(PpStartJob(mpPC))
iErrCode = 2;
}

// make the print context active
if(!iErrCode)
{
pdc = PpContinueJob(mpPC);
if(!pdc)
iErrCode = 3;
}

if (image == NULL)
{
cout << “ERROR: NULL image” << endl;
exit(1);
}

cout << "image size: " << image->size.w << “x” << image->size.h
endl;

iErrCode = PgDrawPhImage(&p, image, 0);

cout << "iErrCode = " << iErrCode << endl;

PpEndJob(mpPC);
PpReleasePC(mpPC);
}

}

// destroy the shared memory you used
PgShmemDestroy(mem);

return 0;
}

int main(int argc,char *argv[])
{
int i;

int iPtInit = PtInit("/dev/photon");

cout << "PtInit returned: " << iPtInit << endl;

// get a connection to Photon
if (iPtInit!=0)
{
perror(“Error: Could not connect to Photon.”);
exit(-1);
}

PhRect_t rect;
char fname[120];

//windows_rect(r,&rect);
rect.ul.x = 0;
rect.ul.y = 0;
rect.lr.x = 1023;
rect.lr.y = 767;
sprintf(fname,“grabscreen.bmp”,i);
snap(fname,rect);

return 0;
}

if the error message is true, PgSetDrawBufferSize() might help =)

Johan Björk wrote:

if the error message is true, PgSetDrawBufferSize() might help =)

Found it, tried to set it to the maximum, and it doesn’t help.