private void RedoRedEyeButtonClickHandler(object sender, RoutedEventArgs e) { if (_redEyeRemovalStep == 2) { if (_manualRedEyeIndex < _redEyeTransform.Transforms.Count) { _manualRedEyeIndex++; _redEyeBitmap.Redo(); _frame.Photo.Source = PhotoItem.CreateBitmapSource(CreatePreviewBitmap(_redEyeBitmap, Aurigma.GraphicsMill.Transforms.ResizeMode.Fit)); _undoRedEyeButton.IsEnabled = _redEyeBitmap.CanUndo; _redoRedEyeButton.IsEnabled = _redEyeBitmap.CanRedo; _stepDescription.Text = (string)FindResource(Constants.ImageEditorRedEyeStep3TextKey); if (_manualRedEyeIndex > 0) { _applyRedEyeButton.IsEnabled = true; } } } else { throw new Exception("Internal state error. RedoRedEyeButtonClickHandler."); } }
public object Clone() { CheckDisposedState(); PhotoItem item = new PhotoItem(_sourceFileName); item._itemState = _itemState; item._imageSize = _imageSize; lock (this) { if (_exifThumbnail != null) { item._exifThumbnail = new Bitmap(); item._exifThumbnail.Create(_exifThumbnail); } if (_image != null) { item._image = new Bitmap(); item._image.Create(_image); } } item._hddFileName = _hddFileName; return(item); }
// Why thread sync is absent here: // RegisterItemAccessTime is called only during BitmapSource requesting. // GUI changes can be made only from owner WPF thread => only one WPF thread can // get BitmapSource => thread sync is not necessary at this time. // I hope so... // Eugene Kosmin public void RegisterItemAccessTime(PhotoItem item) { int oldItemIndex = _lastAccessedItems.FindIndex(delegate(KeyValuePair <PhotoItem, int> itemToCompare) { return(itemToCompare.Key == item); }); if (oldItemIndex >= 0) { _memoryAllocatedForItems += item.MemoryUsed - _lastAccessedItems[oldItemIndex].Value; _lastAccessedItems.RemoveAt(oldItemIndex); _lastAccessedItems.Add(new KeyValuePair <PhotoItem, int>(item, item.MemoryUsed)); } else { _lastAccessedItems.Add(new KeyValuePair <PhotoItem, int>(item, item.MemoryUsed)); _memoryAllocatedForItems += item.MemoryUsed; } if (_memoryAllocatedForItems >= _maxCacheSize) { DisposeLastPhotoItems(); } }
private void ManualRedEyeButtonClickHandler(object sende, RoutedEventArgs e) { _pointAdorner.Visibility = Visibility.Visible; _pointAdorner.Point = new Point(_frame.Photo.ActualWidth / 2, _frame.Photo.ActualHeight / 2); _removeRedEyeButton.Visibility = Visibility.Visible; _manualRedEyeButton.Visibility = Visibility.Collapsed; _nextRedEyeButton.Visibility = Visibility.Collapsed; _applyRedEyeButton.IsEnabled = false; _redEyeBitmap.Undo(); _transformIndex--; _redEyeBitmap.ClearHistory(); _redEyeTransform.Transforms.Clear(); _manualRedEyeIndex = 0; _undoRedEyeButton.IsEnabled = _redEyeBitmap.CanUndo; _redoRedEyeButton.IsEnabled = _redEyeBitmap.CanRedo; _stepDescription.Text = (string)FindResource(Constants.ImageEditorRedEyeStep3TextKey); _frame.Photo.MouseLeftButtonDown += new MouseButtonEventHandler(ManualRedEyeClickHandler); _frame.Photo.Source = PhotoItem.CreateBitmapSource(CreatePreviewBitmap(_redEyeBitmap, Aurigma.GraphicsMill.Transforms.ResizeMode.Fit)); _redEyeRemovalStep = 2; }
public override void Activate(ExecutionEngine engine) { if (ExecutionEngine.Context.Contains(Constants.OrderContextName)) { _currentOrder = (Order)ExecutionEngine.Context[Constants.OrderContextName]; } // Adding photo from Image Editor. if (ExecutionEngine.Context.Contains(Constants.ImageEditorResultKey)) { PhotoItem imageEditorItem = (PhotoItem)ExecutionEngine.Context[Constants.ImageEditorResultKey]; imageEditorItem.CreateCacheData(); ThumbnailItem imageEditorResult = new ThumbnailItem(imageEditorItem); imageEditorResult.HostList = _orderFormingScreen.ListControl.List; ExecutionEngine.Context.Remove(Constants.ImageEditorResultKey); imageEditorResult.SetCheckedProperty(true); _currentOrder.OrderItems.Add(imageEditorResult.Order); imageEditorResult.Order.Reset(); _orderFormingScreen.ListControl.List.AddItem(imageEditorResult); } base.Activate(engine); ExecutionEngine.EventLogger.Write("SelectStage:Activate"); }
private void RefreshPreview() { _undoButton.IsEnabled = _previewBitmap.CanUndo; _redoButton.IsEnabled = _previewBitmap.CanRedo; _frame.Photo.Source = PhotoItem.CreateBitmapSource(_previewBitmap); _frame.Update(); }
private void BlackWhiteEffectButtonClickHandler(object sender, RoutedEventArgs e) { _tmpBitmap = (Aurigma.GraphicsMill.Bitmap)_previewBitmap.Clone(); _tmpBitmap.ColorAdjustment.Desaturate(); _frame.Photo.Source = PhotoItem.CreateBitmapSource(_tmpBitmap); _applyEffectButton.IsEnabled = true; _effect = EffectTransforms.BlackAndWhite; }
public ThumbnailItem(PhotoItem photo) { if (photo == null) { throw new ArgumentNullException("photo"); } _photo = photo; _orderItem = new OrderItem(_photo); }
private void SepiaButtonClickHandler(object sender, RoutedEventArgs e) { _tmpBitmap = (Aurigma.GraphicsMill.Bitmap)_previewBitmap.Clone(); _tmpBitmap.ColorAdjustment.Desaturate(); Single[] objColorBalance = { 0F, 0.05F, 0.1F, 0F }; _tmpBitmap.ColorAdjustment.ChannelBalance(objColorBalance); _frame.Photo.Source = PhotoItem.CreateBitmapSource(_tmpBitmap); _applyEffectButton.IsEnabled = true; _effect = EffectTransforms.Sepia; }
public OrderItem(PhotoItem item) { if (item == null) { throw new ArgumentNullException("item"); } _photoItem = item; _photoCounts = new Dictionary <PaperFormat, int>(ExecutionEngine.Instance.PaperFormats.Count); _photoCrops = new Dictionary <PaperFormat, Rect>(ExecutionEngine.Instance.PaperFormats.Count); foreach (PaperFormat format in ExecutionEngine.Instance.PaperFormats) { _photoCounts.Add(format, 0); _photoCrops.Add(format, new Rect()); } _imprintsCountText = new OutlinedText(); _imprintsCountText.Style = (Style)_imprintsCountText.FindResource("ImprintsCountTextStyle"); _imageCommandButton = new Button(); _imageCommandButton.Style = (Style)_imageCommandButton.FindResource("ImageCommandButtonStyle"); var grid = new Grid(); grid.Width = 60; grid.Height = 60; grid.RowDefinitions.Add(new RowDefinition()); grid.RowDefinitions[0].Height = new GridLength(40); grid.RowDefinitions.Add(new RowDefinition()); grid.RowDefinitions[1].Height = new GridLength(20); _imageCommandImage = new Image(); _imageCommandImage.Stretch = Stretch.None; Grid.SetRow(_imageCommandImage, 0); _imageCommandText = new TextBlock(); _imageCommandText.Margin = new Thickness(3, -5, 3, 0); _imageCommandText.Style = (Style)_imageCommandText.FindResource("ImageCommandTextStyle"); _imageCommandText.VerticalAlignment = VerticalAlignment.Center; _imageCommandText.HorizontalAlignment = HorizontalAlignment.Center; _imageCommandText.TextAlignment = TextAlignment.Center; _imageCommandText.LineHeight = 10; _imageCommandText.LineStackingStrategy = LineStackingStrategy.BlockLineHeight; Grid.SetRow(_imageCommandText, 1); grid.Children.Add(_imageCommandImage); grid.Children.Add(_imageCommandText); _imageCommandButton.Content = grid; }
private void BrightnessContrast() { if ((bool)_autoLevelsCheckBox.IsChecked) { _tmpBitmap = (Aurigma.GraphicsMill.Bitmap)_autoLevelsBitmap.Clone(); } else { _tmpBitmap = (Aurigma.GraphicsMill.Bitmap)_previewBitmap.Clone(); } _tmpBitmap.ColorAdjustment.BrightnessContrast(_brightnessAmount, _contrastAmount); _frame.Photo.Source = PhotoItem.CreateBitmapSource(_tmpBitmap); _applyColorButton.IsEnabled = true; }
public string CacheThumbnail(PhotoItem item) { if (item == null) { throw new ArgumentNullException("item"); } if (item.Image != null && !item.Image.IsEmpty) { string newFileName = GenerateEditedFileName(); item.Image.Save(newFileName, new JpegEncoderOptions()); return(newFileName); } else { throw new Aurigma.GraphicsMill.Exception("There is no Thumbnail to cache."); } }
private void AutoLevelsButtonClickHandler(object sender, RoutedEventArgs e) { if (_brightnessAmount == 0 && _contrastAmount == 0) { if ((bool)_autoLevelsCheckBox.IsChecked) { _frame.Photo.Source = PhotoItem.CreateBitmapSource(_autoLevelsBitmap); } else { _frame.Photo.Source = PhotoItem.CreateBitmapSource(_previewBitmap); } _applyColorButton.IsEnabled = true; } else { BrightnessContrast(); } }
public string CacheSource(PhotoItem item) { if (item == null) { throw new ArgumentNullException("item"); } string cachedFileName; lock (_cachedSources) { if (_cachedSources.Contains(item.SourceFileName)) { cachedFileName = (string)_cachedSources[item.SourceFileName]; } else { cachedFileName = GenerateSourceFileName(); try { File.Copy(item.SourceFileName, cachedFileName); File.SetAttributes(cachedFileName, FileAttributes.Temporary); _cachedSources.Add(item.SourceFileName, cachedFileName); } catch (IOException e) { ExecutionEngine.EventLogger.WriteExceptionInfo(e); } catch (Exception e) { ExecutionEngine.EventLogger.WriteExceptionInfo(e); throw; } } } return(cachedFileName); }
private void RemoveRedEyeButtonClickHandler(object sender, RoutedEventArgs e) { if (_redEyeRemovalStep == 2) { float x = (float)(_pointAdorner.Point.X * (_redEyeBitmap.Width / _frame.Photo.ActualWidth)); float y = (float)(_pointAdorner.Point.Y * (_redEyeBitmap.Height / _frame.Photo.ActualHeight)); var redEyePoint = new System.Drawing.PointF(x, y); if (_manualRedEyeIndex < _redEyeTransform.Transforms.Count) { _redEyeTransform.Transforms[_manualRedEyeIndex] = new ManualRedEyeRemoval(_redEyeRect, redEyePoint); } else { _redEyeTransform.Transforms.Add(new ManualRedEyeRemoval(_redEyeRect, redEyePoint)); } _manualRedEyeIndex++; using (var manualModeTransform = new Aurigma.GraphicsMill.Transforms.RedEyeRemoval()) { manualModeTransform.Mode = Aurigma.GraphicsMill.Transforms.RedEyeRemovalMode.Manual; manualModeTransform.EyePoint = redEyePoint; manualModeTransform.ApplyTransform(_redEyeBitmap); } _frame.Photo.Source = PhotoItem.CreateBitmapSource(CreatePreviewBitmap(_redEyeBitmap, Aurigma.GraphicsMill.Transforms.ResizeMode.Fit)); _undoRedEyeButton.IsEnabled = _redEyeBitmap.CanUndo; _redoRedEyeButton.IsEnabled = _redEyeBitmap.CanRedo; _stepDescription.Text = (string)FindResource(Constants.ImageEditorRedEyeStep3TextKey); _applyRedEyeButton.IsEnabled = true; } else { throw new System.Exception("Internal state error. RemoveRedEyeButtonClickHandler."); } }
private void TimerTickHandler(object sender, EventArgs e) { _elapsedTime += _timer.Interval.TotalMilliseconds; if (!_timer.IsEnabled || !_photosFound) { return; } // No files at all if (_files.Count == 0) { _isThreadAlive = false; _timer.Stop(); if (_photosToRemove.Count != 0) { ExecutionEngine.Context[Constants.PhotosToRemove] = _photosToRemove; } MessageDialog.Show((string)ExecutionEngine.Instance.Resource[Constants.MessageNoFilesFoundKey]); if (Engine.IsShowFolders) { SwitchToSelectFoldersScreen(); } else if (ExecutionEngine.Config.IsBluetoothEnabled()) { SwitchToSelectDeviceScreen(); } else { SwitchToWelcomeScreen(); } return; } // No new files if (_photoItems.Count == 0) { _timer.Stop(); _isThreadAlive = false; SwitchToSelectPhotos(); return; } Bitmap exifSource = null; lock (_exifSources) { if (_exifSources.Count > 0) { exifSource = _exifSources[0]; _exifSources.RemoveAt(0); } } if (exifSource != null) { _progressScreen.AddPreviewPhoto(PhotoItem.CreateBitmapSource(exifSource)); } _progressScreen._progressBar.Value++; if (_elapsedTime >= ExecutionEngine.Config.SearchProcessDuration.Value) { _timer.Stop(); _isThreadAlive = false; SwitchToSelectPhotos(); } }
private void NextRedEyeButtonClickHandler(object sender, RoutedEventArgs e) { // The first step. Auto red eye removal if (_redEyeRemovalStep == 0) { _redEyeBitmap = (Aurigma.GraphicsMill.Bitmap)_sourceBitmap.Clone(); if (!TransformBitmap(_redEyeBitmap)) { return; } _redEyeBitmap.UndoRedoEnabled = true; float x = (float)(_rectangleAdorner.Rectangle.X * (_redEyeBitmap.Width / _frame.Photo.ActualWidth)); float y = (float)(_rectangleAdorner.Rectangle.Y * (_redEyeBitmap.Height / _frame.Photo.ActualHeight)); float width = (float)(_rectangleAdorner.Rectangle.Width * (_redEyeBitmap.Width / _frame.Photo.ActualWidth)); float height = (float)(_rectangleAdorner.Rectangle.Height * (_redEyeBitmap.Height / _frame.Photo.ActualHeight)); _redEyeRect = new System.Drawing.RectangleF(x, y, width, height); _redEyeBitmap.Transforms.Crop(_redEyeRect); _progressDialog = new ProgressDialog((string)ExecutionEngine.Instance.Resource[Constants.MessageTransformImageKey]); var workerThread = new Thread(new ParameterizedThreadStart(DoAutoRedEye)); workerThread.Start((object)_redEyeBitmap); DateTime showDialogTime = DateTime.Now.AddSeconds(Constants.ProgressDialogTimeout); while (DateTime.Now.Second < showDialogTime.Second) { if (_progressDialog.IsComplete) { break; } } if (!_progressDialog.IsComplete) { _progressDialog.ShowDialog(); if (!_progressDialog.DialogResult.Value) { return; } } _redEyeTransform.Transforms.Add(new AutoRedEyeRemoval(_redEyeRect)); RegisterTransform(_redEyeTransform); _frame.Photo.Source = PhotoItem.CreateBitmapSource(CreatePreviewBitmap(_redEyeBitmap, Aurigma.GraphicsMill.Transforms.ResizeMode.Fit)); _rectangleAdorner.Visibility = Visibility.Collapsed; _pointAdorner.Visibility = Visibility.Collapsed; _manualRedEyeButton.Visibility = Visibility.Visible; _applyRedEyeButton.IsEnabled = true; _nextRedEyeButton.Visibility = Visibility.Collapsed; _removeRedEyeButton.Visibility = Visibility.Collapsed; _stepDescription.Text = (string)FindResource(Constants.ImageEditorRedEyeStep2TextKey); _redEyeRemovalStep = 1; } else { throw new System.Exception("Internal state error. NextRedEyeButtonClickHandler"); } }