private Bitmap GetCachedHistogram(Histmode mode, Channel channel)
        {
            Bitmap res = null;

            if (cachedHistograms[mode].Keys.Contains(channel))
            {
                res = cachedHistograms[mode][channel];
            }

            return(res);
        }
        public Bitmap GetHistogram(Channel channel, Color color, Histmode mode)
        {
            Bitmap cached = GetCachedHistogram(mode, channel);

            if (cached == null)
            {
                cached = historgamCreators[channel].getHist(color, mode);
                SetCashedHistogram(mode, channel, cached);
            }

            return(cached);
        }
        public Bitmap getHist(Color clr, Histmode mode)
        {
            Bitmap res  = new Bitmap(BITMAP_WIDTH, BITMAP_HEIGHT);
            var    data = getScaled(mode);

            using (Graphics g = Graphics.FromImage(res))
            {
                Pen p = new Pen(clr);
                for (int i = 0; i < data.Length; i++)
                {
                    Point x = new Point(i, BITMAP_HEIGHT);
                    Point y = new Point(i, BITMAP_HEIGHT - data[i]);
                    g.DrawLine(p, x, y);
                    Console.WriteLine("Ok: i = {0}, x = {1}, y = {2}", i, x, y);
                }
            }
            return(res);
        }
        private int[] getScaled(Histmode mode)
        {
            int[] res = new int[256];
            histdata.CopyTo(res, 0);

            var max_c = res.Max();

            double k = BITMAP_HEIGHT;

            if (mode == Histmode.Lin)
            {
                k /= max_c;
            }
            else if (mode == Histmode.Log)
            {
                k /= Math.Log(max_c);
            }


            for (int i = 0; i < res.Length; i++)
            {
                if (res[i] == 0)
                {
                    continue;
                }
                if (mode == Histmode.Lin)
                {
                    res[i] = (int)Math.Round(res[i] * k);
                }
                else if (mode == Histmode.Log)
                {
                    res[i] = (int)Math.Round(Math.Log(res[i]) * k);
                }
            }
            return(res);
        }
 private void SetCashedHistogram(Histmode mode, Channel channel, Bitmap histogram)
 {
     cachedHistograms[mode].Add(channel, histogram);
 }