예제 #1
0
파일: ColrBitmap.cs 프로젝트: smackem/Colr
        /// <summary>
        /// Analyzes the image and calculates the color distribution.
        /// </summary>
        /// <param name="hueSteps">The number of steps to use for the hue distribution. The granularity
        /// of the hue distribution is <paramref name="hueSteps"/> divided by 360 degrees.
        /// </param>
        /// <param name="saturationSteps">The number of steps to use for the saturation distribution.</param>
        /// <param name="valueSteps">The number of steps to use for the value distribution.</param>
        /// <returns>An instance of <see cref="ColorDistribution"/>. The method
        /// <see cref="ColorDistribution.GetHueDistribution"/> returns <paramref name="hueSteps"/> elements.</returns>
        public ColorDistribution GetColorDistribution(int hueSteps, int saturationSteps, int valueSteps)
        {
            var distribution = new ColorDistribution(hueSteps, saturationSteps, valueSteps);

            foreach (var hsv in hsvPixels)
                distribution.AddPixel(hsv);

            return distribution;
        }
예제 #2
0
파일: ColrBitmap.cs 프로젝트: smackem/Colr
        /// <summary>
        /// Analyzes the image and calculates the color distribution.
        /// </summary>
        /// <param name="hueSteps">The number of steps to use for the hue distribution. The granularity
        /// of the hue distribution is <paramref name="hueSteps"/> divided by 360 degrees.
        /// </param>
        /// <param name="saturationSteps">The number of steps to use for the saturation distribution.</param>
        /// <param name="valueSteps">The number of steps to use for the value distribution.</param>
        /// <param name="rect">The image region to process.</param>
        /// <returns>An instance of <see cref="ColorDistribution"/>. The method
        /// <see cref="ColorDistribution.GetHueDistribution"/> returns <paramref name="hueSteps"/> elements.</returns>
        public ColorDistribution GetColorDistribution(int hueSteps, int saturationSteps, int valueSteps, Rectangle rect)
        {
            Contract.Requires(rect.Left >= 0 && rect.Left <= Bitmap.Width
                           && rect.Right >= 0 && rect.Right <= Bitmap.Width
                           && rect.Top >= 0 && rect.Top <= Bitmap.Height
                           && rect.Bottom >= 0 && rect.Bottom <= Bitmap.Height);

            var distribution = new ColorDistribution(hueSteps, saturationSteps, valueSteps);

            for (var y = 0; y < rect.Height; y++)
            {
                var offset = Bitmap.Width * y + rect.Left;

                for (var x = 0; x < rect.Width; x++)
                    distribution.AddPixel(this.hsvPixels[offset + x]);
            }

            return distribution;
        }