Exemple #1
0
        // If either the colourMapType or the colorMapLength or the interpPoints
        // have changed, then recalculate the colourMap
        public void UpdateColourMap()
        {
            lock (locker)
            {
                double[] pixelPositions = MathHelper.Counter(colorMapLength);
                for (int i = 0; i < pixelPositions.Length; ++i)
                {
                    pixelPositions[i] = (pixelPositions[i] - 0.5) / (double)colorMapLength;
                }
                switch (colourMapMode)
                {
                case ColourMapMode.RGB:
                    red.UpdateLinearSplineCoefficients();
                    green.UpdateLinearSplineCoefficients();
                    blue.UpdateLinearSplineCoefficients();
                    double[] interpolatedRed = red.GetValuesLinear(pixelPositions);
                    interpolatedRed.MultiplyBy(255.0);
                    double[] interpolatedGreen = green.GetValuesLinear(pixelPositions);
                    interpolatedGreen.MultiplyBy(255.0);
                    double[] interpolatedBlue = blue.GetValuesLinear(pixelPositions);
                    interpolatedBlue.MultiplyBy(255.0);
                    colourMap    = new byte[colorMapLength, 4];
                    intColourMap = new int[colorMapLength];
                    for (int i = 0; i < colorMapLength; i++)
                    {
                        colourMap[i, 0] = (byte)alphaValue;
                        colourMap[i, 1] = (byte)interpolatedRed[i];
                        colourMap[i, 2] = (byte)interpolatedGreen[i];
                        colourMap[i, 3] = (byte)interpolatedBlue[i];
                        intColourMap[i] = ((int)interpolatedRed[i] << 16)    // R
                                          | ((int)interpolatedGreen[i] << 8) // G
                                          | ((int)interpolatedBlue[i] << 0); // B
                    }
                    break;

                case ColourMapMode.HSV:
                    hue.UpdateLinearSplineCoefficients();
                    saturation.UpdateLinearSplineCoefficients();
                    value.UpdateLinearSplineCoefficients();
                    double[] interpolatedHue        = hue.GetValuesLinear(pixelPositions);
                    double[] interpolatedSaturation = saturation.GetValuesLinear(pixelPositions);
                    double[] interpolatedValue      = value.GetValuesLinear(pixelPositions);
                    colourMap    = new byte[colorMapLength, 4];
                    intColourMap = new int[colorMapLength];
                    double r = 0, g = 0, b = 0;
                    for (int i = 0; i < colorMapLength; i++)
                    {
                        int    hi = (int)(Math.Floor(interpolatedHue[i] * 6));
                        double f  = interpolatedHue[i] * 6 - (double)hi;
                        double v  = interpolatedSaturation[i];
                        double s  = interpolatedValue[i];
                        double p  = v * (1 - s);
                        double q  = v * (1 - f * s);
                        double t  = v * (1 - (1 - f) * s);
                        switch (hi)
                        {
                        case 0:
                            r = v; g = t; b = p; break;

                        case 1:
                            r = q; g = v; b = p; break;

                        case 2:
                            r = p; g = v; b = t; break;

                        case 3:
                            r = p; g = q; b = v; break;

                        case 4:
                            r = t; g = p; b = v; break;

                        case 5:
                            r = v; g = p; b = q; break;
                        }
                        r *= 255; g *= 255; b *= 255;
                        colourMap[i, 0] = (byte)alphaValue;
                        colourMap[i, 1] = (byte)r;
                        colourMap[i, 2] = (byte)g;
                        colourMap[i, 3] = (byte)b;
                        intColourMap[i] = ((int)r << 16)   // H
                                          | ((int)g << 8)  // S
                                          | ((int)b << 0); // V
                    }
                    break;
                }
            }
        }