| The two samples, CROP.C and
SCALE.C, illustrate how to crop or scale an image with the PX Series. Both
samples are derived from PXGDI3.C, the double-buffered display sample.
Cropping and scaling are discussed
on page 71 in our manual. You crop an image when you are only interested
in a small part of it. You scale an image when you want the entire image
but at a reduced size and resolution. With the PX, scaling is accomplished
by decimation. The board digitizes at a slower rate and hence discards
pixels.
Cropping and scaling are both
accomplished by using the SetImageSize() and SetFieldSize() functions.
You use the SetFieldSize() primarily for non-interlaced video.
SetImageSize(fgh,
resx, resy, X0, Y0, dx, dy, bits);
SetFieldSize(fgh, resx,
resy, X0, Y0, dx, dy, bits);
To crop an image, you set the
"resx" parameter to the full image width (640 for NTSC) and you set the
"x0" and "dx" parameters to the part of the image you want. You do the
same for the vertical direction with the "y0" and "dy" parameters.
To scale an image, you set
the "resx" parameter to less than the full width of the image. The example
below divides it by 2 (320 for NTSC). That means essentially only every
other pixel is digitized. You set the "x0" and "dx" parameters to match
the width you are digitizing. For the vertical direction, you assume the
magic number 256 represents 100% of the image height and you divide it
to get the size you want. The effect is to discard lines.
The following notes are from
the source code of each sample.
CROP.C
HORIZONTAL CROPPING:
Specify the starting column
and the number of columns to keep.
VERTICAL CROPPING:
Specify the starting row and
the number of rows to keep.
For the example, see the GetVideoParameters()
function in this program. This example crops the edges of the image and
leaves 1/4 of the image in the center. It does this by starting at pixel
160 horizontally and keeping 320. Vertically it starts at row 120 and
keeps 240.
See the "Digitize" variable.
It is set to 640. Which means you digitize at the normal clock rate, but
you set the starting column and the width so you don't grab the whole
image.
Digitize = 640;
ImageMaxX = 640 /2;
ImageMaxY = 480 / 2;
StartCol = 160;
StartRow = 120;
SetImageSize(fgh, Digitize,
256, StartCol, StartRow,
ImageMaxX, ImageMaxY,
8);
SCALE.C
HORIZONTAL SCALING:
Specify the number of pixels
you want per horizontal line, using the "resx" parameter of the SetImageSize()
function.
VERTICAL SCALING:
Do not specify the number of
lines you want. Instead use the magic number 256 as representing the whole
height of the frame and divide it to scale the frame. For half of the
height use 256 / 2 or 128. Use this number as the "resy" parameter in
the SetImageSize() function.
For the example, see the GetVideoParameters()
function in this program. Set the values of HORZ and VERT to make changes.
This sample scales the image to 1/4 size or by 1/2 in each direction.
#define HORZ 2
#define VERT 2
ImageMaxX = 640 / HORZ;
ImageMaxY = 480 / VERT;
The SetImageSize() function
uses ImageMaxX to digitize at a slower clock rate and hence get fewer
pixels from each line.
SetImageSize(fgh, ImageMaxX,
256 / VERT, 0, 0,
ImageMaxX, ImageMaxY,
8);
BUG
There is a bug in the Windows
95 driver that causes problems with scaling when the number of lines is
an odd number. Keep the number of lines at an even number when scaling
in Windows 95. This bug does not affect cropping.
|