예제 #1
0
 /// <summary>
 /// Creates the bump map
 /// </summary>
 public virtual Bitmap Create(Bitmap ImageUsing)
 {
     if (ImageUsing == null)
     {
         throw new ArgumentNullException("ImageUsing");
     }
     CreateFilter();
     using (Bitmap TempImageX = FilterX.Create(ImageUsing))
     {
         using (Bitmap TempImageY = FilterY.Create(ImageUsing))
         {
             Bitmap       ReturnImage          = new Bitmap(TempImageX.Width, TempImageX.Height);
             Math.Vector3 TempVector           = new Utilities.Math.Vector3(0.0, 0.0, 0.0);
             BitmapData   TempImageXData       = TempImageX.LockImage();
             BitmapData   TempImageYData       = TempImageY.LockImage();
             BitmapData   ReturnImageData      = ReturnImage.LockImage();
             int          TempImageXPixelSize  = TempImageXData.GetPixelSize();
             int          TempImageYPixelSize  = TempImageYData.GetPixelSize();
             int          ReturnImagePixelSize = ReturnImageData.GetPixelSize();
             for (int y = 0; y < TempImageX.Height; ++y)
             {
                 for (int x = 0; x < TempImageX.Width; ++x)
                 {
                     Color TempPixelX = TempImageXData.GetPixel(x, y, TempImageXPixelSize);
                     Color TempPixelY = TempImageYData.GetPixel(x, y, TempImageYPixelSize);
                     TempVector.X = (double)(TempPixelX.R) / 255.0;
                     TempVector.Y = (double)(TempPixelY.R) / 255.0;
                     TempVector.Z = 1.0;
                     TempVector.Normalize();
                     TempVector.X = ((TempVector.X + 1.0) / 2.0) * 255.0;
                     TempVector.Y = ((TempVector.Y + 1.0) / 2.0) * 255.0;
                     TempVector.Z = ((TempVector.Z + 1.0) / 2.0) * 255.0;
                     ReturnImageData.SetPixel(x, y,
                                              Color.FromArgb((int)TempVector.X,
                                                             (int)TempVector.Y,
                                                             (int)TempVector.Z),
                                              ReturnImagePixelSize);
                 }
             }
             TempImageX.UnlockImage(TempImageXData);
             TempImageY.UnlockImage(TempImageYData);
             ReturnImage.UnlockImage(ReturnImageData);
             return(ReturnImage);
         }
     }
 }
예제 #2
0
 /// <summary>
 /// Creates the bump map
 /// </summary>
 public virtual Bitmap Create(Bitmap ImageUsing)
 {
     ImageUsing.ThrowIfNull("ImageUsing");
     CreateFilter();
     using (Bitmap TempImageX = FilterX.Create(ImageUsing))
     {
         using (Bitmap TempImageY = FilterY.Create(ImageUsing))
         {
             Bitmap     ReturnImage          = new Bitmap(TempImageX.Width, TempImageX.Height);
             BitmapData TempImageXData       = TempImageX.LockImage();
             BitmapData TempImageYData       = TempImageY.LockImage();
             BitmapData ReturnImageData      = ReturnImage.LockImage();
             int        TempImageXPixelSize  = TempImageXData.GetPixelSize();
             int        TempImageYPixelSize  = TempImageYData.GetPixelSize();
             int        ReturnImagePixelSize = ReturnImageData.GetPixelSize();
             int        Width  = TempImageX.Width;
             int        Height = TempImageX.Height;
             Parallel.For(0, Height, y =>
             {
                 Math.Vector3 TempVector = new Utilities.Math.Vector3(0.0, 0.0, 0.0);
                 for (int x = 0; x < Width; ++x)
                 {
                     Color TempPixelX = TempImageXData.GetPixel(x, y, TempImageXPixelSize);
                     Color TempPixelY = TempImageYData.GetPixel(x, y, TempImageYPixelSize);
                     TempVector.X     = (double)(TempPixelX.R) / 255.0;
                     TempVector.Y     = (double)(TempPixelY.R) / 255.0;
                     TempVector.Z     = 1.0;
                     TempVector.Normalize();
                     TempVector.X = ((TempVector.X + 1.0) / 2.0) * 255.0;
                     TempVector.Y = ((TempVector.Y + 1.0) / 2.0) * 255.0;
                     TempVector.Z = ((TempVector.Z + 1.0) / 2.0) * 255.0;
                     ReturnImageData.SetPixel(x, y,
                                              Color.FromArgb((int)TempVector.X,
                                                             (int)TempVector.Y,
                                                             (int)TempVector.Z),
                                              ReturnImagePixelSize);
                 }
             });
             TempImageX.UnlockImage(TempImageXData);
             TempImageY.UnlockImage(TempImageYData);
             ReturnImage.UnlockImage(ReturnImageData);
             return(ReturnImage);
         }
     }
 }