Histogram is used to calculate a histogram for a surface (in a selection, if desired). This can then be used to retrieve percentile, average, peak, and distribution information.
Inheritance: Pinta.Core.Histogram
示例#1
0
		public HistogramWidget ()
		{
			Histogram = new HistogramRgb ();
			selected = new bool[] {true, true, true};
			
			ExposeEvent += HandleExposeEvent;
		}
示例#2
0
        public override void RenderEffect(ImageSurface src, ImageSurface dest, Gdk.Rectangle[] rois)
        {
            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);
        }
示例#3
0
        public void SetFromLeveledHistogram(HistogramRgb inputHistogram, UnaryPixelOps.Level upo)
        {
            if (inputHistogram == null || upo == null) 
            {
                return;
            }

            Clear();

            float[] before = new float[3];
            float[] slopes = new float[3];

            for (int c = 0; c < 3; c++)
            {
                long[] channelHistogramOutput = histogram[c];
                long[] channelHistogramInput = inputHistogram.histogram[c];

                for (int v = 0; v <= 255; v++)
                {
                    ColorBgra after = ColorBgra.FromBgr((byte)v, (byte)v, (byte)v);

                    upo.UnApply(after, before, slopes);

                    if (after[c] > upo.ColorOutHigh[c]
                        || after[c] < upo.ColorOutLow[c]
                        || (int)Math.Floor(before[c]) < 0
                        || (int)Math.Ceiling(before[c]) > 255
                        || float.IsNaN(before[c])) 
                    {
                        channelHistogramOutput[v] = 0;
                    }
                    else if (before[c] <= upo.ColorInLow[c]) 
                    {
                        channelHistogramOutput[v] = 0;

                        for (int i = 0; i <= upo.ColorInLow[c]; i++)
                        {
                            channelHistogramOutput[v] += channelHistogramInput[i];
                        }
                    } 
                    else if (before[c] >= upo.ColorInHigh[c])
                    {
                        channelHistogramOutput[v] = 0;

                        for (int i = upo.ColorInHigh[c]; i < 256; i++)
                        {
                            channelHistogramOutput[v] += channelHistogramInput[i];
                        }
                    }
                    else
                    {
                        channelHistogramOutput[v] = (int)(slopes[c] * Utility.Lerp(
                            channelHistogramInput[(int)Math.Floor(before[c])],
                            channelHistogramInput[(int)Math.Ceiling(before[c])],
                            before[c] - Math.Floor(before[c])));
                    }
                }
            }

            OnHistogramUpdated();
        }
示例#4
0
 public void ResetHistogram()
 {
     Histogram = new HistogramRgb();
 }
示例#5
0
        public void SetFromLeveledHistogram(HistogramRgb inputHistogram, UnaryPixelOps.Level upo)
        {
            if (inputHistogram == null || upo == null)
            {
                return;
            }

            Clear();

            float[] before = new float[3];
            float[] slopes = new float[3];

            for (int c = 0; c < 3; c++)
            {
                long[] channelHistogramOutput = histogram[c];
                long[] channelHistogramInput  = inputHistogram.histogram[c];

                for (int v = 0; v <= 255; v++)
                {
                    ColorBgra after = ColorBgra.FromBgr((byte)v, (byte)v, (byte)v);

                    upo.UnApply(after, before, slopes);

                    if (after[c] > upo.ColorOutHigh[c] ||
                        after[c] < upo.ColorOutLow[c] ||
                        (int)Math.Floor(before[c]) < 0 ||
                        (int)Math.Ceiling(before[c]) > 255 ||
                        float.IsNaN(before[c]))
                    {
                        channelHistogramOutput[v] = 0;
                    }
                    else if (before[c] <= upo.ColorInLow[c])
                    {
                        channelHistogramOutput[v] = 0;

                        for (int i = 0; i <= upo.ColorInLow[c]; i++)
                        {
                            channelHistogramOutput[v] += channelHistogramInput[i];
                        }
                    }
                    else if (before[c] >= upo.ColorInHigh[c])
                    {
                        channelHistogramOutput[v] = 0;

                        for (int i = upo.ColorInHigh[c]; i < 256; i++)
                        {
                            channelHistogramOutput[v] += channelHistogramInput[i];
                        }
                    }
                    else
                    {
                        channelHistogramOutput[v] = (int)(slopes[c] * Utility.Lerp(
                                                              channelHistogramInput[(int)Math.Floor(before[c])],
                                                              channelHistogramInput[(int)Math.Ceiling(before[c])],
                                                              before[c] - Math.Floor(before[c])));
                    }
                }
            }

            OnHistogramUpdated();
        }
示例#6
0
文件: Layer.cs 项目: asbjornu/Pinta
        public unsafe void AutoLevel()
        {
            ImageSurface dest = Surface.Clone ();
            ColorBgra* dstPtr = (ColorBgra*)dest.DataPtr;
            ColorBgra* srcPtr = (ColorBgra*)Surface.DataPtr;

            int len = Surface.Data.Length / 4;

            UnaryPixelOps.Level levels = null;

            HistogramRgb histogram = new HistogramRgb();
            histogram.UpdateHistogram (Surface, new Rectangle (0, 0, Surface.Width, Surface.Height));
            levels = histogram.MakeLevelsAuto();

            if (levels.isValid)
                levels.Apply (dstPtr, srcPtr, len);

            using (Context g = new Context (Surface)) {
                g.AppendPath (PintaCore.Layers.SelectionPath);
                g.FillRule = FillRule.EvenOdd;
                g.Clip ();

                g.SetSource (dest);
                g.Paint ();
            }

            (dest as IDisposable).Dispose ();
        }