【问题标题】:Image Masking in postscript using maskdict使用 maskdict 在 postscript 中进行图像遮罩
【发布时间】:2016-07-21 20:48:05
【问题描述】:

我是 Postscript 的新手,所以请多多包涵。 我正在尝试使用 maskdict 对图像进行遮罩,以便当我将此图像放置在“显示页面”之前时可以创建混合水印效果。我已推荐https://partners.adobe.com/public/developer/en/ps/sdk/TN5601.MaskedImages.pdf 以在后记中了解有关此功能的更多信息。不幸的是,我无法想出一个简单的工作示例。

如果我能得到一个使用“ImageType 3 和 InterleaveType 3”以及 maskdict 的简单工作示例,那将非常有帮助,这样我就可以在此基础上进行构建。

提前致谢。

【问题讨论】:

    标签: printing postscript printers


    【解决方案1】:

    这是一个例子。这是从 /ghostpdl/lib/image-qa.ps 中与 Ghostscript 一起分发的一组更完整的示例中提取的,其中包括对 1、3 和 4 类图像的测试。

    这意味着它不是最简单的示例,但足以让一个称职的 PostScript 程序员理解或进一步简化。

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

    【讨论】:

      猜你喜欢
      • 2013-04-05
      • 1970-01-01
      • 2011-07-04
      • 2018-05-29
      • 2016-01-07
      • 2022-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多