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();
        }
        //private bool mRequestedSnapshot = false;
        protected override void DoWork_impl()
        {
            if (mWorkerLogMessageAvailable)
            {
                TestExecution().LogMessageWithTimeFromTrigger("Snapshot worker: " + mWorkerLogMessage);
                mWorkerLogMessageAvailable = false;
            }

            if (IsComplete()) // this is (currently) needed as a hack for the times when images are loaded via drag & drop.  The drag & drop event loads the image and sets the IsComplete, but the TestExecution doesn't remove it from the execution array until AFTER DoWork() is called...so it is called an extra time...and the loaded image gets lost
            {
                return;
            }

            if (mWorker != null)
            {
                // TODO: throw an exception if it is not busy?  log something when it stops being busy? after it stops being busy this object will get marked completed and shouldn't be called again
                return;
            }

            if (mPrerequisite != null && !mPrerequisite.ValueAsBoolean())
            {
                TestExecution().LogMessageWithTimeFromTrigger(Name + ": prerequisites not met. Skipping.");
                mSnapshotImage.SetIsComplete(); // need to set this since this snapshot tool uses it for its IsComplete method
            }
            else
            {
                //mRequestedSnapshot = true;
                TestExecution().LogMessageWithTimeFromTrigger("Requesting snapshot");

                //CameraSnapshotDefinition theDefinition = (CameraSnapshotDefinition)Definition();

                if (mCameraSnapshotDefintion.DragAndDropFileNames.Count > 0)
                {
                    string filename = mCameraSnapshotDefintion.DragAndDropFileNames.Dequeue();
                    string ext      = Path.GetExtension(filename).ToLower();
                    if ((ext == ".jpg") || (ext == ".png") || (ext == ".bmp"))
                    {
                        // load image from disk
                        Bitmap theImage = new Bitmap(filename);

                        // set result image of instance in active test execution
                        ProcessNewImage(theImage, filename);
                    }
                }
                else if (mCameraSnapshotDefintion.NumberOfImagesAvailableForRetesting() > 0)
                {
                    ProcessNewImage(mCameraSnapshotDefintion.GetImageToRetest(), "Retest");
                }
                else
                {
                    switch (mCameraSnapshotDefintion.SimulationMode)
                    {
                    case CameraSnapshotDefinition.SimulationModes.Directory_Loop:
                        // TODO: make a way for file names to be passed to ProcessNewImage()...maybe by calling ProcessNewImage() from within theDefinition.Get___Image()
                        ProcessNewImage(mCameraSnapshotDefintion.GetNextSimulatedImage(true), "SIMULATION");     // this marks the instance complete
                        break;

                    case CameraSnapshotDefinition.SimulationModes.Directory_Sequence:
                        ProcessNewImage(mCameraSnapshotDefintion.GetNextSimulatedImage(false), "SIMULATION");     // this marks the instance complete
                        break;

                    case CameraSnapshotDefinition.SimulationModes.Directory_Random:
                        ProcessNewImage(mCameraSnapshotDefintion.GetRandomSimulatedImage(), "SIMULATION");     // this marks the instance complete
                        break;

                    case CameraSnapshotDefinition.SimulationModes.Off:

                        mWorker = new HTTPImageGetter(this);
                        mWorker.RunWorkerAsync();

                        break;

                    default:
                        throw new ArgumentException("Current simulation mode isn't supported. 38479");
                    }
                }
            }
            // thread pooling: http://www.c-sharpcorner.com/UploadFile/mmehta/Multithreading411162005051609AM/Multithreading4.aspx?ArticleID=a3d4a3e9-533e-49c3-9fda-5bb6a7359953
        }