PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes...
Transcript of PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes...
![Page 1: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/1.jpg)
PostScript Internals
15-463 Graphics II
Spring 1999
![Page 2: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/2.jpg)
2
Background
PostScript raster image processor for MacAll Level 1 features
Some support for color and multi-bit devices
Undergrad independent study: MacRIP
Commercial product: TScriptSold by TeleTypesetting Co.
Still around (!)
![Page 3: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/3.jpg)
3
PostScript Features
Device/resolution independence
OrthogonalityVector shapes, images, text treated uniformly
e.g. transforms and clips images and text
“Composability”
Complete language
High-quality outline fonts
![Page 4: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/4.jpg)
4
Focus
Level1 implementationLevel 2 adds many complex features
Level 3 adds even more
Laser printer-like output deviceOne bit per pixel
Medium resolution: ~300 dpi• 2400x3000 pixels on a page = 1Mb frame buffer
Non-interactive/batch model
![Page 5: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/5.jpg)
5
Topics
Language Overview
Language Implementation
Graphics Overview
Scan Conversion and Clipping
Fonts
Images and Halftones
![Page 6: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/6.jpg)
Language Overview
![Page 7: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/7.jpg)
7
Syntax
Stream of tokens with little structurePostfix notation
No precedence, lexical scope, etc.
TokensInteger and real: 3 4.0 5e6
String: (Call the doctor.)
Name: John yaya 3plus4 ==proc
Procedure: {add 2 div}
![Page 8: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/8.jpg)
8
More Object Types
Array: vector of arbitrary objects
Dictionary:finite mapping on objects
Operator: built-in procedure
Boolean: true and false
Null
Mark
![Page 9: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/9.jpg)
9
Stacks
Operand stack: accumulates arguments
Execution stack: object to evaluate next
Dictionary stack: explicit variable scope
Types checked at run timeAll objects have an inherent type
![Page 10: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/10.jpg)
10
Object Attributes
Literal: push to the operand stack
ExecutableName: look up on dictionary stack
Array: execute elements in order
String: parse and execute code
Operator: execute built-in operation
Accessunlimited > read-only > execute-only > none
![Page 11: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/11.jpg)
11
Virtual Memory
Virtual memory is just the allocation heap
save “snapshots” all mutable objectsStrings, arrays, dictionaries
restore returns virtual memory to aprevious snapshot
All intervening mutations are undone
Throw away all new objects
Good for batch processing model
![Page 12: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/12.jpg)
Language Implementation
![Page 13: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/13.jpg)
13
Object Representation
struct object {unsigned short type:4, exec:1, access:2;unsigned short length;union {
int integer;float real;unsigned char *string;struct name *name;struct object *array;struct dict *dict;unsigned int operator;int boolean;
} u;};
![Page 14: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/14.jpg)
14
Dictionary Representation
Typically a hash table based on keys
Corresponding values in parallel array
struct dict {unsigned int access;unsigned short length;unsigned short maxlength;struct object *keys[maxlength];struct object *values[maxlength];
};
![Page 15: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/15.jpg)
15
Name Representation
Typically a global hash table for all names
Cache with current binding for fast lookup
struct name {struct name *next;struct object cache;unsigned short hash;unsigned short length;unsigned char string[length];
};
![Page 16: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/16.jpg)
16
Implementing Virtual Memory
Allocate objects linearly from a large arena
save remembers current allocation pointer
restore resets allocation pointer
What about mutated values?Could just block copy active heap: slow!
Better to save location on first modification
restore just walks through the “undo list”
![Page 17: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/17.jpg)
Graphics Overview
![Page 18: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/18.jpg)
18
Path
Sequence of line and curve segmentsNeed not be connected or closed
Connected sequences of segments are subpaths
Specified by path elementsmoveto starts a new, disconnected subpath
lineto specifies a connected line
curveto specifies a connected, cubic
closepath connects an open subpath to its start
![Page 19: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/19.jpg)
19
Graphics State
Collects parameters for graphics operatorsOperators implicitly refer to current gstate
Saved and restored by gsave and grestore
Some specific parametersCurrent matrix allows affine transformations
Current color is color to paint with
Current path is shape to fill or outline
Current clipping path restricts painted area
Current font determines appearance of text
![Page 20: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/20.jpg)
20
Graphics Operators
fill paints inside of current pathUses non-zero winding number rule
Permits arbitrary self-intersections
Implicitly closes all open subpaths
stroke outlines current path
image renders a rectangular pixmap
show renders a string using current font
![Page 21: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/21.jpg)
Scan Conversion and Clipping
![Page 22: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/22.jpg)
22
Flattening Curves
Flattening approximates curves by linesCurrent flatness parameter limits deviation (inpixels) from true curve
flattenpath flattens current path (in place)
Recursive subdivision can work well
Forward differencing has a faster inner loopx[t+1] = x[t]+dx[t]dx[t+1] = dx[t]+ddx[t]ddx[t+1] = ddx[t]+dddx[0]
![Page 23: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/23.jpg)
23
Approximating Circular Arcs
Arcs are approximated by cubic Required, since user can iterate over paths
Some affine transformations of arcs are not arcs
Each arc segment
Control points are along tangents to arcF = (4/3)(1/(1+sqrt(1+(d/r)^2)))
![Page 24: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/24.jpg)
24
Filling Flattened Paths
Can use active edge lists (Foley+van Dam)
Linear DDA doesn’t need edge structuresclear x transition listsloop curve segments in current path loop t using curve DDA loop y using line DDA store x coordinate on transition list for yrepeat for clip pathsort transition listsfill intersection of “inside” intervals according to rule
![Page 25: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/25.jpg)
25
Stroking Flattened Paths
Stroke of a path is a path itself
Precise specification of line shapeCurrent line width
Current line join
Current line cap
strokepath replaces path with its stroke
Special case for rendering zero-width lines
![Page 26: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/26.jpg)
26
Clipping Flattened Paths
clip intersects current path and clip path
Computes polygon intersections
Scan convert path and clip in parallelUse interior of both paths for rasterization
Can generate trapezoids from modifiedscan converter
Sample at segment extrema and intersections
Reconstruct original segments, where possible
![Page 27: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/27.jpg)
Fonts
![Page 28: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/28.jpg)
28
Font Representation
Fonts come in two flavorsType 1 are condensed path descriptions
Type 3 are ordinary PostScript programs
Font matrix defines character coordinates
Font encoding maps character codes tocharacter names
Font cache retains bitmaps for mostcommonly used characters
![Page 29: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/29.jpg)
29
Type 3 BuildChar
Algorithm: Check font cache for character mask Concatenate font matrix with current matrix Call BuildChar with font dictionary and character code Save bits in font cache, if appropriate
Typical BuildChar procedure: Look up character name in Encoding vector Set character width and bounding box Construct path for character outline fill
![Page 30: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/30.jpg)
30
Type 1 Font Hints
Tunes rasterizer at low resolutions
Blue values declare standard heights ofcharacter features (from baseline)
Stem width hints declare standard widths ofcharacter features
Character stem hints identify stems incharacter outlines
![Page 31: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/31.jpg)
31
Interpreting Font Hints
All feature heights for a given blue valueare rounded consistently
“Fuzz” parameter is slop for matching heights
All standard stem widths are roundedconsistently
Overshoot suppression gives “flat” and“round” characters same height
Flex feature straightens shallow curves
![Page 32: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/32.jpg)
Images and Halftones
![Page 33: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/33.jpg)
33
Images
image specifies absolute color values
imagemask pours color through a stencil
Matrix specifies pixel coordinate system
Procedure supplies pixel/bitmap values
![Page 34: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/34.jpg)
34
Image Rendering
Reverse sample through inverted matrix
Scan convert clip path as additional mask
Use anti-aliasing for multi-bit devices
![Page 35: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/35.jpg)
35
Halftones
Laser printers can’t place pixels in isolation=> Can’t use standard dithering techniques
Frequency specifies cells per inch
Angle specifies orientation of grid lines
Spot procedure determines shape of cellsCircular spots are typical
Example: 60 lpi = 25 grays at 300 dpi
![Page 36: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/36.jpg)
36
Halftone Rendering
Offset cells into a repeating tileUsually, only discrete angles are available
Call spot function on pixel centers
Set n pixels with least spot valuesn = round((1-gray_level)*spot_area)
![Page 37: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/37.jpg)
37
Extensions
Multi-bit devices
Level 2Forms and patterns
Color spaces
User paths and graphics states
Display PostScriptConcurrency
View clip
![Page 38: PostScript Internals...Clipping Flattened Paths clip intersects current path and clip path Computes polygon intersections Scan convert path and clip in parallel Use interior of both](https://reader033.fdocuments.in/reader033/viewer/2022042802/5f40789e1fc5b738f228c671/html5/thumbnails/38.jpg)
38
References
Adobe PostScript Language ReferenceManual (Second Edition)
Adobe Type 1 Font Format
“Tutorial on Forward Differencing”, BobWallis, Graphics Gems I
“Fast Scan Conversion of ArbitraryPolygons”, Bob Wallis, Graphics Gems I