home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1996 September
/
PCWK996.iso
/
sharewar
/
95
/
narzedzi
/
ambra
/
ambr32a1.exe
/
FILE
/
ARCHIVE.Z
/
ACROBAT
/
VIEWER32.EXE
/
PSPROCSET
/
10
< prev
next >
Wrap
Text File
|
1996-02-22
|
15KB
|
436 lines
%%BeginFile: pdfimg1i.prc
%%Copyright: Copyright 1987-1993 Adobe Systems Incorporated. All Rights Reserved.
% PDF Image Operators for Level 1 (Indexed Color)
% This code is based on David Gelphman's emulation of the indexed colorspace.
% It has been expanded to handle DeviceGray and DeviceCMYK colorspaces.
PDF /PDFImage get begin
Level2? not StartLoad {
% Utility function: testsystemdict
% Determines whether the key on the stack first occurs in systemdict
/testsystemdict {
false exch where { systemdict eq { pop true } if } if
} bd
% Variable: NDColors
% Determine the number of device colors
/NDColors 1 def % This will be the value if colorimage does not exist
ColorImage? StartLoad {
/NDColors 0 % Define the number of printer colors
statusdict begin
/processcolors where {
pop pop processcolors
}{
/deviceinfo where {
pop deviceinfo /Colors known {
pop deviceinfo /Colors get
} if
} if
} ifelse
end % statusdict
def
NDColors 0 ne {
/colorimage testsystemdict
/setcolortransfer testsystemdict and
/currentcolortransfer testsystemdict and
/currentcmykcolor testsystemdict and not {
% better make sure that lookups on colorimage, setcolortransfer and
% currentcolortransfer will result in the systemdict functionality,
% else our transfer function strategy will not work. If this is the
% case, use slow but reliable technique
/NDColors 0 def
} if
} if
% if NDColors isn't 1,3,4 then it should be 0
NDColors dup 1 ne exch dup 3 ne exch 4 ne and and {
/NDColors 0 def
}if
} EndLoad % Colorimage?
/BaseSpace? { ColorSpace 1 get } bd
% NDColors is not 0 (Optimized cases)
% The Gray CLUT code should always be available, even on RGB/CMY and
% CMYK devices. We want to set the transfer function and then do the image.
% Note: we could use color image if it was available, but it may be slower
% than converting the CLUT and then doing an image. Might want to test this
% in the future.
NDColors 0 ne StartLoad {
% *Internal* Name: rgbtogray
% Convert an RGB value to a gray value.
/rgbtogray { % r g b rgbtogray gray
0.11 mul exch 0.59 mul add exch 0.3 mul add round cvi
} bd
% *Internal* Name: ConvRGBtoGray
% Takes in an RGB CLUT and creates a gray CLUT out of it
/ConvRGBtoGray { % RGB
dup length 3 idiv % RGB #entries
0 1 3 -1 roll 1 sub { % RGB loop
1 index exch 2 copy 3 mul % RGB RGB loop RGB idx
2 copy get 3 1 roll % RGB RGB loop R RGB idx
2 copy 1 add get 3 1 roll % RGB RGB loop R G RGB idx
2 add get
rgbtogray
put % RGB
} for
dup length 3 idiv 0 exch getinterval % GrayCLUT
} bd
% *Internal* Name: cmyktogray
% Convert a CMYK value to a gray value.
/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
% *Internal* Name: ConvCMYKtoGray
% Takes in an CMYK CLUT and creates a gray CLUT out of it
/ConvCMYKtoGray { % CMYK
dup length 4 idiv % CMYK #entries
0 1 3 -1 roll 1 sub { % CMYK loop
1 index exch 2 copy 4 mul % CMYK CMYK loop CMYK idx
2 copy get 3 1 roll % CMYK CMYK loop C CMYK idx
2 copy 1 add get 3 1 roll % CMYK CMYK loop C M CMYK idx
2 copy 2 add get 3 1 roll % CMYK CMYK loop C M Y CMYK idx
3 add get cmyktogray put % CMYK
} for
dup length 4 idiv 0 exch getinterval % GrayCLUT
} bd
% Utility function: setupgrayclut
% Create gray subcluts.
/setupgrayclut {
/CIbit1x CIgclut length 1 sub pv
} bd
% Utility function: 1compute
% This proc converts a CLUT index into a grayscale value.
/1compute {
exch 2 BitsPerComponent exp 1 sub mul round cvi
dup CIbit1x gt { pop pop 0 } { get 255 div } ifelse
} bd
/DoGrayCLUT {
% Set up the transfer function.
ColorSpace 3 get /CIgclut exch pv setupgrayclut
[ { CIgclut 1compute } /exec load dup currenttransfer exch ]
cvx settransfer
% Do the B/W image
Width Height BitsPerComponent ImageMatrix ImageFilter image
} bd
} EndLoad
% NDColors is 1
% We're dealing strictly with a BW device.
NDColors 1 eq StartLoad {
% Utility function: Indexed
% This proc will be run at image time, it does the indexed color stuff
/Indexed [ 1
{
% Convert the CLUT if necessary.
BaseSpace? /DeviceRGB eq {
ColorSpace dup 3 get ConvRGBtoGray 3 exch put
} {
BaseSpace? /DeviceCMYK eq {
ColorSpace dup 3 get ConvCMYKtoGray 3 exch put
} if
} ifelse
DoGrayCLUT
}
] InstallImage
} EndLoad
% What follows are some utility functions that are used in both the 3 or 4
% color cases.
NDColors dup 3 eq exch 4 eq or StartLoad {
/NULLPROC {} bd
% Utility function: concatutil
% This proc is helps to concatenate transfer functions
/concatutil { % a b c d [ newtransferfunct
/exec load % a b c d [ newtransferfunct exec
7 -1 roll /exec load % b c d [ newtransferfunct exec a exec
} bd
% Utility function: spconcattransfer
% This proc is designed specifically to handle the problem of
% concatenating COLOR transfer functions as compactly as possible and
% to share the code between the 3 and 4 color cases
/spconcattransfer { % key RorCtable GorMtable BorYtable GRorKtable
/Dclut exch pv
/Cclut exch pv
/Bclut exch pv
/Aclut exch pv
/ncompute exch load pv
currentcolortransfer % r g b gr
[ { Aclut ncompute } concatutil ] cvx % g b gr {r'}
[ { Bclut ncompute } concatutil ] cvx % b gr {r'} {g'}
[ { Cclut ncompute } concatutil ] cvx % gr {r'} {g'} {b'}
[ { Dclut ncompute } concatutil ] cvx % {r'} {g'} {b'} {gr'}
setcolortransfer
} bd
% Utility function: pvsubclut
% Utility function to help create subcluts
/pvsubclut { % key str index length-1
1 add getinterval pv
} bd
} EndLoad
% NDColors is 3
% We're dealing with either a RGB or a CMY device. In this case, we want to
% set the color transfer functions and then do a colorimage.
NDColors 3 eq StartLoad {
% Utility function: cmyktorgb
% Convert a CMYK value to an rgb value.
/cmyktorgb { % c m y k cmyktorgb r g b
dup 5 -1 roll add 255 exch sub 4 1 roll % r=255-(k+c) m y k
dup 4 -1 roll add 255 exch sub 3 1 roll % r g=255-(k+g) y k
add 255 exch sub % r g b=255-(y+k)
3 { dup 0 lt { pop 0 } if cvi 3 1 roll } repeat
} bd
% Utility function: ConvCMYKtoRGB
% Takes in an CMYK CLUT and creates a RGB CLUT out of it
% It looks like we're building the RGB CLUT backwards, but we're not.
/ConvCMYKtoRGB { % CLUT
dup length 4 idiv % CLUT #entries
0 1 3 -1 roll 1 sub { % CLUT loop
dup 3 mul exch 4 mul % CLUT RGBidx CMYKidx
2 index exch 4 getinterval { } forall % CLUT RGBidx C M Y K
cmyktorgb % CLUT RGBidx R G B
5 -2 roll 2 copy 7 -1 roll put % G B CLUT RGBidx
2 copy 1 add 6 -1 roll put % B CLUT RGBidx
2 copy 2 add 5 -1 roll put % CLUT RGBidx
pop % CLUT
} bind for
dup length 4 idiv 3 mul 0 exch getinterval % RGBCLUT
} bd
% Utility function: setuprgbcluts
% Utility function to create subcluts
/setuprgbcluts {
/CIbit3x CIrgbclut length 3 sub pv
/CIrclut CIrgbclut pv % make substr of clut for easy indexing
/CIgclut CIrclut 1 CIbit3x pvsubclut % green = red + 1
/CIbclut CIrclut 2 CIbit3x pvsubclut % blue = red + 2
} bd
% Utility function: 3compute
% Utility function to convert CLUT index into a color value
/3compute { % value color_clut
exch 2 BitsPerComponent exp 3 mul 3 sub
mul % color_clut clut_index
round % round so that we get to nearest int
cvi % must be an int to index into clut
dup CIbit3x gt { pop pop 0 } { get 255 div } ifelse
} bd
/DoRGBCLUT {
% Set up the color transfer function
ColorSpace 3 get /CIrgbclut exch pv setuprgbcluts
/3compute CIrclut CIgclut CIbclut dup spconcattransfer
% Do the color image
Width Height BitsPerComponent ImageMatrix ImageFilter
[ exch /exec load /dup load dup ] cvx /NULLPROC load dup true 3
colorimage
} bd
% Install the image Indexed colorspace handler (3 color device).
/Indexed [ 1
{
% Convert the CLUT if necessary.
BaseSpace? /DeviceCMYK eq {
ColorSpace dup 3 get ConvCMYKtoRGB 3 exch put
} if
BaseSpace? /DeviceGray eq { DoGrayCLUT }
{ DoRGBCLUT } ifelse
} bind
] InstallImage
} EndLoad
% NDColors is 4
% We're dealing with a CMYK device. In this case, we want to set the color
% transfer functions and then do a colorimage.
NDColors 4 eq StartLoad
{
% Utility function: rgbtocmyk
% Convert RGB to CMYK
/rgbtocmyk { % r g b rgbtocmyk c m y k
3 { 255 div 3 1 roll } repeat
setrgbcolor currentcmykcolor
4 { 1 exch sub 255 mul round cvi 4 1 roll } repeat
} bd
% Utility function: ConvRGBtoCMYK
% Takes in an RGB CLUT and creates a CMYK CLUT out of it
% It looks like we're building the CMYK CLUT backwards, but we're not.
/ConvRGBtoCMYK { % RGB
dup length 3 idiv % RGB #entries
dup 4 mul string 3 1 roll % CMYK RGB #entries
0 1 3 -1 roll 1 sub { % CMYK RGB loop
dup 4 mul 3 index length 4 sub exch sub % CMYK RGB loop CMYKidx
3 1 roll 3 mul % CMYK CMYKidx RGB RGBidx
1 index exch 3 getinterval {} forall % CMYK CMYKidx RGB R G B
rgbtocmyk % CMYK CMYKidx RGB C M Y K
7 -2 roll 2 copy 8 -1 roll put % RGB M Y K CMYK CMYKidx
2 copy 1 add 7 -1 roll put % RGB Y K CMYK CMYKidx
2 copy 2 add 6 -1 roll put % RGB K CMYK CMYKidx
2 copy 3 add 5 -1 roll put % RGB CMYK CMYKidx
pop exch % CMYK RGB
} bind for
pop % CMYK
} bd
% Utility function: setupcmykcluts
/setupcmykcluts {
/CIbit4x CIcmykclut length 4 sub pv
/CIcclut CIcmykclut pv % Make substr of CLUT for easy indexing
/CImclut CIcclut 1 CIbit4x pvsubclut % magenta = cyan + 1
/CIyclut CIcclut 2 CIbit4x pvsubclut % yellow = cyan + 2
/CIkclut CIcclut 3 CIbit4x pvsubclut % black = cyan + 3
} bd
% Utility function: 4compute
% Convert CLUT index into a color value
/4compute {
exch 2 BitsPerComponent exp 4 mul 4 sub mul round cvi
dup CIbit4x gt { pop pop 0 } { get 255 div } ifelse
} bd
/DoCMYKCLUT {
% Set up the color transfer function
ColorSpace 3 get /CIcmykclut exch pv setupcmykcluts
/4compute CIcclut CImclut CIyclut CIkclut spconcattransfer
% Do the color image
Width Height BitsPerComponent ImageMatrix ImageFilter
[ exch /exec load /dup load dup dup ] cvx
/NULLPROC load dup dup true 4 colorimage
} bd
% Install the image Indexed colorspace handler (4 color device).
/Indexed [ 1
{
% Convert the CLUT if necessary.
BaseSpace? /DeviceRGB eq {
ColorSpace dup 3 get ConvRGBtoCMYK 3 exch put
} if
BaseSpace? /DeviceGray eq { DoGrayCLUT } { DoCMYKCLUT } ifelse
} bind
] InstallImage
} EndLoad
% NDColors is 0
% This is the ultra-conservative case. We're not sure what the number of
% device colors is and/or we may be performing a separation. In this case,
% do a lookup in the CLUT for every sample.
% Gray Limits:
% 65535/4 = 16384 BYTES = 131072 BITS = 65536 SAMPLES WIDE @ 2 BPC
% 65535/2 = 32768 BYTES = 262144 BITS = 65536 SAMPLES WIDE @ 4 BPC
% RGB Limits:
% 65535/12 = 6561 BYTES = 43690 BITS = 21845 SAMPLES WIDE @ 2 BPC
% 65535/6 = 10922 BYTES = 87380 BITS = 21845 SAMPLES WIDE @ 4 BPC
% 65535/3 = 21845 BYTES = 174760 BITS = 21845 SAMPLES WIDE @ 8 BPC
% CMYK Limits:
% 65535/16 = 4096 BYTES = 32768 BITS = 16384 SAMPLES WIDE @ 2 BPC
% 65535/8 = 8192 BYTES = 65536 BITS = 16384 SAMPLES WIDE @ 4 BPC
% 65535/4 = 16384 BYTES = 131072 BITS = 16384 SAMPLES WIDE @ 8 BPC
% at 300 dpi, 11 inch wide paper has room for 3300 samples
% at 1500 dpi, 11 wide paper has room for 16500 samples
% at 1985 dpi, 11 wide paper has room for 21835 samples
% This means we're likely to have problems with CMYK images at 1985 dpi
% or higher.
NDColors 0 eq StartLoad {
/CICSLookup 3 dict begin
/DeviceGray {
get % expstr j gclut expstr j value
put exch % expstr gclut j
1 add exch 3 copy % expstr j+1 gclut expstr j+1 gclut
} bd
/DeviceRGB {
3 mul % expstr j rgbclut expstr j rgbclut 3xstrelement(i)
3 getinterval % expstr j rgbclut expstr j 3elementstring
putinterval exch % expstr rgbclut j
3 add exch 3 copy % expstr j+3 rgbclut expstr j+3 rgbclut
} bd
/DeviceCMYK {
4 mul % expstr j cmykclut expstr j rgbclut 4xstrelement(i)
4 getinterval % expstr j cmykclut expstr j 4elementstring
putinterval exch % expstr cmykclut j
4 add exch 3 copy % expstr j+4 cmykclut expstr j+4 cmykclut
} bd
currentdict end pv
/CIBLookup 3 dict begin
8 { lookupandstore } bd
4 { % expstr j rgbclut expstr j rgbclut stringelement(i)
/shiftbyte 1 index pv
-4 bitshift % left 4 bits of string element
lookupandstore % lookup and put into expstr
shiftbyte 15 and % right 4 bits of string element
lookupandstore % lookup and put into expstr
} bd
2 { % expstr j rgbclut expstr j rgbclut stringelement(i)
/shiftbyte 1 index pv
-6 bitshift % left 2 bits of string element
lookupandstore % lookup and put into expstr
shiftbyte -4 bitshift
3 and % next 2 bits of string element
lookupandstore % lookup and put into expstr
shiftbyte -2 bitshift
3 and % next 2 bits of string element
lookupandstore % lookup and put into expstr
shiftbyte 3 and % right 2 bits of string element
lookupandstore % lookup and put into expstr
} bd
currentdict end pv
/colorexpand { % unexpandedstr
BufferExp 0 CLUT % unexpstr expstr j CLUT
3 copy % unexpstr expstr j CLUT expstr j CLUT
7 -1 roll % expstr j CLUT expstr j CLUT unexpstr
% expstr j CLUT expstr j CLUT strelement(i)
/BitLookup load % proc on stack for 'forall'
forall
pop pop pop pop pop
} bd
% Install the image Indexed colorspace handler (conservative case).
/Indexed [ 1
{
/CLUT ColorSpace 3 get pv
/BitLookup CIBLookup BitsPerComponent get pv
/lookupandstore BaseSpace? CICSLookup exch get pv
/BufferExp CIBuffer length 8 mul BitsPerComponent idiv
BaseSpace? ColorComps? mul string pv
Width Height 8 ImageMatrix
[
ImageFilter /exec load /colorexpand load /exec load 0
Width BaseSpace? ColorComps? mul /getinterval load /exec
load
] cvx
BaseSpace? ColorComps? ColorImage
} bind
] InstallImage
} EndLoad
currentdict readonly pop
} EndLoad % Level2? not
end
%%EndFile