⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 viewpbm.ps

📁 GhostScript的源代码
💻 PS
字号:
%    Copyright (C) 1992, 1995, 1996 Aladdin Enterprises.  All rights reserved.
% 
% This file is part of Aladdin Ghostscript.
% 
% Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
% or distributor accepts any responsibility for the consequences of using it,
% or for whether it serves any particular purpose or works at all, unless he
% or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
% License (the "License") for full details.
% 
% Every copy of Aladdin Ghostscript must include a copy of the License,
% normally in a plain ASCII text file named PUBLIC.  The License grants you
% the right to copy, modify and redistribute Aladdin Ghostscript, but only
% under certain conditions described in the License.  Among other things, the
% License requires that the copyright notice and this notice be preserved on
% all copies.

% $Id: viewpbm.ps $
% viewpbm.ps
% Display a PBM/PGM/PPM file.
% Requires the Level 2 `image' operator (to handle variable pixel widths).
% If SCALE is defined, maps input pixels to output pixels with that scale;
% if SCALE is undefined, scales the image to fit the page.

/s 100 string def
/readmaxv
 { f s readline pop cvx exec /maxv exch def
 } bind def
/readrow
 { 0 1 row length 1 sub { row exch f token pop put } for
 } bind def
/read01			% <count> read01 <byte>
 { 0 exch { f read pop 48 xor dup 1 le { exch dup add add } { pop } ifelse } repeat
 } bind def
/P1			% ASCII 1-bit white/black
 {	{ /bpc 1 def /maxv 1 def /rsize w 7 add 8 idiv def
	  /wrem w 8 mod def
          /ncomp 1 def /invert true def
	}
	{ 0 1 w 8 idiv { row exch 8 read01 put } for
	  wrem 0 ne
	   { row rsize 1 sub wrem read01 8 wrem sub bitshift put
	   } if
	  row
	}
   runpbm
 } bind def
/P2			% ASCII 8-bit gray
 {	{ /bpc 8 def readmaxv /rsize w def
	  /ncomp 1 def /invert false def
	}
	{ readrow row }
   runpbm
 } bind def
/P3			% ASCII 8-bit RGB
 {	{ /bpc 8 def readmaxv /rsize w 3 mul def
          /ncomp 3 def /invert false def /DeviceRGB setcolorspace
	}
	{ readrow row }
   runpbm
 } bind def
/P4			% Binary 1-bit white/black
 {	{ /bpc 1 def /maxv 1 def /rsize w 7 add 8 idiv def
	  /ncomp 1 def /invert true def
	}
	{ f row readstring pop }
   runpbm
 } bind def
/P5			% Binary 8-bit gray
 {	{ /bpc 8 def readmaxv /rsize w def
	  /ncomp 1 def /invert false def
	}
	{ f row readstring pop }
   runpbm
 } bind def
/P6			% Binary 8-bit RGB
 {	{ /bpc 8 def readmaxv /rsize w 3 mul def
	  /ncomp 3 def /invert false def /DeviceRGB setcolorspace
	}
	{ f row readstring pop }
   runpbm
 } bind def
/viewpbm { run } def
/runpbm				% <initproc> <readproc> runpbm -
 { /readproc exch def
   /initproc exch def
   currentfile /f exch def
   f s readline pop		% check for comment
   (#) anchorsearch
    { pop pop f s readline pop }
   if
   cvx exec /h exch def /w exch def
   erasepage
   /DeviceGray setcolorspace
   initproc			% sets bpc, maxv, rsize, ncomp, invert
   /row rsize string def
   /SCALE where
    { pop
	% Map pixels SCALE-for-1.  Assume orthogonal transformation.
      w 1 0 dtransform add abs div SCALE mul
      h 0 1 dtransform add abs div SCALE mul
    }
    {	% Scale the image (uniformly) to fit the page.
      clippath pathbbox pop pop translate
      pathbbox min exch pop exch pop ceiling
      dup h w gt { w mul h div exch } { h mul w div } ifelse
    }
   ifelse scale
   20 dict begin		% image dictionary
     /ImageType 1 def
     /Width w def
     /Height h def
     /ImageMatrix [w 0 0 h neg 0 h] def
     /BitsPerComponent bpc def
     /Decode [ 0 255 maxv div invert { exch } if ncomp 1 sub { 2 copy } repeat ] def
     /DataSource /readproc load def
   currentdict end
   image
   showpage
 } def

% If the program was invoked from the command line, run it now.
[ shellarguments
 { counttomark 1 ge
    { ] { viewpbm } forall
    }
    { cleartomark
      (Usage: gs [--] viewpbm.ps filename.p*m ...\n) print
      ( e.g.: gs [--] viewpbm.ps my.ppm another.ppm\n) print flush
    }
   ifelse
 }
 { pop
 }
ifelse

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -