%!PS % PS Bitmap Image Shader % =================================== % by Don Lancaster % Copyright c 2003 by Don Lancaster & Synergetics, Box 809, Thatcher, AZ, 85552 % (928) 428-4073 Email: don@tinaja.com Website: http://www.tinaja.com % Consulting services available http://www.tinaja.com/info01.html % All commercial rights and all electronic media rights ~fully~ reserved. % Linking usually welcome. Reposting expressly forbidden. Version 1.1 % PostScript-as-language utility reads a 24-bit uncompressed bitmap file and % adjusts brightness of each color triad depending on its distance from four % corner brightness values. Useful to correct shading caused by flash proximity. % To use, load into wp or editor, change filenames and shading values below and % send to Distiller. A "no Acrobat PDF file produced" error is normal and expected. % ========= % IMPORTANT NOTE: Don Lancaster's file gonzo.ps is required for this program. % After obvious location mods, uncomment ONE of the following two lines: (C:\\windows\\desktop\\gonzo\\gonzo.ps) run % use internal gonzo % (A:\\gonzo.ps) run % use external gonzo % NOTE THAT ALL PS FILENAME STRINGS !!!DEMAND!!! DOUBLE REVERSE SLASHES. % GONZO20A Guru Gonzo PostScript power tools (Interim release) % Includes gonzo justification and layout utilities. % Copyright c 1990, 1996, 2001 by Don Lancaster and Synergetics, Box 809, % Thatcher Arizona, 5552 (928) 428-4073 don@tinaja.com support % via http://www.tinaja.com All commercial rights and all electronic % media rights **FULLY** reserved. Reposting is expressly forbidden. % ======== /guru { gonzo begin ps.util.1 begin printerror nuisance begin} def guru % activate gonzo utilities % ========= % Define shading here. 1.0 brighness stays the same. /sul 1.0 store % upper left shading /sur 1.20 store % upper right shading /slr 1.0 store % lower right shading /sll 0.8 store % lower left shading % alternate "post and tilt" method /xneut 0.85 store % "no change" x position /yneut 0.85 store % "no change" y position /xgain 0.17 store % gain in brightness /ygain 0.17 store % gain in brightness /calcedges { /vtop 1 yneut sub ygain mul 1 add store /vbot yneut ygain mul neg 1 add store /sur 1 xneut sub xgain mul 1 add vtop mul store /sul xneut xgain mul neg 1 add vtop mul store /slr 1 xneut sub xgain mul 1 add vbot mul store /sll xneut xgain mul neg 1 add vbot mul store } store calcedges sul == sur == sll == slr == /nofixwhite true store % Leave true white pixels the way they were for knockout? /maxclip nofixwhite {254}{255} ifelse store % % input name of bmp file to be evaluated here... /diskfileheader (C:\\WINDOWS\\Desktop\\aaraw_pix\\) store /diskfilesourcename (termy7.bmp) store /diskfiletargetname (termz7.bmp) store /sourcefilename diskfileheader diskfilesourcename mergestr store /targetfilename diskfileheader diskfiletargetname mergestr store /readfile sourcefilename (r) file store % establish input read file /writefile targetfilename (w+) file store % establish output target file /whiteref (XXX) def % truewhite reference whiteref 0 255 put whiteref 1 255 put whiteref 2 255 put /bitsperpixelposition 28 store % BMP header positioning info /datastartposition 10 store /horizontalpixels 18 store /verticalpixels 22 store /backcount 0 store %%%%%%%%% CHECK FOR VALID 24-BIT UNCOMPRESSED BITMAP %%%%%%%%%%%%% % BM check: readfile (XX) readstring pop % error message if file not two chars long (BM) eq {(File has correct "BM" as first two bytes.\n) print } { sourcefilename ( is not in .BMP format; further eval terminated.\n\n\n) mergestr print quit } ifelse % 24 bit check: readfile bitsperpixelposition setfileposition % access 2 {readfile read pop} repeat % get color planes error if not present 1 {256 mul add} repeat % calculate bits per pixel dup /bpp exch store % save for expanded analysis 10 string cvs % make string (24) eq {(File has correct 24-bit color format.\n) print } { sourcefilename ( is not in 24-bit format; further eval terminated.\n\n\n) mergestr print quit } ifelse % Compression mode: 4 {readfile read pop} repeat % get color planes error if not present 3 {256 mul add} repeat % calculate compression mode dup /cmm exch store % save for expanded analysis 10 string cvs % make string (0) eq {(File has correct 0 uncompressed format.\n) print } { sourcefilename ( is not in uncompressed format; further action terminated.\n\n\n) mergestr print quit } ifelse % Bitmap Width: readfile horizontalpixels setfileposition % access 4 {readfile read pop} repeat % get bitmap width bytes error if not present 3 {256 mul add} repeat % calculate data start dup /hres exch def 10 string cvs % make string (Bitmap width is ) exch mergestr ( pixels.\n) mergestr print flush % Bitmap Width: readfile verticalpixels setfileposition % access 4 {readfile read pop} repeat % get bitmap width bytes error if not present 3 {256 mul add} repeat % calculate data start dup /vres exch def 10 string cvs % make string (Bitmap height is ) exch mergestr ( pixels.\n) mergestr print flush % Find padding % .BMP rows MUST end on a 32-bit boundary! Zero, one, two, or three 00 % padding bits are required depending upon the actual width. /padding hres 3 mul cvi 4 mod % find start of next 32-byte block [ 0 3 2 1 ] exch get % TLU correction def (Padding 8-bit bytes per line are ) padding 10 string cvs mergestr ( .\n\n) mergestr print flush (Active storage 8-bit RGB bytes per line are ) hres 3 mul dup cvi /activestore exch store 10 string cvs mergestr ( .\n) mergestr print flush activestore 4 div ceiling cvi 4 mul /totalbytesperline exch store %%%%%%%%%%%%%%%% COPY HEADER TO TARGET FILE %%%%%%%%%%%%%%%%%% % Data Start: readfile datastartposition setfileposition % access 4 {readfile read pop} repeat % get data start bytes error if not present 3 {256 mul add} repeat % calculate data start /actualdatastart exch store readfile 0 setfileposition readfile actualdatastart 1 sub string readstring not { sourcefilename ( has a short header; further action terminated.\n\n\n) mergestr print quit } if writefile exch writestring % write the entire header to new file %%%%%%%%%%%%%% SERVICE UTILS %%%%%%%%%% % calclinelimits finds the brightness limit for each line end /calclinelimits { /vfract vline vres 1 sub div store % distance up screen /scl sul sll sub vfract mul sll add store % left limit /scr sur slr sub vfract mul slr add store % right limit } store /clipcheck { dup maxclip ge {pop maxclip} if } store %%%%%%%%%%%%%%%% COPY DATA TO TARGET FILE, SHADING AS NEEDED %%%%%%%%%%%%%%%%%% /linestring hres 3 mul string store % read file line buffer /targetstring hres 3 mul padding add string store % write file line buffer targetstring dup length 1 sub 0 put % zero max padding targetstring dup length 2 sub 0 put targetstring dup length 3 sub 0 put /oldcolor (ZZZ) def /whitecount 0 store /mainloop { 0 1 vres 1 sub { /vline exch store % start of next hires line vline 24 mod 0 eq % pretty print progress {(.) print flush} if vline hres 3 mul padding add mul actualdatastart add dup % position read and write identically readfile exch setfileposition writefile exch setfileposition readfile linestring readstring % grab a line of characters not {big_time_read_error} if /sourcestring exch store calclinelimits 0 3 hres 1 sub 3 mul { /posn exch store % start line pixel loop sourcestring posn 3 getinterval /curpixelstring exch store /corr scr scl sub posn hres 1 sub 3 mul div mul scl add store curpixelstring whiteref eq nofixwhite and not { % do not correct white? curpixelstring dup 0 get corr mul cvi clipcheck 0 exch put % shade blue curpixelstring dup 1 get corr mul cvi clipcheck 1 exch put % shade green curpixelstring dup 2 get corr mul cvi clipcheck 2 exch put % shade red } if curpixelstring targetstring exch posn exch putinterval } for % next line MUST start on an even 32-bit boundary writefile targetstring writestring } for % (\nA total of ) backcount 12 string cvs mergestr % ( pixels have been substituted\n\n) mergestr print flush } bind def stopwatchon mainloop % this does it all stopwatchoff (\nFinished.\n) print % report % EOF