introduction
12–1 image demo
PS
the image operator / scan
121
Let’s look closer at each argument for image:
The width and height are the number of cells wide and high for the picture. In the example above, the picture's width and height is 16 by 16 pixels.
The bits value is 1 since the picture is a 1-bit picture.
Next is the matrix array which determines the size of the picture. This matrix array operates differently with image than for concat (section 10.4) and makefont
(section 11.1). With concat and makefont, if we wanted an object larger, we would have used a larger number in the first and fourth position of the array. Here it is the opposite; a smaller number is used. The calculation is different with image
because of a difference in how it handles pictures. It can be explained in this way. Had the matrix array been [1 0 0 1 0 0], the shamrock would be as shown in figure 12–5.
Figure 12–5 is this size because the 1 in the [1 0 0 1 0 0] matrix array means each pixel is actual size. The 16x16 pixel width and height will measure 16x16 points. A 16x16 pixel width and height using a [.1 0 0 .1 0 0] matrix is 160x160 points. This is arrived at by dividing 16 by .1 equaling 160, and 160
divided by 16 equals 10. With a dimension of 160x160, and the cells width and height being 16x16, we then know the individual pixels will be 10 points square. If the matrix array had been [.2 0 0 .2 0 0] the pixels would be 5 points square.
{currentfile picStr readhexstring pop} is the data acquisition procedure for the image operator. currentfile identifies that the data for the picture will follow after shamrock is used in the program. /picStr defines a space large enough for a string two characters long. picStr is a temporary holding place for the data for each row of the picture. The first two characters that make up the first row of the shamrock are the two hexadecimal characters FF and
1F. They represent the two sets of binary characters 11111111 and 00011111.
readhexstring identifies that the data is in hexadecimal. pop clears the picStr
so the procedure can be repeated. The procedure is repeated until the 16 rows of data in increments of two are filled.
Writing the program in this way permits all the data for the picture to follow the PostScript commands that control its painting. In most cases, scanned pictures are very large files. Having the data follow a PostScript header permits easier editing of the program.
16 pixels wide 16 pixels high
1 bit per pixel
16 16 1 [.1 0 0 .1 0 0]
{currentfile picStr readhexstring pop} image
matrix: .1 makes each pixel 10 points in size
data acquisit ion procedure
PostScript operator
figure 12–4
122
the image operator / scanThis picture was obtained by using a scanner and saving the file in a PostScript format by its software. I have edited the PostScript from its original form supplied by the scanning software. The original file had definitions to accommodate a number of different scanning situations and I wish to focus on the basic similarity with the previous shamrock example.
The program that produced the picture follows, minus the picture data to save space. It would have taken up about eight pages.
%!PS-Adobe-2.0 EPSF-1.2 %%Title:relief.eps
%%BoundingBox:0 0 224 225
/height 225 def /width 224 def
/nheight height neg def /picstr 112 string def
/makePicture
{ width height 4 [width 0 0 nheight 0 height] { currentfile picstr readstring pop } image } def
gsave
{1 exch sub} settransfer width height scale
makePicture
ˇˇˇˇˇ›fl››ªª›ª€€∫∫∫∫ª´∫∫∫∫ª ™ ™ππππógfUTVUEDDUgfyzô´›flfl
– 25.6K of picture data, etc –
Ì›Ì∫∫∫∫ª∫∫∫∫ö™óyxºÃÃfiˇˇˇˇ˛‹Ã õŒˇˇ‹ºÃÕÙº›Ôˇ grestore
PS
learn
the image operator / scan
123
This program is basically the same as shamrock_1.eps but with a few differences. First, many of the values have been given names such as height and
width. This section of the program is written by the scanning software so the same file beginning can be used for every file it creates.
height defines the height of the picture to be 225.
width defines the width of the picture to be 224.
nheight defines height to have a negative value. The reason for this is many scanners digitize from the top down as opposed to from the bottom up. Having the transformation matrix be [width 0 0 nheight 0 height] adjusts for this by flopping the picture.
picStr, as discussed at the end of section 12.2, is a holding space for a string. In this definition, the holding place is 112. This would hold enough data for one row of the picture.
makePicture defines the image operation as shamrock did for the
shamrock_1.eps example earlier.
width height 4 [width 0 0 nheight 0 height]
is the same as
224 225 4 [224 0 0 -255 0 255].
The picture is a 4-bit picture (64 grays) and the matrix array maps it, so it is very small. To get it to the right size,
width height scale
scales the picture up to 224 225.
{1 exch sub} settransfer inverts the picture. Without this line, the picture would appear as a negative. This compensates for the way the scanner scans the picture.