public void PerformOperations(bool selectedOnly, MultiFrameThreadDirection direction) { try { processing = true; if (operations.Count == 0 || !_dirty) { processing = false; return; } if (originalBitmap == null && originalBitmap.Count == 0) { processing = false; return; } if (initOrigRequired) { InitOperatedOrigBitmaps(); DisposeToBeDisposed(); } initOrigRequired = true; List <Op> currentList = new List <Op>(); lock (operations) { foreach (Op o in operations) { currentList.Add(o); } } int total = currentList.Count; int step = 100 / total; progress = 0; if (selectedOnly && direction == MultiFrameThreadDirection.None) { ReInitOperatedBitmaps(); } else if (direction == MultiFrameThreadDirection.Backward) { _dirty = false; } int start = 0; int end = operatedBitmap.Count; if (!selectedOnly && direction == MultiFrameThreadDirection.Forward) { start = selectedIndex + 1; } else if (!selectedOnly && direction == MultiFrameThreadDirection.Backward) { end = selectedIndex; } for (int i = start; i < end; i++) { if (selectedOnly && i != selectedIndex) { continue; } foreach (Op o in currentList) { Bitmap oldImage = (Bitmap)operatedBitmap[i]; switch (o.OpName) { case OperatorName.ROTATE: Filters.iRotate(oldImage, (RotateFlipType)o.param1); break; case OperatorName.FLIP: Filters.iRotate(oldImage, (RotateFlipType)o.param1); break; case OperatorName.SMOOTH: Filters.Smooth(oldImage, (int)o.param1); break; case OperatorName.EMBOSS: if (o.param1 > 0) { operatedBitmap[i] = Filters.Emboss(oldImage, (int)o.param1); } break; case OperatorName.CONTRAST: Filters.Contrast(oldImage, o.param1); operatedBitmap[i] = (Bitmap)oldImage.Clone(); break; case OperatorName.BRIGHTNESS: Filters.Brightness(oldImage, o.param1); break; //case OperatorName.ZOOM: //if(o.param2 != 0) // operatedBitmap[selectedIndex] = Filters.Resize(oldImage, (float)o.param2); //break; case OperatorName.LUT: if (o.param3.Trim().ToUpper() != "NONE") { string resourceName = "Genetibase.NuGenMediImage" + ".LUTs." + o.param3 + ".LUT"; Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName); Filters.ReadAndApplyLUT(stream, oldImage); stream.Close(); } break; } progress += step; } if (direction == MultiFrameThreadDirection.Forward || direction == MultiFrameThreadDirection.Backward) { if (SliceProccesed != null) { SliceProccesed(this, new SliceEventArgs(i)); } } } try { SetPicBoxImage(); //picBox.Image = operatedBitmap[selectedIndex]; } catch { } //picBox.Refresh(); Application.DoEvents(); } catch (System.Threading.ThreadAbortException) { SetPicBoxImage(); } processing = false; //DisposeToBeDisposed(); //currentList.Clear(); //InitOperatedOrigBitmaps(); //initOrigRequired = false; }
public void PerformOperations(bool selectedOnly, MultiFrameThreadDirection direction) { try { processing = true; if (operations.Count == 0 || !_dirty) { processing = false; return; } if (originalBitmap == null && originalBitmap.Count == 0) { processing = false; return; } if (initOrigRequired) { InitOperatedOrigBitmaps(); DisposeToBeDisposed(); } initOrigRequired = true; List<Op> currentList = new List<Op>(); lock (operations) { foreach (Op o in operations) { currentList.Add(o); } } int total = currentList.Count; int step = 100 / total; progress = 0; if (selectedOnly && direction == MultiFrameThreadDirection.None) { ReInitOperatedBitmaps(); } else if (direction == MultiFrameThreadDirection.Backward) { _dirty = false; } int start = 0; int end = operatedBitmap.Count; if (!selectedOnly && direction == MultiFrameThreadDirection.Forward) { start = selectedIndex + 1; } else if (!selectedOnly && direction == MultiFrameThreadDirection.Backward) { end = selectedIndex; } for (int i = start; i < end; i++) { if (selectedOnly && i != selectedIndex) continue; foreach (Op o in currentList) { Bitmap oldImage = (Bitmap)operatedBitmap[i]; switch (o.OpName) { case OperatorName.ROTATE: Filters.iRotate(oldImage, (RotateFlipType)o.param1); break; case OperatorName.FLIP: Filters.iRotate(oldImage, (RotateFlipType)o.param1); break; case OperatorName.SMOOTH: Filters.Smooth(oldImage, (int)o.param1); break; case OperatorName.EMBOSS: if (o.param1 > 0) { operatedBitmap[i] = Filters.Emboss(oldImage, (int)o.param1); } break; case OperatorName.CONTRAST: Filters.Contrast(oldImage, o.param1); operatedBitmap[i] = (Bitmap)oldImage.Clone(); break; case OperatorName.BRIGHTNESS: Filters.Brightness(oldImage, o.param1); break; //case OperatorName.ZOOM: //if(o.param2 != 0) // operatedBitmap[selectedIndex] = Filters.Resize(oldImage, (float)o.param2); //break; case OperatorName.LUT: if (o.param3.Trim().ToUpper() != "NONE") { string resourceName = "Genetibase.NuGenMediImage" + ".LUTs." + o.param3 + ".LUT"; Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName); Filters.ReadAndApplyLUT(stream, oldImage); stream.Close(); } break; } progress += step; } if (direction == MultiFrameThreadDirection.Forward || direction == MultiFrameThreadDirection.Backward) { if (SliceProccesed != null) { SliceProccesed(this, new SliceEventArgs(i)); } } } try { SetPicBoxImage(); //picBox.Image = operatedBitmap[selectedIndex]; } catch { } //picBox.Refresh(); Application.DoEvents(); } catch (System.Threading.ThreadAbortException) { SetPicBoxImage(); } processing = false; //DisposeToBeDisposed(); //currentList.Clear(); //InitOperatedOrigBitmaps(); //initOrigRequired = false; }