private void LoadInit(MsgCommand mc) { Best = mc.Best; BestComparison = mc.BestComparison; Properties = mc.Properties; Img = mc.Img; WorkingImg = new FastBitmap(Img.Width, Img.Height, PixelFormat.Format24bppRgb); Entropy = mc.Entropy; }
private void SendBestYet() { var msg = new MsgCommand(this, MsgCommandCommands.SaveBestYet) { BestComparison = BestComparison, Best = Best }; _output.Enqueue(msg); }
private void BroadcastBestYet(List <JobCompare> jobs) { foreach (JQJob job in jobs) { MsgCommand msgot = new MsgCommand(null, MsgCommandCommands.LoadBestYet); msgot.BestComparison = CurrentProject.BestComparison; msgot.Best = CurrentProject.BestYet; job.Input.Clear(); job.Input.Enqueue(msgot); } }
public override void Run() { try { while (!_stop) { if (_input.Count > 0) { MsgCommand mc = (MsgCommand)_input.Dequeue(); switch (mc.Command) { case MsgCommandCommands.Init: LoadInit(mc); break; case MsgCommandCommands.LoadBestYet: LoadBestYet(mc); break; case MsgCommandCommands.Stop: _stop = true; break; } } if (Img != null) { if (ProcessIteration()) { SendBestYet(); Thread.Sleep(0); } } Thread.Sleep(0); } CallFinished(new JQEventArgs(this)); } catch (Exception e) { CallError(new JQEventArgs(this), e); } }
private void workerthread() { int lastgen = (int)CurrentProject.BestYet.Generation; DateTime started = DateTime.Now; FastBitmap imagebitmap = new FastBitmap(CurrentProject.SourceImage.Width, CurrentProject.SourceImage.Height, PixelFormat.Format24bppRgb); List <JobCompare> jobs = new List <JobCompare>(); JQMessageQueue results = new JQMessageQueue(); for (int i = 0; i < CurrentProject.Properties.ThreadLimit; i++) { JobCompare job = new JobCompare(); job.Input = new JQMessageQueue(); job.Output = results; jobs.Add(job); MsgCommand msg = new MsgCommand(null, MsgCommandCommands.Init); msg.Best = CurrentProject.BestYet; msg.BestComparison = CurrentProject.BestComparison; msg.Entropy = rd; msg.Img = CurrentProject.SourceImage.Duplicate(); msg.Properties = CurrentProject.Properties; job.Input.Enqueue(msg); control.ScheduleJob(job); } while (!stopthread) { results.Trigger.WaitOne(100); while (results.Count > 0) { MsgCommand msg = (MsgCommand)results.Dequeue(); switch (msg.Command) { case MsgCommandCommands.SaveBestYet: lastiterations++; if (msg.BestComparison < CurrentProject.BestComparison) { ACpG.Update(CurrentProject.BestComparison - msg.BestComparison); AIpG.Update((int)(lastiterations - CurrentProject.BestYet.Iterations)); lastjobbest = jobs.IndexOf((JobCompare)msg.Job); CurrentProject.BestYet = msg.Best; CurrentProject.BestComparison = msg.BestComparison; CurrentProject.Changed = true; CurrentProject.BestYet.Generation++; CurrentProject.BestYet.Iterations = lastiterations; } break; } } TimeSpan sofar = DateTime.Now - started; if (sofar.TotalMilliseconds > 1000) { CurrentProject.BestYet.DrawToFastBitmap(imagebitmap); DisplayImageBitmap(imagebitmap); changed = true; started = DateTime.Now; BroadcastBestYet(jobs); Gps.Update((int)CurrentProject.BestYet.Generation - lastgen); lastgen = (int)CurrentProject.BestYet.Generation; GC.Collect(); } } foreach (JQJob job in jobs) { MsgCommand msgot = new MsgCommand(null, MsgCommandCommands.Stop); job.Input.Enqueue(msgot); } stopthread = false; }
private void LoadBestYet(MsgCommand mc) { Best = mc.Best; BestComparison = mc.BestComparison; }