Example #1
0
        private void LightnessMenu_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (_hslValues == null)
                {
                    _hslValues = HslSpace.RgbToHsl(_rgbValues);
                }

                if (_lightnessBms == null)
                {
                    var newJpegBytes = new byte[BmsEngine.DataLength];
                    for (var i = 0; i < BmsEngine.DataLength; i += 4)
                    {
                        newJpegBytes[i + (int)Rgb.Red]          =
                            newJpegBytes[i + (int)Rgb.Green]    =
                                newJpegBytes[i + (int)Rgb.Blue] = (byte)(_hslValues[i + (int)Hsl.Lightness] * 255);
                    }
                    _lightnessBms = BmsEngine.CloneBms(newJpegBytes);
                }
                ImgPhoto.Source = _lightnessBms;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Eroare: " + ex.Message, "Efecte poze", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Example #2
0
 private void OpenMenu_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         var op = new OpenFileDialog
         {
             RestoreDirectory = true,
             InitialDirectory = "C:\\",
             FilterIndex      = 1,
             Title            = "Alegeti poza",
             Filter           = "|*.jpg;*.jpeg;*.png|" +
                                "(*.jpg;*.jpeg)|*.jpg;*.jpeg|" +
                                "(*.png)|*.png"
         };
         if (op.ShowDialog() == true)
         {
             Stream imageStreamSource = new FileStream(op.FileName, FileMode.Open, FileAccess.Read,
                                                       FileShare.Read);
             //PixelFormat
             var decoder = new JpegBitmapDecoder(imageStreamSource, BitmapCreateOptions.None,
                                                 BitmapCacheOption.Default);
             BitmapSource bitmapSource = decoder.Frames[0];
             BmsEngine.Init(bitmapSource);
             ImgPhoto.Source = _rgbBms = bitmapSource;
             _rgbValues      = BmsEngine.GetRgbData();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Eroare: " + ex.Message, "Efecte poze", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Example #3
0
        private void BlackMenu_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (_cmykValues == null)
                {
                    _cmykValues = CmykSpace.RgbToCmyk(_rgbValues);
                }

                if (_blackBms == null)
                {
                    var newJpegBytes = new byte[BmsEngine.DataLength];
                    for (var i = 0; i < BmsEngine.DataLength; i += 4)
                    {
                        newJpegBytes[i + (int)Rgb.Blue]        =
                            newJpegBytes[i + (int)Rgb.Green]   =
                                newJpegBytes[i + (int)Rgb.Red] =
                                    (byte)Math.Min(255.0, (255 * (1.0 - _cmykValues[i + (int)Cmyk.Black])));
                    }
                    _blackBms = BmsEngine.CloneBms(newJpegBytes);
                }
                ImgPhoto.Source = _blackBms;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Eroare: " + ex.Message, "Efecte poze", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Example #4
0
 private void DesaturateMenu_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (_desaturateBms == null)
         {
             var newJpegBytes = BmsEngine.GetRgbData();
             for (var i = 0; i < BmsEngine.DataLength; i += 4)
             {
                 var minRgb = Math.Min(Math.Min(_rgbValues[i + (int)Rgb.Blue], _rgbValues[i + (int)Rgb.Green]),
                                       _rgbValues[i + (int)Rgb.Red]);
                 var maxRgb = Math.Max(Math.Max(_rgbValues[i + (int)Rgb.Blue], _rgbValues[i + (int)Rgb.Green]),
                                       _rgbValues[i + (int)Rgb.Red]);
                 var desatVal = (byte)((minRgb + maxRgb) / 2);
                 newJpegBytes[i + (int)Rgb.Blue]  = desatVal;
                 newJpegBytes[i + (int)Rgb.Green] = desatVal;
                 newJpegBytes[i + (int)Rgb.Red]   = desatVal;
             }
             _desaturateBms = BmsEngine.CloneBms(newJpegBytes);
         }
         ImgPhoto.Source = _desaturateBms;
     }
     catch (Exception ex)
     {
         MessageBox.Show("Eroare: " + ex.Message, "Efecte poze", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Example #5
0
 private void HslToRGBMenu_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (_hslValues == null)
         {
             _hslValues = HslSpace.RgbToHsl(_rgbValues);
         }
         if (_hslToRgbBms == null)
         {
             var newJpegBytes = HslSpace.HslToRgb(_hslValues);
             _hslToRgbBms = BmsEngine.CloneBms(newJpegBytes);
         }
         ImgPhoto.Source = _hslToRgbBms;
     }
     catch (Exception ex)
     {
         MessageBox.Show("Eroare: " + ex.Message, "Efecte poze", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Example #6
0
 private void YellowMenu_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (_yellowBms == null)
         {
             var newJpegBytes = BmsEngine.GetRgbData();
             for (var i = 0; i < BmsEngine.DataLength; i += 4)
             {
                 newJpegBytes[i + (int)Rgb.Blue] = 0;  //Yellow=R+G;
             }
             _yellowBms = BmsEngine.CloneBms(newJpegBytes);
         }
         ImgPhoto.Source = _yellowBms;
     }
     catch (Exception ex)
     {
         MessageBox.Show("Eroare: " + ex.Message, "Efecte poze", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Example #7
0
 private void GrayMenu_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (_grayBms == null)
         {
             var newJpegBytes = BmsEngine.GetRgbData();
             for (var i = 0; i < BmsEngine.DataLength; i += 4)
             {
                 var grayVal = 0.114 * _rgbValues[i + (int)Rgb.Blue] + 0.587 * _rgbValues[i + (int)Rgb.Green] +
                               0.299 * _rgbValues[i + (int)Rgb.Red];
                 newJpegBytes[i + (int)Rgb.Blue]  = (byte)grayVal; //blue
                 newJpegBytes[i + (int)Rgb.Green] = (byte)grayVal; //green
                 newJpegBytes[i + (int)Rgb.Red]   = (byte)grayVal; //red
             }
             _grayBms = BmsEngine.CloneBms(newJpegBytes);
         }
         ImgPhoto.Source = _grayBms;
     }
     catch (Exception ex)
     {
         MessageBox.Show("Eroare: " + ex.Message, "Efecte poze", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }