<> <> <> <> <> <<>> DIRECTORY Basics USING [BITSHIFT], ColorNames USING [HSLToRope], ConstantColors USING [NameToColor, RGBToColor, ColorToName, HSLToColor], Graphics USING [Context], Imager USING [Context, Create, FONT, MakeFont, MaskRectangle, MaskVector, SetColor, Pair, SetXY, ShowCharacters, SetFont, SpecialOp], ImagerColorAIS USING [GetAISFile, Get3AISFiles, PutAISFile, PutFastAISFile], ImagerBasic USING [IntRectangle], ImagerDisplay USING [DisplayData], ImagerDisplayExtras USING [RGBSequence], ImagerPixelMaps USING [PixelMap, BoundedWindow, DeviceRectangle], ImagerPixelMapsExtras USING [FillTrap, DrawLine, DrawBltLine], IO USING [PutRope, PutF, STREAM, int], QuickViewer USING [DrawInViewer, BuildViewer], Real USING [FixI, FixC], RealFns USING [Power], Rope USING [ROPE], ViewerIO USING [CreateViewerStreams], ImagerColorTestMain; ImagerColorTestMainImpl: CEDAR PROGRAM IMPORTS Basics, ColorNames, ConstantColors, Imager, ImagerColorAIS, ImagerPixelMaps, ImagerPixelMapsExtras, IO, QuickViewer, Real, RealFns, ViewerIO EXPORTS ImagerColorTestMain = BEGIN displayContext: Imager.Context _ NIL; contexts: ARRAY [0..10) OF Imager.Context _ ALL[NIL]; contextCount: NAT _ 0; in, out: IO.STREAM; -- I/O to log viewer nullRectangle: ImagerBasic.IntRectangle _ [0, 0, 0, 0]; activeButton: ATOM; GetDisplayContext: PUBLIC PROC RETURNS[ Imager.Context] ~ { RETURN[ displayContext]; }; GetDisplayData: PUBLIC PROC RETURNS[ ImagerDisplay.DisplayData] ~ { RETURN[ NARROW[displayContext.data, ImagerDisplay.DisplayData]]; }; NameColor: PUBLIC PROC [color: Rope.ROPE] ~ { Imager.SetColor[displayContext, ConstantColors.NameToColor[color]]; }; RGBColor: PUBLIC PROC [r, g, b: REAL] ~ { Imager.SetColor[displayContext, ConstantColors.RGBToColor[r, g, b]]; }; HSLToName: PUBLIC 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: PUBLIC 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"]; }; LoadAndRotate8BitMap: PUBLIC PROC [duration: NAT] ~ { start: REF NAT _ NEW[NAT]; length: NAT _ 512; entries: REF ImagerDisplayExtras.RGBSequence _ NEW[ ImagerDisplayExtras.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 _ i*6; entries[i + 471].r _ entries[i + 471].g _ entries[i + 471].b _ 255 - i*6; ENDLOOP; FOR i: NAT IN [0..216) DO -- 6 x 6 x 6 color cube entries[i].r _ 36 * (i/36 + 1); entries[i + 255].r _ 255 - entries[i].r; entries[i].g _ 36 * ((i/6) MOD 6 + 1); entries[i + 255].g _ 255 - entries[i].g; entries[i].b _ 36 * (i MOD 6 + 1); entries[i + 255].b _ 255 - entries[i].b; ENDLOOP; data _ CONS[start, data]; data _ CONS[entries, data]; [] _ Imager.SpecialOp[displayContext, $LoadColorMap, data]; 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..length) DO entries[j-1] _ entries[j]; ENDLOOP; entries[length-1] _ [ color.r, color.g, color.b ]; [] _ Imager.SpecialOp[displayContext, $LoadColorMap, data]; ENDLOOP; }; LoadGrey8BitMap: PUBLIC PROC [] ~ { start: REF NAT _ NEW[NAT]; length: NAT _ 512; entries: REF ImagerDisplayExtras.RGBSequence _ NEW[ ImagerDisplayExtras.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 + 255].r _ 255 - entries[i].r; entries[i].g _ j; entries[i + 255].g _ 255 - entries[i].g; entries[i].b _ j; entries[i + 255].b _ 255 - entries[i].b; ENDLOOP; data _ CONS[start, data]; data _ CONS[entries, data]; [] _ Imager.SpecialOp[displayContext, $LoadColorMap, data]; }; FillRectangle: PUBLIC PROC [x, y, w, h: REAL] ~ { Imager.MaskRectangle[displayContext, x, y, w, h]; }; FillTrap: PUBLIC PROC [top, bottom, leftTop, leftBot, rightTop, rightBot: INTEGER, color: NAT] ~ { displayData: ImagerDisplay.DisplayData _ NARROW[displayContext.data, ImagerDisplay.DisplayData]; ImagerPixelMapsExtras.FillTrap[displayData[0], top, bottom, leftTop, leftBot, rightTop, rightBot, color]; }; DrawLine: PUBLIC PROC [pt1, pt2: Imager.Pair, width: REAL] ~ { Imager.MaskVector[displayContext, pt1, pt2, width]; }; DrawGrid: PUBLIC PROC[boxWidth: NAT] ~ { ax, ay, bx, by: INTEGER; displayData: ImagerDisplay.DisplayData _ NARROW[displayContext.data, ImagerDisplay.DisplayData]; window: ImagerPixelMaps.DeviceRectangle; window _ ImagerPixelMaps.BoundedWindow[displayData[0]]; FOR i: NAT IN [0..window.fSize/boxWidth] DO ax _ window.sMin; ay _ window.fMin + i*boxWidth; bx _ window.sMin + window.sSize; by _ window.fMin + i*boxWidth; ImagerPixelMapsExtras.DrawLine[displayData[0], [ay, ax], [by, bx], 0]; ENDLOOP; FOR i: NAT IN [0..window.sSize/boxWidth] DO ax _ window.sMin + i*boxWidth; ay _ window.fMin; bx _ window.sMin + i*boxWidth; by _ window.fMin + window.fSize; ImagerPixelMapsExtras.DrawLine[displayData[0], [ay, ax], [by, bx], 0]; ENDLOOP; }; LineTest: PUBLIC 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: PUBLIC 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: PUBLIC 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: PUBLIC PROC[deviceType: ATOM, box: ImagerBasic.IntRectangle] ~{ IF box = nullRectangle THEN displayContext _ Imager.Create[deviceType] ELSE { refBox: REF ImagerBasic.IntRectangle _ NEW[ImagerBasic.IntRectangle]; refPinned: REF BOOLEAN _ NEW[BOOLEAN _ FALSE]; -- don't pin this pixelmap creationList: LIST OF REF ANY _ LIST[refBox, refPinned]; refBox.x _ box.x; refBox.y _ box.y; refBox.w _ box.w; refBox.h _ box.h; displayContext _ Imager.Create[deviceType, creationList]; }; contexts[contextCount] _ displayContext; contextCount _ contextCount + 1; NameColor["Black"]; FillRectangle[0.0, 0.0, .26, .2]; -- clear screen }; RecoverContext: PUBLIC PROC[contextNumber: NAT] ~ { displayContext _ contexts[contextNumber]; }; PinMap: PUBLIC PROC[] ~ { [] _ Imager.SpecialOp[displayContext, $DisplayContext, NIL]; }; PinOverlay: PUBLIC PROC[] ~ { [] _ Imager.SpecialOp[displayContext, $OverlayContext, 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]; }; DrawX: PUBLIC PROC[x, y, size: REAL] ~ { DoDrawX: PUBLIC 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"]; }; <<$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];>> $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.