1826 lines · 71.6 KB · Text
RawDownload
%!PS%    Copyright (C) 2000 Aladdin Enterprises.  All rights reserved.% % This software is provided AS-IS with no warranty, either express or% implied.% % This software is distributed under license and may not be copied,% modified or distributed except as expressly authorized under the terms% of the license contained in the file LICENSE in this distribution.% % For more information about licensing, please refer to% http://www.ghostscript.com/licensing/. For information on% commercial licensing, go to http://www.artifex.com/licensing/ or% contact Artifex Software, Inc., 101 Lucas Valley Road #110,% San Rafael, CA  94903, U.S.A., +1(415)492-9861.%% $Id: image-qa.ps,v 1.5 2002/02/21 21:49:28 giles Exp $% Tests for the image operators % Specifications for Image operator testing.% % 1.  All 8 standard orientations (0, 90, 180, 270 degree rotations with%     and without reflection); ditto those orientations perturbed by +/-%     10 degrees, and by 45 degrees.%%     Enough space is provided around images on a test page to allow%     these permutations to use the same page layout. This will make%     test page construction easier and simplify page checking.% % 2.  All 9 image types (ImageType 1 mask, ImageType 1 opaque,%     ImageType 3 with all 3 InterleaveTypes and with unequal scaling%     for InterleaveType 2 and 3, ImageType 4 with both range and%     single-point matching).% % 3.  DeviceGray, DeviceRGB, and DeviceN color, both direct and Indexed.%     Indexed color will use the common pallete size of 256 colors.% % 4.  For simple masks, both colored and uncolored Patterns.% % 5.  CombineWithColor true and false; several different colors for the%     true case (including black, white, other solid colors, halftones,%     and patterns).% % 6.  Source transparency true and false.% % 7.  Texture transparency true and false.% % 8.  Different RasterOp values.% % 9.  For ImageType 4, different color keys (out-of-range, specific%     color other than white, range without white).% % 10. String, file, and procedure data sources; for multi-component%     color spaces, MultipleDataSources = true. This is tested by%     constructing string data sources that are used as input to%     SubFileDecode filter to create a filetype data source. These%     filters are read into scratch strings for the procedure data %     source case. The procedure data source scratch string length%     does not match the raster width, and the width x height is%     not an integer multiple of the string length.%%     Also for the File case, the number of bytes consumed is%     checked after the image operator to verify that the exact%     amount of data is used. This is particularly important when%     the currentfile is used as a source (possibly through a%     filter.%%     Image bytes per line are < 500 bytes to exercise direct and%     buffer copy gs_image_next_planes mode with the default stream%     buffer size of 512 bytes. Procedure string size is greater%     than the image bytes per line for the same reason (sM and sD).%%     Total string size is kept below 65535. /WidthRGB	83 def/HeightRGB	89 def % % 11. Banded and non-banded rendering. This can be tested by running%     test files throuch with different page device parameters to%     force banding vs. page mode.%% -------------------------------------------------------------------------%% Testing the RasterOp-related functions (5/6/7/8) is not necessary at this% time.  They are well isolated logically.% % Testing orientation (1) and color masking (9) would be a good idea at some% point, because this code has broken many times in the past and has had a% long bug tail.% % The really important things to test are 2 (image type), 3/4 (color space --% but only with regard to number of components, plus DeviceN and simple masks% with a Pattern, which exercise special control paths), 10 (data source),% and 11 (banding modes).% % ========================================================================== %% 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 %% WM and HM must be defined prior to invocation%     BPC MaskGenBPC -	%% The mask data is stored into a string named /MaskData%% The mask consists of a "target". BPC is the size of the elements% in the MaskData string (must be 4, 8 or 12)%/MaskGenBPC {  /BPC exch def  /X0 WM 2 div def  /Y0 HM 2 div def  /WB WM BPC mul 7 add 8 div cvi def		% Width in Bytes  /MaskData WB HM mul string def  0 1 HM 1 sub {    /Y exch def    0 1 WM 1 sub {      /X exch def      MaskData				% Target string      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      X BPC mul 8 div Y WB mul add exch      [        { }						% BPC = 0	{ { 1 } { 0 } ifelse put4bit }			% BPC = 4	{ { 255 } { 0 } ifelse exch cvi exch put }	% BPC = 8	{ { 1 } { 0 } ifelse put12bit }			% BPC = 12      ] BPC 4 div cvi get exec    } for  } for % Rows in the mask} bind 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 for ImageMatrix creation/IMLRTB { [ WD 0 0 HD neg 0 HD ] } def/IMLRBT { [ WD 0 0 HD 0 0 ] } def/IMRLTB { [ WD neg 0 0 HD neg WD HD ] } def/IMRLBT { [ WD neg 0 0 HD WD 0 ] } def% -----------------------------------------------------------------------%% Procedure to make invocation of image operators more concise%% YY, SX, SY, WD and HD should be defined prior to invocation% X matrix source decode DoImageMask -%/DoImageMask {  gsave  /D exch def  /S exch def  /M 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  .5 .5 translate  IR rotate  -.5 -.5 translate  <<  /ImageType		1  /Width		WM  /Height		HM  /ImageMatrix		M  /MultipleDataSources	false  /DataSource		S  /Decode		D  /BitsPerComponent	1  >>  imagemask  grestore} bind def % YY, SX, SY, WD and HD should be defined prior to invocation% X Y BPC matrix source multi decode DoImage1 -%/DoImage1 {  gsave  CSpace setcolorspace  /D exch def  /MS exch def  /S exch def		% May be an array of sources  /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  .5 .5 translate  IR rotate  -.5 -.5 translate  <<  /ImageType		1  /Width		WD  /Height		HD  /ImageMatrix		M  /MultipleDataSources	MS  /DataSource		S  /BitsPerComponent	BPC  /Decode		D  >>  image  grestore} bind def  % YY, SX, SY, WD and HD should be defined prior to invocation% X Y BPC matrix source multi decode MaskColor DoImage4 -%/DoImage4 {  gsave  CSpace setcolorspace  /MC exch def  /D exch def  /MS exch def  /S exch def		% May be an array of sources  /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  .5 .5 translate  IR rotate  -.5 -.5 translate  <<  /ImageType		4  /Width		WD  /Height		HD  /ImageMatrix		M  /MultipleDataSources	MS  /DataSource		S  /BitsPerComponent	BPC  /Decode		D  /MaskColor		MC  >>  image  grestore} 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  CSpace 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  .5 .5 translate  IR rotate  -.5 -.5 translate  /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  % -----------------------------------------------------------------------%/Helvetica-Bold findfont 20 scalefont /TitleFont exch def /FontSize 10 def/Helvetica-Narrow findfont FontSize scalefont /LegendFont exch def /blockshow {	% like "show" but '\n' causes new-line  dup = flush	%DEBUG  currentpoint /showY exch def /showX exch def  {    dup 10 ne    { 1 string dup 0 4 -1 roll put show }    { pop showX showY FontSize sub dup /showY exch def moveto }    ifelse  } forall} bind def /TX 013 def	% Title left X/SX 036 def/XA 060 def/XB XA SX 1.5 mul add def/XC XA SX 3.0 mul add def/XD XA SX 4.5 mul add def/XE XA SX 6.0 mul add def/XF XA SX 7.5 mul add def/XG XA SX 9.0 mul add def/XH XA SX 10.5 mul add def/XI XA SX 12.0 mul add def/XJ XA SX 13.5 mul add def /BY 036 def	% Bottom Title Top line/SY 037 def/YA 050 def/YB YA SY 1.8 mul add def/YC YA SY 3.6 mul add def/YD YA SY 5.4 mul add def/YE YA SY 7.2 mul add def/YF YA SY 9.0 mul add def/YG YA SY 10.8 mul add def/YH YA SY 12.6 mul add def/YI YA SY 14.4 mul add def/YJ YA SY 16.2 mul add def/YK YA SY 18.0 mul add def % -----------------------------------------------------------------------%%     Utility procedures to support storing 4 and 12 bit elements in%     strings.%%     <string> <index> <value> put##bit -%%     <index> will have a fractional part ( .5 ) if the element%     starts on a 4-bit boundary.%%     <value> is between 0 and 1 and is scaled 0 to 15 (4bit) or%     0 to 4095 (12 bit) /put4bit {  15 mul cvi   exch dup cvi dup 3 1 roll eq 3 -1 roll exch  { % integer index means high nibble.    16 mul put  }  { % low nibble -- combine with high nibble    2 index 2 index get or put  }  ifelse} bind def /put12bit {  1 index cvi /I exch def  2 index /S exch def  4095 mul cvi   exch dup dup cvi eq  { % integer index means high byte is aligned    cvi exch 3 copy 16 div cvi put    exch 1 add exch 15 and 16 mul put  }  { % low nibble -- combine with high nibble    cvi exch 3 copy 2 index 2 index get exch 256 div cvi or put    255 and exch 1 add exch put  }  ifelse} 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 /FileTailString (12345) def		% Marker string to check file data usage /AppendFileTail {    %  <string> AppendFileTail <string_with_tail> <original_length>  dup length FileTailString length add string  dup 0 3 index putinterval  dup 2 index length FileTailString putinterval  exch length} bind def

Lines 1–500 of 1826.