Ejemplo n.º 1
0
        public void SetPixel(int x, int y, ColorD c)
        {
            Color sdc  = c.ToColor();
            var   rgba = new byte[] { sdc.R, sdc.G, sdc.B, sdc.A };

            Pixels.SetArea(x, y, 1, 1, rgba);
        }
Ejemplo n.º 2
0
        public ColorD GetPixel(int x, int y)
        {
            var   rgba = Pixels.GetArea(x, y, 1, 1);
            Color sdc  = Color.FromArgb(rgba[0], rgba[1], rgba[2], rgba[3]);

            return(ColorD.FromColor(sdc));
        }
Ejemplo n.º 3
0
        public ColorD GetColor(double index, double maximum)
        {
            double z = index / maximum;

            GradientColour(z, Grad, out double r, out double g, out double b, out double a);
            return(ColorD.FromArgb(a, r, g, b));
        }
Ejemplo n.º 4
0
        static void CreateColorMapTest()
        {
            IColorMap cmap = GetColorMap(out string name);

            using (var img = new MagicCanvas(Options.Width, Options.Height))
            {
                for (int x = 0; x < Options.Width; x++)
                {
                    ColorD c = cmap.GetColor(x, Options.Width);
                    img.DrawLine(c, x, 0, x, Options.Height - 1);
                }
                img.SavePng("ColorMapTest-" + name + ".png");
            }
        }
Ejemplo n.º 5
0
        static ColorD FindColorFromRange(double min, double max, double val)
        {
            //iterate HSL L=[0 to 1] S=1 H[0 to 360]
            double range    = max - min;
            double spacemax = 256.0 * 360.0;             //L * H
            double pos      = (val - min) / range * spacemax;

            //basically map 2D HxL space into one dimension
            double s = 1.0;
            //double l = (pos / spacemax) * 0.9 + 0.05; //clip the edges by 5%
            double l = pos / spacemax;
            double h = (pos % (360.0 * 4)) / (360.0 * 4);             //4 slows down the cycle 4x

            ColorHelpers.HSLToRGB(h, s, l, out double r, out double g, out double b);
            return(ColorD.FromArgb(1.0, r, g, b));
        }
Ejemplo n.º 6
0
        static void PaintImageData(IDensityMatrix matrix, IColorMap cm, ICanvas img, ColorComponent comp = ColorComponent.None)
        {
            double lm = matrix.Maximum;

            // find minimum method
            double ln = double.MaxValue;

            for (int y = 1; y < Options.Height - 1; y++)
            {
                for (int x = 1; x < Options.Width - 1; x++)
                {
                    double li = matrix[x, y];
                    if (li > 0.0 && li < ln)
                    {
                        ln = li;
                    }
                }
            }
            Debug.WriteLine("ln = " + ln);

            //chop at most frequent value
            //double hmax = 0.0;
            //int cmax = 0;
            //var histogram = new Dictionary<double,int>();
            //for (int y = 1; y < Options.Height - 1; y++) {
            //	for (int x = 1; x < Options.Width - 1; x++) {
            //		double li = matrix[x, y];
            //		if (li < double.Epsilon || double.IsInfinity(li) || double.IsNaN(li)) { continue; }
            //		if (!histogram.TryGetValue(li,out int val)) {
            //			val = 1;
            //		} else {
            //			val++;
            //		}
            //		if (val > cmax) {
            //			cmax = val;
            //			hmax = li;
            //		}
            //		histogram[li] = val;
            //	}
            //}
            // Debug.WriteLine("hmax = "+hmax+" cmax = "+cmax);

            //find minimum method using average of blocks
            //double ln = double.MaxValue;
            //int aspect = 32;
            //int aw = (Options.Width - 1) / aspect;
            //int ah = (Options.Height - 1) / aspect;
            //for (int ay = 1; ay < ah; ay++) {
            //	for (int ax = 1; ax < aw; ax++) {
            //		int ys = ay * aspect; int ye = ys + aspect - 1;
            //		int xs = ax * aspect; int xe = xs + aspect - 1;
            //		double avg = 0.0;
            //		for(int y = ys; y < ye; y++) {
            //			for(int x = xs; x < xe; x++) {
            //				if (x >= 0 && x < Options.Width && y >=0 && y < Options.Height) {
            //					double li = matrix[x, y];
            //					avg += li;
            //				}
            //			}
            //		}
            //		avg /= (aspect * aspect);
            //		if (avg > 0.0 && avg < ln) { ln = avg; }
            //	}
            //}
            //Debug.WriteLine("ln = "+ln);

            //find average method
            //double total = 0.0;
            //long count = 0;
            //for (int y = 1; y < Options.Height - 1; y++) {
            //	for (int x = 1; x < Options.Width - 1; x++) {
            //		double li = matrix[x, y];
            //		if (li >= 0.0 && !double.IsInfinity(li) && !double.IsNaN(li)) {
            //			total += li;
            //			count++;
            //		}
            //	}
            //}
            //double ln = total / count;
            //Debug.WriteLine("ln = "+ln);

            for (int y = 0; y < Options.Height; y++)
            {
                for (int x = 0; x < Options.Width; x++)
                {
                    double li = matrix[x, y];
                    ColorD c  = cm.GetColor(li - ln, lm - ln);
                    if (comp != ColorComponent.None)
                    {
                        img.SetPixelComponent(x, y, comp, c.GetComponent(comp));
                    }
                    else
                    {
                        img.SetPixel(x, y, c);
                    }
                }
            }
        }
Ejemplo n.º 7
0
 public void DrawLine(ColorD color, double x1, double y1, double x2, double y2)
 {
     Draws.FillColor(color.ToColor());
     Draws.Line(x1, y1, x2, y2);
 }
Ejemplo n.º 8
0
        public ColorD GetColor(double index, double maximum)
        {
            double pct = Math.Log(1 + index) / Math.Log(1 + maximum);

            return(ColorD.FromArgb(1.0, pct, pct, pct));
        }