<> <> <> DIRECTORY Basics, AIS, ImagerPixelMaps, ImagerAISUtil, PrincOps USING [BBTable], FS USING [StreamOpen], IO USING [Close, PutRope, STREAM], IPMaster, Rope, Terminal; IPCreateTestImpl: CEDAR PROGRAM IMPORTS Basics, IPMaster, IO, FS, Terminal, ImagerPixelMaps, ImagerAISUtil, Rope ~ BEGIN OPEN IPMaster; ROPE: TYPE ~ Rope.ROPE; STREAM: TYPE ~ IO.STREAM; SetUpTransformation: PROC [stream: STREAM] ~ { PutRational[stream, 254, 3000000]; -- Want to talk in 300 units per inch PutOp[stream, scale]; PutOp[stream, concatt]; }; DoUnderTranslate: PROC [stream: STREAM, x, y: INT, proc: PROC] ~ { PutOp[stream, dosavesimplebody]; PutOp[stream, beginBody]; PutInt[stream, x]; PutInt[stream, y]; PutOp[stream, translate]; PutOp[stream, concatt]; proc[]; PutOp[stream, endBody]; }; Open: PROC [name: ROPE] RETURNS [STREAM] ~ { stream: STREAM ~ FS.StreamOpen[name, $create]; IO.PutRope[stream, "Interpress/Xerox/2.1 "]; PutOp[stream, beginBlock]; PutOp[stream, beginBody]; PutOp[stream, endBody]; PutOp[stream, beginBody]; SetUpTransformation[stream]; RETURN[stream]; }; NewPage: PROC [stream: STREAM] ~ { PutOp[stream, endBody]; PutOp[stream, beginBody]; SetUpTransformation[stream]; }; PutRectangle: PROC [stream: STREAM, x, y, w, h: INT] ~ { PutInt[stream, x]; PutInt[stream, y]; PutInt[stream, w]; PutInt[stream, h]; PutOp[stream, maskrectangle]; }; PutScreenPixelArray: PROC [stream: STREAM] ~ TRUSTED { bb: PrincOps.BBTable _ Terminal.GetBitBltTable[Terminal.Current[]]; PutInt[stream, bb.height/2]; -- xPixels PutInt[stream, bb.width]; -- yPixels PutInt[stream, 1]; -- samplesPerPixel PutInt[stream, 1]; -- maxSampleValue PutInt[stream, 1]; -- samplesInterleaved PutInt[stream, 0]; -- Unit transformation PutOp[stream, rotate]; -- m PutBits[ stream: stream, base: bb.dst.word, wordsPerLine: bb.dstBpl/16, sMin: 0, fMin: 0, sSize: bb.height/2, fSize: bb.width ]; -- bits, bits PutOp[stream, makepixelarray]; }; PutPixelArray: PROC [stream: STREAM] ~ TRUSTED { PutInt[stream, 16]; -- xPixels PutInt[stream, 32]; -- yPixels PutInt[stream, 1]; -- samplesPerPixel PutInt[stream, 1]; -- maxSampleValue PutInt[stream, 1]; -- samplesInterleaved PutInt[stream, 0]; -- Unit transformation PutOp[stream, rotate]; -- m PutBits[ stream: stream, base: @bittyHeart, wordsPerLine: 2, sMin: 0, fMin: 0, sSize: 16, fSize: 32 ]; -- bits, bits, bits PutOp[stream, makepixelarray]; }; Finish: PROC [stream: STREAM] ~ { PutOp[stream, endBody]; PutOp[stream, endBlock]; IO.Close[stream]; }; bittyHeart: ARRAY [0..16) OF PACKED ARRAY [0..32) OF [0..1] _ [ [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,0,0,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] ]; Test: PROC ~ { stream: STREAM ~ Open["Test.interpress"]; PutRectangle[stream, 300, 400, 500, 600]; PutRectangle[stream, 800, 1000, 500, 600]; { proc: PROC ~ { PutPixelArray[stream]; PutOp[stream, maskpixel]; PutInt[stream, 90]; PutOp[stream, rotate]; PutOp[stream, concatt]; PutPixelArray[stream]; PutOp[stream, maskpixel]; PutInt[stream, 90]; PutOp[stream, rotate]; PutOp[stream, concatt]; PutPixelArray[stream]; PutOp[stream, maskpixel]; PutInt[stream, 90]; PutOp[stream, rotate]; PutOp[stream, concatt]; PutPixelArray[stream]; PutOp[stream, maskpixel]; }; DoUnderTranslate[stream, 800+500+100, 1000+600+100, proc] }; { proc: PROC ~ { PutPixelArray[stream]; PutOp[stream, maskpixel]; PutInt[stream, 180]; PutOp[stream, rotate]; PutOp[stream, concatt]; PutPixelArray[stream]; PutOp[stream, maskpixel]; }; DoUnderTranslate[stream, 800+500+100+300, 1000+600+100, proc] }; { proc: PROC ~ { PutScreenPixelArray[stream]; PutOp[stream, maskpixel]; <> <> <> <> <> <> <> <> <> <> <> <> }; DoUnderTranslate[stream, 800+500, 1024+100, proc] }; Finish[stream]; }; PutPixelMap: PROC [stream: STREAM, pixelMap: ImagerPixelMaps.PixelMap] ~ TRUSTED { w: ImagerPixelMaps.DeviceRectangle ~ pixelMap.Window; PutInt[stream, w.sSize]; -- xPixels PutInt[stream, w.fSize]; -- yPixels PutInt[stream, 1]; -- samplesPerPixel PutInt[stream, Basics.BITSHIFT[1, Basics.BITSHIFT[1, pixelMap.refRep.lgBitsPerPixel]]-1]; -- maxSampleValue PutInt[stream, 1]; -- samplesInterleaved PutInt[stream, w.sMin]; -- x translation PutInt[stream, w.fMin]; -- y translation PutOp[stream, translate]; -- m PutBits[ stream: stream, base: pixelMap.refRep.pointer, wordsPerLine: pixelMap.refRep.rast, sMin: pixelMap.sMin, fMin: pixelMap.fMin, sSize: pixelMap.sSize, fSize: pixelMap.fSize ]; -- bits, bits, bits PutOp[stream, makepixelarray]; }; AreYouSureYouKnowWhatYoureDoing: SIGNAL ~ CODE; IPFromAIS: PROC [fileNameRoot: ROPE, rotateDegrees: INT _ 90] ~ { stream: STREAM ~ Open[fileNameRoot.Concat[".interpress"]]; {ENABLE UNWIND => IO.Close[stream, TRUE]; raster: AIS.Raster; pixelMap: ImagerPixelMaps.PixelMap; scratch: REF ImagerPixelMaps.PixelMapRep _ NIL; [pixelMap, raster] _ ImagerAISUtil.PixelMapFromAIS[fileNameRoot.Concat[".ais"]]; IF raster.bitsPerPixel # 0 THEN SIGNAL AreYouSureYouKnowWhatYoureDoing; IF ABS[rotateDegrees] > 360 THEN SIGNAL AreYouSureYouKnowWhatYoureDoing; WHILE rotateDegrees > 0 DO rotateDegrees _ rotateDegrees - 360 ENDLOOP; IF ABS[rotateDegrees] > 360 THEN ERROR; WHILE rotateDegrees <= -90 DO new: ImagerPixelMaps.PixelMap _ pixelMap.Rotate[scratch]; scratch _ pixelMap.refRep; pixelMap _ new; rotateDegrees _ rotateDegrees + 90; ENDLOOP; IF rotateDegrees # 0 THEN SIGNAL AreYouSureYouKnowWhatYoureDoing; pixelMap.sOrigin _ pixelMap.fOrigin _ 0; { w: ImagerPixelMaps.DeviceRectangle ~ pixelMap.Window; bufferLimit: INT ~ MIN[w.fSize*10, 32767]; -- enough for 160 scanlines, maybe lines: NAT ~ (bufferLimit+pixelMap.refRep.rast-1)/pixelMap.refRep.rast; proc: PROC ~ { FOR s: INT _ w.sMin, s+lines UNTIL s >= pixelMap.sSize DO PutPixelMap[stream, pixelMap.Clip[[s, w.fMin, lines, w.fSize]]]; PutOp[stream, maskpixel]; ENDLOOP; }; DoUnderTranslate[stream, (30*85-w.sSize)/2, (300*11-w.fSize)/2, proc]; }; }; Finish[stream]; }; END.