DIRECTORY Basics USING [BITSHIFT], Rope USING [ROPE], Real USING [FixI, FixC, RoundC], RealFns USING [Power], IO USING [PutRope, PutF, STREAM, int], Terminal USING [Virtual, Current, GetColor, SetColor, WaitForBWVerticalRetrace], ViewerIO USING [CreateViewerStreams], Graphics USING [Context], QuickViewer USING [DrawInViewer, BuildViewer], Imager USING [Context, Create, ClipRectangle, MaskRectangle, MaskVector, SetColor, Pair, SetXY, ShowCharacters, FONT, MakeFont, SetFont, SpecialOp], ImagerBasic USING [IntRectangle], ImagerDisplay USING [DisplayData], ImagerStdColorDisplay USING [RGBSequence], ImagerPixelMapsExtras USING [FillConstantTrap, DrawLine, DrawBltLine], ConstantColors USING [NameToColor, RGBToColor, ColorToName, HSLToColor], ImagerColorAIS USING [GetAISFile, Get3AISFiles, PutAISFile, Put3AISFiles, PutFastAISFile], ColorNames USING [HSLToRope]; ImagerColorTestMain: CEDAR PROGRAM IMPORTS Imager, ConstantColors, ColorNames, IO, Terminal, ViewerIO, QuickViewer, ImagerPixelMapsExtras, Basics, Real, RealFns, ImagerColorAIS = BEGIN displayContext: Imager.Context _ NIL; contexts: ARRAY [0..4) OF Imager.Context _ ALL[NIL]; contextMax: NAT _ 4; contextCount: NAT _ 0; in, out: IO.STREAM; -- I/O to log viewer nullRectangle: ImagerBasic.IntRectangle _ [0, 0, 0, 0]; activeButton: ATOM; NameColor: PROC [color: Rope.ROPE] ~ { Imager.SetColor[displayContext, ConstantColors.NameToColor[color]]; }; RGBColor: PROC [r, g, b: REAL] ~ { Imager.SetColor[displayContext, ConstantColors.RGBToColor[r, g, b]]; }; HSLToName: PROC [h, s, l: REAL] ~ { name: Rope.ROPE; name _ ConstantColors.ColorToName[ConstantColors.HSLToColor[h, s, l]]; IO.PutRope[out, name]; IO.PutF[out, "\n"]; }; HSLToLongName: PROC [h, s, l: REAL, levels: NAT] ~ { name: Rope.ROPE; name _ ColorNames.HSLToRope[h, s, l, levels]; IO.PutRope[out, name]; IO.PutF[out, "\n"]; }; Load8BitMap: PROC [] ~ { start: REF NAT _ NEW[NAT]; length: NAT _ 256; entries: REF ImagerStdColorDisplay.RGBSequence _ NEW[ ImagerStdColorDisplay.RGBSequence[length] ]; data: LIST OF REF ANY _ NIL; start^ _ 1; FOR i: NAT IN [0..40) DO -- greyscale entries[i + 216].r _ entries[i + 216].g _ entries[i + 216].b _ Real.RoundC[i*6.5]; ENDLOOP; FOR i: NAT IN [0..216) DO -- 6 x 6 x 6 color cube entries[i].r _ Real.RoundC[42.5 * (i/36 + 1)]; entries[i].g _ Real.RoundC[42.5 * ((i/6) MOD 6 + 1)]; entries[i].b _ Real.RoundC[42.5 * (i MOD 6 + 1)]; ENDLOOP; data _ CONS[start, data]; data _ CONS[entries, data]; [] _ Imager.SpecialOp[displayContext, $LoadColorMap, data]; }; Rotate8BitMap: PROC [duration: NAT] ~ { -- rotates color map without moving zeroth entry entries: REF ImagerStdColorDisplay.RGBSequence _ NEW[ ImagerStdColorDisplay.RGBSequence[256] ]; vt: Terminal.Virtual _ Terminal.Current[]; vt.WaitForBWVerticalRetrace[]; -- await vt selection and top of scan (to control update rate) FOR i: NAT IN [0..256) DO -- 6 x 6 x 6 color cube [entries[i].r, entries[i].g, entries[i].b] _ Terminal.GetColor[ vt, i]; ENDLOOP; FOR i: NAT IN [0..duration*60) DO color: RECORD[ r, g, b: [0..256) ] _ [ entries[1].r, entries[1].g, entries[1].b ]; FOR j: NAT IN [2..256) DO entries[j-1] _ entries[j]; ENDLOOP; entries[255] _ [ color.r, color.g, color.b ]; FOR i: NAT IN [0..256) DO Terminal.SetColor[ vt, i, 0, entries[i].r, entries[i].g, entries[i].b]; ENDLOOP; ENDLOOP; }; LoadGrey8BitMap: PROC [] ~ { start: REF NAT _ NEW[NAT]; length: NAT _ 256; entries: REF ImagerStdColorDisplay.RGBSequence _ NEW[ ImagerStdColorDisplay.RGBSequence[length] ]; data: LIST OF REF ANY _ NIL; start^ _ 0; FOR i: NAT IN [0..256) DO -- greyscale j: NAT _ Real.FixC[RealFns.Power[i/256.0, .43] * 256.0]; entries[i].r _ j; entries[i].g _ j; entries[i].b _ j; ENDLOOP; data _ CONS[start, data]; data _ CONS[entries, data]; [] _ Imager.SpecialOp[displayContext, $LoadColorMap, data]; }; Show8BitMap: PROC [] ~ { displayData: ImagerDisplay.DisplayData _ NARROW[displayContext.data, ImagerDisplay.DisplayData]; firstBottom: INTEGER _ displayData[0].sSize + displayData[0].sMin - 80; firstTop: INTEGER _ firstBottom + 9; firstLeft: INTEGER _ (displayData[0].fSize - 320) / 2 + displayData[0].fMin; firstRight: INTEGER _ firstLeft + 10; FOR i: NAT IN [0..256) DO top: NAT _ firstTop + 10 * (i / 32); bottom: NAT _ firstBottom + 10 * (i / 32); left: NAT _ firstLeft + 10 * (i MOD 32); right: NAT _ firstRight + 10 * (i MOD 32); FillTrap[top, bottom, left, left, right, right, i]; ENDLOOP; }; Load8BitRampMap: PROC [r1, g1, b1, r2, g2, b2, exponent: REAL] ~ { start: REF NAT _ NEW[NAT]; length: NAT _ 256; entries: REF ImagerStdColorDisplay.RGBSequence _ NEW[ ImagerStdColorDisplay.RGBSequence[length] ]; data: LIST OF REF ANY _ NIL; start^ _ 0; r1 _ MAX[0.0, MIN[1.0, r1]]; r2 _ MAX[0.0, MIN[1.0, r2]]; g1 _ MAX[0.0, MIN[1.0, g1]]; g2 _ MAX[0.0, MIN[1.0, g2]]; b1 _ MAX[0.0, MIN[1.0, b1]]; b2 _ MAX[0.0, MIN[1.0, b2]]; FOR i: NAT IN [0..256) DO -- linear ramp jr: NAT _ Real.FixC[RealFns.Power[r1 + i/255.0 * (r2 - r1), exponent] * 255.0]; -- linearize jg: NAT _ Real.FixC[RealFns.Power[g1 + i/255.0 * (g2 - g1), exponent] * 255.0]; jb: NAT _ Real.FixC[RealFns.Power[b1 + i/255.0 * (b2 - b1), exponent] * 255.0]; entries[i].r _ jr; entries[i].g _ jg; entries[i].b _ jb; ENDLOOP; data _ CONS[start, data]; data _ CONS[entries, data]; [] _ Imager.SpecialOp[displayContext, $LoadColorMap, data]; }; ClipRectangle: PROC [x, y, w, h: REAL] ~ { Imager.ClipRectangle[displayContext, x, y, w, h]; NameColor["Black"]; FillRectangle[0.0, 0.0, .6, .45]; -- clear within clipper }; FillRectangle: PROC [x, y, w, h: REAL] ~ { Imager.MaskRectangle[displayContext, x, y, w, h]; }; FillTrap: PROC [top, bottom, leftTop, leftBot, rightTop, rightBot: INTEGER, color: NAT] ~ { displayData: ImagerDisplay.DisplayData _ NARROW[displayContext.data, ImagerDisplay.DisplayData]; IF rightTop > displayData[0].fSize + displayData[0].fMin THEN rightTop _ displayData[0].fSize + displayData[0].fMin; IF rightBot > displayData[0].fSize + displayData[0].fMin THEN rightTop _ displayData[0].fSize + displayData[0].fMin; IF leftTop < displayData[0].fMin THEN rightTop _ displayData[0].fMin; IF leftBot < displayData[0].fMin THEN rightTop _ displayData[0].fMin; IF top > displayData[0].sSize + displayData[0].sMin THEN top _ displayData[0].sSize + displayData[0].sMin; IF bottom < displayData[0].sMin THEN bottom _ displayData[0].sMin; ImagerPixelMapsExtras.FillConstantTrap[displayData[0], top, bottom, leftTop, leftBot, rightTop, rightBot, color]; }; DrawLine: PROC [pt1, pt2: Imager.Pair, width: REAL] ~ { Imager.MaskVector[displayContext, pt1, pt2, width]; }; LineTest: PROC[color: CARDINAL, length, times: NAT] ~ { ax, ay, bx, by, xOffset, yOffset: INTEGER; displayData: ImagerDisplay.DisplayData _ NARROW[displayContext.data, ImagerDisplay.DisplayData]; logBitsPerPixel: NAT _ displayData[0].refRep.lgBitsPerPixel; mapLength: NAT _ Basics.BITSHIFT[1, Basics.BITSHIFT[1, logBitsPerPixel]]; xMax: NAT _ displayData[0].fSize; yMax: NAT _ displayData[0].sSize; IF length > yMax THEN length _ yMax; xOffset _ (xMax - length) / 2; yOffset _ (yMax - length) / 2; FOR i: NAT IN [0..times) DO FOR j: NAT IN [0..length] DO ax _ j + xOffset; ay _ length + yOffset; bx _ length + xOffset; by _ length - j + yOffset; color _ (color MOD mapLength) + 1; ImagerPixelMapsExtras.DrawLine[displayData[0], [ax, ay], [bx, by], color]; ENDLOOP; FOR j: NAT IN [0..length] DO ax _ length + xOffset; ay _ length - j + yOffset; bx _ length - j + xOffset; by _ 0 + yOffset; color _ (color MOD mapLength) + 1; ImagerPixelMapsExtras.DrawLine[displayData[0], [ax, ay], [bx, by], color]; ENDLOOP; FOR j: NAT IN [0..length] DO ax _ length - j + xOffset; ay _ 0 + yOffset; bx _ 0 + xOffset; by _ j + yOffset; color _ (color MOD mapLength) + 1; ImagerPixelMapsExtras.DrawLine[displayData[0], [ax, ay], [bx, by], color]; ENDLOOP; FOR j: NAT IN [0..length] DO ax _ 0 + xOffset; ay _ j + yOffset; bx _ j + xOffset; by _ length + yOffset; color _ (color MOD mapLength) + 1; ImagerPixelMapsExtras.DrawLine[displayData[0], [ax, ay], [bx, by], color]; ENDLOOP; ENDLOOP; }; BltLineTest: PROC[color: CARDINAL, length, times: NAT] ~ { ax, ay, bx, by, xOffset, yOffset: INTEGER; displayData: ImagerDisplay.DisplayData _ NARROW[displayContext.data, ImagerDisplay.DisplayData]; logBitsPerPixel: NAT _ displayData[0].refRep.lgBitsPerPixel; mapLength: NAT _ Basics.BITSHIFT[1, Basics.BITSHIFT[1, logBitsPerPixel]]; xMax: NAT _ displayData[0].fSize; yMax: NAT _ displayData[0].sSize; IF length > yMax THEN length _ yMax; xOffset _ (xMax - length) / 2; yOffset _ (yMax - length) / 2; FOR i: NAT IN [0..times) DO FOR j: NAT IN [0..length] DO ax _ j + xOffset; ay _ length + yOffset; bx _ length + xOffset; by _ length - j + yOffset; color _ (color MOD mapLength) + 1; ImagerPixelMapsExtras.DrawBltLine[displayData[0], [ax, ay], [bx, by], color, [xor, null]]; ENDLOOP; FOR j: NAT IN [0..length] DO ax _ length + xOffset; ay _ length - j + yOffset; bx _ length - j + xOffset; by _ 0 + yOffset; color _ (color MOD mapLength) + 1; ImagerPixelMapsExtras.DrawBltLine[displayData[0], [ax, ay], [bx, by], color, [xor, null]]; ENDLOOP; FOR j: NAT IN [0..length] DO ax _ length - j + xOffset; ay _ 0 + yOffset; bx _ 0 + xOffset; by _ j + yOffset; color _ (color MOD mapLength) + 1; ImagerPixelMapsExtras.DrawBltLine[displayData[0], [ax, ay], [bx, by], color, [xor, null]]; ENDLOOP; FOR j: NAT IN [0..length] DO ax _ 0 + xOffset; ay _ j + yOffset; bx _ j + xOffset; by _ length + yOffset; color _ (color MOD mapLength) + 1; ImagerPixelMapsExtras.DrawBltLine[displayData[0], [ax, ay], [bx, by], color, [xor, null]]; ENDLOOP; ENDLOOP; }; ShowRope: PROC[x, y: REAL, rope: Rope.ROPE, fontRope: Rope.ROPE _ NIL, size: REAL _ .008] ~ { font: Imager.FONT; IF fontRope = NIL THEN fontRope _ "Xerox/Pressfonts/TimesRoman/MRR"; font _ Imager.MakeFont[fontRope, size]; Imager.SetFont[displayContext, font]; Imager.SetXY[displayContext, [x, y]]; Imager.ShowCharacters[displayContext, rope, ]; }; SetDevice: PROC[deviceType: ATOM, box, box2: ImagerBasic.IntRectangle, pinned: BOOLEAN] ~{ IF box = nullRectangle THEN displayContext _ Imager.Create[deviceType] ELSE { refBox: REF ImagerBasic.IntRectangle _ NEW[ImagerBasic.IntRectangle]; refBox2: REF ImagerBasic.IntRectangle _ NEW[ImagerBasic.IntRectangle]; refPinned: REF BOOLEAN _ NEW[BOOLEAN _ pinned]; -- display this pixelmap if true creationList: LIST OF REF ANY _ LIST[refBox, refPinned]; refBox.x _ box.x; refBox.y _ box.y; refBox.w _ box.w; refBox.h _ box.h; IF box2.w > 0 AND box2.h > 0 THEN { refBox2.x _ box2.x; refBox2.y _ box2.y; refBox2.w _ box2.w; refBox2.h _ box2.h; creationList _ LIST[refBox, refPinned, refBox2]; }; displayContext _ Imager.Create[deviceType, creationList]; }; contexts[contextCount] _ displayContext; contextCount _ contextCount + 1; IF contextCount = contextMax THEN contextCount _ contextMax - 1; NameColor["White"]; FillRectangle[0.0, 0.0, .6, .45]; -- clear screen }; RecoverContext: PROC[contextNumber: NAT] ~ { displayContext _ contexts[contextNumber]; }; PinMap: PROC[] ~ { [] _ Imager.SpecialOp[displayContext, $DisplayContext, NIL]; }; UnPinMap: PROC[] ~ { [] _ Imager.SpecialOp[displayContext, $UnDisplayContext, NIL]; }; PinOverlay: PROC[] ~ { [] _ Imager.SpecialOp[displayContext, $OverlayContext, NIL]; }; MoveOverlayTo: PROC[x, y: NAT] ~ { refX: REF INTEGER _ NEW[INTEGER _ x]; refY: REF INTEGER _ NEW[INTEGER _ y]; data: LIST OF REF ANY _ LIST[refX, refY]; [] _ Imager.SpecialOp[displayContext, $MoveOverlay, data]; }; SwitchBuffers: PROC[] ~ { [] _ Imager.SpecialOp[displayContext, $SwitchBuffers, NIL]; }; GetAISFile: PUBLIC PROC[fileName: Rope.ROPE, xOffSet, yOffSet: INTEGER _ 0] ~ { ImagerColorAIS.GetAISFile[displayContext, fileName, xOffSet, yOffSet]; }; Get3AISFiles: PUBLIC PROC[redFile, greenFile, blueFile: Rope.ROPE, xOffSet, yOffSet: INTEGER _ 0] ~ { ImagerColorAIS.Get3AISFiles[displayContext, redFile, greenFile, blueFile, xOffSet, yOffSet]; }; PutAISFile: PUBLIC PROC[fileName: Rope.ROPE] ~ { ImagerColorAIS.PutAISFile[displayContext, fileName]; }; PutFastAISFile: PUBLIC PROC[fileName: Rope.ROPE] ~ { ImagerColorAIS.PutFastAISFile[displayContext, fileName]; }; Put3AISFiles: PUBLIC PROC[redFile, greenFile, blueFile: Rope.ROPE] ~ { ImagerColorAIS.Put3AISFiles[displayContext, redFile, greenFile, blueFile]; }; DrawX: PROC[x, y, size: REAL] ~ { DoDrawX: PROC [dc: Graphics.Context] ~ { DrawLine[[x, y], [x+size, y+size], size/10.0]; DrawLine[[x+size, y], [x, y+size], size/10.0]; }; QuickViewer.DrawInViewer[DoDrawX]; -- ask the viewer procs to call you back }; MenuHit: PROCEDURE[command: ATOM, x, y: REAL] = { SELECT command FROM $Button => activeButton _ NIL; $MoveDCB => { activeButton _ $MoveDCB; IO.PutF[out, "Button received\n"]; }; $RightHeld => IF activeButton = $MoveDCB THEN { displayData: ImagerDisplay.DisplayData _ NARROW[contexts[0].data, ImagerDisplay.DisplayData]; displayData[0].sOrigin _ 50 + Real.FixI[-y]; displayData[0].fOrigin _ 100 + Real.FixI[x]; displayContext _ contexts[0]; PinMap[]; }; $LeftHeld => IF activeButton = $MoveDCB THEN { displayData: ImagerDisplay.DisplayData _ NARROW[contexts[1].data, ImagerDisplay.DisplayData]; displayData[0].sOrigin _ 50 + Real.FixI[-y]; displayData[0].fOrigin _ 100 + Real.FixI[x]; displayContext _ contexts[1]; PinOverlay[]; IO.PutF[out, "x = %g, y = %g\n", IO.int[displayData[0].fOrigin], IO.int[displayData[0].sOrigin]]; }; ENDCASE; }; ReDraw: PROCEDURE [dc: Graphics.Context] = { }; ShutDown: PROCEDURE [] = { IO.PutF[out, "Imager Color Test over -- Bye\n"]; -- say goodbye }; Init: PROCEDURE [] = { QuickViewer.BuildViewer[LIST[$Button, $MoveDCB], ReDraw, ShutDown, MenuHit, "ImagerColorTest"]; [in, out] _ ViewerIO.CreateViewerStreams["ImagerColorTest.log"]; -- initialize i/o viewer }; END.  ImagerColorTestMain.mesa Copyright c 1984 by Xerox Corporation. All rights reserved. Authored by Frank Crow Last Edited by: Crow, August 16, 1984 10:25:30 am PDT ImagerBridge USING [SetViewFromGraphicsContext], ImagerBridge, $Boxes, $Circles, $Exes, $Octagons => drawMode _ command; $LeftButton, $LeftHeld => { pointList _ CONS[ [x, y], pointList]; SELECT drawMode FROM $Exes => DrawX[pointList.first, size, black]; $Boxes => DrawBox[pointList.first, size, black]; $Circles => DrawCircle[pointList.first, size, black]; $Octagons => DrawOct[pointList.first, size, black]; ENDCASE; }; $MiddleButton => DrawX[[x, y], size, black]; $RightButton => DrawCircle[[x, y], size, black]; $MiddleHeld => DrawX[[x, y], size, white]; ʘJšœ™Jšœ Ïmœ1™˜]š žœžœžœ žœ Ÿ˜;JšœG˜GJšžœ˜—šžœžœžœž˜!KšœžœE˜RKš žœžœžœ žœžœ˜?Kšœ-˜-šžœžœžœ žœ˜KšœG˜GKšžœ˜—Kšžœ˜—K˜K˜—š œžœ˜Kš œžœžœžœžœ˜Kšœžœ˜Kšœ žœ%žœ˜5Kšœ;˜;Kš œžœžœžœžœžœ˜Kšœ ˜ K˜š žœžœžœ žœ Ÿ ˜0Jšœžœ2˜8Jšœ˜Jšœ˜Jšœ˜Jšžœ˜—Kšœžœ˜Kšœžœ˜Kšœ;˜;K˜K˜—š  œžœ˜Kšœ)žœ˜EKšœ*˜*Kšœ žœ3˜GKšœ žœ˜$Kšœ žœ:˜LKšœ žœ˜%K˜šžœžœžœ ž˜Kšœžœ˜%Kšœžœ ˜+Kšœžœžœ˜)Kšœžœžœ˜+Kšœ3˜3Kšžœ˜—Kšœ˜K˜—š œžœ$žœ˜BKš œžœžœžœžœ˜Kšœžœ˜Kšœ žœ%žœ˜5Kšœ;˜;Kš œžœžœžœžœžœ˜Kšœ ˜ K˜Kš œžœžœžœžœ ˜9Kš œžœžœžœžœ ˜9Kš œžœžœžœžœ ˜9K˜š žœžœžœ žœ Ÿ˜2JšœžœHŸ ˜\JšœžœH˜OJšœžœH˜OJšœ˜Jšœ˜Jšœ˜Jšžœ˜—Kšœžœ˜Kšœžœ˜Kšœ;˜;K˜K˜—š  œžœžœ˜+Kšœ1˜1Kšœ˜Kšœ%Ÿ˜˜>J˜J˜—š  œžœ˜Jšœ<˜™>Jšœ<™<—Jšžœ™J™ Jšœ,™,Jšœ0™0Jšœ+™+šœžœžœ˜0Jšœ)žœ˜BKšœ*˜*Jšœ0˜0Jšœ,˜,Jšœ˜Jšœ ˜ J˜—šœžœžœ˜/Jšœ)žœ˜BKšœ*˜*Jšœ0˜0Jšœ,˜,Jšœ˜Jšœ ˜ Jšžœ˜!JšœH˜HJ˜——Jšžœ˜J˜J˜—š œž œ˜-J˜J˜—š œž œ ˜Kšžœ6Ÿ˜FJ˜J˜—š œž œ˜šœžœ˜0Jšœ6˜6—JšœAŸ˜YJ˜J˜J˜—Jšžœ˜J˜—…—7¦JÙ