Browse Source

Used the new pixel code to optimize the BMP encoder.

af/merge-core
dirk 10 years ago
parent
commit
8dc2610ff0
  1. 30
      src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs

30
src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs

@ -155,19 +155,12 @@ namespace ImageSharp.Formats
where TColor : struct, IPackedPixel<TPacked> where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct where TPacked : struct
{ {
for (int y = pixels.Height - 1; y >= 0; y--) using (PixelRow<TColor, TPacked> row = new PixelRow<TColor, TPacked>(pixels.Width, ComponentOrder.BGRA, this.padding))
{ {
for (int x = 0; x < pixels.Width; x++) for (int y = pixels.Height - 1; y >= 0; y--)
{ {
// Convert back to b-> g-> r-> a order. pixels.CopyTo(row, y);
Color color = new Color(pixels[x, y].ToVector4()); writer.Write(row.Data);
writer.Write(new[] { color.B, color.G, color.R, color.A });
}
// Pad
for (int i = 0; i < this.padding; i++)
{
writer.Write((byte)0);
} }
} }
} }
@ -183,19 +176,12 @@ namespace ImageSharp.Formats
where TColor : struct, IPackedPixel<TPacked> where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct where TPacked : struct
{ {
for (int y = pixels.Height - 1; y >= 0; y--) using (PixelRow<TColor, TPacked> row = new PixelRow<TColor, TPacked>(pixels.Width, ComponentOrder.BGR, this.padding))
{ {
for (int x = 0; x < pixels.Width; x++) for (int y = pixels.Height - 1; y >= 0; y--)
{
// Convert back to b-> g-> r order.
Color color = new Color(pixels[x, y].ToVector4());
writer.Write(new[] { color.B, color.G, color.R });
}
// Pad
for (int i = 0; i < this.padding; i++)
{ {
writer.Write((byte)0); pixels.CopyTo(row, y);
writer.Write(row.Data);
} }
} }
} }

Loading…
Cancel
Save