home *** CD-ROM | disk | FTP | other *** search
- %%BeginFile: pdfimg1c.prc
- %%Copyright: Copyright 1987-1993 Adobe Systems Incorporated. All Rights Reserved.
- % PDF Image Operators for Level 1 (Color)
- % This code is based on Glenn Reid's and Scott Byer's emulation of the
- % colorimage operator. This particular version of the code does not handle
- % multiple data sources and uses a less efficient but more accurate conversion
- % between RGB and CMYK values to gray space. The original code used the
- % following formulas:
- % gray = 0.25R + 0.5G + 0.25B gray = 1 - (C+M+Y+K)/4
- % The recommended conversions on page 304-305 of the PLRM are as follows:
- % gray = 0.3R + 0.59G + 0.11B gray = 1 - min(1, 0.3C+0.59M+0.11Y+K)
- % Using these formulas results in a better representation of the image.
- % In fact, the image will look the same as if it was drawn on a B/W device
- % that has the colorimage operator available albeit *millions* of times slower.
-
- PDF /PDFImage get begin
-
- Level2? not StartLoad {
- % Install the image DeviceRGB Handler
- /DeviceRGB [ 3
- {
- Width Height BitsPerComponent ImageMatrix ImageFilter 3
- ColorImage
- } bind
- ] InstallImage
- % Install the image DeviceCMYK Handler
- /DeviceCMYK [ 4
- {
- Width Height BitsPerComponent ImageMatrix ImageFilter 4
- ColorImage
- } bind
- ] InstallImage
-
- % Utility function: ColorImage?
- % ColorImage? contains true if the colorimage operator is defined,
- % false otherwise
- /ColorImage? /colorimage where { pop true } { false } ifelse def
- % /ColorImage? false def
-
- % Depending on the machine, color image may or may not be available.
- % We will want to provide an emulation if it is not.
- ColorImage? StartLoad {
- /ColorImage { false exch colorimage } bd
- } EndLoad % ColorImage?
- ColorImage? not StartLoad {
- % Utility procedures
- /SetupColorImage {
- /CIConv 255 2 BitsPerComponent exp 1 sub div pv % Threshold
- /CIMask 0 not BitsPerComponent bitshift not pv % Mask off bits
- /CIBSelect BitsPerComponent 1 sub not 7 and pv
- /CIBufferExp CIWidth string pv
- } bd
-
- /rgbtogray { % r g b rgbtogray gray
- 0.11 mul exch 0.59 mul add exch 0.3 mul add round cvi
- } bd
- /cmyktogray { % c m y k cmyktogray gray
- exch 0.11 mul add exch 0.59 mul add exch 0.3 mul add round cvi
- dup 255 gt { pop 255 } if
- 255 exch sub
- } bd
-
- % Optimized for 8 bits / sample for RGB
- /FastRGB {
- CIDataProc dup % str str
- 0 3 2 index length 3 sub
- { % str str loopcnt
- dup 3 idiv % str str loopcnt idx
- 2 index 2 index get % str str loopcnt idx r
- 3 index 3 index 1 add get % str str loopcnt idx r g
- 4 index 4 index 2 add get % str str loopcnt idx r g b
- rgbtogray % str str loopcnt idx gray
- 3 -1 roll pop put dup % str str
- } for
- 0 exch length 3 idiv getinterval % str'
- } bd
- % Optimized for 8 bits / sample for CMYK
- /FastCMYK {
- CIDataProc dup % str str
- 0 4 2 index length 4 sub { % str str loopcnt
- dup 4 idiv % str str loopcnt idx
- 2 index 2 index get % str str loopcnt idx c
- 3 index 3 index 1 add get % str str loopcnt idx c m
- 4 index 4 index 2 add get % str str loopcnt idx c m y
- 5 index 5 index 3 add get % str str loopcnt idx c m y k
- cmyktogray % str str loopcnt idx gray
- 3 -1 roll pop put dup % str str
- } for
- 0 exch length 4 idiv getinterval % str'
- } bd
- % Slower emulation for 1, 2, and 4 bits / sample
- /SlowRGB {
- CIDataProc pop % Get scan line
- % Loop over each sample
- 0 1 CIWidth 1 sub { % samp
- % Loop over each component
- 0 1 2 { % samp src
- 1 index 3 mul add CIBPC mul % samp src nbit
- CIBSelect 1 index 1 index and sub % samp src nbit bit
- exch 8 idiv % samp src bit byte
- CIBuffer exch get % samp src bit val
- exch neg bitshift CIMask and CIConv mul exch
- } for
- 4 1 roll rgbtogray % samp gray
- CIBufferExp 3 1 roll put
- } for
- CIBufferExp
- } bd
- % Slower emulation for CMYK 1, 2, and 4 bits / sample
- /SlowCMYK {
- CIDataProc pop % Get first sample string
- % Loop over each sample
- 0 1 CIWidth 1 sub { % samp
- % Loop over each component of each sample
- 0 1 3 { % samp src
- 1 index 4 mul add CIBPC mul % samp src nbit
- CIBSelect 1 index 1 index and sub % samp src nbit bit
- exch 8 idiv % samp src bit byte
- CIBuffer exch get % samp src bit val
- exch neg bitshift CIMask and CIConv mul exch
- } for
- 5 1 roll cmyktogray % samp gray
- CIBufferExp 3 1 roll put
- } for
- CIBufferExp
- } bd
-
- /ColorImage { % w h bpc im if #comps
- % This emulation does not handle multiple sources.
- /CINumComps exch pv
- /CIDataProc exch pv
- /CIIMatrix exch pv
- /CIBPC exch pv
- /CIHeight exch pv
- /CIWidth exch pv
-
- CIWidth CIHeight 8 CIIMatrix
- % Load the correct data acquisition procedure, depends on the
- % number of color components, and the number of bits per component.
- CINumComps 1 eq { /CIDataProc } {
- CINumComps 3 eq {
- CIBPC 8 eq { /FastRGB
- } { SetupColorImage /SlowRGB } ifelse
- } {
- CIBPC 8 eq { /FastCMYK
- } { SetupColorImage /SlowCMYK } ifelse
- } ifelse
- } ifelse
- load image
- } bd
- } EndLoad
-
- } EndLoad % Level2? not
-
- end % PDFImage
- %%EndFile