Пример #1
0
        private void ProcessPerPixelBase(IList <Point> path, Delegate processingAction, Int32 parallelTaskCount = 4)
        {
            // checks parameters
            Guard.CheckNull(path, "path");
            Guard.CheckNull(processingAction, "processPixelFunction");

            // determines mode
            Boolean isAdvanced = processingAction is ProcessPixelAdvancedFunction;

            // prepares the per pixel task
            Action <LineTask> processPerPixel = lineTask =>
            {
                // initializes variables per task
                Pixel pixel = new Pixel(this);

                for (Int32 pathOffset = lineTask.StartOffset; pathOffset < lineTask.EndOffset; pathOffset++)
                {
                    Point   point = path[pathOffset];
                    Boolean allowWrite;

                    // enumerates the pixel, and returns the control to the outside
                    pixel.Update(point.X, point.Y);

                    // when read is allowed, retrieves current value (in bytes)
                    if (CanRead)
                    {
                        ReadPixel(pixel);
                    }

                    // process the pixel by custom user operation
                    if (isAdvanced)
                    {
                        ProcessPixelAdvancedFunction processAdvancedFunction = (ProcessPixelAdvancedFunction)processingAction;
                        allowWrite = processAdvancedFunction(pixel, this);
                    }
                    else // use simplified version with pixel parameter only
                    {
                        ProcessPixelFunction processFunction = (ProcessPixelFunction)processingAction;
                        allowWrite = processFunction(pixel);
                    }

                    // when write is allowed, copies the value back to the row buffer
                    if (CanWrite && allowWrite)
                    {
                        WritePixel(pixel);
                    }
                }
            };

            // processes image per pixel
            ProcessInParallel(path, processPerPixel, parallelTaskCount);
        }
Пример #2
0
 public void ProcessPerPixelAdvanced(IList<Point> path, ProcessPixelAdvancedFunction processPixelAdvancedFunction, Int32 parallelTaskCount = 4)
 {
     ProcessPerPixelBase(path, processPixelAdvancedFunction, parallelTaskCount);
 }
Пример #3
0
 public void ProcessPerPixelAdvanced(IList <Point> path, ProcessPixelAdvancedFunction processPixelAdvancedFunction, Int32 parallelTaskCount = 4)
 {
     ProcessPerPixelBase(path, processPixelAdvancedFunction, parallelTaskCount);
 }
Пример #4
0
        private void ProcessPerPixelBase(IList <Point> path = null, Int32 parallelTaskCount = 4, params Delegate[] passes)
        {
            // checks parameters
            Guard.CheckNull(passes, "passes");

            // determines mode
            Boolean isAdvanced = passes.Length > 0 && passes[0] is ProcessPixelAdvancedFunction;

            // creates default path, if none is available
            if (path == null)
            {
                path = StandardPathProvider.CreatePath(Width, Height);
            }

            // prepares the per pixel task
            Action <LineTask> processPerPixel = lineTask =>
            {
                // initializes variables per task
                Pixel    pixel = CreatePixel();
                Delegate pass  = passes[lineTask.PassIndex];

                for (Int32 pathOffset = lineTask.StartOffset; pathOffset < lineTask.EndOffset; pathOffset++)
                {
                    Point   point = path[pathOffset];
                    Boolean allowWrite;

                    // enumerates the pixel, and returns the control to the outside
                    pixel.Update(point.X, point.Y);

                    // when read is allowed, retrieves current value (in bytes)
                    if (CanRead)
                    {
                        ReadPixel(pixel);
                    }

                    // process the pixel by custom user operation
                    if (isAdvanced)
                    {
                        ProcessPixelAdvancedFunction processAdvancedFunction = (ProcessPixelAdvancedFunction)pass;
                        allowWrite = processAdvancedFunction(lineTask.PassIndex, pixel, this);
                    }
                    else // use simplified version with pixel parameter only
                    {
                        ProcessPixelFunction processFunction = (ProcessPixelFunction)pass;
                        allowWrite = processFunction(lineTask.PassIndex, pixel);
                    }

                    // when write is allowed, copies the value back to the row buffer
                    if (CanWrite && allowWrite)
                    {
                        WritePixel(pixel);
                    }
                }
            };

            // processes image per pixel
            for (Int32 passIndex = 0; passIndex < passes.Length; passIndex++)
            {
                ProcessInParallel(passIndex, processPerPixel, path, parallelTaskCount);
            }
        }