Exemple #1
0
        protected override void DoWork_impl()
        {
            // TODO: using bit locking

            // TODO: this is a pretty lame averaging method. it only looks at the row/column of the pixel...not a rectangle or elipse around each pixel

            Bitmap newImage = new Bitmap(mSourceImage.Bitmap.Width, mSourceImage.Bitmap.Height);
            long   sumR     = 0;
            long   sumG     = 0;
            long   sumB     = 0;
            double averageR;
            double averageG;
            double averageB;
            int    numPixels = (XAxisRadius * 2) + (YAxisRadius * 2) + 2; // we actually count the center dot twice! oops
            Color  color;

            for (int newX = 0 + XAxisRadius; newX < newImage.Width - XAxisRadius; newX++)
            {
                for (int newY = 0 + YAxisRadius; newY < newImage.Height - YAxisRadius; newY++)
                {
                    sumR = 0;
                    sumG = 0;
                    sumB = 0;
                    for (int oldX = newX - XAxisRadius; oldX <= newX + XAxisRadius; oldX++)
                    {
                        color = mSourceImage.Bitmap.GetPixel(oldX, newY);
                        sumR += color.R;
                        sumG += color.G;
                        sumB += color.B;
                    }
                    for (int oldY = newY - YAxisRadius; oldY <= newY + YAxisRadius; oldY++)
                    {
                        color = mSourceImage.Bitmap.GetPixel(newX, oldY);
                        sumR += color.R;
                        sumG += color.G;
                        sumB += color.B;
                    }
                    averageR = (double)sumR / (double)numPixels;
                    averageG = (double)sumG / (double)numPixels;
                    averageB = (double)sumB / (double)numPixels;
                    color    = Color.FromArgb((int)averageR, (int)averageG, (int)averageB);
                    newImage.SetPixel(newX, newY, color);
                }
            }

            mSmoothedImage.SetImage(newImage);
            mSmoothedImage.SetIsComplete();
        }
        public void ProcessNewImage(Bitmap theImage, string fileName)
        {
            if (mWorkerLogMessageAvailable)
            {
                TestExecution().LogMessageWithTimeFromTrigger("Snapshot worker after completed: " + mWorkerLogMessage);
                mWorkerLogMessageAvailable = false;
            }

            TestExecution().LogMessageWithTimeFromTrigger(Name + " acquired image from '" + fileName + "'");

            mSnapshotImage.SetImageGenerator(this);
            mSnapshotImage.SetSource(fileName);
            mSnapshotImage.SetImage(theImage);
            mSnapshotImage.SetIsComplete();
            TestExecution().LogMessageWithTimeFromTrigger("Snapshot complete");
        }