home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Fish 1
/
GoldFishApril1994_CD1.img
/
d2xx
/
d234
/
wbpic
/
wbpic.mod
< prev
next >
Wrap
Text File
|
1989-08-02
|
6KB
|
237 lines
(*---------------------------------------------------------------------------
:Program. WPic.mod
:Author. Fridtjof Siebert
:Address. Nobileweg 67, D-7-Stgt-40
:Phone. (0)711/822509
:Shortcut. [fbs]
:Version. 1.0
:Date. 24-Dec-1988
:Copyright. PD
:Language. Modula-II
:Translator. M2Amiga v3.1d
:Imports. IFFSupport [fbs].
:UpDate. none.
:Contents. Replaces Workbench's Color # 0 by a Picture.
:Remark. Use Hires-Non-Interlaced Pictures with 2 or 4 colors.
:Usage. WPic <IFF-Pic>
---------------------------------------------------------------------------*)
MODULE WBPic;
FROM SYSTEM IMPORT ADR;
FROM Arts IMPORT Assert, TermProcedure, Terminate, BreakPoint;
FROM Arguments IMPORT NumArgs, GetArg;
FROM Dos IMPORT Delay;
FROM Exec IMPORT Forbid, Permit, FreeMem, UByte, MsgPortPtr, MessagePtr,
PutMsg, GetMsg, ReplyMsg, FindPort, Message, WaitPort,
NodeType;
FROM ExecSupport IMPORT CreatePort, DeletePort;
FROM Graphics IMPORT BitMap, BitMapPtr, BltBitMap;
FROM Intuition IMPORT ScreenPtr, MakeScreen, RethinkDisplay, WindowPtr,
NewWindow, WindowFlags, WindowFlagSet, ScreenFlags,
CloseWindow, ScreenFlagSet, IDCMPFlags, IDCMPFlagSet,
OpenWindow;
FROM Heap IMPORT AllocMem;
FROM IFFSupport IMPORT ReadILBM, ReadILBMFlags, ReadILBMFlagSet, NuScreen,
IFFInfo;
(*------ CONSTS: ------*)
CONST
WindowTitle = "WBPic © Fridtjof Siebert";
PortName = "NewWBPlanes[fbs].Port";
ReplyName = "NewWBPlanes[fbs].ReplyPort";
(*------ TYPES: ------*)
TYPE
ColTable = ARRAY[0..31] OF CARDINAL;
(*------ VARS: ------*)
VAR
WBScreen: ScreenPtr;
i: CARDINAL;
ScreenDummy: ScreenPtr;
WindowDummy: WindowPtr;
Name: ARRAY[0..79] OF CHAR;
length: INTEGER;
MyBitMap: BitMapPtr;
CMap: ColTable;
OldColTable: POINTER TO ColTable;
Window: WindowPtr;
NuWindow: NewWindow;
MyPort,OldPort: MsgPortPtr;
MyMsg: Message;
QuitMessage: MessagePtr;
WBBitMap: BitMap;
w,h: CARDINAL;
(*------ CleanUp: ------*)
PROCEDURE CleanUp();
BEGIN
(*------ Remove Picture from WB: ------*)
IF WBScreen#NIL THEN
Forbid();
IF OldColTable#NIL THEN
WBScreen^.viewPort.colorMap^.colorTable := OldColTable;
END;
MakeScreen(WBScreen);
Permit();
RethinkDisplay();
END;
(*------ Free BitMap's Memory: ------*)
IF MyBitMap#NIL THEN
WITH MyBitMap^ DO
FOR i:=0 TO depth-1 DO
IF planes[i]#NIL THEN
FreeMem(planes[i],LONGINT(bytesPerRow)*LONGINT(rows));
END;
END;
END;
FreeMem(MyBitMap,SIZE(BitMap));
END;
(*------ Close Window: ------*)
IF Window#NIL THEN CloseWindow(Window) END;
(*------ Remove Port: ------*)
IF MyPort#NIL THEN
Forbid();
IF QuitMessage=NIL THEN QuitMessage := GetMsg(MyPort) END;
WHILE QuitMessage#NIL DO
ReplyMsg(QuitMessage);
QuitMessage := GetMsg(MyPort);
END;
DeletePort(MyPort);
Permit();
END;
END CleanUp;
(*------ MAIN: ------*)
BEGIN
(*------ Initialization: ------*)
WBScreen := NIL; MyBitMap := NIL; OldColTable := NIL; Window := NIL;
MyPort := NIL; QuitMessage := NIL;
TermProcedure(CleanUp);
(*------ Have we already been started? ------*)
OldPort := FindPort(ADR(PortName));
IF OldPort#NIL THEN
MyPort := CreatePort(ADR(ReplyName),0);
Assert(MyPort#NIL,ADR("CreatePort failed"));
MyMsg.node.type := message;
MyMsg.replyPort := MyPort;
PutMsg(OldPort,ADR(MyMsg)); (* Signal task to quit *)
WaitPort(MyPort);
DeletePort(MyPort);
MyPort := NIL;
END;
MyPort := CreatePort(ADR(PortName),0);
Assert(MyPort#NIL,ADR("CreatePort failed"));
(*------ Open Window: ------*)
WITH NuWindow DO
leftEdge := 0; topEdge := 0;
width := 1; height := 1;
detailPen := 0; blockPen := 1;
idcmpFlags := IDCMPFlagSet{closeWindow};
flags := WindowFlagSet{windowClose,backDrop};
firstGadget := NIL;
checkMark := NIL; title := ADR(WindowTitle);
screen := NIL; bitMap := NIL;
type := ScreenFlagSet{wbenchScreen};
END;
Window := OpenWindow(NuWindow);
Assert(Window#NIL,ADR("Cnt'pnWndw!!!"));
WBScreen := Window^.wScreen;
(*------ Get Name: ------*)
IF NumArgs()#0 THEN GetArg(1,Name,length) ELSE Terminate(0) END;
(*------ Read ILBM: ------*)
Assert(ReadILBM(Name,ReadILBMFlagSet{front,visible,dontopen},ScreenDummy,
WindowDummy),ADR("Can't Load Pic!"));
(*------ Get BitMap: ------*)
MyBitMap := NuScreen.customBitMap;
(*------ Set Colors: ------*)
OldColTable := WBScreen^.viewPort.colorMap^.colorTable;
CMap := OldColTable^;
WITH IFFInfo.CMAP DO
FOR i:=0 TO 3 DO
CMap[ 4*i] := 256*ORD(red[i]) + 16*ORD(green[i]) + ORD(blue[i]);
CMap[1+4*i] := CMap[1];
CMap[2+4*i] := CMap[2];
CMap[3+4*i] := CMap[3];
END;
END;
WBScreen^.viewPort.colorMap^.colorTable := ADR(CMap);
(*------ Put Picture on WBScreen: ------*)
WBBitMap := WBScreen^.bitMap;
WITH WBBitMap DO
IF MyBitMap^.depth>1 THEN depth := 2 ELSE depth := 1 END;
FOR i:=0 TO depth-1 DO
AllocMem(planes[i],LONGINT(rows)*LONGINT(bytesPerRow),TRUE);
END;
w := bytesPerRow; h := rows;
WITH MyBitMap^ DO
IF w>bytesPerRow THEN w := bytesPerRow END;
IF h>rows THEN h := rows END;
END;
i := BltBitMap(MyBitMap,0,0,ADR(WBBitMap),0,0,w*8,h,0C0H,3,NIL);
END;
(*------ Free IFF's Memory: ------*)
WITH MyBitMap^ DO
FOR i:=0 TO depth-1 DO
FreeMem(planes[i],LONGINT(bytesPerRow)*LONGINT(rows));
planes[i] := NIL;
END;
END;
FreeMem(MyBitMap,SIZE(BitMap));
MyBitMap := NIL;
(*------ Wait to Quit: ------*)
REPEAT
Forbid();
WITH WBScreen^.bitMap DO
depth := 2 + WBBitMap.depth;
planes[2] := WBBitMap.planes[0];
planes[3] := WBBitMap.planes[1];
MakeScreen(WBScreen);
depth := 2;
END;
Permit();
RethinkDisplay();
Delay(25);
QuitMessage := GetMsg(MyPort);
UNTIL QuitMessage#NIL;
END WBPic.