<> <> <> DIRECTORY ColorTrixMod, ColorTrixMap, ImagerSample, ImagerPixelMap, PrincOps, PixelMapOps, Process, Real; ColorTrixModImpl: CEDAR PROGRAM IMPORTS ColorTrixMap, ImagerSample, ImagerPixelMap, PixelMapOps, Process, Real EXPORTS ColorTrixMod ~ { <> Up: PUBLIC PROC [pm: ImagerPixelMap.PixelMap, shift: INT] ~ { startClip, secondShift: INT; t: ImagerPixelMap.PixelMap; IF shift = 0 THEN RETURN; IF shift > 0 THEN {startClip _ 0; secondShift _ pm.sSize-shift}; IF shift < 0 THEN {startClip _ pm.sSize+shift; secondShift _ -pm.sSize-shift}; t _ ImagerPixelMap.Copy[ImagerPixelMap.Clip[pm, [startClip, 0, ABS[shift], pm.fSize]]]; ImagerPixelMap.Transfer[pm, ImagerPixelMap.ShiftMap[pm, -shift, 0]]; ImagerPixelMap.Transfer[pm, ImagerPixelMap.ShiftMap[t, secondShift, 0]]; }; Left: PUBLIC PROC [pm: ImagerPixelMap.PixelMap, shift: INT] ~ { startClip, secondShift: INT; t: ImagerPixelMap.PixelMap; IF shift = 0 THEN RETURN; IF shift > 0 THEN {startClip _ 0; secondShift _ pm.fSize-shift}; IF shift < 0 THEN {startClip _ pm.fSize+shift; secondShift _ -pm.fSize-shift}; t _ ImagerPixelMap.Copy[ImagerPixelMap.Clip[pm, [0, startClip, pm.sSize, ABS[shift]]]]; ImagerPixelMap.Transfer[pm, ImagerPixelMap.ShiftMap[pm, 0, -shift]]; ImagerPixelMap.Transfer[pm, ImagerPixelMap.ShiftMap[t, 0, secondShift]]; }; Negate: PUBLIC PROC [pm: ImagerPixelMap.PixelMap] ~ { ImagerPixelMap.Transfer[pm, pm, [null, complement]]; }; ReflectH: PUBLIC PROC [pm: ImagerPixelMap.PixelMap] ~ { line1: ImagerSample.SampleBuffer ~ ImagerSample.ObtainScratchBuffer[1, pm.fSize]; line2: ImagerSample.SampleBuffer ~ ImagerSample.ObtainScratchBuffer[1, pm.fSize]; FOR dy: NAT IN [0..pm.sSize/2] DO y: NAT _ pm.sMin+dy; yy: NAT _ pm.sMin+pm.sSize-1-dy; Process.CheckForAbort[]; PixelMapOps.GetF[pm, y, pm.fMin, line1, 0, 0, pm.fSize]; PixelMapOps.GetF[pm, yy, pm.fMin, line2, 0, 0, pm.fSize]; PixelMapOps.PutF[pm, y, pm.fMin, line2, 0, 0, pm.fSize, null, null]; PixelMapOps.PutF[pm, yy, pm.fMin, line1, 0, 0, pm.fSize, null, null]; ENDLOOP; }; ReflectV: PUBLIC PROC [pm: ImagerPixelMap.PixelMap] ~ { action: PROC [line: ImagerSample.SampleBuffer] ~ TRUSTED { sample: ImagerSample.UnsafeSamples ~ ImagerSample.GetPointer[line, 0, 0, pm.fSize]; xRight: NAT _ pm.fSize-1; FOR y: INT IN [pm.sMin..pm.sMin+pm.sSize) DO Process.CheckForAbort[]; PixelMapOps.GetF[pm, y, pm.fMin, line, 0, 0, pm.fSize]; FOR x: NAT IN [0..pm.fSize/2] DO t: NAT _ sample[x]; xx: NAT _ xRight-x; sample[x] _ sample[xx]; sample[xx] _ t; ENDLOOP; PixelMapOps.PutF[pm, y, pm.fMin, line, 0, 0, pm.fSize, null, null]; ENDLOOP; }; ImagerSample.DoWithScratchBuffer[1, pm.fSize, action]; }; MirrorH: PUBLIC PROC [pm: ImagerPixelMap.PixelMap, topToBottom: BOOL _ TRUE] ~ { action: PROC [line: ImagerSample.SampleBuffer] ~ TRUSTED { y1, y2: NAT; FOR dy: NAT IN [0..pm.sSize/2] DO Process.CheckForAbort[]; IF topToBottom THEN {y1 _ pm.sMin+dy; y2 _ pm.sMin+pm.sSize-1-dy} ELSE {y1 _ pm.sMin+pm.sSize-1-dy; y2 _ pm.sMin+dy}; PixelMapOps.GetF[pm, y1, pm.fMin, line, 0, 0, pm.fSize]; PixelMapOps.PutF[pm, y2, pm.fMin, line, 0, 0, pm.fSize, null, null]; ENDLOOP; }; ImagerSample.DoWithScratchBuffer[1, pm.fSize, action]; }; MirrorV: PUBLIC PROC [pm: ImagerPixelMap.PixelMap, leftToRight: BOOL _ TRUE] ~ { action: PROC [line: ImagerSample.SampleBuffer] ~ TRUSTED { sample: ImagerSample.UnsafeSamples ~ ImagerSample.GetPointer[line, 0, 0, pm.fSize]; xRight: NAT _ pm.fSize-1; FOR y: INT IN [pm.sMin..pm.sMin+pm.sSize) DO Process.CheckForAbort[]; PixelMapOps.GetF[pm, y, pm.fMin, line, 0, 0, pm.fSize]; IF leftToRight THEN FOR x: NAT IN [0..pm.fSize/2] DO sample[xRight-x] _ sample[x]; ENDLOOP ELSE FOR x: NAT IN [0..pm.fSize/2] DO sample[x] _ sample[xRight-x]; ENDLOOP; PixelMapOps.PutF[pm, y, pm.fMin, line, 0, 0, pm.fSize, null, null]; ENDLOOP; }; ImagerSample.DoWithScratchBuffer[1, pm.fSize, action]; }; Indirect: PUBLIC PROC [pm: ImagerPixelMap.PixelMap, table: ColorTrixMod.Table] ~ { action: PROC [line: ImagerSample.SampleBuffer] ~ TRUSTED { sample: ImagerSample.UnsafeSamples ~ ImagerSample.GetPointer[line, 0, 0, pm.fSize]; FOR y: INT IN [pm.sMin..pm.sMin+pm.sSize) DO Process.CheckForAbort[]; PixelMapOps.GetF[pm, y, pm.fMin, line, 0, 0, pm.fSize]; FOR x: NAT IN [0..pm.fSize) DO sample[x] _ table[sample[x]]; ENDLOOP; PixelMapOps.PutF[pm, y, pm.fMin, line, 0, 0, pm.fSize, null, null]; ENDLOOP; }; ImagerSample.DoWithScratchBuffer[1, pm.fSize, action]; }; Lum: PUBLIC PROC [pm: ImagerPixelMap.PixelMap] ~ { table: ColorTrixMod.Table _ NEW[ColorTrixMod.TableRep]; cm: ColorTrixMap.Cmap _ ColorTrixMap.Read[]; FOR i: INT IN [0..256) DO table[i] _ MIN[255, MAX[0, Real.RoundI[.30*cm[0][i] + .59*cm[1][i] + .11*cm[2][i]]]]; ENDLOOP; ColorTrixMap.Mono[]; Indirect[pm, table]; }; PVal: PUBLIC PROC [pm: ImagerPixelMap.PixelMap, new: NAT, old: LIST OF NAT] ~ { table: ColorTrixMod.Table _ NEW[ColorTrixMod.TableRep]; IF old = NIL THEN RETURN; FOR i: NAT IN [0..256) DO table[i] _ i; ENDLOOP; new _ MIN[255, MAX[0, INTEGER[new]]]; FOR o: LIST OF NAT _ old, o.rest WHILE o # NIL DO table[MIN[255, MAX[0, INTEGER[o.first]]]] _ new; ENDLOOP; Indirect[pm, table]; }; }. <> <> <<};>> <<>> <> <> <> <> <> <> <> <> <> <> <> <> <<};>> <> <> <> <> <> <<};>> <> <> <> <> <> <> <> <> <> <> <> <> <<};>> <> <<};>> <<>> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <<};>> <> <<};>> <<>>