2016-07-21 5 views
2

저는 포스트 스크립트에 익숙하지 않으므로 나와 함께하시기 바랍니다. "showpage"앞에이 이미지를 놓을 때 혼합 워터 마크 효과를 만들 수 있도록 maskdict를 사용하여 이미지를 마스크하려고합니다. 나는 포스트 스크립트에서이 특징에 대해 더 많이 이해하기 위해 https://partners.adobe.com/public/developer/en/ps/sdk/TN5601.MaskedImages.pdf을 언급했다. 불행히도 나는 간단한 예제로 생각해 낼 수 없었다.Image maskdict를 사용한 포스트 스크립트의 마스킹

maskdict와 함께 "ImageType 3 및 InterleaveType 3"을 사용하는 간단한 작업 예제를 얻을 수 있다면 정말 도움이 될 것입니다.

미리 감사드립니다.

답변

2

다음은 예입니다. 이것은 유형 1, 유형 3 및 유형 4 이미지에 대한 테스트를 포함하는 /ghostpdl/lib/image-qa.ps의 Ghostscript와 함께 배포되는보다 완벽한 예제 세트에서 추출되었습니다.

이것은 가장 간단한 예제는 아니지만 유능한 포스트 스크립트 프로그래머가 이해할 수 있거나 더 간소화해야 함을 의미합니다.

%!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