コード例 #1
0
        /// <summary>
        /// Implements the operator |.
        /// </summary>
        /// <param name="Image1">The first image.</param>
        /// <param name="Image2">The second image</param>
        /// <returns>The result of the operator.</returns>
        public static SwiftBitmap operator |(SwiftBitmap Image1, SwiftBitmap Image2)
        {
            Contract.Requires <ArgumentNullException>(Image1 != null, "Image1");
            Contract.Requires <ArgumentNullException>(Image2 != null, "Image2");
            Image1.Lock();
            Image2.Lock();
            var Result = new SwiftBitmap(Image1.Width, Image1.Height);

            Result.Lock();
            Parallel.For(0, Result.Width, x =>
            {
                for (int y = 0; y < Result.Height; ++y)
                {
                    var Pixel1 = Image1.GetPixel(x, y);
                    var Pixel2 = Image2.GetPixel(x, y);
                    Result.SetPixel(x, y,
                                    Color.FromArgb(Pixel1.R | Pixel2.R,
                                                   Pixel1.G | Pixel2.G,
                                                   Pixel1.B | Pixel2.B));
                }
            });
            Image2.Unlock();
            Image1.Unlock();
            return(Result.Unlock());
        }
コード例 #2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="Image">Image to load</param>
 public RGBHistogram(SwiftBitmap Image = null)
 {
     R = new float[256];
     G = new float[256];
     B = new float[256];
     if (Image != null)
     {
         LoadImage(Image);
     }
 }
コード例 #3
0
 /// <summary>
 /// Copies the image from one image to this one.
 /// </summary>
 /// <param name="SwiftBitmap">The SwiftBitmap to copy from.</param>
 /// <returns>This</returns>
 public unsafe SwiftBitmap Copy(SwiftBitmap SwiftBitmap)
 {
     Contract.Requires <NullReferenceException>(InternalBitmap != null);
     if (SwiftBitmap == null)
     {
         return(this);
     }
     Unlock();
     InternalBitmap.Dispose();
     InternalBitmap = (Bitmap)SwiftBitmap.InternalBitmap.Clone();
     return(this);
 }
コード例 #4
0
 /// <summary>
 /// Loads an image
 /// </summary>
 /// <param name="ImageUsing">Image to load</param>
 public virtual void LoadImage(SwiftBitmap ImageUsing)
 {
     Contract.Requires <ArgumentNullException>(ImageUsing != null, "ImageUsing");
     Width  = ImageUsing.Width;
     Height = ImageUsing.Height;
     ImageUsing.Lock();
     R.Clear();
     G.Clear();
     B.Clear();
     for (int x = 0; x < ImageUsing.Width; ++x)
     {
         for (int y = 0; y < ImageUsing.Height; ++y)
         {
             var TempColor = ImageUsing.GetPixel(x, y);
             ++R[(int)TempColor.R];
             ++G[(int)TempColor.G];
             ++B[(int)TempColor.B];
         }
     }
     ImageUsing.Unlock();
 }
コード例 #5
0
 /// <summary>
 /// Applies the convolution filter to the image
 /// </summary>
 /// <param name="filter">The filter.</param>
 /// <param name="absolute">if set to <c>true</c> then the absolute value is used</param>
 /// <param name="offset">The offset to use for each pixel</param>
 /// <returns>Returns the image with the filter applied</returns>
 public SwiftBitmap ApplyConvolutionFilter(int[][] filter, bool absolute = false, int offset = 0)
 {
     Contract.Requires <NullReferenceException>(InternalBitmap != null);
     using (SwiftBitmap Result = new SwiftBitmap(Width, Height))
     {
         Lock();
         Result.Lock();
         Parallel.For(0, Width, x =>
         {
             for (int y = 0; y < Height; ++y)
             {
                 int RValue   = 0;
                 int GValue   = 0;
                 int BValue   = 0;
                 int Weight   = 0;
                 int XCurrent = -filter[0].Length / 2;
                 for (int x2 = 0; x2 < filter[0].Length; ++x2)
                 {
                     if (XCurrent + x < Width && XCurrent + x >= 0)
                     {
                         int YCurrent = -filter.Length / 2;
                         for (int y2 = 0; y2 < filter.Length; ++y2)
                         {
                             if (YCurrent + y < Height && YCurrent + y >= 0)
                             {
                                 var Pixel = GetPixel(XCurrent + x, YCurrent + y);
                                 RValue   += filter[x2][y2] * Pixel.R;
                                 GValue   += filter[x2][y2] * Pixel.G;
                                 BValue   += filter[x2][y2] * Pixel.B;
                                 Weight   += filter[x2][y2];
                             }
                             ++YCurrent;
                         }
                     }
                     ++XCurrent;
                 }
                 var MeanPixel = GetPixel(x, y);
                 if (Weight == 0)
                 {
                     Weight = 1;
                 }
                 if (Weight > 0)
                 {
                     if (absolute)
                     {
                         RValue = System.Math.Abs(RValue);
                         GValue = System.Math.Abs(GValue);
                         BValue = System.Math.Abs(BValue);
                     }
                     RValue    = (RValue / Weight) + offset;
                     RValue    = RValue.Clamp(255, 0);
                     GValue    = (GValue / Weight) + offset;
                     GValue    = GValue.Clamp(255, 0);
                     BValue    = (BValue / Weight) + offset;
                     BValue    = BValue.Clamp(255, 0);
                     MeanPixel = Color.FromArgb(RValue, GValue, BValue);
                 }
                 Result.SetPixel(x, y, MeanPixel);
             }
         });
         Unlock();
         Result.Unlock();
         return(Copy(Result));
     }
 }