示例#1
0
        public override Bitmap Run()
        {
            int width  = image.Width;
            int height = image.Height;

            int stripHeight     = height / strips;
            int lastStripHeight = stripHeight + height % strips;

            Async[] stages = new PipelineStage[filters.Length];

            Address next = Address;

            for (int i = filters.Length - 1; i >= 0; i--)
            {
                Async stage = new PipelineStage(filters[i], strips, next).Start();
                stages[i] = stage;
                next      = stage.Address;
            }

            Address first = stages[0].Address;

            int[] pixels       = ImageProcessing.GetPixels(image);
            int[] resultPixels = new int[width * height];

            for (int i = 0; i < strips - 1; i++)
            {
                int yStart = i * stripHeight;
                int yEnd   = yStart + stripHeight;
                Send(new PipelineJob(pixels, resultPixels, width, height, yStart, yEnd), first);
            }

            int yStartLast = (strips - 1) * stripHeight;
            int yEndLast   = yStartLast + lastStripHeight;

            Send(new PipelineJob(pixels, resultPixels, width, height, yStartLast, yEndLast), first);

            PipelineJob job = null;

            for (int i = 0; i < strips; i++)
            {
                job = Receive <PipelineJob>();
            }

            Bitmap result = new Bitmap(width, height);

            ImageProcessing.SetPixels(result, job.srcImage);
            return(result);
        }