%!PS % POSTSCRIPT BASED BITMAP MANIPULATOR V 1.3 % ============================================= % Copyright c 2001 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.5 % This utility shows how to programatically manipulate bitmaps using PostScript % as a general purpose computer language. One demoed use is to add topo map % features to an aerial photograph. % To use, read and edit this file in a suitable ASCII editor or word processor. % Then distill the new file using Adobe Acrobat or GhostScript. Then pull up the % generated .BMP file in Paint or wherever. % A "WARNING: No PDF File Produced" error message is normal and expected. % IMPORTANT NOTE: Don Lancaster's file gonzo.ps is reccomended to enhance 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 % mergestr merges the two top stack strings into one top stack string /mergestr {2 copy length exch length add string dup dup 4 3 roll 4 index length exch putinterval 3 1 roll exch 0 exch putinterval} def %%%%%%%%%%%%%%%% CONTROL VARIABLES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% /prefix (C:\\WINDOWS\\desktop\\blender\\) store % filename prefix /sname1(alphamap.bmp) store % short name of first BMP input file /sn1 prefix sname1 mergestr store sn1 (r) file /source1 exch store % create read file /sname2(alphaimg.bmp) store % short name of secondBMP input file /sn2 prefix sname2 mergestr store sn2 (r) file /source2 exch store % create read file /tname1(alphaone.bmp) store % short name of first BMP output file /tn1 prefix tname1 mergestr store tn1 (w+) file /targ1 exch store % create read file /tname2(alphaone.bmp) store % short name of first BMP output file /tn1 prefix tname2 mergestr store tn1 (w+) file /targ2 exch store % create read file /str 1024 string store /readheader1 { source1 str readstring pop pop %%% ??? in string??? str 0 2 getinterval (BM) eq % bytes 0 and 1 should be BM {(\nvalid BMP file\n) print} {(\nNOT A BMP FILE!!!\n) print} ifelse /fl1 str 2 get store % bytes 2-5 are filelength /fl2 str 3 get store /fl3 str 4 get store /fl4 str 5 get store /flength fl4 256 mul fl3 add 256 mul fl2 add 256 mul fl1 add store (total filelength = ) print flength == % bytes 6-9 are reserved & ignored /ol1 str 10 get store % bytes 10-13 are header offset /ol2 str 11 get store /ol3 str 12 get store /ol4 str 13 get store /olength ol4 256 mul ol3 add 256 mul ol2 add 256 mul ol1 add store (header offset = ) print olength == /il1 str 14 get store % bytes 14-17 are info header size /il2 str 15 get store /il3 str 16 get store /il4 str 17 get store /ilength il4 256 mul il3 add 256 mul il2 add 256 mul il1 add store (header size = ) print ilength == /hl1 str 18 get store % bytes 18 - 21 are horiz pixels /hl2 str 19 get store /hl3 str 20 get store /hl4 str 21 get store /hpixels hl4 256 mul hl3 add 256 mul hl2 add 256 mul hl1 add store (horizontal pixels = ) print hpixels == /vl1 str 22 get store % bytes 23 - 25 are vertical pixels /vl2 str 23 get store /vl3 str 24 get store /vl4 str 25 get store /vpixels vl4 256 mul vl3 add 256 mul vl2 add 256 mul vl1 add store (vertical pixels = ) print vpixels == % bytes 26 - 27 are planes and ignored /cl1 str 28 get store % bytes 28-29 are color bits /cl2 str 29 get store /colors cl2 256 mul cl1 add store (bits of color = ) print colors == colors 24 ne {(THESE ROUTINES FOR 24-BIT COLOR ONLY!!!\n) print} if % rest of data presently ignored /cloneheader str 0 olength 1 sub getinterval store % save header for reuse } def readheader1 % /simplecopy makes a new bitmap just like the old one /simplecopy { targ1 cloneheader writestring source1 olength 1 sub setfileposition hpixels vpixels mul 3 mul { source1 read { targ1 exch write} if } repeat targ1 0 write % ??? one byte short otherwise } store % /blacktored makes a new bitmap just like the old one /thresh 200 store /alpha 1 store /blacktored { targ1 cloneheader writestring source1 olength setfileposition targ1 olength setfileposition hpixels vpixels mul { /bb source1 read pop store /gg source1 read pop store /rr source1 read pop store bb gg sub abs 6 lt bb rr sub abs 6 lt or bb thresh lt and { targ1 bb 3 div cvi write % red or pink pixel targ1 gg 3 div cvi write targ1 255 write } { targ1 255 write % white pixel targ1 255 write targ1 255 write } ifelse } repeat targ1 0 write % ??? one byte short otherwise } store % blacktored % /fulloverlay is first real trial /thresh 200 store /alpha 1 store /fulloverlay { targ1 cloneheader writestring source1 olength setfileposition source2 olength setfileposition targ1 olength setfileposition hpixels vpixels mul { /bb source1 read pop store /gg source1 read pop store /rr source1 read pop store bb gg sub abs 6 lt bb rr sub abs 6 lt or bb thresh lt and { targ1 bb 3 div cvi write % red or pink pixel % targ1 gg 3 div cvi write targ1 145 write targ1 255 write 3 {source2 read pop pop} repeat } { source2 read pop targ1 exch write % image pixel source2 read pop targ1 exch write source2 read pop targ1 exch write } ifelse } repeat targ1 0 write % ??? one byte short otherwise } store % fulloverlay % /trueblend does an alpha mix /thresh 200 store /alpha 1 store /trueblend { targ1 cloneheader writestring source1 olength setfileposition source2 olength setfileposition targ1 olength setfileposition hpixels vpixels mul { /bb source1 read pop store /gg source1 read pop store /rr source1 read pop store /bx source2 read pop store /gx source2 read pop store /rx source2 read pop store /xx bb 200 gt gg 200 gt and rr 200 gt and not store /alpha1 alpha bb gg sub abs 5 lt bb rr sub abs 5 lt and bb 200 lt and {pop 1} if store /alpha1 alpha store /xx true store targ1 bx xx {dup bb sub alpha1 mul sub cvi} if write targ1 gx xx {dup gg sub alpha1 mul sub cvi} if write targ1 rx xx {dup rr sub alpha1 mul sub cvi} if write } repeat targ1 0 write % ??? one byte short otherwise } store /alpha 0.30 store trueblend % NOTE: This demo is in "full automatic" mode. Results can be dramatically improved % by Paint editing an intermediate overlay. Custom demos on request. % Water in blue and foilage in green is easily added. % Also, apparently the dates of the topo and the image appear to be different.