parallelized version of flip

Feb 22, 2015 at 4:38 AM
I’ve parallelized the flip method. Can the team consider this for the wpf and perhaps Silverlight platforms ? Here goes:
public static WriteableBitmap Flip(this WriteableBitmap bmp, FlipMode flipMode)
  {
     using (var context = bmp.GetBitmapContext())
     {
        // Use refs for faster access (really important!) speeds up a lot!
        var w = context.Width;
        var h = context.Height;
        var p = context.Pixels;
        var i = 0;
        WriteableBitmap result = null;

        if (flipMode == FlipMode.Horizontal)
        {
           result = BitmapFactory.New(w, h);
           using (var destContext = result.GetBitmapContext())
           {
              var rp = destContext.Pixels;
             //for (var y = h - 1; y >= 0; y--)                  
              Parallel.For(0, h, y =>
            {
                //for (var x = 0; x < w; x++)                     
                Parallel.For(0, w, x =>
                {
                    var srcInd = y * w + x;
                    var destInd = x + w * (h - 1 - y);
                    rp[destInd] = p[srcInd];
                    //i++;
                });
            });
           }
        }
        else if (flipMode == FlipMode.Vertical)
        {
           result = BitmapFactory.New(w, h);
           using (var destContext = result.GetBitmapContext())
           {
              var rp = destContext.Pixels;

             //for (var y = 0; y < h; y++)                  
              Parallel.For(0, h, y =>
            {
                //for (var x = w - 1; x >= 0; x--)                     
                Parallel.For(0, w, x =>
                {
                    var srcInd = y * w + x;
                    var destInd = w - 1 - x + w * y;
                    rp[destInd] = p[srcInd];
                    //i++;
                });
            });
           }
        }

        return result;
     }
  }