--CopyBandsImpl.mesa
--copys PBAND.* in the right order to BANDS
--Ken Pier October 8, 1982 4:31 pm
-- Eric Bier on November 3, 1982 10:32 pm

DIRECTORY
CIFS USING [Delete],
CopyBands,
CGBandStream USING [OpenBand, GetBand, PutBand, StartGetBand,
BandStreamHandle, CloseBand, BandIndex],
IO USING [STREAM, CreateOutputStreamToRope, GetOutputStreamRope, PutF],
Rope USING [ROPE],
UnsafeStorage USING [GetSystemUZone];

CopyBandsImpl: PROGRAM
IMPORTS CIFS, IO, UnsafeStorage, CGBandStream EXPORTS CopyBands = {
OPEN BS: CGBandStream;

uz: UNCOUNTED ZONE ← UnsafeStorage.GetSystemUZone[];
Buffer: TYPE = RECORD[SEQUENCE COMPUTED CARDINAL OF WORD];
BufferP: TYPE = LONG POINTER TO Buffer;
bufSize: CARDINAL = 256*50; -- 50 pages
wordsRead: CARDINAL ← 0;
outband, inband: BS.BandStreamHandle ← NIL;

DeleteBand: PRIVATE PROC [baseName: Rope.ROPE, num: NAT] = {
 fullName: Rope.ROPE;
 fullNameStream: IO.STREAM;
 fullNameStream ← IO.CreateOutputStreamToRope[];
 fullNameStream.PutF["/local/%g.%g",[rope[baseName]], [integer[num]]];
 fullName ← IO.GetOutputStreamRope[fullNameStream];
CIFS.Delete[fullName, NIL];
 };

Copy: PUBLIC PROC[numberOfBands: CARDINAL] ={

buf: BufferP ← uz.NEW[Buffer[bufSize]];
outband ← BS.OpenBand["BANDS"L, LAST[BS.BandIndex], overwrite]; --

FOR x: CARDINAL IN [0..numberOfBands) DO
inband ← BS.OpenBand["PBAND."L, x, read];
BS.StartGetBand[inband];
UNTIL (wordsRead ← BS.GetBand[inband, buf, bufSize])#bufSize DO
BS.PutBand[outband, buf, bufSize];
ENDLOOP;
IF wordsRead#0 THEN BS.PutBand[outband, buf, wordsRead];
BS.CloseBand[inband];
DeleteBand["PBAND", x]; -- now that we are done with it, delete it.
ENDLOOP;
BS.CloseBand[outband];
uz.FREE[@buf];
};

}. --CopyBandsImpl

Log

Bier on November 3, 1982 10:32 pm
Added
DeleteBand to help reduce disk storage requirements of large pictures