public static Color GetColorGradient(float value, bool selected, bool grayscale) { if (!AColor.gradient_inited) { AColor.PreComputeGradient(); } int idx = (int)(value * (AColor.gradientSteps - 1)); // TODO: select return(Color.Aquamarine); }
public static Color GetColorGradient(float percentage) { if (!AColor.gradient_inited) { AColor.PreComputeGradient2(); } float i = percentage * (AColor.gradientSteps - 1); int idx = (int)i; Color c = Color.White; try { c = gradient_preloaded[idx]; } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Error looking up color id: " + idx); System.Diagnostics.Debug.WriteLine(e); } return(c); }
public void drawSpectrogram4(String prefix, String filename, float[][] data) { float amplitude; double numberOfSamplesX = data.Length; double numberOfSamplesY = data[0].Length; // set width and height int width = (int)numberOfSamplesX; int height = (int)numberOfSamplesY; String filenameToSave = String.Format("C:\\{0}-{1}x{2}-{3}.png", prefix, width, height, System.IO.Path.GetFileNameWithoutExtension(filename)); System.Console.Out.WriteLine("Writing " + filenameToSave); double horizontalScaleFactor = (double)width / numberOfSamplesX; double verticalScaleFactor = (double)height / numberOfSamplesY; // Now, you need to figure out the incremental jump between samples to adjust for the scale factor. This works out to be: int incrementX = (int)(numberOfSamplesX / (numberOfSamplesX * horizontalScaleFactor)); if (incrementX == 0) { incrementX = 1; } int incrementY = (int)(numberOfSamplesY / (numberOfSamplesY * verticalScaleFactor)); if (incrementY == 0) { incrementY = 1; } Bitmap png = new Bitmap(width, height, PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(png); Rectangle rect = new Rectangle(0, 0, width, height); g.FillRectangle(Brushes.White, rect); int x = 0; int y = 0; for (x = 0; x < numberOfSamplesX; x += incrementX) { for (y = 0; y < numberOfSamplesY; y += incrementY) { int xCoord = (int)MathUtils.RoundDown(x * horizontalScaleFactor, 0); int yCoord = (int)MathUtils.RoundDown(y * verticalScaleFactor, 0); amplitude = data[x][y]; // Convert float to dB float MinDb = -60.0f; float MaxDb = 0.0f; float db = 20 * (float)Math.Log10((float)amplitude); if (db < MinDb) { db = MinDb; } if (db > MaxDb) { db = MaxDb; } float percentage = (db - MinDb) / (MaxDb - MinDb); Color c = AColor.GetColorGradient(percentage); png.SetPixel(xCoord, yCoord, c); } } png.Save(filenameToSave); g.Dispose(); }