18
Appendixes 4. An Introduction to PostScript ® CVG Lab

Appendixes 4. An Introduction to PostScript ® CVG Lab

Embed Size (px)

Citation preview

Page 1: Appendixes 4. An Introduction to PostScript ® CVG Lab

Appendixes4. An Introduction to PostScript®

CVG Lab

Page 2: Appendixes 4. An Introduction to PostScript ® CVG Lab

Introduction

• PostScript® is known as a “page description” programming language.

→ it is commonly used to specify how a page should be printed.

• An important feature of PostScript:

-. Its device independence.

• The usual way to work with PostScript is to use a text processor to fashion a PostScript, and then to submit the file to a PostScript printer.

-. The printer can be set to interpret the script and make a picture rather than simply print the script as text.

Page 3: Appendixes 4. An Introduction to PostScript ® CVG Lab

Introduction

• Ghostscript -. Provide a convenient alternative. -. Freely available and operates on a variety of PC and workstation pl

atforms. -. Interprets a PostScript script -. Displays the picture on the PC monitor. -. Can make debugging a script much easier → immediately see the

results of a script

Page 4: Appendixes 4. An Introduction to PostScript ® CVG Lab

About the PostScript Language

• Scripts in PostScript are readable by humans

1. Some Preliminares• Different character appearing in a sript take on different meani

ngs. -. Comments. All characters from ‘%’ to the end of the current line

are comments and are ignored by the interpreter. -. Case. Case is significant. -. White space. Characters such as spaces, tabs, or newlines leav

e spaces on the script page, and are collectively called “white space.”

Page 5: Appendixes 4. An Introduction to PostScript ® CVG Lab

About the PostScript Language

Numbers in PostScript

-. Numbers are written in the usual way, either with or without a decimal point.

2. PostScript Is “Stack based” -. PostScript is similar to the language Forth in that it maintains a stack

of objects called the operand stack.

34 –5.2 % push 34 than –5.2 onto the stack

12 % push 12 on top

<empty> (meaning the stack is empty)

34

34 -5.2

34 -5,2 12

Page 6: Appendixes 4. An Introduction to PostScript ® CVG Lab

About the PostScript Language

3. Some Stack Operators: pop, dup, exch, and clear -. pop 12 → — -. dup 12 → 12 12 -. exch -5.2 12 exch → 12 -5.2 -. clear 34 -5.2 clear → <empty>

Page 7: Appendixes 4. An Introduction to PostScript ® CVG Lab

4. More Advanced Stack Operators

-. n index counts down n items into the stack, and pushes a copy of the nth item

on to the stack: 34 12 94 2 index → 34 12 93 34 6 0 index → 6 6 % same as dup -. n copy n copy pops the n and then pushes a copy of the top n elements of the

stack: 12 6 2 copy → 12 6 12 6 12 95 23 3 copy → 12 95 23 12 95 23

About the PostScript Language

Page 8: Appendixes 4. An Introduction to PostScript ® CVG Lab

About the PostScript Language

-. num shifts roll

num shifts roll pops shifts and num, and then does a circular shift of the top num elements shifts times

-3 144 78 3 1 roll → 78 -3 144

-3 144 78 3 -1 roll → 144 78 -3

23 12 -3 144 4 -2 roll → 23 144 78 12 -3

-. count

count the number of items on the stack and pushes that value onto the stack.

12 35 121 count → 12 35 121 3

Page 9: Appendixes 4. An Introduction to PostScript ® CVG Lab

5. Some Arithmetic Operators -. Add: -5.2 12 add → 6.8 -. subtract: - 5.2 12 sub → -17.2 -. Multiply: -5.2 12 mul → -62.4 -. Division: -27 8 div→ -3.375 -. Integer Division: -27 8 idiv→ -3 -. Modulo: 178 34 25 7 mod → 178 34 4 178 18 2547 10 mod → 178 18 7 -. and, or, exclusive or, complement (&, |, ^, and !) -. abs, neg, floor, ceiling, truncate, round, sqrt, ln, log, cos, sin exp,

atan Random-number Generation

About the PostScript Language

Page 10: Appendixes 4. An Introduction to PostScript ® CVG Lab

Graphics Operators in PostScript

• PostScript has operators that make it easy to draw lines, circles, Bezier curves, and many other figures.

1. Coordinate Systems and Transformations

Page 11: Appendixes 4. An Introduction to PostScript ® CVG Lab

Graphics Operators in PostScript

2. Path Construction Verbs -. Move to pops the top two items off of the stack and set the CP

accordingly x y moveto → —

newpath 1 1 moveto

1 3 lineto 3 3 lineto

3 1 lineto closepath stroke

2 2 moveto 4 2 lineto 4 0 lineto

2 0 lineto closepath fill

showpage

Page 12: Appendixes 4. An Introduction to PostScript ® CVG Lab

Graphics Operators in PostScript

3. Arcs of Circles -. Acrs of circles are drawn in PostScript by using one of the two v

erbs arc and acrn. center.x center.y rad start_angle end_angle arc → — center.x center.y rad start_angle end_angle arcn → —

Page 13: Appendixes 4. An Introduction to PostScript ® CVG Lab

Graphics Operators in PostScript

4. Used for Painting Verbs -. stroke -. fill -. setlinewidth -. setgray -. setrgbcolor -. clip -. setlinecap -. setlinejoin

Page 14: Appendixes 4. An Introduction to PostScript ® CVG Lab

Graphics Operators in PostScript

5. Coordinate Transformations

Page 15: Appendixes 4. An Introduction to PostScript ® CVG Lab

2. Automatic dodging-and burning• Bringing “up” selected dark regions or bringing “down” selected

light regions to avoid loss of detail.• Dodging-and-burning is typically applied over an entire region b

ounded by large contrasts. -. Chose a center-surround function derived from Blommaert’s mo

del for brightness perception. -. This function is constructed using circularly symmetric Gaussian

profiles of the form:

Algorithm

2

22

2 )(exp

)(

1),,(

s

yx

ssyxR

iii

).,,(),(),,( syxRyxLsyxV ii

Page 16: Appendixes 4. An Introduction to PostScript ® CVG Lab

Algorithm

Page 17: Appendixes 4. An Introduction to PostScript ® CVG Lab

-. The center-surround function defined by;

Algorithm

),,(/2

),,(),,(),,(

12

21

syxVsa

syxVsyxVsyxV

|V(x, y, sm)|<є

)),(,,,(1

),(),(

1 yxsyxV

yxLyxL

md

… Computed for the sole purpose of establishing a measure of locality for each pixel, which amounts to finding a scale sm of appropriate size.

… This scale may be different for each pixel, and the procedure for its selection is the key to the success of our dodging-and-burning technique.

… It is also a deviation from the original Blommaert model.

Page 18: Appendixes 4. An Introduction to PostScript ® CVG Lab

• The luminance of a dark pixel in a relatively bright region will satisfy L<V1, so this operator will decrease the display luminance Ld, thereby increasing the contrast at that pixel. “dodging”

• A pixel in a relatively dark region sill be compressed less. “burned”

Algorithm

)),(,,,(1

),(),(

1 yxsyxV

yxLyxL

md