2016-07-21 27 views
2

Ich bin neu in Postscript, also bitte tragen Sie mit mir. Ich versuche ein Bild mit maskdict zu maskieren, so dass ich einen gemischten Wasserzeicheneffekt erzeugen kann, wenn ich dieses Bild vor "showpage" platziere. Ich habe https://partners.adobe.com/public/developer/en/ps/sdk/TN5601.MaskedImages.pdf verwiesen, um mehr über dieses Merkmal in Postscript zu verstehen. Leider konnte ich mir kein einfaches Arbeitsbeispiel einfallen lassen.Bildmaskierung in Postscript mit Maskdict

Es wäre wirklich hilfreich, wenn ich ein einfaches Arbeitsbeispiel bekommen könnte, das "ImageType 3 und InterleaveType 3" zusammen mit maskdict verwendet, so dass ich darauf aufbauen kann.

Vielen Dank im Voraus.

Antwort

2

Hier ist ein Beispiel. Dies wurde aus einem umfassenderen Satz von Beispielen entnommen, die mit Ghostscript in /ghostpdl/lib/image-qa.ps verteilt wurden, was Tests für Typ 1, 3 und Typ 4 Bilder beinhaltet.

Dies bedeutet, es ist nicht die einfachste Beispiele, aber es sollte für einen kompetenten PostScript-Programmierer ausreichen, Sinn zu machen oder weiter zu vereinfachen.

%!PS 

/WidthRGB 83 def 
/HeightRGB 89 def 

/SX 036 def 
/SY 037 def 
/XA 060 def 

% 
% Procedure to generate test mask data 
% 
% WM and HM must be defined prior to invocation 
%  MaskGen - 
% 
% The mask data is stored into a string named /MaskData 
% 
% The mask consists of a "target". Bits past width WM are 
% filled with 1's to make sure that pad bits are ignored. 
% 
/MaskGen { 
    /H8 HM 8 div def 
    /X0 WM 2 div def 
    /Y0 HM 2 div def 
    /WB WM 7 add 8 div cvi def 
    /MaskData WB HM mul string def 
    /MB [ 128 64 32 16 8 4 2 1 ] def 
    0 1 HM 1 sub { 
    /Y exch def 
    0 1 WB 1 sub { 
     /B exch def % byte within the row 
     /C B Y WB mul add def 
     /P 0 def 
     0 1 7 { 
     /b exch def % bit within the character 
     /X b B 8 mul add def 
     X WM lt 
      { X Y eq 
      X HM 1 sub Y sub eq or 
      Y Y0 gt X X0 sub abs 2 le and or 
      X X0 sub WM div dup mul Y Y0 sub HM div dup mul add sqrt 9 mul cvi 2 mod 1 eq or 
      } 
      { true } % pad bits are always set 
     ifelse 
     % stack: true if pixel is set 
     { 
      MB b get P or /P exch def 
     } if 
     } for % Bits within a byte 
     MaskData C P put 
    } for % Bytes within the row 
    } for % Rows in the mask 
} bind def   % MaskGen 

% ----------------------------------------------------------------------- 

% ----------------------------------------------------------------------- 
% 
% Procedures for ImageMatrix creation 
/IMLRTB { [ WD 0 0 HD neg 0 HD ] } def 

% Procedure to generate image data 
% 
% WD and HD must be defined prior to invocation 
% { proc } ImageGen - 
% 
% The procedure is called once for each pixel 
% Local definitions are R, G, B, X and Y 

% Example: Generate RGB Chunky pixel data (single data source) BPC = 8 
%  /WD WidthRGB def 
%  /HD HeightRGB def 
%  /RGBData WD HD mul 3 mul string def 
% { X Y WD mul add 3 mul RGBData 
%  dup 2 index R 255 mul cvi put 
%  dup 2 index 1 add G 255 mul cvi put 
%  exch 2 add B 255 mul cvi put 
% } ImageGen 

/ImageGen { 
    gsave 
    0 1 HD 1 sub { 
    /Y exch def 
    0 1 WD 1 sub { 
     /X exch def 
     /D X WD 2 div sub WD div dup mul Y HD 2 div sub HD div dup mul add sqrt def 
     /D D .6 div def 
     /A X WD 2 div sub Y HD 2 div sub atan 360 div def 
     A        % Hue 
     .7 D .3 sub .60 div sub % Saturation 
     dup 0.05 lt 
     { .95 D .8 sub 3 mul sub 3 mul cvi 3 div sqrt } % Level once Saturation < 0 
     { .7 D .25 sub .75 div add } % Level inside 
     ifelse 
     X WD 2 div gt Y HD 2 div sub abs 2 le and { pop 0 } if % asymmetric marker 
     sethsbcolor 
     currentrgbcolor /B exch def /G exch def /R exch def 
     dup exec 
    } for 
    } for 
    pop  % discard the procedure 
    grestore 
} bind def 

% ----------------------------------------------------------------------- 
% 
%  Procedures to use generated string data as procedure or files 

/WD WidthRGB def 
/HD HeightRGB def 

/sM WidthRGB 2 mul 1 sub string def % long enough to hold more than one mask line 
/sD WidthRGB 7 mul 1 sub string def % long enough to hold more than one 12 bit RGB line 
           % worst case is 12bit ImageType3 InterleaveType 1 == 48 bits 

/MaskDProc { 
    /FM MaskData dup length() /SubFileDecode filter def 
    { { FM sM readstring pop } } 
} bind def 

/MaskDFile { 
    MaskData dup length() /SubFileDecode filter 
    /MDF 1 index def 
} bind def 

/RGBDProc { 
    /FD RGBData dup length() /SubFileDecode filter def 
    { { FD sD readstring pop } } 
} bind def 

/RGBDFile { 
    RGBData dup length() /SubFileDecode filter 
    /RGBDF 1 index def 
} bind def 

% YY, SX, SY, W, HD (Data) WM, HM (Mask) should be defined prior to invocation 
%             (IT is InterleaveType) 
% X Y BPC matrix source multi MaskDecode DataDecode IT DoImage3 - 
% 
/DoImage3 { 
    gsave 
    /DeviceRGB setcolorspace 
    /IT exch def 
    /DD exch def 
    /DM exch def 
    /MS exch def 
    /S exch def  % May be an array of sources - For InterleaveType 3 
         % S[0] is the Mask DataSource 
    /M exch def 
    /BPC exch def 
    /XX 1 index def 
    YY translate SX SY scale 
    0 setlinewidth 0 0 moveto 1 0 lineto 1 1 lineto 0 1 lineto 0 0 lineto stroke 

    /DataImage 
    << 
    /ImageType  1 
    /Width  WD 
    /Height  HD 
    /ImageMatrix  M 
    /MultipleDataSources MS 
    /DataSource  IT 3 ne { S } { S 1 get exec } ifelse 
    /BitsPerComponent BPC 
    /Decode  DD 
    >> 
    def 
    /MaskImage 
    << 
    /ImageType  1 
    /Width  WM 
    /Height  HM 
    /ImageMatrix  % construct the mask matrix using signs from the DataImage matrix 
         /M0 M 0 get WD abs div cvi def 
         /M3 M 3 get HD abs div cvi def 
         /M4 M 4 get WD abs div cvi def 
         /M5 M 5 get HD abs div cvi def 
         [ WM M0 mul 0 0 HM M3 mul WM M4 mul HM M5 mul ] 
    IT 3 eq { 
    /DataSource  S 0 get exec % DataSource only allowed for InterleaveType 3 
    } if 
    /BitsPerComponent IT 1 eq { BPC } { 1 } ifelse 
    /Decode  DM 
    >> 
    def 
    << 
    /ImageType  3 
    /DataDict  DataImage 
    /MaskDict  MaskImage 
    /InterleaveType IT 
    >> 
    image 
    grestore 
} bind def 

% ---------------------------------------------------------------------- 
%  InterleaveType 3, BPC==8, WM=WD, HM=HD 
%  IT 3 is line interleave -- Mask and Data in separate sources 
%  RGB Image Data chunky (MultipleDatasources==false). 
    /YY 50 def 

    % Generate the MaskData first 
    /WM WD def 
    /HM HD def 
    MaskGen 

    % Generate the Data Image 
    /RGBData WD HD mul 3 mul string def 
    { X Y WD mul add 3 mul RGBData 
    dup 2 index R 255 mul cvi put 
    dup 2 index 1 add G 255 mul cvi put 
    exch 2 add B 255 mul cvi put 
    } ImageGen 

    50 8 IMLRTB [ MaskData RGBData ] false [0 1] [1 0 1 0 1 0] 3 DoImage3 

% ---------------------------------------------------------------------- 

showpage