Exemple #1
0
        private UnaryPixelOp MakeUop()
        {
            UnaryPixelOp op;

            byte[][] transferCurves;
            int      entries;

            switch (Data.Mode)
            {
            case ColorTransferMode.Rgb:
                UnaryPixelOps.ChannelCurve cc = new UnaryPixelOps.ChannelCurve();
                transferCurves = new byte[][] { cc.CurveR, cc.CurveG, cc.CurveB };
                entries        = 256;
                op             = cc;
                break;

            case ColorTransferMode.Luminosity:
                UnaryPixelOps.LuminosityCurve lc = new UnaryPixelOps.LuminosityCurve();
                transferCurves = new byte[][] { lc.Curve };
                entries        = 256;
                op             = lc;
                break;

            default:
                throw new InvalidEnumArgumentException();
            }


            int channels = transferCurves.Length;

            for (int channel = 0; channel < channels; channel++)
            {
                SortedList <int, int> channelControlPoints = Data.ControlPoints[channel];
                IList <int>           xa           = channelControlPoints.Keys;
                IList <int>           ya           = channelControlPoints.Values;
                SplineInterpolator    interpolator = new SplineInterpolator();
                int length = channelControlPoints.Count;

                for (int i = 0; i < length; i++)
                {
                    interpolator.Add(xa[i], ya[i]);
                }

                for (int i = 0; i < entries; i++)
                {
                    transferCurves[channel][i] = Utility.ClampToByte(interpolator.Interpolate(i));
                }
            }

            return(op);
        }
Exemple #2
0
        protected override void DrawGeometry(StreamGeometryContext context)
        {
            var interpolator = new SplineInterpolator();

            foreach (var lineConnector in Connectors)
            {
                interpolator.Add(lineConnector.PosPoint.X, lineConnector.PosPoint.Y);
            }

            var start = Connectors.Min(x => x.PosPoint.X);
            var end   = Connectors.Max(x => x.PosPoint.X);

            var step   = Math.Sign(end - start);
            var firstY = interpolator.Interpolate(start);

            context.BeginFigure(new Point(start, firstY), true, false);
            start += step;

            for (var x = start; x <= end; x += step)
            {
                var y = interpolator.Interpolate(x);
                context.LineTo(new Point(x, y), true, true);
            }
        }
		private UnaryPixelOp MakeUop (SortedList<int, int>[] controlPoints, ColorTransferMode mode)
		{
			UnaryPixelOp op;
			byte[][] transferCurves;
			int entries;

			switch (mode) {
				case ColorTransferMode.Rgb:
					var cc = new ChannelCurveOp ();
					transferCurves = new byte[][] { cc.CurveR, cc.CurveG, cc.CurveB };
					entries = 256;
					op = cc;
					break;

				case ColorTransferMode.Luminosity:
					var lc = new LuminosityCurveOp ();
					transferCurves = new byte[][] { lc.Curve };
					entries = 256;
					op = lc;
					break;

				default:
					throw new InvalidEnumArgumentException ();
			}


			int channels = transferCurves.Length;

			for (int channel = 0; channel < channels; channel++) {
				var channelControlPoints = controlPoints[channel];
				var xa = channelControlPoints.Keys;
				var ya = channelControlPoints.Values;
				SplineInterpolator interpolator = new SplineInterpolator ();
				int length = channelControlPoints.Count;

				for (int i = 0; i < length; i++) {
					interpolator.Add (xa[i], ya[i]);
				}

				for (int i = 0; i < entries; i++) {
					transferCurves[channel][i] = Utility.ClampToByte (interpolator.Interpolate (i));
				}
			}

			return op;
		}
Exemple #4
0
        private void DrawSpline(Context g)
        {
            var infos = GetDrawingInfos();

            foreach (var controlPoints in ControlPoints)
            {
                int points = controlPoints.Count;
                SplineInterpolator interpolator = new SplineInterpolator();
                IList <int>        xa           = controlPoints.Keys;
                IList <int>        ya           = controlPoints.Values;
                PointD[]           line         = new PointD[size];

                for (int i = 0; i < points; i++)
                {
                    interpolator.Add(xa[i], ya[i]);
                }

                for (int i = 0; i < line.Length; i++)
                {
                    line[i].X = (float)i;
                    line[i].Y = (float)(Utility.Clamp(size - 1 - interpolator.Interpolate(i), 0, size - 1));
                }

                g.LineWidth = 2;
                g.LineJoin  = LineJoin.Round;

                g.MoveTo(line[0]);
                for (int i = 1; i < line.Length; i++)
                {
                    g.LineTo(line[i]);
                }

                infos.MoveNext();
                var info = infos.Current;

                g.SetSourceColor(info.Color);
                g.LineWidth = info.IsActive ? 2 : 1;
                g.Stroke();
            }
        }
        private UnaryPixelOp MakeUop()
        {
            UnaryPixelOp uopRet;
            byte[][] transferCurves;
            int entries;

            switch (colorTransferMode)
            {
                case ColorTransferMode.Rgb:
                    UnaryPixelOps.ChannelCurve cc = new UnaryPixelOps.ChannelCurve();
                    transferCurves = new byte[][] { cc.CurveR, cc.CurveG, cc.CurveB };
                    entries = 256;
                    uopRet = cc;
                    break;

                case ColorTransferMode.Luminosity:
                    UnaryPixelOps.LuminosityCurve lc = new UnaryPixelOps.LuminosityCurve();
                    transferCurves = new byte[][] { lc.Curve };
                    entries = 256;
                    uopRet = lc;
                    break;

                default:
                    throw new InvalidEnumArgumentException();
            }

            
            int channels = transferCurves.Length;

            for (int channel = 0; channel < channels; ++channel)
            {
                SortedList<int, int> channelControlPoints = controlPoints[channel];
                IList<int> xa = channelControlPoints.Keys;
                IList<int> ya = channelControlPoints.Values;
                SplineInterpolator interpolator = new SplineInterpolator();
                int length = channelControlPoints.Count;

                for (int i = 0; i < length; ++i)
                {
                    interpolator.Add(xa[i], ya[i]);
                }

                for (int i = 0; i < entries; ++i)
                {
                    transferCurves[channel][i] = Utility.ClampToByte(interpolator.Interpolate(i));
                }
            }

            return uopRet;
        }