title: Fastest way of setting pixels in C# is slow on small Bitmap
body: <p>I'm trying to edit pixels of a <code>Bitmap</code> (960x510), and I'm using the fastest method I could find. But it's still painfully slow (7 FPS).</p>
  <pre><code>unsafe
  {
      BitmapData bitmapData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, bmp.PixelFormat);
      int bytesPerPixel = Image.GetPixelFormatSize(bmp.PixelFormat) / 8;
      int heightInPixels = bitmapData.Height;
      int widthInBytes = bitmapData.Width * bytesPerPixel;
      byte* PtrFirstPixel = (byte*)bitmapData.Scan0;
      for(int y = 0; y &lt; heightInPixels; y++)
      {
          byte* currentLine = PtrFirstPixel + (y * bitmapData.Stride);
          for (int x = 0; x &lt; widthInBytes; x = x + bytesPerPixel)
          {
              for (int i = 0; i &lt; Shaders.Count; i++)
              {
                  rgba color = new rgba(currentLine[x], currentLine[x + 1], currentLine[x + 2], -1);
                  if (bytesPerPixel == 4) color.a = currentLine[x + 3];
                  Shaders[i].pixel(new xy(x * bytesPerPixel % bmp.Width, x * bytesPerPixel / bmp.Height), color);
                  currentLine[x] = (byte)color.r;
                  currentLine[x + 1] = (byte)color.g;
                  currentLine[x + 2] = (byte)color.b;
                  if (bytesPerPixel == 4) currentLine[x + 3] = (byte)color.a;
              }
          }
      }
      bmp.UnlockBits(bitmapData);
  }
  </code></pre>
  <p>The method inside <code>Shaders[i].pixel</code> changes the <code>color.r</code>, <code>color.g</code>, <code>color.b</code> and <code>color.a</code> values.
  How can I increase performance?</p>