PtCreateImage produces smear image

I am using PhCreateImage and a PtLabel widget (set as Pt_IMAGE) to
display an image. I understand that bpl has to be padded correctly else
the image comes out squirrelly. Images with the width and height
divisible by 8 are displayed correctly. Why doesn’t PhCreateImage
automatically correct for those images not divisible by 8? Is there a
problem with using the widget and PhCreateImage together? Is there a
simple solution? Here is some code snippet:

PhImage_t img;
char qptr;
img = PhCreateImage( NULL, NumberOfColumns
sf, NumberOfRows
sf,
Pg_IMAGE_PALETTE_BYTE, palette, ncolors, 0);
img->flags |= Ph_RELEASE_IMAGE_ALL;
qptr = img->image;
//fill qptr with data here
PtSetArg(&arg[0], Pt_ARG_LABEL_IMAGE, img, sizeof (PhImage_t));
PtSetResources(ABW_image_r_bs, 1, arg);
PtFlush();
free(img);

bpl is the number of bytes per line and is calculated based on the image
type and the width and height. If you have a 24 bit image then the bpl
will be: (width * 3). You can add padding if you like by making the bpl
larger and keeping the same width and image type. PhCreateImage however
uses the above calculation. If your image data looks wrong you may be
filling it incorrectly. What is ‘sf’ in your code, and what do you do
to fill the data?

Brian


S. Ribail wrote:

I am using PhCreateImage and a PtLabel widget (set as Pt_IMAGE) to
display an image. I understand that bpl has to be padded correctly else
the image comes out squirrelly. Images with the width and height
divisible by 8 are displayed correctly. Why doesn’t PhCreateImage
automatically correct for those images not divisible by 8? Is there a
problem with using the widget and PhCreateImage together? Is there a
simple solution? Here is some code snippet:

PhImage_t img;
char qptr;
img = PhCreateImage( NULL, NumberOfColumns
sf, NumberOfRows
sf,
Pg_IMAGE_PALETTE_BYTE, palette, ncolors, 0);
img->flags |= Ph_RELEASE_IMAGE_ALL;
qptr = img->image;
//fill qptr with data here
PtSetArg(&arg[0], Pt_ARG_LABEL_IMAGE, img, sizeof (PhImage_t));
PtSetResources(ABW_image_r_bs, 1, arg);
PtFlush();
free(img);

I don’t understand. When I print bpl for the following widths: 255, 253, 252,
251, 250, and 249, I get the result of 256. A width of 248 produces a bpl of
248. A width of 266 produces a bpl of 272. I am using an 8 bit image.

sf is my scale factor and is used for zooming. For sf = 1, width = 266 and
height = 80, I observed that the displayed image contains about 1 and 1/2
raster lines of solid color at the bottom of pic. Here is the code that shows
how I fill qptr:

Byte rcolor;
int pixel;
pixel = 0;
for( row=0; row<NumberOfRows; row++ )
{
for( r1=0; r1<sf; r1++)
{
for( col=0; col<NumberOfColumns; col++ )
{
rcolor = scan_dat.Image[row][col].range;
rcolor = RangeColorTable[rcolor]; // lookup table with
8 bit values
for( r2 = 0; r2 < sf; r2++)
{
qptr[pixel+r2] = rcolor;
}
pixel += sf;
}
}
}
I printed the results of qptr for a test case with a constant value and it
appears okay.

Brian Edmond wrote:

bpl is the number of bytes per line and is calculated based on the image
type and the width and height. If you have a 24 bit image then the bpl
will be: (width * 3). You can add padding if you like by making the bpl
larger and keeping the same width and image type. PhCreateImage however
uses the above calculation. If your image data looks wrong you may be
filling it incorrectly. What is ‘sf’ in your code, and what do you do
to fill the data?

Brian

S. Ribail wrote:
I am using PhCreateImage and a PtLabel widget (set as Pt_IMAGE) to
display an image. I understand that bpl has to be padded correctly else
the image comes out squirrelly. Images with the width and height
divisible by 8 are displayed correctly. Why doesn’t PhCreateImage
automatically correct for those images not divisible by 8? Is there a
problem with using the widget and PhCreateImage together? Is there a
simple solution? Here is some code snippet:

PhImage_t img;
char qptr;
img = PhCreateImage( NULL, NumberOfColumns
sf, NumberOfRows
sf,
Pg_IMAGE_PALETTE_BYTE, palette, ncolors, 0);
img->flags |= Ph_RELEASE_IMAGE_ALL;
qptr = img->image;
//fill qptr with data here
PtSetArg(&arg[0], Pt_ARG_LABEL_IMAGE, img, sizeof (PhImage_t));
PtSetResources(ABW_image_r_bs, 1, arg);
PtFlush();
free(img);

For this image type (and most other types for that matter), the padding must
be 8 pixels. PhCreateImage() does this padding for you, which explains
the bpl behaviour you’re seeing.

As long as your code is always aware of the bytes per line of the image
(bpl) you should be ok. But from the description of your problem, it sounds
like you might be looking to the width (rather than the bpl) to figure out
how many bytes are in each row (line). You’re writing data into the padding
at the end of the line, and then falling short of the start of the next
line. This error accumulates as you work your way down the image, leaving
the result skewed and an unwritten run at the end.

“S. Ribail” <saul.ribail@lmco.com> wrote in message
news:3C67E6C0.22C4B4D7@lmco.com

I don’t understand. When I print bpl for the following widths: 255, 253,
252,
251, 250, and 249, I get the result of 256. A width of 248 produces a bpl
of
248. A width of 266 produces a bpl of 272. I am using an 8 bit image.

sf is my scale factor and is used for zooming. For sf = 1, width = 266
and
height = 80, I observed that the displayed image contains about 1 and 1/2
raster lines of solid color at the bottom of pic. Here is the code that
shows
how I fill qptr:

Byte rcolor;
int pixel;
pixel = 0;
for( row=0; row<NumberOfRows; row++ )
{
for( r1=0; r1<sf; r1++)
{
for( col=0; col<NumberOfColumns; col++ )
{
rcolor = scan_dat.Image[row][col].range;
rcolor = RangeColorTable[rcolor]; // lookup table
with
8 bit values
for( r2 = 0; r2 < sf; r2++)
{
qptr[pixel+r2] = rcolor;
}
pixel += sf;
}
}
}
I printed the results of qptr for a test case with a constant value and it
appears okay.

Brian Edmond wrote:

bpl is the number of bytes per line and is calculated based on the image
type and the width and height. If you have a 24 bit image then the bpl
will be: (width * 3). You can add padding if you like by making the bpl
larger and keeping the same width and image type. PhCreateImage however
uses the above calculation. If your image data looks wrong you may be
filling it incorrectly. What is ‘sf’ in your code, and what do you do
to fill the data?

Brian

S. Ribail wrote:
I am using PhCreateImage and a PtLabel widget (set as Pt_IMAGE) to
display an image. I understand that bpl has to be padded correctly
else
the image comes out squirrelly. Images with the width and height
divisible by 8 are displayed correctly. Why doesn’t PhCreateImage
automatically correct for those images not divisible by 8? Is there a
problem with using the widget and PhCreateImage together? Is there a
simple solution? Here is some code snippet:

PhImage_t img;
char qptr;
img = PhCreateImage( NULL, NumberOfColumns
sf, NumberOfRows
sf,
Pg_IMAGE_PALETTE_BYTE, palette, ncolors, 0);
img->flags |= Ph_RELEASE_IMAGE_ALL;
qptr = img->image;
file://fill qptr with data here
PtSetArg(&arg[0], Pt_ARG_LABEL_IMAGE, img, sizeof (PhImage_t));
PtSetResources(ABW_image_r_bs, 1, arg);
PtFlush();
free(img);
\