Beispiel #1
0
        /// <summary>
        /// This sets the new given stream with pixels to the bitmap
        /// and makes the ApplyReset stackPanel of the current popup to appear.
        /// </summary>
        /// <param name="givenStream"> Stream data to be written to the bitmap </param>
        /// <param name="givenBitmap"> Bitmap for saving the stream to </param>
        /// <param name="givenImage"> RemedyImage to display the bitmap </param>
        public void setStream(Stream givenStream, WriteableBitmap givenBitmap, RemedyImage givenImage)
        {

            givenStream.Seek(0, SeekOrigin.Begin);
            givenStream.Write(givenImage.dstPixels, 0, givenImage.dstPixels.Length);
            givenBitmap.Invalidate();
            if (givenImage == image)
            {
                if (FiltersPopup.Popup.IsOpen)
                    FiltersPopup.FilterApplyReset.Visibility = Visibility.Visible;
                else if (ColorsPopup.Popup.IsOpen)
                    ColorsPopup.ColorApplyReset.Visibility = Visibility.Visible;
                else if (RotatePopup.Popup.IsOpen)
                    RotatePopup.RotateApplyReset.Visibility = Visibility.Visible;
                else if (ExposurePopup.Popup.IsOpen)
                    ExposurePopup.ExposureApplyReset.Visibility = Visibility.Visible;
            }
        }
Beispiel #2
0
 /// <summary>
 /// This calculates the width and height of the bitmap image
 /// and sets the Stream and the pixels byte array
 /// </summary>
 /// <param name="stream"> The stream where the pixels data will be written </param>
 /// <param name="bitmap"> The image from where the data will be taken </param>
 /// <param name="givenImage"> The RemedyImage where the bitmap will be displayed</param>
 public void prepareImage(Stream stream, WriteableBitmap bitmap, RemedyImage givenImage)
 {
     givenImage.width = (int)bitmap.PixelWidth;
     givenImage.height = (int)bitmap.PixelHeight;
     stream = bitmap.PixelBuffer.AsStream();
     givenImage.dstPixels = new byte[4 * bitmap.PixelWidth * bitmap.PixelHeight];
     givenImage.Reset();
 }
Beispiel #3
0
 // Change the image with crystal filter applied
 public void doCrystal(Stream stream, WriteableBitmap bitmap, RemedyImage givenImage)
 {
     rootPage.prepareImage(stream, bitmap, givenImage);
     givenImage.ColorChange(0, 0, 0, 50, 35, 35);
     rootPage.setStream(stream, bitmap, givenImage);
 }
Beispiel #4
0
 public void doColorize(Stream stream, WriteableBitmap bitmap, RemedyImage givenImage)
 {
     // Call the colorize function
     rootPage.prepareImage(stream, bitmap, givenImage);
     givenImage.Colorize(blueForColorize, redForColorize, greenForColorize, yellowForColorize,
                                 orangeForColorize, purpleForColorize, cyanForColorize, limeForColorize);
     rootPage.setStream(stream, bitmap, givenImage);
     ColorizeApplyReset.Visibility = Visibility.Visible;
 }
Beispiel #5
0
 // Change the image with brighten filter applied
 public void doBrighten(Stream stream, WriteableBitmap bitmap, RemedyImage givenImage)
 {
     rootPage.prepareImage(stream, bitmap, givenImage);
     givenImage.ColorChange(70, 70, 70, 0, 0, 0);
     rootPage.setStream(stream, bitmap, givenImage);
 }
Beispiel #6
0
 // Change the image with shadow filter applied
 public void doShadow(Stream stream, WriteableBitmap bitmap, RemedyImage givenImage)
 {
     rootPage.prepareImage(stream, bitmap, givenImage);
     givenImage.ColorChange(-80, -80, -80, 0, 0, 0);
     rootPage.setStream(stream, bitmap, givenImage);
 }
Beispiel #7
0
        public async void setFilterBitmaps()
        {
            // This creates temporary Streams and WriteableBitmap objects for every filter available.
            // We set the bitmaps as source to the XAML rootPage.image objects.
            // After this, we apply different filter for each of the WriteableBitmap objects.

            RemedyImage filterimage = new RemedyImage();
            uint newWidth = (uint)rootPage.bitmapImage.PixelWidth;
            uint newHeight = (uint)rootPage.bitmapImage.PixelHeight;

            while (newWidth > 150 && newHeight > 150)
            {
                newWidth = newWidth / 2;
                newHeight = newHeight / 2;
            }

            Stream
            blackWhiteStream = null,
            emboss2Stream = null,
            embossStream = null,
            invertStream = null,
            blurStream = null,
            blur2Stream = null,
            sharpenStream = null,
            noiseStream = null;

            WriteableBitmap
            blackWhiteBitmap = await rootPage.OptionsPopup.ResizeImage(rootPage.bitmapImage, newWidth, newHeight),
			embossBitmap = await rootPage.OptionsPopup.ResizeImage(rootPage.bitmapImage, newWidth, newHeight),
			emboss2Bitmap = await rootPage.OptionsPopup.ResizeImage(rootPage.bitmapImage, newWidth, newHeight),
			invertBitmap = await rootPage.OptionsPopup.ResizeImage(rootPage.bitmapImage, newWidth, newHeight),
			blurBitmap = await rootPage.OptionsPopup.ResizeImage(rootPage.bitmapImage, newWidth, newHeight),
			blur2Bitmap = await rootPage.OptionsPopup.ResizeImage(rootPage.bitmapImage, newWidth, newHeight),
			sharpenBitmap = await rootPage.OptionsPopup.ResizeImage(rootPage.bitmapImage, newWidth, newHeight),
			noiseBitmap = await rootPage.OptionsPopup.ResizeImage(rootPage.bitmapImage, newWidth, newHeight);

            blackWhiteFilter.Source = blackWhiteBitmap;
            embossFilter.Source = embossBitmap;
            emboss2Filter.Source = emboss2Bitmap;
            invertFilter.Source = invertBitmap;
            blurFilter.Source = blurBitmap;
            blur2Filter.Source = blur2Bitmap;
            sharpenFilter.Source = sharpenBitmap;
            noiseFilter.Source = noiseBitmap;

            blackWhiteStream = blackWhiteBitmap.PixelBuffer.AsStream();
            embossStream = embossBitmap.PixelBuffer.AsStream();
            emboss2Stream = emboss2Bitmap.PixelBuffer.AsStream();
            invertStream = invertBitmap.PixelBuffer.AsStream();
            blurStream = blurBitmap.PixelBuffer.AsStream();
            blur2Stream = blur2Bitmap.PixelBuffer.AsStream();
            sharpenStream = sharpenBitmap.PixelBuffer.AsStream();
            noiseStream = noiseBitmap.PixelBuffer.AsStream();

            initializeBitmap(blackWhiteStream, blackWhiteBitmap, filterimage);
            initializeBitmap(embossStream, embossBitmap, filterimage);
            initializeBitmap(emboss2Stream, emboss2Bitmap, filterimage);
            initializeBitmap(invertStream, invertBitmap, filterimage);
            initializeBitmap(blurStream, blurBitmap, filterimage);
            initializeBitmap(blur2Stream, blur2Bitmap, filterimage);
            initializeBitmap(sharpenStream, sharpenBitmap, filterimage);
            initializeBitmap(noiseStream, noiseBitmap, filterimage);

            rootPage.prepareImage(blackWhiteStream, blackWhiteBitmap, filterimage);
            rootPage.setStream(blackWhiteStream, blackWhiteBitmap, filterimage);

            doFilter(blackWhiteStream, blackWhiteBitmap, filterimage, "blackwhite");
            doFilter(embossStream, embossBitmap, filterimage, "emboss");
            doFilter(emboss2Stream, emboss2Bitmap, filterimage, "emboss2");
            doFilter(invertStream, invertBitmap, filterimage, "invert");
            doFilter(blurStream, blurBitmap, filterimage, "blur");
            doFilter(blur2Stream, blur2Bitmap, filterimage, "blur2");
            doFilter(sharpenStream, sharpenBitmap, filterimage, "sharpen");
            doFilter(noiseStream, noiseBitmap, filterimage, "noise");

            Stream
            hardNoiseStream = null,
            retroStream = null,
            darkenStream = null,
            edgeDetectStream = null,
            edgeEnhanceStream = null,
            brightenStream = null,
            shadowStream = null,
            crystalStream = null;

            WriteableBitmap
			hardNoiseBitmap = await rootPage.OptionsPopup.ResizeImage(rootPage.bitmapImage, newWidth, newHeight),
			edgeDetectBitmap = await rootPage.OptionsPopup.ResizeImage(rootPage.bitmapImage, newWidth, newHeight),
			edgeEnhanceBitmap = await rootPage.OptionsPopup.ResizeImage(rootPage.bitmapImage, newWidth, newHeight),
			retroBitmap = await rootPage.OptionsPopup.ResizeImage(rootPage.bitmapImage, newWidth, newHeight),
			darkenBitmap = await rootPage.OptionsPopup.ResizeImage(rootPage.bitmapImage, newWidth, newHeight),
			brightenBitmap = await rootPage.OptionsPopup.ResizeImage(rootPage.bitmapImage, newWidth, newHeight),
			shadowBitmap = await rootPage.OptionsPopup.ResizeImage(rootPage.bitmapImage, newWidth, newHeight),
			crystalBitmap = await rootPage.OptionsPopup.ResizeImage(rootPage.bitmapImage, newWidth, newHeight);

            hardNoiseFilter.Source = hardNoiseBitmap;
            edgeDetectFilter.Source = edgeDetectBitmap;
            edgeEnhanceFilter.Source = edgeEnhanceBitmap;
            retroFilter.Source = retroBitmap;
            darkenFilter.Source = darkenBitmap;
            brightenFilter.Source = brightenBitmap;
            shadowFilter.Source = shadowBitmap;
            crystalFilter.Source = crystalBitmap;

            hardNoiseStream = hardNoiseBitmap.PixelBuffer.AsStream();
            edgeDetectStream = edgeDetectBitmap.PixelBuffer.AsStream();
            edgeEnhanceStream = edgeEnhanceBitmap.PixelBuffer.AsStream();
            retroStream = retroBitmap.PixelBuffer.AsStream();
            darkenStream = darkenBitmap.PixelBuffer.AsStream();
            brightenStream = brightenBitmap.PixelBuffer.AsStream();
            shadowStream = shadowBitmap.PixelBuffer.AsStream();
            crystalStream = crystalBitmap.PixelBuffer.AsStream();

            initializeBitmap(hardNoiseStream, hardNoiseBitmap, filterimage);
            initializeBitmap(edgeDetectStream, edgeDetectBitmap, filterimage);
            initializeBitmap(edgeEnhanceStream, edgeEnhanceBitmap, filterimage);
            initializeBitmap(retroStream, retroBitmap, filterimage);
            initializeBitmap(darkenStream, darkenBitmap, filterimage);
            initializeBitmap(brightenStream, brightenBitmap, filterimage);
            initializeBitmap(shadowStream, shadowBitmap, filterimage);
            initializeBitmap(crystalStream, crystalBitmap, filterimage);

            rootPage.prepareImage(hardNoiseStream, hardNoiseBitmap, filterimage);
            rootPage.setStream(hardNoiseStream, hardNoiseBitmap, filterimage);

            doFilter(hardNoiseStream, hardNoiseBitmap, filterimage, "hardNoise");
            doFilter(edgeDetectStream, edgeDetectBitmap, filterimage, "EdgeDetect");
            doFilter(edgeEnhanceStream, edgeEnhanceBitmap, filterimage, "EdgeEnhance");
            doFilter(retroStream, retroBitmap, filterimage, "retro");
            doFilter(darkenStream, darkenBitmap, filterimage, "darken");
            doFilter(brightenStream, brightenBitmap, filterimage, "brighten");
            doFilter(shadowStream, shadowBitmap, filterimage, "shadow");
            doFilter(crystalStream, crystalBitmap, filterimage, "crystal");
        }
Beispiel #8
0
        // Change the image with edgeEnhance filter applied
        public void doEdgeEnhance(Stream stream, WriteableBitmap bitmap, RemedyImage givenImage)
        {
            rootPage.prepareImage(stream, bitmap, givenImage);
            int[,] coeff = new int[5, 5];
            int offset = 0, scale = 0;
            EdgeEnhance_SetValues(ref coeff, ref offset, ref scale);
            CustomFilter custom_image = new CustomFilter(givenImage.srcPixels, givenImage.width, givenImage.height, offset, scale, coeff);
            givenImage.dstPixels = custom_image.Filter();
            rootPage.setStream(stream, bitmap, givenImage);

        }
Beispiel #9
0
        // Change the image with hardnoise filter applied
        public void doHardNoise(Stream stream, WriteableBitmap bitmap, RemedyImage givenImage)
        {
            rootPage.prepareImage(stream, bitmap, givenImage);

            givenImage.Noise(1);
            rootPage.setStream(stream, bitmap, givenImage);
        }
Beispiel #10
0
        // Change the image with noise filter applied
        public void doNoise(Stream stream, WriteableBitmap bitmap, RemedyImage givenImage)
        {
            rootPage.prepareImage(stream, bitmap, givenImage);

            givenImage.Noise(givenImage.Noise_GetSquareWidth(20));
            rootPage.setStream(stream, bitmap, givenImage);
        }
Beispiel #11
0
 // Change the image with black and white filter applied
 private void doBlackWhite(Stream stream, WriteableBitmap bitmap, RemedyImage givenImage)
 {
     rootPage.prepareImage(stream, bitmap, givenImage);
     givenImage.BlackAndWhite(givenImage.dstPixels, givenImage.srcPixels);
     rootPage.setStream(stream, bitmap, givenImage);
 }
Beispiel #12
0
 public void doFilter(Stream givenStream, WriteableBitmap givenBitmap, RemedyImage givenImage, string filter)
 {
     // Filter the passed image with the passed filter as a string.
     switch (filter)
     {
         case "blackwhite":
             doBlackWhite(givenStream, givenBitmap, givenImage);
             break;
         case "invert":
             doInvert(givenStream, givenBitmap, givenImage);
             break;
         case "emboss":
             doEmboss(givenStream, givenBitmap, givenImage);
             break;
         case "emboss2":
             doEmboss2(givenStream, givenBitmap, givenImage);
             break;
         case "blur":
             doBlur(givenStream, givenBitmap, givenImage);
             break;
         case "blur2":
             doBlur2(givenStream, givenBitmap, givenImage);
             break;
         case "sharpen":
             doSharpen(givenStream, givenBitmap, givenImage);
             break;
         case "noise":
             doNoise(givenStream, givenBitmap, givenImage);
             break;
         case "hardNoise":
             doHardNoise(givenStream, givenBitmap, givenImage);
             break;
         case "EdgeDetect":
             doEdgeDetect(givenStream, givenBitmap, givenImage);
             break;
         case "EdgeEnhance":
             doEdgeEnhance(givenStream, givenBitmap, givenImage);
             break;
         case "retro":
             doRetro(givenStream, givenBitmap, givenImage);
             break;
         case "darken":
             doDarken(givenStream, givenBitmap, givenImage);
             break;
         case "brighten":
             doBrighten(givenStream, givenBitmap, givenImage);
             break;
         case "shadow":
             doShadow(givenStream, givenBitmap, givenImage);
             break;
         case "crystal":
             doCrystal(givenStream, givenBitmap, givenImage);
             break;
         default:
             break;
     }
 }
Beispiel #13
0
 public async void initializeBitmap(Stream givenStream, WriteableBitmap givenBitmap, RemedyImage givenImage)
 {
     // This makes the required operations for initializing the WriteableBitmap.
     givenStream = givenBitmap.PixelBuffer.AsStream();
     givenImage.srcPixels = new byte[(uint)givenStream.Length];
     await givenStream.ReadAsync(givenImage.srcPixels, 0, givenImage.srcPixels.Length);
 }