예제 #1
0
        public static void ProcessPixels(ArgbColor[] pixelData, Size size, IPixelTransform pixelTransform, IErrorDiffusion dither)
        {
            ArgbColor current;
            ArgbColor transformed;
            int       index;

            for (int row = 0; row < size.Height; row++)
            {
                for (int col = 0; col < size.Width; col++)
                {
                    index   = row * size.Width + col;
                    current = pixelData[index];

                    // transform the pixel
                    if (pixelTransform != null)
                    {
                        transformed      = pixelTransform.Transform(pixelData, current, col, row, size.Width, size.Height);
                        pixelData[index] = transformed;
                    }
                    else
                    {
                        transformed = current;
                    }

                    // apply a dither algorithm to this pixel
                    // assuming it wasn't done before
                    dither?.Diffuse(pixelData, current, transformed, col, row, size.Width, size.Height);
                }
            }
        }
예제 #2
0
        public static void ProcessPixels(Color[] pixelData, Size size, IPixelTransform pixelTransform, IErrorDiffusion dither, WorkerData bw = null)
        {
            Color current;
            Color transformed;
            int   index = 0;

            for (int row = 0; row < size.Height; row++)
            {
                for (int col = 0; col < size.Width; col++)
                {
                    if (bw != null && bw.Worker.CancellationPending == true)
                    {
                        bw.Args.Cancel = true;
                        return;
                    }

                    current = pixelData[index];

                    if (pixelTransform != null)
                    {
                        transformed      = pixelTransform.Transform(current);
                        pixelData[index] = transformed;
                    }
                    else
                    {
                        transformed = current;
                    }
                    index++;

                    // apply a dither algorithm to this pixel
                    // assuming it wasn't done before
                    dither?.Diffuse(pixelData, current, transformed, col, row, size.Width, size.Height);
                }
            }
        }
예제 #3
0
        public void AddTransform(IPixelTransform transform)
        {
            if (source.IsValueCreated)
            {
                throw new NotSupportedException("A Transform cannot be added once the Pipeline Source is materialized");
            }

            if (transform is IPixelTransformInternal tint)
            {
                tint.Init(Context);
                return;
            }

            transform.Init(Context.Source.AsIPixelSource());
            Context.Source = transform.AsPixelSource();
        }
예제 #4
0
        /// <summary>Adds a new transform filter to the pipeline.  Because a filter may alter dimensions or pixel format of an image, filters may not be added once the <see cref="PixelSource" /> has been retrieved.</summary>
        /// <param name="transform">The <see cref="IPixelTransform" /> that implements the filter.</param>
        public ProcessingPipeline AddTransform(IPixelTransform transform)
        {
            if (source.IsValueCreated)
            {
                throw new NotSupportedException("A Transform cannot be added once the Pipeline Source is materialized");
            }

            if (transform is IPixelTransformInternal tint)
            {
                tint.Init(Context);
                return(this);
            }

            MagicTransforms.AddExternalFormatConverter(Context);

            transform.Init(Context.Source.AsIPixelSource());
            Context.Source = transform.AsPixelSource();
            return(this);
        }
예제 #5
0
        public static Bitmap RequestImageTransform(Bitmap image, IPixelTransform transform, IErrorDiffusion ditherer)
        {
            WorkerData workerData;

            if (image.PixelFormat != System.Drawing.Imaging.PixelFormat.Format32bppArgb)
            {
                using (Bitmap tmp = image)
                {
                    image = tmp.Copy();
                }
            }

            workerData = new WorkerData
            {
                Image     = image,
                Transform = transform,
                Dither    = ditherer
            };

            return(backgroundWorker_RunWorkerCompleted(null, new RunWorkerCompletedEventArgs(GetTransformedImage(workerData), null, false)));
        }