예제 #1
0
        public void SetParameters(Surface src, Rectangle rgn)
        {
            HistogramRgb histogram = new HistogramRgb();

            histogram.UpdateHistogram(src, rgn);
            this.levels = histogram.MakeLevelsAuto();
        }
예제 #2
0
        private void HandleButtonAutoClicked(object sender, EventArgs e)
        {
            Levels = histogramInput.Histogram.MakeLevelsAuto();

            UpdateFromLevelsOp();
            UpdateLevels();
        }
        protected override void InitDialogFromToken(EffectConfigToken effectToken)
        {
            UnaryPixelOps.Level levels = ((LevelsEffectConfigToken)effectToken).Levels;

            float gamma = MaskGamma(levels);
            int   lo    = MaskAvg(levels.ColorOutLow);
            int   hi    = MaskAvg(levels.ColorOutHigh);
            int   md    = (int)(lo + (hi - lo) * Math.Pow(0.5, gamma));

            outputHiUpDown.Value    = hi;
            outputGammaUpDown.Value = (decimal)gamma;
            outputLowUpDown.Value   = lo;
            inputHiUpDown.Value     = MaskAvg(levels.ColorInHigh);
            inputLoUpDown.Value     = MaskAvg(levels.ColorInLow);

            gradientOutput.SetValue(0, lo);
            gradientOutput.SetValue(1, md);
            gradientOutput.SetValue(2, hi);

            swatchInHigh.BackColor = levels.ColorInHigh.ToColor();
            swatchInLow.BackColor  = levels.ColorInLow.ToColor();
            swatchOutMid.BackColor = levels.Apply(((HistogramRgb)histogramInput.Histogram).GetMeanColor()).ToColor();
            swatchOutMid.Invalidate();
            swatchOutHigh.BackColor = levels.ColorOutHigh.ToColor();
            swatchOutLow.BackColor  = levels.ColorOutLow.ToColor();
        }
        protected override void InitTokenFromDialog()
        {
            UnaryPixelOps.Level levels = ((LevelsEffectConfigToken)theEffectToken).Levels;

            levels.ColorOutHigh = UpdateByMask(levels.ColorOutHigh, (byte)outputHiUpDown.Value);
            levels.ColorOutLow  = UpdateByMask(levels.ColorOutLow, (byte)outputLowUpDown.Value);

            levels.ColorInHigh = UpdateByMask(levels.ColorInHigh, (byte)inputHiUpDown.Value);
            levels.ColorInLow  = UpdateByMask(levels.ColorInLow, (byte)inputLoUpDown.Value);

            UpdateGammaByMask(levels, (float)outputGammaUpDown.Value);

            swatchInHigh.BackColor = levels.ColorInHigh.ToColor();
            swatchInHigh.Invalidate();

            swatchInLow.BackColor = levels.ColorInLow.ToColor();
            swatchInLow.Invalidate();

            swatchOutHigh.BackColor = levels.ColorOutHigh.ToColor();
            swatchOutHigh.Invalidate();

            swatchOutMid.BackColor = levels.Apply(((HistogramRgb)histogramInput.Histogram).GetMeanColor()).ToColor();
            swatchOutMid.Invalidate();

            swatchOutLow.BackColor = levels.ColorOutLow.ToColor();
            swatchOutLow.Invalidate();
        }
        private void swatch_DoubleClick(object sender, System.EventArgs e)
        {
            SystemLayer.Tracing.Ping((sender as Control).Name);

            UnaryPixelOps.Level levels = ((LevelsEffectConfigToken)theEffectToken).Levels;

            using (ColorDialog cd = new ColorDialog())
            {
                if ((sender is Panel))
                {
                    cd.Color    = ((Panel)sender).BackColor;
                    cd.AnyColor = true;

                    if (cd.ShowDialog(this) == DialogResult.OK)
                    {
                        ColorBgra col = ColorBgra.FromColor(cd.Color);

                        if (sender == swatchInLow)
                        {
                            levels.ColorInLow = col;
                        }
                        else if (sender == swatchInHigh)
                        {
                            levels.ColorInHigh = col;
                        }
                        else if (sender == swatchOutLow)
                        {
                            levels.ColorOutLow = col;
                        }
                        else if (sender == swatchOutMid)
                        {
                            ColorBgra lo     = levels.ColorInLow;
                            ColorBgra md     = ((HistogramRgb)histogramInput.Histogram).GetMeanColor();
                            ColorBgra hi     = levels.ColorInHigh;
                            ColorBgra out_lo = levels.ColorOutLow;
                            ColorBgra out_hi = levels.ColorOutHigh;

                            for (int i = 0; i < 3; i++)
                            {
                                double logA    = (col[i] - out_lo[i]) / (out_hi[i] - out_lo[i]);
                                double logBase = (md[i] - lo[i]) / (hi[i] - lo[i]);
                                double logVal  = (logBase == 1.0) ? 0.0 : Math.Log(logA, logBase);

                                levels.SetGamma(i, (float)Utility.Clamp(logVal, 0.1, 10.0));
                            }
                        }
                        else if (sender == swatchOutHigh)
                        {
                            levels.ColorOutHigh = col;
                        }
                        else if (sender == swatchInHigh)
                        {
                            levels.ColorInHigh = col;
                        }

                        InitDialogFromToken();
                    }
                }
            }
        }
예제 #6
0
        protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            HistogramRgb histogram = new HistogramRgb();

            histogram.UpdateHistogram(srcArgs.Surface, this.EnvironmentParameters.GetSelection(dstArgs.Bounds));
            this.levels = histogram.MakeLevelsAuto();

            base.OnSetRenderInfo(newToken, dstArgs, srcArgs);
        }
예제 #7
0
        public override void Render(ImageSurface src, ImageSurface dest, Gdk.Rectangle[] rois)
        {
            if (op == null)
            {
                HistogramRgb histogram = new HistogramRgb();
                histogram.UpdateHistogram(src, new Gdk.Rectangle(0, 0, src.Width, src.Height));

                op = histogram.MakeLevelsAuto();
            }

            if (op.isValid)
            {
                op.Apply(dest, src, rois);
            }
        }
예제 #8
0
        public override void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs,
                                    Rectangle[] rois, int startIndex, int length)
        {
            if (levels == null)
            {
                HistogramRgb histogram = new HistogramRgb();
                histogram.UpdateHistogram(srcArgs.Surface, this.EnvironmentParameters.GetSelection(dstArgs.Bounds));
                levels = histogram.MakeLevelsAuto();
            }

            if (levels.isValid)
            {
                levels.Apply(dstArgs.Surface, srcArgs.Surface, rois, startIndex, length);
            }
        }
        private float MaskGamma(UnaryPixelOps.Level levels)
        {
            int   count = 0;
            float total = 0;

            for (int c = 0; c < 3; c++)
            {
                if (mask[c])
                {
                    total += levels.GetGamma(c);
                    count++;
                }
            }

            if (count > 0)
            {
                return(total / count);
            }
            else
            {
                return(1);
            }
        }
        private void UpdateGammaByMask(UnaryPixelOps.Level levels, float val)
        {
            float average = -1;

            if (!(mask[0] || mask[1] || mask[2]))
            {
                return;
            }

            do
            {
                average = MaskGamma(levels);
                float factor = val / average;

                for (int c = 0; c < 3; c++)
                {
                    if (mask[c])
                    {
                        levels.SetGamma(c, factor * levels.GetGamma(c));
                    }
                }
            } while (Math.Abs(val - average) > 0.001);
        }
예제 #11
0
 public LevelsData()
 {
     Levels = new UnaryPixelOps.Level();
 }
 public LevelsEffectConfigToken()
 {
     levels = new UnaryPixelOps.Level();
 }
예제 #13
0
 public LevelsEffectConfigToken()
 {
     levels = new UnaryPixelOps.Level();
 }
예제 #14
0
 public override void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, int startIndex, int length)
 {
     UnaryPixelOps.Level levels = (parameters as LevelsEffectConfigToken).Levels;
     levels.Apply(dstArgs.Surface, srcArgs.Surface, rois, startIndex, length);
 }