Advertisement
f0rkB0mb

The Filter-class for manipulating images in c#

Dec 29th, 2012
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 16.10 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Drawing;
  5. using System.Drawing.Imaging;
  6. using System.Windows.Forms;
  7.  
  8. using System.Runtime.InteropServices;
  9.  
  10. namespace LowLevelBitmapEdit
  11. {
  12.     /// <summary>
  13.     /// This static class accessing the given picture via its Scan0 ptr.
  14.     /// <para />
  15.     /// The normal access goes via:
  16.     /// <para />
  17.     /// <remarks>
  18.     /// void Method(Bitmap bmp)<para />
  19.     /// {<para />
  20.     ///     BitmapData bmpDat;<para />
  21.     ///     bmpDat = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppRgb);<para />
  22.     ///     unsafe<para />
  23.     ///     {<para />
  24.     ///         byte* picPtr = (byte*)bmpDat.Scan0;<para />
  25.     ///         int size = bmp.Height * bmp.Width;<para />
  26.     ///         for (int i = 0; i &lt; size; i++)<para />
  27.     ///         {<para />
  28.     ///             //do some operations here<para />
  29.     ///         }<para />
  30.     ///     }<para />
  31.     ///     bmp.UnlockBits(bmpDat);<para />
  32.     /// }<para />
  33.     /// </remarks>
  34.     /// </summary>
  35.     public static class Filters
  36.     {
  37.         #region Manipulating Methods
  38.         /// <summary>
  39.         ///
  40.         /// </summary>
  41.         /// <param name="bmp"></param>
  42.         public static void SetOnlyBlue(Bitmap bmp)
  43.         {
  44.             BitmapData bmpDat;
  45.             byte blue;
  46.  
  47.             bmpDat = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppRgb);
  48.  
  49.             unsafe
  50.             {
  51.                 byte* picPtr = (byte*)bmpDat.Scan0;
  52.                 int size = (bmp.Height) * (bmp.Width);
  53.                 for (int i = 0; i < size; i++)
  54.                 {
  55.                     blue = picPtr[0];
  56.                     picPtr[0] = 0;
  57.                     picPtr += 4;
  58.                 }
  59.             }
  60.             bmp.UnlockBits(bmpDat);
  61.         }
  62.  
  63.         /// <summary>
  64.         ///
  65.         /// </summary>
  66.         /// <param name="bmp"></param>
  67.         public static void Invertion(Bitmap bmp)
  68.         {
  69.             BitmapData bmpDat;
  70.             bmpDat = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
  71.  
  72.             unsafe
  73.             {
  74.                 byte* picPtr = (byte*)bmpDat.Scan0;
  75.                 int size = bmp.Height * bmp.Width * 4;
  76.                 for (int i = 0; i < size; i++)
  77.                     picPtr[i] = (byte)(255 - picPtr[i]);
  78.             }
  79.             bmp.UnlockBits(bmpDat);
  80.         }
  81.  
  82.         /// <summary>
  83.         ///
  84.         /// </summary>
  85.         /// <param name="bmp"></param>
  86.         public static void GreyScale(Bitmap bmp)
  87.         {
  88.             BitmapData bmpDat;
  89.  
  90.             bmpDat = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppRgb);
  91.             unsafe
  92.             {
  93.                 byte* picPtr = (byte*)bmpDat.Scan0;
  94.                 int size = bmp.Height * bmp.Width;
  95.                 for (int i = 0; i < size; i++)
  96.                 {
  97.                     //getting the rgb colors/values
  98.                     byte blue = picPtr[0];
  99.                     byte green = picPtr[1];
  100.                     byte red = picPtr[2];
  101.                     //computing the grey colors:
  102.                     byte grey = (byte)((77 * blue + 151 * green + 28 * red) / 256);
  103.                     //write it back to the picture:
  104.                     picPtr[0] = picPtr[1] = picPtr[2] = grey;
  105.                     picPtr += 4;
  106.                 }
  107.             }
  108.             bmp.UnlockBits(bmpDat);
  109.         }
  110.  
  111.         /// <summary>
  112.         ///
  113.         /// </summary>
  114.         /// <param name="bmp"></param>
  115.         /// <param name="val"></param>
  116.         public static void Brightness(Bitmap bmp, short val)
  117.         {
  118.             //at first we computes a so called Look-Up-Table (lut)
  119.             //that makes sense for the performance by very large pictures.
  120.             //because in this way we writes the picture bytes into an array,
  121.             //and could simply accessing the needed bytes via this array.
  122.             //here we go with our LUT:
  123.             byte[] picBytes = new byte[256];
  124.             for (int i = 0; i < 256; i++)
  125.             {
  126.                 picBytes[i] = Norming(i + val);
  127.             }
  128.  
  129.             BitmapData bmpDat;
  130.  
  131.             bmpDat = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppRgb);
  132.             unsafe
  133.             {
  134.                 byte* picPtr = (byte*)bmpDat.Scan0;
  135.                 int size = bmp.Height * bmp.Width;
  136.                 for (int i = 0; i < size; i++)
  137.                 {
  138.                     //and now we simply get the values from our LUT:
  139.                     picPtr[0] = picBytes[picPtr[0]];    //blue
  140.                     picPtr[1] = picBytes[picPtr[1]];    //green
  141.                     picPtr[2] = picBytes[picPtr[2]];    //red
  142.                     //increment our ptr with 4;
  143.                     picPtr += 4;
  144.                 }
  145.             }
  146.             bmp.UnlockBits(bmpDat);
  147.         }
  148.  
  149.         /// <summary>
  150.         ///
  151.         /// </summary>
  152.         /// <param name="bmp"></param>
  153.         /// <param name="val"></param>
  154.         public static void SetContrast(Bitmap bmp, float val)
  155.         {
  156.             byte[] picBytes = new byte[256];
  157.             val = (1 + val / 100);
  158.             //creating our LUT:
  159.             for (int i = 0; i < 256; i++)
  160.             {
  161.                 picBytes[i] = Norming((int)((i - 128) * val) + 128);
  162.             }
  163.             BitmapData bmpDat;
  164.  
  165.             bmpDat = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppRgb);
  166.             unsafe
  167.             {
  168.                 byte* picPtr = (byte*)bmpDat.Scan0;
  169.                 int size = bmp.Height * bmp.Width;
  170.                 for (int i = 0; i < size; i++)
  171.                 {
  172.                     //and now we simply get the values from our LUT:
  173.                     picPtr[0] = picBytes[picPtr[0]];    //blue
  174.                     picPtr[1] = picBytes[picPtr[1]];    //green
  175.                     picPtr[2] = picBytes[picPtr[2]];    //red
  176.                     //increment our ptr with 4;
  177.                     picPtr += 4;
  178.                 }
  179.             }
  180.             bmp.UnlockBits(bmpDat);
  181.         }
  182.  
  183.         /// <summary>
  184.         ///
  185.         /// </summary>
  186.         /// <param name="bmp"></param>
  187.         /// <param name="val"></param>
  188.         public static void SetGamma(Bitmap bmp, double val)
  189.         {
  190.             byte[] picBytes = new byte[256];
  191.             for (int i = 0; i < 256; i++)
  192.             {
  193.                 picBytes[i] = (byte)Math.Min(255, (int)((255.0 * Math.Pow(i / 255.0, 1.0 / val)) + 0.5));
  194.             }
  195.  
  196.             BitmapData bmpDat;
  197.  
  198.             bmpDat = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppRgb);
  199.             unsafe
  200.             {
  201.                 byte* picPtr = (byte*)bmpDat.Scan0;
  202.                 int size = bmp.Height * bmp.Width;
  203.                 for (int i = 0; i < size; i++)
  204.                 {
  205.                     //and now we simply get the values from our LUT:
  206.                     picPtr[0] = picBytes[picPtr[0]];    //blue
  207.                     picPtr[1] = picBytes[picPtr[1]];    //green
  208.                     picPtr[2] = picBytes[picPtr[2]];    //red
  209.                     //increment our ptr with 4;
  210.                     picPtr += 4;
  211.                 }
  212.             }
  213.             bmp.UnlockBits(bmpDat);
  214.         }
  215.  
  216.         /// <summary>
  217.         /// This Method is needed to stretch the Histograph of a Picture.<para />
  218.         /// This could be useful for Photos with a wrong exposure.
  219.         /// </summary>
  220.         /// <param name="bmp"></param>
  221.         public static void AutoAdjustment(Bitmap bmp)
  222.         {
  223.             //this time we need a little bit more computations.
  224.             //at first we start also with our LUT, but we need to compute every color-layer:
  225.             int[,] picBytes = new int[256, 3];
  226.  
  227.             BitmapData bmpDat;
  228.  
  229.             bmpDat = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppRgb);
  230.             unsafe
  231.             {
  232.                 byte* picPtr = (byte*)bmpDat.Scan0;
  233.                 int size = bmp.Height * bmp.Width;
  234.                 for (int i = 0; i < size; i++)
  235.                 {
  236.                     //no we create the histograph with our LUT,
  237.                     //and counting the given color/byte values
  238.                     picBytes[picPtr[0], 0]++;   //blue layer
  239.                     picBytes[picPtr[1], 1]++;   //green layer
  240.                     picBytes[picPtr[2], 2]++;   //red layer
  241.                     picPtr += 4;
  242.                 }
  243.  
  244.                 //here we have to compute every single color-channel:
  245.                 for (int colr = 0; colr < 3; colr++)
  246.                 {
  247.                     //determine whats the minimal and the maximal uses color value:
  248.                     //min:
  249.                     int i = 0;
  250.                     while (picBytes[i, colr] == 0)
  251.                         i++;
  252.                     int min = i;
  253.                     //max:
  254.                     i = 255;
  255.                     while (picBytes[i, colr] == 0)
  256.                         i--;
  257.                     int max = i;
  258.  
  259.                     //compute the scale
  260.                     float scale = 255 / (float)(max - min);
  261.  
  262.                     //getting the LUT for the specific color channel
  263.                     for (int k = 0; k < 244; k++)
  264.                     {
  265.                         picBytes[k, colr] = Norming((int)((k - min) * scale));
  266.                     }
  267.                 }
  268.  
  269.                 //setting the ptr to the first byte:
  270.                 picPtr = (byte*)bmpDat.Scan0;
  271.  
  272.                 //working on all color-channels via the LUT:
  273.                 for (int i = 0; i < size; i++)
  274.                 {
  275.                     //and now we simply get the values from our LUT:
  276.                     picPtr[0] = (byte)picBytes[picPtr[0], 0];   //blue
  277.                     picPtr[1] = (byte)picBytes[picPtr[1], 1];   //green
  278.                     picPtr[2] = (byte)picBytes[picPtr[2], 2];   //red
  279.                     //increment our ptr with 4;
  280.                     picPtr += 4;
  281.                 }
  282.  
  283.             }
  284.             bmp.UnlockBits(bmpDat);
  285.         }
  286.  
  287.         #region ShortedMethods
  288.         /// <summary>
  289.         ///
  290.         /// </summary>
  291.         /// <param name="bmp"></param>
  292.         public static void GaussianSmoothing(Bitmap bmp)
  293.         {
  294.             GraphicFilter gf = new GraphicFilter();
  295.             gf.Divider = 16;
  296.  
  297.             gf.ColorMatrix[0, 0] = 1;
  298.             gf.ColorMatrix[1, 0] = 2;
  299.             gf.ColorMatrix[2, 0] = 1;
  300.  
  301.             gf.ColorMatrix[0, 1] = 2;
  302.             gf.ColorMatrix[1, 1] = 4;
  303.             gf.ColorMatrix[2, 1] = 2;
  304.  
  305.             gf.ColorMatrix[0, 2] = 1;
  306.             gf.ColorMatrix[1, 2] = 2;
  307.             gf.ColorMatrix[2, 2] = 1;
  308.             gf.Execution(bmp);
  309.         }
  310.  
  311.         /// <summary>
  312.         ///
  313.         /// </summary>
  314.         /// <param name="bmp"></param>
  315.         public static void Emboss(Bitmap bmp)
  316.         {
  317.             GraphicFilter gf = new GraphicFilter();
  318.             gf.Divider = 1;
  319.             gf.Offset = 127;
  320.             gf.ColorMatrix[0, 0] = -1;
  321.             gf.ColorMatrix[1, 0] = 0;
  322.             gf.ColorMatrix[2, 0] = -1;
  323.  
  324.             gf.ColorMatrix[0, 1] = 0;
  325.             gf.ColorMatrix[1, 1] = 4;
  326.             gf.ColorMatrix[2, 1] = 0;
  327.  
  328.             gf.ColorMatrix[0, 2] = -1;
  329.             gf.ColorMatrix[1, 2] = 0;
  330.             gf.ColorMatrix[2, 2] = -1;
  331.             gf.Execution(bmp);
  332.         }
  333.  
  334.         /// <summary>
  335.         ///
  336.         /// </summary>
  337.         /// <param name="bmp"></param>
  338.         public static void Smoothing(Bitmap bmp)
  339.         {
  340.             GraphicFilter gf = new GraphicFilter();
  341.             gf.Divider = 8;
  342.             gf.ColorMatrix[0, 0] = 1;
  343.             gf.ColorMatrix[1, 0] = 1;
  344.             gf.ColorMatrix[2, 0] = 1;
  345.  
  346.             gf.ColorMatrix[0, 1] = 1;
  347.             gf.ColorMatrix[1, 1] = 1;
  348.             gf.ColorMatrix[2, 1] = 1;
  349.  
  350.             gf.ColorMatrix[0, 2] = 1;
  351.             gf.ColorMatrix[1, 2] = 1;
  352.             gf.ColorMatrix[2, 2] = 1;
  353.             gf.Execution(bmp);
  354.         }
  355.  
  356.         /// <summary>
  357.         ///
  358.         /// </summary>
  359.         /// <param name="bmp"></param>
  360.         public static void Sharpen(Bitmap bmp)
  361.         {
  362.             GraphicFilter gf = new GraphicFilter();
  363.             gf.Divider = 3;
  364.  
  365.             gf.ColorMatrix[0, 0] = 0;
  366.             gf.ColorMatrix[1, 0] = -2;
  367.             gf.ColorMatrix[2, 0] = 0;
  368.  
  369.             gf.ColorMatrix[0, 1] = -2;
  370.             gf.ColorMatrix[1, 1] = 11;
  371.             gf.ColorMatrix[2, 1] = -2;
  372.  
  373.             gf.ColorMatrix[0, 2] = 0;
  374.             gf.ColorMatrix[1, 2] = -2;
  375.             gf.ColorMatrix[2, 2] = 0;
  376.             gf.Execution(bmp);
  377.         }
  378.  
  379.         #endregion
  380.         #endregion
  381.  
  382.         #region helperMethod
  383.         /// <summary>
  384.         /// Ensures that the values got its correct/allowed values between 0 and 255.
  385.         /// </summary>
  386.         /// <param name="val"><see cref="System.Int32"/>.</param>
  387.         /// <returns>A <see cref="System.Byte"/>.</returns>
  388.         private static byte Norming(int val)
  389.         {
  390.             if (val < 0)
  391.                 return 0;
  392.             if (val > 255)
  393.                 return 255;
  394.             return (byte)val;
  395.         }
  396.         #endregion
  397.  
  398.         public static Bitmap MedianFilter(Bitmap Image, int Size)
  399.         {
  400.  
  401.             Bitmap TempBitmap = Image;
  402.             Bitmap NewBitmap = new Bitmap(TempBitmap.Width, TempBitmap.Height);
  403.             Graphics NewGraphics = Graphics.FromImage(NewBitmap);
  404.             NewGraphics.DrawImage(TempBitmap, new Rectangle(0, 0, TempBitmap.Width, TempBitmap.Height), new Rectangle(0, 0, TempBitmap.Width, TempBitmap.Height), GraphicsUnit.Pixel);
  405.             NewGraphics.Dispose();
  406.  
  407.             Random TempRandom = new Random();
  408.  
  409.             int ApetureMin = -(Size / 2);
  410.             int ApetureMax = (Size / 2);
  411.  
  412.             for (int x = 0; x < NewBitmap.Width; ++x)
  413.             {
  414.                 for (int y = 0; y < NewBitmap.Height; ++y)
  415.                 {
  416.                     List<int> RValues = new List<int>();
  417.                     List<int> GValues = new List<int>();
  418.                     List<int> BValues = new List<int>();
  419.  
  420.                     for (int x2 = ApetureMin; x2 < ApetureMax; ++x2)
  421.                     {
  422.                         int TempX = x + x2;
  423.                         if (TempX >= 0 && TempX < NewBitmap.Width)
  424.                         {
  425.                             for (int y2 = ApetureMin; y2 < ApetureMax; ++y2)
  426.                             {
  427.                                 int TempY = y + y2;
  428.  
  429.                                 if (TempY >= 0 && TempY < NewBitmap.Height)
  430.                                 {
  431.                                     Color TempColor = TempBitmap.GetPixel(TempX, TempY);
  432.                                     RValues.Add(TempColor.R);
  433.                                     GValues.Add(TempColor.G);
  434.                                     BValues.Add(TempColor.B);
  435.                                 }
  436.                             }
  437.                         }
  438.                     }
  439.  
  440.                     RValues.Sort();
  441.                     GValues.Sort();
  442.                     BValues.Sort();
  443.  
  444.                     Color MedianPixel = Color.FromArgb( RValues[RValues.Count / 2],
  445.                                                         GValues[GValues.Count / 2],
  446.                                                         BValues[BValues.Count / 2]);
  447.  
  448.                     NewBitmap.SetPixel(x, y, MedianPixel);
  449.                 }
  450.             }
  451.             return NewBitmap;
  452.         }
  453.  
  454.         public static Bitmap MedianFilter(Bitmap bmp)
  455.         {
  456.             int Size = 2;
  457.             List<byte> R = new List<byte>();
  458.             List<byte> G = new List<byte>();
  459.             List<byte> B = new List<byte>();
  460.             int ApetureMin = -(Size / 2);
  461.             int ApetureMax = (Size / 2);
  462.             BitmapData imageData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppRgb);
  463.             unsafe
  464.             {
  465.                 byte* start = (byte*)imageData.Scan0;
  466.                 for (int x = 0; x < imageData.Width; x++)
  467.                 {
  468.                     for (int y = 0; y < imageData.Height; y++)
  469.                     {
  470.                         for (int x1 = ApetureMin; x1 < ApetureMax; x1++)
  471.                         {
  472.                             int valx = x + x1;
  473.                             if (valx >= 0 && valx < imageData.Width)
  474.                             {
  475.                                 for (int y1 = ApetureMin; y1 < ApetureMax; y1++)
  476.                                 {
  477.                                     int valy = y + y1;
  478.                                     if (valy >= 0 && valy < imageData.Height)
  479.                                     {
  480.                                         // error come from here
  481.                                         Color tempColor = bmp.GetPixel(valx, valy);
  482.  
  483.                                         R.Add(tempColor.R);
  484.                                         G.Add(tempColor.G);
  485.                                         B.Add(tempColor.B);
  486.                                     }
  487.                                 }
  488.                             }
  489.                         }
  490.                     }
  491.                 }
  492.                 R.Sort();
  493.                 G.Sort();
  494.                 B.Sort();
  495.             }
  496.             bmp.UnlockBits(imageData);
  497.             return bmp;
  498.         }
  499.     }
  500.  
  501.     /// <summary>
  502.     /// This Class helps us to encapsulates and to compute the nearly same actions.
  503.     /// </summary>
  504.     public class GraphicFilter
  505.     {
  506.         /// <summary>
  507.         ///
  508.         /// </summary>
  509.         public int[,] ColorMatrix = { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } };
  510.         /// <summary>
  511.         ///
  512.         /// </summary>
  513.         public int Divider = 0;
  514.         /// <summary>
  515.         ///
  516.         /// </summary>
  517.         public int Offset = 0;
  518.  
  519.         /// <summary>
  520.         /// Ensures that the values got its correct/allowed values between 0 and 255.
  521.         /// </summary>
  522.         /// <param name="val"><see cref="System.Int32"/>.</param>
  523.         /// <returns>A <see cref="System.Byte"/>.</returns>
  524.         private byte Norming(int val)
  525.         {
  526.             if (val < 0)
  527.                 return 0;
  528.             if (val > 255)
  529.                 return 255;
  530.             return (byte)val;
  531.         }
  532.  
  533.         /// <summary>
  534.         /// This Method represents all the actions we have to do by manipulating Bitmaps.
  535.         /// </summary>
  536.         /// <param name="bmp"></param>
  537.         public void Execution(Bitmap bmp)
  538.         {
  539.             //create a copy of the bmp:
  540.             Bitmap bmpSource = (Bitmap)bmp.Clone();
  541.             BitmapData bmpSourceDat = bmpSource.LockBits(new Rectangle(0, 0, bmpSource.Width, bmpSource.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppRgb);
  542.             BitmapData bmpDestinationDat = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppRgb);
  543.  
  544.             unsafe
  545.             {
  546.                 byte* pByte = (byte*)bmpDestinationDat.Scan0 + bmp.Width * 4 + 4;
  547.                 byte* pLine0 = (byte*)bmpSourceDat.Scan0;
  548.                 byte* pLine1 = (byte*)bmpSourceDat.Scan0 + bmp.Width * 4;
  549.                 byte* pLine2 = (byte*)bmpSourceDat.Scan0 + bmp.Width * 8;
  550.  
  551.                 int size = (bmp.Width - 2) * (bmp.Height - 2);
  552.  
  553.                 for (int i = 0; i < size; i++)
  554.                 {
  555.                     pByte[0] = Norming((((pLine0[0] * ColorMatrix[0, 0]) + (pLine0[4] * ColorMatrix[1, 0]) + (pLine0[8] * ColorMatrix[2, 0]) +
  556.                                          (pLine1[0] * ColorMatrix[0, 1]) + (pLine1[4] * ColorMatrix[1, 1]) + (pLine1[8] * ColorMatrix[2, 1]) +
  557.                                          (pLine2[0] * ColorMatrix[0, 2]) + (pLine2[4] * ColorMatrix[1, 2]) + (pLine2[8] * ColorMatrix[2, 2])) / Divider) + Offset);
  558.  
  559.                     pByte[1] = Norming((((pLine0[1] * ColorMatrix[0, 0]) + (pLine0[5] * ColorMatrix[1, 0]) + (pLine0[9] * ColorMatrix[2, 0]) +
  560.                                          (pLine1[1] * ColorMatrix[0, 1]) + (pLine1[5] * ColorMatrix[1, 1]) + (pLine1[9] * ColorMatrix[2, 1]) +
  561.                                          (pLine2[1] * ColorMatrix[0, 2]) + (pLine2[5] * ColorMatrix[1, 2]) + (pLine2[9] * ColorMatrix[2, 2])) / Divider) + Offset);
  562.  
  563.                     pByte[2] = Norming((((pLine0[2] * ColorMatrix[0, 0]) + (pLine0[6] * ColorMatrix[1, 0]) + (pLine0[10] * ColorMatrix[2, 0]) +
  564.                                          (pLine1[2] * ColorMatrix[0, 1]) + (pLine1[6] * ColorMatrix[1, 1]) + (pLine1[10] * ColorMatrix[2, 1]) +
  565.                                          (pLine2[2] * ColorMatrix[0, 2]) + (pLine2[6] * ColorMatrix[1, 2]) + (pLine2[10] * ColorMatrix[2, 2])) / Divider) + Offset);
  566.  
  567.                     pByte += 4;
  568.                     pLine0 += 4;
  569.                     pLine1 += 4;
  570.                     pLine2 += 4;
  571.                 }
  572.             }
  573.             bmp.UnlockBits(bmpDestinationDat);
  574.             bmpSource.UnlockBits(bmpSourceDat);
  575.             bmpSource.Dispose();
  576.         }
  577.     }
  578. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement