DIRECTORY Basics, ColorTrixBasics, ColorDisplay, Draw2d, Imager, ImagerColorMap, ImagerOps, ImagerPixelMap, ImagerRaster, ImagerSample, ImagerSmooth, ImagerTerminal, InterminalBackdoor, PixelMapOps, Process, Rope, RuntimeError, Terminal, Vector2; ColorTrixBasicsImpl: CEDAR MONITOR IMPORTS ColorDisplay, Draw2d, Imager, ImagerColorMap, ImagerOps, ImagerPixelMap, ImagerRaster, ImagerSample, ImagerSmooth, ImagerTerminal, InterminalBackdoor, PixelMapOps, Process, RuntimeError, Terminal EXPORTS ColorTrixBasics ~ BEGIN DeviceRectangle: TYPE ~ ImagerPixelMap.DeviceRectangle; PixelMap: TYPE ~ ImagerPixelMap.PixelMap; PixelMapMisc: TYPE ~ ColorTrixBasics.PixelMapMisc; VtMode: TYPE ~ ColorTrixBasics.VtMode; PixelProc: TYPE ~ ColorTrixBasics.PixelProc; ValueProc: TYPE ~ ColorTrixBasics.ValueProc; RGBProc: TYPE ~ ColorTrixBasics.RGBProc; screenPixelsPerMeter: REAL _ 72/0.0254; ColorDisplayNotReady: PUBLIC ERROR = CODE; OrderBox: PROC [x0, y0, x1, y1: INTEGER] RETURNS [INTEGER,INTEGER,INTEGER,INTEGER] ~ { IF x0 > x1 THEN {t: INTEGER _ x0; x0 _ x1; x1 _ t}; IF y0 > y1 THEN {t: INTEGER _ y0; y0 _ y1; y1 _ t}; RETURN[x0, y0, x1, y1]; }; InsureColorDisplayOn: PUBLIC PROC [bpp: NAT] ~ { on, onLeft, gray: BOOL; bppA, bppB: CARDINAL; monitorType: Rope.ROPE; [on, onLeft, gray, bppA, bppB, monitorType] _ ColorDisplay.GetColorDisplayStatus[]; IF NOT on OR bppA # bpp THEN { IF bpp = 24 THEN {monitorType _ "640x480"; gray _ FALSE}; ColorDisplay.SetColorDisplayStatus[TRUE, onLeft, gray, bpp, bppB, monitorType]; }; }; GetColorDisplayPm: PUBLIC PROC RETURNS [pm: PixelMap] ~ { InsureColorDisplayOn[8]; pm _ ImagerOps.PixelMapFromFrameBuffer[ Terminal.GetColorFrameBufferA[InterminalBackdoor.terminal]]; }; ShowPm: PUBLIC PROC [pm: PixelMap] ~ { ImagerPixelMap.Transfer[GetColorDisplayPm[], pm]; }; FillPm: PUBLIC PROC [pm: PixelMap, color: CARDINAL] ~ { ImagerPixelMap.Fill[pm, [pm.sMin, pm.fMin, pm.sSize, pm.fSize], color]; }; PutPixel: PUBLIC PROC [pm: PixelMap, x, y: INTEGER, value: CARDINAL] ~ { ImagerPixelMap.PutPixel[pm, y, x, value ! RuntimeError.BoundsFault => CONTINUE]; }; GetPixel: PUBLIC PROC [pm: PixelMap, x, y: INTEGER] RETURNS [value: CARDINAL] ~ { RETURN[ImagerPixelMap.GetPixel[pm, y, x ! RuntimeError.BoundsFault => CONTINUE]]; }; PutBox: PUBLIC PROC [pm: PixelMap, x0, y0, x1, y1: INTEGER, value: CARDINAL] ~ { [x0, y0, x1, y1] _ OrderBox[x0, y0, x1, y1]; ImagerPixelMap.Fill[pm, [y0, x0, y1-y0+1, x1-x0+1], value]; }; PutLine: PUBLIC PROC [pm: PixelMap, x0, y0, x1, y1: INTEGER, value: CARDINAL] ~ { proc: PixelProc ~ { ImagerPixelMap.PutPixel[pm, y, x, value ! RuntimeError.BoundsFault => CONTINUE]; }; Draw2d.DoWithLine[[x0, y0], [x1, y1], proc]; }; PutScanLine: PUBLIC PROC [ pm: PixelMap, y: INTEGER, proc: ValueProc, data: REF ANY _ NIL] ~ { line: ImagerSample.SampleBuffer ~ ImagerSample.ObtainScratchBuffer[1, pm.fSize]; FOR x: NAT IN [0..pm.fSize) DO line.samples[x] _ proc[x, y, data]; ENDLOOP; PixelMapOps.PutF[pm, y, 0, line, 0, 0, pm.fSize, null, null]; ImagerSample.ReleaseScratchBuffer[line]; }; PutFrame: PUBLIC PROC [pm: PixelMap, proc: ValueProc, data: REF ANY _ NIL] ~ { line: ImagerSample.SampleBuffer ~ ImagerSample.ObtainScratchBuffer[1, pm.fSize]; FOR y: NAT IN [0..pm.sSize) DO Process.CheckForAbort[]; FOR x: NAT IN [0..pm.fSize) DO line.samples[x] _ proc[x, y, data]; ENDLOOP; PixelMapOps.PutF[pm, y, 0, line, 0, 0, pm.fSize, null, null]; ENDLOOP; ImagerSample.ReleaseScratchBuffer[line]; }; FillRGBPm: PUBLIC PROC [pmMisc: PixelMapMisc, r, g, b: CARDINAL] ~ { IF pmMisc.bpp # 24 THEN RETURN; FillPm[pmMisc.rg, 256*r+g]; FillPm[pmMisc.b, b]; }; PutRGBPixel: PUBLIC PROC [pmMisc: PixelMapMisc, x, y: INTEGER, r, g, b: CARDINAL] ~ { IF pmMisc.bpp # 24 THEN RETURN; ImagerPixelMap.PutPixel[pmMisc.rg, y, x, 256*r+g ! RuntimeError.BoundsFault => CONTINUE]; ImagerPixelMap.PutPixel[pmMisc.b, y, x, b ! RuntimeError.BoundsFault => CONTINUE]; }; GetRGBPixel: PUBLIC PROC [pmMisc: PixelMapMisc, x, y: INTEGER] RETURNS [r, g, b: CARDINAL] ~ { IF pmMisc.bpp = 24 THEN { rg: CARDINAL; rg _ ImagerPixelMap.GetPixel[pmMisc.rg, y, x ! RuntimeError.BoundsFault => CONTINUE]; r _ rg/256; g _ rg MOD 256; b _ ImagerPixelMap.GetPixel[pmMisc.b, y, x ! RuntimeError.BoundsFault => CONTINUE]; }; }; PutRGBBox: PUBLIC PROC [ pmMisc: PixelMapMisc, x0, x1, y0, y1: INTEGER, r, g, b: CARDINAL] ~ { IF pmMisc.bpp # 24 THEN RETURN; [x0, y0, x1, y1] _ OrderBox[x0, y0, x1, y1]; ImagerPixelMap.Fill[pmMisc.rg, [y0, x0, y1-y0+1, x1-x0+1], 256*r+g]; ImagerPixelMap.Fill[pmMisc.b, [y0, x0, y1-y0+1, x1-x0+1], b]; }; PutRGBLine: PUBLIC PROC [ pmMisc: PixelMapMisc, x0, x1, y0, y1: INTEGER, r, g, b: CARDINAL] ~ { proc: PixelProc ~ { ImagerPixelMap.PutPixel[ pmMisc.rg, y, x, 256*r+g ! RuntimeError.BoundsFault => CONTINUE]; ImagerPixelMap.PutPixel[pmMisc.b, y, x, b ! RuntimeError.BoundsFault => CONTINUE]; }; IF pmMisc.bpp = 24 THEN Draw2d.DoWithLine[[x0, y0], [x1, y1], proc]; }; PutRGBScanLine: PUBLIC PROC [ pmMisc: PixelMapMisc, y: INTEGER, proc: RGBProc, data: REF ANY _ NIL] ~ { IF pmMisc.bpp = 24 THEN { rgLine: ImagerSample.SampleBuffer ~ ImagerSample.ObtainScratchBuffer[1, pmMisc.w]; bLine: ImagerSample.SampleBuffer ~ ImagerSample.ObtainScratchBuffer[1, pmMisc.w]; FOR x: NAT IN [0..pmMisc.w) DO r, g: CARDINAL; [r, g, bLine.samples[x]] _ proc[x, y, data]; rgLine.samples[x] _ 256*r+g; ENDLOOP; PixelMapOps.PutF[pmMisc.rg, y, 0, rgLine, 0, 0, pmMisc.w, null, null]; PixelMapOps.PutF[pmMisc.b, y, 0, bLine, 0, 0, pmMisc.w, null, null]; ImagerSample.ReleaseScratchBuffer[rgLine]; ImagerSample.ReleaseScratchBuffer[bLine]; }; }; PutRGBFrame: PUBLIC PROC [ pmMisc: PixelMapMisc, proc: RGBProc, data: REF ANY _ NIL] ~ { IF pmMisc.bpp = 24 THEN { rgLine: ImagerSample.SampleBuffer ~ ImagerSample.ObtainScratchBuffer[1, pmMisc.w]; bLine: ImagerSample.SampleBuffer ~ ImagerSample.ObtainScratchBuffer[1, pmMisc.w]; FOR y: NAT IN [0..pmMisc.h) DO Process.CheckForAbort[]; FOR x: NAT IN [0..pmMisc.w) DO r, g: CARDINAL; [r, g, bLine.samples[x]] _ proc[x, y, data]; rgLine.samples[x] _ 256*r+g; ENDLOOP; PixelMapOps.PutF[pmMisc.rg, y, 0, rgLine, 0, 0, pmMisc.w, null, null]; PixelMapOps.PutF[pmMisc.b, y, 0, bLine, 0, 0, pmMisc.w, null, null]; ENDLOOP; ImagerSample.ReleaseScratchBuffer[rgLine]; ImagerSample.ReleaseScratchBuffer[bLine]; }; }; GetColorDisplayPmMisc: PUBLIC PROC RETURNS [pmMisc: PixelMapMisc] ~ { on: BOOL; window: DeviceRectangle; [on: on, bpp: pmMisc.bpp] _ ColorDisplay.GetColorDisplayStatus[]; IF NOT on THEN ColorDisplay.SetColorDisplayStatus[on: TRUE]; SELECT pmMisc.bpp FROM 8 => window _ ImagerPixelMap.Window[pmMisc.bw _ GetColorDisplayPm[]]; 24 => { pmMisc.rg _ ImagerOps.PixelMapFromFrameBuffer[ Terminal.GetColorFrameBufferA[InterminalBackdoor.terminal]]; pmMisc.b _ ImagerOps.PixelMapFromFrameBuffer[ Terminal.GetColorFrameBufferB[InterminalBackdoor.terminal]]; window _ ImagerPixelMap.Window[pmMisc.rg]; }; ENDCASE; pmMisc.x _ window.fMin; pmMisc.y _ window.sMin; pmMisc.w _ window.fSize; pmMisc.h _ window.sSize; }; ShowPmMisc: PUBLIC PROC [pmMisc: PixelMapMisc] ~ { SELECT pmMisc.bpp FROM 8 => ShowPm[pmMisc.bw]; 24 => { cd: PixelMapMisc; InsureColorDisplayOn[24]; cd _ GetColorDisplayPmMisc[]; ImagerPixelMap.Transfer[cd.rg, pmMisc.rg]; ImagerPixelMap.Transfer[cd.b, pmMisc.b]; }; ENDCASE; }; SetPmMiscWindow: PUBLIC PROC [pm: PixelMapMisc, x, y, w, h: NAT] RETURNS [PixelMapMisc] ~ { pm.x _ x; pm.y _ y; pm.w _ w; pm.h _ h; SELECT pm.bpp FROM 8 => pm.bw _ ImagerPixelMap.SetWindow[pm.bw, [y, x, h, w]]; 24 => { pm.rg _ ImagerPixelMap.SetWindow[pm.rg, [y, x, h, w]]; pm.b _ ImagerPixelMap.SetWindow[pm.b, [y, x, h, w]]; }; ENDCASE; RETURN[pm]; }; FillPmMisc: PUBLIC PROC [pm: PixelMapMisc, r, g, b: CARDINAL _ 0] ~ { SELECT pm.bpp FROM 8 => FillPm[pm.bw, r]; 24 => FillRGBPm[pm, r, g, b]; ENDCASE; }; WindowFromPmMisc: PUBLIC PROC [pm: PixelMapMisc] RETURNS [DeviceRectangle] ~ { RETURN[[pm.y, pm.x, pm.h, pm.w]]; }; CreatePmMisc: PUBLIC PROC [bpp, x, y, w, h: NAT] RETURNS [pm: PixelMapMisc] ~ { window: DeviceRectangle ~ [pm.y _ y, pm.x _ x, pm.h _ h, pm.w _ w]; SELECT pm.bpp _ bpp FROM 8 => pm.bw _ ImagerPixelMap.Create[3, window]; 24 => { pm.rg _ ImagerPixelMap.Create[4, window]; pm.b _ ImagerPixelMap.Create[3, window]; }; ENDCASE; }; CopyPmMisc: PUBLIC PROC [src, dst: PixelMapMisc] ~ { SELECT dst.bpp FROM 8 => ImagerPixelMap.Transfer[dst.bw, src.bw]; 24 => { ImagerPixelMap.Transfer[dst.rg, src.rg]; ImagerPixelMap.Transfer[dst.b, src.b]; }; ENDCASE; }; CopyClippedPmMisc: PUBLIC PROC [src, dst: PixelMapMisc, xSrc, ySrc, w, h: NAT] ~ { Inner: PROC [src, dst: PixelMap] ~ { src _ ImagerPixelMap.Clip[src, [ySrc, xSrc, h, w]]; ImagerPixelMap.Transfer[dst, ImagerPixelMap.ShiftMap[src, dst.sMin-ySrc, dst.fMin-xSrc]]; }; SELECT src.bpp FROM 8 => Inner[src.bw, dst.bw]; 24 => { Inner[src.rg, dst.rg]; Inner[src.b, dst.b]; }; ENDCASE; }; InitCd: PUBLIC PROC [type: ColorTrixBasics.CdType, pixelUnits: BOOL _ TRUE, clear: BOOL _ FALSE, cmapInit: BOOL _ TRUE] RETURNS [Imager.Context] ~ { cd: Imager.Context; IF NOT ColorDisplay.GetColorDisplayStatus[].on THEN ColorDisplay.SetColorDisplayStatus[on: TRUE]; cd _ SELECT type FROM gray => InitGrayCd[InterminalBackdoor.terminal, pixelUnits, cmapInit], smooth => InitSmoothCd[InterminalBackdoor.terminal, pixelUnits, cmapInit], color => InitColorCd[InterminalBackdoor.terminal, pixelUnits, cmapInit], ENDCASE => NIL; IF clear AND cd # NIL THEN ClearCd[cd]; RETURN[cd]; }; InitGrayCd: PROC [vt: Terminal.Virtual _ InterminalBackdoor.terminal, pixelUnits: BOOL _ TRUE, cmapInit: BOOL _ TRUE] RETURNS [cd: Imager.Context] ~ { [] _ SetVtMode[gray]; cd _ ImagerRaster.Create[ -- the color display ImagerRaster.NewGrayDevice[vt], TRUE, NIL, 0]; IF cmapInit THEN ImagerColorMap.SetStandardGrayMap[vt]; -- g corrected cmap IF NOT pixelUnits THEN Imager.ScaleT[cd, screenPixelsPerMeter]; }; InitSmoothCd: PROC [vt: Terminal.Virtual _ InterminalBackdoor.terminal, pixelUnits: BOOL _ FALSE, cmapInit: BOOL _ TRUE] RETURNS [cd: Imager.Context] ~ { cd _ ImagerSmooth.Create[ ImagerOps.PixelMapFromFrameBuffer[Terminal.GetColorFrameBufferA[vt]], $Intensity, ImagerSmooth.LikeScreen[vt.colorHeight], IF pixelUnits THEN 1.0 ELSE screenPixelsPerMeter]; IF cmapInit THEN ImagerColorMap.SetStandardGrayMap[vt]; -- g corrected cmap }; InitColorCd: PROC [vt: Terminal.Virtual _ InterminalBackdoor.terminal, pixelUnits: BOOL _ TRUE, cmapInit: BOOL _ TRUE] RETURNS [cd: Imager.Context] ~ { [] _ SetVtMode[dither]; cd _ ImagerTerminal.ColorContext[vt, TRUE]; IF cmapInit THEN ImagerColorMap.SetStandardColorMap[vt]; -- dither colormap IF NOT pixelUnits THEN Imager.ScaleT[cd, screenPixelsPerMeter]; }; ClearCd: PUBLIC PROC [cd: Imager.Context, color: Imager.ConstantColor _ Imager.black] ~ { Imager.SetColor[cd, color]; -- clear buffer Imager.MaskRectangle[cd, [0, 0, 1024, 768]]; -- visibilize Terminal.TurnOnColorDisplay[InterminalBackdoor.terminal]; }; ClearVt: PUBLIC PROC [vt: Terminal.Virtual _ NIL, val: INTEGER _ 0] ~ { pm: PixelMap; IF vt = NIL THEN vt _ InterminalBackdoor.terminal; pm _ ImagerOps.PixelMapFromFrameBuffer[Terminal.GetColorFrameBufferA[vt: vt]]; ImagerPixelMap.Fill[pm, ImagerPixelMap.Window[pm], val]; }; SetVtMode: PUBLIC PROC [vtMode: VtMode] RETURNS [Terminal.Virtual] ~ { ENABLE UNWIND => NULL; vt: Terminal.Virtual _ InterminalBackdoor.terminal; IF NOT vt.hasColorDisplay THEN ERROR ColorDisplayNotReady; IF vtMode = gray THEN ColorDisplay.SetColorDisplayStatus[on: TRUE, gray: TRUE, bpp: 8] ELSE ColorDisplay.SetColorDisplayStatus[on: TRUE]; RETURN[InterminalBackdoor.terminal]; }; END. .. :ColorTrixBasicsImpl.mesa Copyright c 1985 by Xerox Corporation. All rights reserved. Plass and Bloomenthal, December 4, 1986 9:27:40 pm PST Support Procedures Miscellaneous Operations 8 Bit Pixel Map Operations 24 Bit Pixel Map Operations PixelMapMisc Operations Imager Context Operations Miscellaneous Κ D˜šœ™Jšœ Οmœ1™Jšžœ žœ˜šžœžœ˜Jšœž ˜ JšœKžœ˜UJ˜ Jšœžœ˜JšœIžœ˜SJ˜—J˜—J˜š  œž œ˜Jšœ&žœ žœ˜EJšžœžœžœ˜Jšœ,˜,JšœD˜DJšœ=˜=J˜J™—š  œž œ˜Jšœ&žœ žœ˜Ešœ˜šœ˜Lšœ7žœ˜A—LšœHžœ˜RJšœ˜—Jšžœžœ-˜DJ˜J˜—š œžœžœ˜Jš œžœžœžœžœ˜Išžœžœ˜LšœR˜RLšœQ˜QL˜šžœžœžœž˜Jšœžœ˜Lšœ,˜,Lšœ˜Lšžœ˜L˜—JšœF˜FJšœD˜DLšœ*˜*Lšœ)˜)L˜—J˜J˜—š  œžœžœ˜Jšœ+žœžœžœ˜=šžœžœ˜LšœR˜RLšœQ˜QL˜šžœžœžœž˜Lšœ˜šžœžœžœž˜Jšœžœ˜Lšœ,˜,Lšœ˜Lšžœ˜—JšœF˜FJšœD˜DJšžœ˜J˜—Lšœ*˜*Lšœ)˜)J˜—J˜——™š œžœžœžœ˜EJšœžœ˜ J˜JšœA˜AJšžœžœžœ(žœ˜<šžœ ž˜J˜E˜šœ.˜.Jšœ<˜<—šœ-˜-Jšœ<˜<—J˜*J˜—Jšžœ˜—Jšœ˜Jšœ˜Jšœ˜Jšœ˜J˜J˜—š  œž œ˜2šžœ ž˜J˜˜Jšœ˜J˜Jšœ˜Jšœ*˜*Jšœ(˜(J˜—Jšžœ˜—J˜J˜—š œž œ žœ˜@Jšžœ˜J˜ J˜ J˜ J˜ šžœž˜Jšœ;˜;˜Jšœ6˜6Jšœ4˜4J˜—Jšžœ˜—Jšžœ˜ J˜J˜—š  œž œžœ ˜Ešžœž˜Jšœ˜Jšœ˜Jšžœ˜—J˜J˜—š œž œžœ˜NJšžœ˜!J˜J˜—š  œž œžœžœ˜OJ˜Cšžœž˜Jšœ.˜.˜Jšœ)˜)Jšœ(˜(J˜—Jšžœ˜—J˜J˜—š  œž œ˜4šžœ ž˜Jšœ-˜-˜Jšœ(˜(Jšœ&˜&J˜—Jšžœ˜—J˜J˜—š œž œ,žœ˜Rš œžœ˜$J˜3JšœY˜YL˜—šžœ ž˜Lšœ˜šœ˜Lšœ˜Lšœ˜Lšœ˜—Lšžœ˜—J˜——™š œžœžœ,žœžœ žœžœ žœžœžœ˜”Lšœ˜L˜šžœžœ)ž˜3Jšœ'žœ˜-—šœžœž˜LšœF˜FLšœJ˜JLšœH˜HLšžœžœ˜—L˜Lšžœžœžœžœ ˜'Lšžœ˜ J˜J˜—š  œžœBžœžœ žœžœžœ˜–J•StartOfExpansionΘ[device: ImagerDevice.Device, pixelUnits: BOOL _ FALSE, fontCache: ImagerCache.Ref _ NIL, rastWeight: REAL _ 1.0, fontTuner: ImagerRaster.FontTuner _ NIL, class: REF Imager.ClassRep _ NIL]˜šœ'Οc˜;Jšœ˜Jšžœžœ˜—Jšžœ žœ'‘Πcg‘˜OJšžœžœ žœ)˜?J˜J˜—š  œžœBžœžœ žœžœžœ˜™šœ˜JšœE˜EJšœ ˜ Jšœ(˜(Jšžœ žœžœ˜2—Jšžœ žœ+‘’‘˜OJ˜J˜—š  œžœBžœžœ žœžœžœ˜—J˜Jšœ%žœ˜+Jšžœ žœ,‘˜OJšžœžœ žœ)˜?J˜J˜—š œž œE˜YJšœ‘˜8Jšœ5‘ ˜BJšœ9˜9J˜J˜—š  œžœžœžœžœ ˜GJšœ ˜ Jšžœžœžœ"˜2JšœN˜NJšœ8˜8J˜——™ š  œž œžœ˜FJšžœžœžœ˜Jšœ3˜3Lšžœžœžœžœ˜:šžœ˜Lšžœ(žœžœ ˜ELšžœ)žœ˜3—Jšžœ˜$J˜J˜——Jšžœ˜˜J˜——…—-\;Ϊ