home *** CD-ROM | disk | FTP | other *** search
AmigaBASIC Source Code | 1986-11-20 | 8.6 KB | 372 lines |
- ConvertIFFtoPAT:
- REM ****
- REM **** A PROGRAM TO CONVERT IFF FILES TO 'TRACER.PAT'-TYPE PATTERNS
- REM **** COPYRIGHT (C) 1987, ARTHUR E. BLUME
- REM ****
- Title:
- PRINT:PRINT TAB(17);:COLOR 3,2
- PRINT " *** RAY-TRACE CONVERSION PROGRAM *** ":COLOR 1,0:PRINT
- Instructions:
- PRINT " This program converts IFF files to .PAT files suitable for
- PRINT "use with TRACER.ARC."
- PRINT " See 'IFFtoPAT.doc' for more instructions.":PRINT
- Filenames:
- LINE INPUT "Input filename: ";ILBMname$
- LINE INPUT "Output filename <.PAT>: ";OUTPAT$
- IF UCASE$(RIGHT$(OUTPAT$,4))<>".PAT" THEN
- OUTPAT$=OUTPAT$+".PAT":PRINT "<"OUTPAT$">"
- END IF
-
- SetUpScreen:
- SCREEN 1,320,200,5,1
- WINDOW 2,,,16,1
- WINDOW OUTPUT 2
- FOR P=0 TO 15:PF=P/15:PALETTE P,PF,PF,PF:PALETTE P+16,PF,PF,PF:NEXT
-
- PleaseWait:
- WINDOW 3,,(0,94)-(311,100),0,1:WINDOW OUTPUT 3:PALETTE 1,1,0,0
- IF LEN(ILBMname$)>15 THEN PF$=LEFT$(ILBMname$,12)+"..." :ELSE PF$=ILBMname$
- T$="Loading "+PF$+" ; please wait.":TS=(39-(23+LEN(PF$)))/2
- PRINT TAB(TS);:PRINT "Loading ";:COLOR 0,1:PRINT PF$;
- COLOR 1,0:PRINT " ; please wait.";
- FOR T=0 TO 10000:NEXT:WINDOW CLOSE 3
- WINDOW OUTPUT 2:PALETTE 1,0.066,0.066,0.066
- LoadFile:
- GOSUB PictureLoad
- IF loaderror$<>"" THEN STOP
-
- UseMouse:
- WINDOW OUTPUT 2
- FOR P=0 TO 15:PF=P/15:PALETTE P,PF,PF,PF:PALETTE P+16,PF,PF,PF:NEXT
- WINDOW 3,,(0,94)-(311,106),0,1:WINDOW OUTPUT 3:PALETTE 1,1,0,0
- T$="Use mouse to select area for pattern.":PRINT TAB((39-LEN(T$))/2);T$
- T$="< Click mouse to continue >":PRINT TAB((39-LEN(T$))/2);T$;
- CM0:IF MOUSE(0)<>0 THEN CM0
- TM1:IF MOUSE(0)=0 THEN TM1
- WINDOW CLOSE 3:WINDOW OUTPUT 2:PALETTE 1,0.066,0.066,0.066
-
- ScreenSelect:
- WINDOW OUTPUT 2
- InvertVideo:CALL SetDrMd&(WINDOW(8),3) ' inverse drawing
- CM1:IF MOUSE(0)<>0 THEN CM1
- PollMouse:
- M=MOUSE(0) ' poll mouse
- IF M>0 THEN X1=MOUSE(3):Y1=MOUSE(4):GOTO OtherCorner
- GOTO PollMouse
-
- OtherCorner:
- CM2:IF MOUSE(0)<>0 THEN CM2
- ' find the other corner
- LastMX=0:LastMY=0 ' initialize coordinates
- StartFlag=1 ' flag to show if box has been drawn
- PollMouse2:
- M=MOUSE(0) ' poll mouse
- IF ABS(M)>0 THEN X2=MOUSE(3):Y2=MOUSE(4):GOTO SortOutCoordinates
- MX=MOUSE(1):MY=MOUSE(2) ' get mouse coordinates
- IF MX=LastMX AND MY=LastMY THEN PollMouse2 ' don't move box
- IF StartFlag=1 THEN StartFlag=0:GOTO DrawRect ' nothing to erase
- EraseRect:LINE (X1,Y1)-(LastMX,LastMY),1,B
- DrawRect:LINE (X1,Y1)-(MX,MY),1,B
- LastMX=MX:LastMY=MY
- GOTO PollMouse2 ' loop
-
- SortOutCoordinates:
- IF X1>X2 THEN SWAP X1,X2
- IF Y1>Y2 THEN SWAP Y1,Y2
- EraseBox:LINE (X1,Y1)-(MX,MY),1,B
- GOTO SaveFile
-
- SaveFile:
- CALL SetDrMd&(WINDOW(8),0) ' normal drawing
- LIBRARY CLOSE
- WINDOW OUTPUT 2
- OPEN "O",#1,OUTPAT$
- FOR Y=Y1 TO Y2
- L$="":FOR X=X1 TO X2
- P=POINT(X,Y):IF P>15 THEN P=P-16
- L$=L$+CHR$(64+P*4)
- NEXT
- PRINT #1,L$
- LINE (X1,Y)-(X2,Y),15
- NEXT
- CLOSE
-
- SCREEN CLOSE 1
- WINDOW OUTPUT 1
- PRINT "Pattern saved: <"OUTPAT$"> ..."
- END
-
- PictureLoad:
-
- REM *** LOADS AN .ILBM PICTURE INTO THE CURRENT WINDOW
- REM *** FILENAME: ILBMname$
-
- REM - LoadILBM-SaveACBM
- REM - by Carolyn Scheppner CBM 04/86
-
- Main:
-
- DIM bPlane&(5), cTabWork%(32), cTabSave%(32)
-
- REM - Functions from dos.library
- DECLARE FUNCTION xOpen& LIBRARY
- DECLARE FUNCTION xRead& LIBRARY
- DECLARE FUNCTION xWrite& LIBRARY
- DECLARE FUNCTION IoErr& LIBRARY
- REM - xClose returns no value
-
- REM - Functions from exec.library
- DECLARE FUNCTION AllocMem&() LIBRARY
- REM - FreeMem returns no value
-
- LIBRARY "dos.library"
- LIBRARY "exec.library"
- LIBRARY "graphics.library"
-
- REM - Load the IFF ILBM pic
- loaderror$ = ""
- GOSUB LoadILBM
- IF loaderror$ <> "" THEN GOTO Mcleanup
-
- Mcleanup:
- WINDOW OUTPUT 1
-
- Mcleanup2:
- PRINT loaderror$
- RETURN
- END
-
- LoadILBM:
- REM - Requires the following variables
- REM - to have been initialized:
- REM - ILBMname$ (IFF filename)
-
- REM - init variables
- f$ = ILBMname$
- fHandle& = 0
- mybuf& = 0
- foundBMHD = 0
- foundCMAP = 0
- foundCAMG = 0
- foundCCRT = 0
- foundBODY = 0
-
- REM - From include/libraries/dos.h
- REM - MODE_NEWFILE = 1006
- REM - MODE_OLDFILE = 1005
-
- filename$ = f$ + CHR$(0)
- fHandle& = xOpen&(SADD(filename$),1005)
- IF fHandle& = 0 THEN
- loaderror$ = "Can't open/find pic file"
- GOTO Lcleanup
- END IF
-
- REM - Alloc ram for work buffers
- ClearPublic& = 65537
- mybufsize& = 360
- mybuf& = AllocMem&(mybufsize&,ClearPublic&)
- IF mybuf& = 0 THEN
- loaderror$ = "Can't alloc buffer"
- GOTO Lcleanup
- END IF
-
- inbuf& = mybuf&
- cbuf& = mybuf& + 120
- ctab& = mybuf& + 240
-
- REM - Should read FORMnnnnILBM
- rLen& = xRead&(fHandle&,inbuf&,12)
- tt$ = ""
- FOR kk = 8 TO 11
- tt% = PEEK(inbuf& + kk)
- tt$ = tt$ + CHR$(tt%)
- NEXT
-
- IF tt$ <> "ILBM" THEN
- loaderror$ = "Not standard ILBM pic file"
- GOTO Lcleanup
- END IF
-
- REM - Read ILBM chunks
-
- ChunkLoop:
- REM - Get Chunk name/length
- rLen& = xRead&(fHandle&,inbuf&,8)
- icLen& = PEEKL(inbuf& + 4)
- tt$ = ""
- FOR kk = 0 TO 3
- tt% = PEEK(inbuf& + kk)
- tt$ = tt$ + CHR$(tt%)
- NEXT
-
- IF tt$ = "BMHD" THEN 'BitMap header
- foundBMHD = 1
- rLen& = xRead&(fHandle&,inbuf&,icLen&)
- iWidth% = PEEKW(inbuf&)
- iHeight% = PEEKW(inbuf& + 2)
- iDepth% = PEEK(inbuf& + 8)
- iCompr% = PEEK(inbuf& + 10)
- scrWidth% = PEEKW(inbuf& + 16)
- scrHeight% = PEEKW(inbuf& + 18)
-
- iRowBytes% = iWidth% /8
- scrRowBytes% = scrWidth% / 8
- nColors% = 2^(iDepth%)
-
- REM - Enough free ram to display ?
- AvailRam& = FRE(-1)
- NeededRam& = ((scrWidth%/8)*scrHeight%*(iDepth%+1))+5000
- IF AvailRam& < NeededRam& THEN
- loaderror$ = "Not enough free ram"
- GOTO Lcleanup
- END IF
-
- kk = 1
- IF scrWidth% > 320 THEN kk = kk + 1
- IF scrHeight% > 200 THEN kk = kk + 2
- REM - Get addresses of structures
- GOSUB GetScrAddrs
-
- REM - Black out screen
- REM CALL LoadRGB4&(sViewPort&,ctab&,nColors%)
-
-
- ELSEIF tt$ = "CMAP" THEN 'ColorMap
- foundCMAP = 1
- rLen& = xRead&(fHandle&,cbuf&,icLen&)
-
- REM - Build Color Table
- FOR kk = 0 TO nColors% - 1
- red% = PEEK(cbuf&+(kk*3))
- gre% = PEEK(cbuf&+(kk*3)+1)
- blu% = PEEK(cbuf&+(kk*3)+2)
- regTemp% = (red%*16)+(gre%)+(blu%/16)
- POKEW(ctab&+(2*kk)),regTemp%
- NEXT
-
- ELSEIF tt$ = "CAMG" THEN 'Amiga ViewPort Modes
- foundCAMG = 1
- rLen& = xRead&(fHandle&,inbuf&,icLen&)
- camgModes& = PEEKL(inbuf&)
-
- ELSEIF tt$ = "CCRT" THEN 'Graphicraft color cycle info
- foundCCRT = 1
- rLen& = xRead&(fHandle&,inbuf&,icLen&)
- ccrtDir% = PEEKW(inbuf&)
- ccrtStart% = PEEK(inbuf& + 2)
- ccrtEnd% = PEEK(inbuf& + 3)
- ccrtSecs& = PEEKL(inbuf& + 4)
- ccrtMics& = PEEKL(inbuf& + 8)
-
- ELSEIF tt$ = "BODY" THEN 'BitMap
- foundBODY = 1
-
- IF iCompr% = 0 THEN 'no compression
- FOR rr = 0 TO iHeight% -1
- FOR pp = 0 TO iDepth% -1
- scrRow& = bPlane&(pp)+(rr*scrRowBytes%)
- rLen& = xRead&(fHandle&,scrRow&,iRowBytes%)
- NEXT
- NEXT
-
- ELSEIF iCompr% = 1 THEN 'cmpByteRun1
- FOR rr = 0 TO iHeight% -1
- FOR pp = 0 TO iDepth% -1
- scrRow& = bPlane&(pp)+(rr*scrRowBytes%)
- bCnt% = 0
-
- WHILE (bCnt% < iRowBytes%)
- rLen& = xRead&(fHandle&,inbuf&,1)
- inCode% = PEEK(inbuf&)
- IF inCode% < 128 THEN
- rLen& = xRead&(fHandle&,scrRow& + bCnt%, inCode%+1)
- bCnt% = bCnt% + inCode% + 1
- ELSEIF inCode% > 128 THEN
- rLen& = xRead&(fHandle&,inbuf&,1)
- inByte% = PEEK(inbuf&)
- FOR kk = bCnt% TO bCnt% + 257 - inCode%
- POKE(scrRow&+kk),inByte%
- NEXT
- bCnt% = bCnt% + 257 - inCode%
- END IF
- WEND
- NEXT
- NEXT
-
- ELSE
- loaderror$ = "Unknown compression algorithm"
- GOTO Lcleanup
- END IF
-
- ELSE
- REM - Reading unknown chunk
- FOR kk = 1 TO icLen&
- rLen& = xRead&(fHandle&,inbuf&,1)
- NEXT
- REM - If odd length, read 1 more byte
- IF (icLen& OR 1) = icLen& THEN
- rLen& = xRead&(fHandle&,inbuf&,1)
- END IF
-
- END IF
-
- REM - Done if got all chunks
- IF foundBMHD AND foundCMAP AND foundBODY THEN
- GOTO GoodLoad
- END IF
-
- REM - Good read, get next chunk
- IF rLen& > 0 THEN GOTO ChunkLoop
-
- IF rLen& < 0 THEN 'Read error
- loaderror$ = "Read error"
- GOTO Lcleanup
- END IF
-
- REM - rLen& = 0 means EOF
- IF (foundBMHD=0) OR (foundBODY=0) OR (foundCMAP=0) THEN
- loaderror$ = "Needed ILBM chunks not found"
- GOTO Lcleanup
- END IF
-
- GoodLoad:
- loaderror$ = ""
-
- REM Load proper Colors
- IF foundCMAP THEN
- CALL LoadRGB4&(sViewPort&,ctab&,nColors%)
- END IF
-
- Lcleanup:
- IF fHandle& <> 0 THEN CALL xClose&(fHandle&)
- IF mybuf& <> 0 THEN CALL FreeMem&(mybuf&,mybufsize&)
-
- RETURN
-
-
- GetScrAddrs:
- REM - Get addresses of screen structures
- sWindow& = WINDOW(7)
- sScreen& = PEEKL(sWindow& + 46)
- sViewPort& = sScreen& + 44
- sRastPort& = sScreen& + 84
- sColorMap& = PEEKL(sViewPort& + 4)
- colorTab& = PEEKL(sColorMap& + 4)
- sBitMap& = PEEKL(sRastPort& + 4)
-
- REM - Get screen parameters
- scrWidth% = PEEKW(sScreen& + 12)
- scrHeight% = PEEKW(sScreen& + 14)
- scrDepth% = PEEK(sBitMap& + 5)
- nColors% = 2^scrDepth%
-
- REM - Get addresses of Bit Planes
- FOR kk = 0 TO scrDepth% - 1
- bPlane&(kk) = PEEKL(sBitMap&+8+(kk*4))
- NEXT
- RETURN
-
- END
-
-