Example #1
0
 public static IList<Point> CreatePath(Int32 width, Int32 height)
 {
     StandardPathProvider result = new StandardPathProvider();
     return result.GetPointPath(width, height);
 }
Example #2
0
        public Double CalculateMeanError(ImageBuffer target, Int32 parallelTaskCount = 4)
        {
            // checks parameters
            Guard.CheckNull(target, "target");

            // initializes the error
            Int64 totalError = 0;

            // prepares the function
            TransformPixelFunction calculateMeanError = (passIndex, sourcePixel, targetPixel) =>
            {
                Color sourceColor = sourcePixel.GetColor();
                Color targetColor = targetPixel.GetColor();
                totalError += ColorModelHelper.GetColorEuclideanDistance(ColorModel.RedGreenBlue, sourceColor, targetColor);
                return false;
            };

            // performs the image scan, using a chosen method
            IList<Point> standardPath = new StandardPathProvider().GetPointPath(Width, Height);
            TransformPerPixelBase(target, standardPath, parallelTaskCount, calculateMeanError);

            // returns the calculates RMSD
            return Math.Sqrt(totalError/(3.0*Width*Height));
        }
Example #3
0
        public void ChangeFormat(ImageBuffer target, IColorQuantizer quantizer, Int32 parallelTaskCount = 4)
        {
            // checks parameters
            Guard.CheckNull(target, "target");
            Guard.CheckNull(quantizer, "quantizer");

            // gathers some information about the target format
            Boolean hasSourceAlpha = PixelFormat.HasAlpha();
            Boolean hasTargetAlpha = target.PixelFormat.HasAlpha();
            Boolean isTargetIndexed = target.PixelFormat.IsIndexed();
            Boolean isSourceDeepColor = PixelFormat.IsDeepColor();
            Boolean isTargetDeepColor = target.PixelFormat.IsDeepColor();

            // prepares the palette if needed
            if (isTargetIndexed)
            {
                // synthetises palette using provided quantizer
                List<Color> targetPalette = SynthetizePalette(quantizer, target.PixelFormat.GetColorCount(), parallelTaskCount);

                // updates the bitmap palette
                target.bitmap.SetPalette(targetPalette);
                target.UpdatePalette(true);
            }

            // prepares the quantization function
            TransformPixelFunction changeFormat = (passIndex, sourcePixel, targetPixel) =>
            {
                // if both source and target formats are deep color formats, copies a value directly
                if (isSourceDeepColor && isTargetDeepColor)
                {
                    //UInt64 value = sourcePixel.Value;
                    //targetPixel.SetValue(value);
                }
                else
                {
                    // retrieves a source image color
                    Color color = sourcePixel.GetColor();

                    // if alpha is not present in the source image, but is present in the target, make one up
                    if (!hasSourceAlpha && hasTargetAlpha)
                    {
                        Int32 argb = 255 << 24 | color.R << 16 | color.G << 8 | color.B;
                        color = Color.FromArgb(argb);
                    }

                    // sets the color to a target pixel
                    targetPixel.SetColor(color, quantizer);
                }

                // allows to write (obviously) the transformed pixel
                return true;
            };

            // generates the target image
            IList<Point> standardPath = new StandardPathProvider().GetPointPath(Width, Height);
            TransformPerPixelBase(target, standardPath, parallelTaskCount, changeFormat);
        }
Example #4
0
        public static IList <Point> CreatePath(Int32 width, Int32 height)
        {
            StandardPathProvider result = new StandardPathProvider();

            return(result.GetPointPath(width, height));
        }