Write:
PUBLIC
PROC [
name: ROPE,
map: SampleMap,
placement: AISIO.Placement ¬ NIL,
photometry: AISIO.Photometry ¬ NIL,
comments: LIST OF ROPE ¬ NIL]
~ {
WritePartHeader:
PROC [type: AISFileFormat.PartType, nBytesInPart:
INT] ~ {
nWordsTotal: INT ¬ (nBytesInPart+AISFileFormat.byteSizePartHeader)/2;
part:
MACHINE
DEPENDENT
RECORD [
c: PartHeader, p: PACKED ARRAY [0..(BITS[WORD]-(BITS[PartHeader] MOD BITS[WORD])) MOD BITS[WORD]) OF [0..1]];
part.c ¬ [type, nWordsTotal/256, nWordsTotal MOD 256];
IF type = nil THEN part.c.lengthHi ¬ part.c.lengthLo ¬ 0;
TRUSTED {WriteBytes[out, @part, AISFileFormat.byteSizePartHeader]};
};
wordsHeader: INT ¬ 2048;
out: IO.STREAM ~ PFS.StreamOpen[PFS.PathFromRope[name], write];
header:
MACHINE
DEPENDENT
RECORD [
c: AttributeHeader, p: PACKED ARRAY [0..(BITS[WORD]-(BITS[AttributeHeader] MOD BITS[WORD])) MOD BITS[WORD]) OF [0..1]];
raster:
MACHINE
DEPENDENT
RECORD [
c: RasterPart, p: PACKED ARRAY [0..(BITS[WORD]-(BITS[RasterPart] MOD BITS[WORD])) MOD BITS[WORD]) OF [0..1]];
uca:
MACHINE
DEPENDENT
RECORD [
c: UCACoding, p: PACKED ARRAY [0..(BITS[WORD]-(BITS[UCACoding] MOD BITS[WORD])) MOD BITS[WORD]) OF [0..1]];
box: ImagerSample.Box ¬ ImagerSample.GetBox[map];
size: ImagerSample.Vec ¬ ImagerSample.GetSize[map];
bpp: ImagerSample.BitsPerSample ¬ MAX[1, ImagerSample.GetBitsPerSample[map]];
aisWordsPerLine: INT ¬ (size.f*bpp+15)/16;
buf: RasterSampleMap ¬ ImagerSample.NewSampleMap[[max: [1, size.f]], bpp];
base: LONG POINTER TO WORD ¬ ImagerSample.GetBase[buf].word;
IF MIN[size.f, size.s] = 0 THEN Error["no pixels in map"];
header.c ¬ [AISFileFormat.passwordValue, Card[wordsHeader]];
raster.c ¬ [Card[size.s], Card[size.f], Card[3], Card[1], 0, uca, AISFileFormat.nil];
uca.c ¬ [Card[bpp], Card[aisWordsPerLine], AISFileFormat.nil, AISFileFormat.nil];
TRUSTED {WriteBytes[out, @header, AISFileFormat.byteSizeAttributeHeader]};
WritePartHeader[raster, AISFileFormat.byteSizeRasterPart+AISFileFormat.byteSizeUCACoding];
TRUSTED {WriteBytes[out, @raster, AISFileFormat.byteSizeRasterPart]};
TRUSTED {WriteBytes[out, @uca, AISFileFormat.byteSizeUCACoding]};
IF placement #
NIL
THEN {
part:
MACHINE
DEPENDENT
RECORD [
c: AISFileFormat.PlacementPart, p: PACKED ARRAY [0..(BITS[WORD]-(BITS[UCACoding] MOD BITS[WORD])) MOD BITS[WORD]) OF [0..1]];
part.c ¬ placement;
WritePartHeader[placement, AISFileFormat.byteSizePlacementPart];
TRUSTED {WriteBytes[out, @part, AISFileFormat.byteSizePlacementPart]};
};
IF photometry #
NIL
THEN {
part:
MACHINE
DEPENDENT
RECORD [
c: AISFileFormat.PhotometryPart, p: PACKED ARRAY [0..(BITS[WORD]-(BITS[UCACoding] MOD BITS[WORD])) MOD BITS[WORD]) OF [0..1]];
part.c ¬ photometry;
WritePartHeader[photometry, AISFileFormat.byteSizePhotometryPart];
TRUSTED {WriteBytes[out, @part, AISFileFormat.byteSizePhotometryPart]};
};
IF comments # NIL THEN {--ugh--};
WritePartHeader[nil, 0]; -- end header
IO.SetIndex[out, 2*wordsHeader];
FOR s:
NAT
IN [box.min.s..box.max.s)
DO
ImagerSample.BasicTransfer[buf, map, [0, 0], [s, box.min.f], [1, size.f]];
TRUSTED {WriteBytes[out, base, aisWordsPerLine*2]};
ENDLOOP;
IO.Close[out];
};