Example #1
0
        public override WriteableBitmap ApplyFunctionFilter(System.Windows.Media.Imaging.BitmapImage originalBitmapImage)
        {
            WriteableBitmap writableImage = new WriteableBitmap(originalBitmapImage);

            byte[] byteArr = writableImage.WriteableBitMapImageToArray();

            double pixel;

            Offset = (100 + Offset) / 100.0;
            for (int i = 0; i < byteArr.Length; i++)
            {
                pixel  = ((double)byteArr[i]) / 255.0;
                pixel -= 0.5;
                pixel *= Offset;
                pixel += 0.5;
                pixel *= 255;

                pixel = (pixel < 0 ? 0 : pixel);
                pixel = (pixel > 255 ? 255 : pixel);

                byteArr[i] = (byte)pixel;
            }

            WriteableBitmap result = originalBitmapImage.ByteArrayToWritableBitmap(byteArr);

            return(result);
        }
Example #2
0
        public override WriteableBitmap ApplyFunctionFilter(System.Windows.Media.Imaging.BitmapImage originalBitmapImage)
        {
            WriteableBitmap writableImage = new System.Windows.Media.Imaging.WriteableBitmap(originalBitmapImage);

            byte[] byteArr = writableImage.WriteableBitMapImageToArray();

            for (int i = 0; i < byteArr.Length; i++)
            {
                byteArr[i] = (byte)(255 - byteArr[i]);
            }

            WriteableBitmap result = originalBitmapImage.ByteArrayToWritableBitmap(byteArr);

            return(result);
        }
Example #3
0
        public override WriteableBitmap ApplyFunctionFilter(System.Windows.Media.Imaging.BitmapImage originalBitmapImage)
        {
            WriteableBitmap writableImage = new System.Windows.Media.Imaging.WriteableBitmap(originalBitmapImage);

            byte[] byteArr = writableImage.WriteableBitMapImageToArray();

            int num = 0;

            for (int i = 0; i < byteArr.Length; i++)
            {
                num = (int)(byteArr[i]);
                int val = (int)_customFunction[num] + (int)this.Offset;
                val        = (val < 0 ? 0 : val);
                val        = (val > 255 ? 255 : val);
                byteArr[i] = (byte)(val);
            }

            WriteableBitmap result = originalBitmapImage.ByteArrayToWritableBitmap(byteArr);

            return(result);
        }
        public override WriteableBitmap ApplyFunctionFilter(System.Windows.Media.Imaging.BitmapImage originalBitmapImage)
        {
            WriteableBitmap writableImage = new WriteableBitmap(originalBitmapImage);

            byte[] byteArr = writableImage.WriteableBitMapImageToArray();

            int num = 0;

            for (int i = 0; i < byteArr.Length; i++)
            {
                num = (int)(byteArr[i] + this.Offset);

                num = (num < 0 ? 0 : num);
                num = (num > 255 ? 255 : num);

                byteArr[i] = (byte)num;
            }

            WriteableBitmap result = originalBitmapImage.ByteArrayToWritableBitmap(byteArr);

            return(result);
        }
Example #5
0
        /*
         * public override byte[] Function {
         *  get {
         *      byte[] function = new byte[256];
         *
         *      int num = 0;
         *
         *      int subvalues = 4;
         *      int length = 256 / subvalues;
         *      for (int i = 0; i * subvalues < length; i += subvalues) {
         *
         *          int grayScalePx = (int)((i * .299) + ((i + 1) * .587) + ((i + 2) * .114));
         *
         *          if (grayScalePx < this.Offset)
         *              num = 0;
         *          else
         *              num = 255;
         *
         *          for (int j = i; j < (i + subvalues); j++) {
         *              function[j] = (byte)num;
         *          }
         *      }
         *
         *      _function = function;
         *      return _function;
         *  }
         *  set {
         *      base.Function = value;
         *  }
         * }
         */

        public override WriteableBitmap ApplyFunctionFilter(System.Windows.Media.Imaging.BitmapImage originalBitmapImage)
        {
            WriteableBitmap writableImage = new System.Windows.Media.Imaging.WriteableBitmap(originalBitmapImage);

            byte[] byteArr = writableImage.WriteableBitMapImageToArray();

            for (int i = 0; i < byteArr.Length; i += 4)
            {
                byte a = byteArr[i + 3];

                if (a > 0)
                {
                    double ad = (double)a / 255.0;
                    double rd = (double)byteArr[i + 2] / ad;
                    double gd = (double)byteArr[i + 1] / ad;
                    double bd = (double)byteArr[i + 0] / ad;

                    double luminance = 0.2126 * rd + 0.7152 * gd + 0.0722 * bd;
                    double newR      = luminance * ad;

                    if (newR < this.Offset)
                    {
                        newR = 0;
                    }
                    else
                    {
                        newR = 255;
                    }

                    byteArr[i + 0] = (byte)newR;
                    byteArr[i + 1] = (byte)newR;
                    byteArr[i + 2] = (byte)newR;
                }
            }

            WriteableBitmap result = originalBitmapImage.ByteArrayToWritableBitmap(byteArr);

            return(result);
        }