Browse Source

Cleanup bmp encoder

Former-commit-id: e6ae6c39ce5d83da0762fde1a2bd2c6428dced97
Former-commit-id: f81b2f43de2696e18fe5399fbb456f0f9a9b0cda
Former-commit-id: 849e263b02fbb25a317a732da50f94172af719ff
pull/1/head
James Jackson-South 10 years ago
parent
commit
39153debab
  1. 20
      src/ImageProcessorCore/Formats/Bmp/BmpEncoderCore.cs

20
src/ImageProcessorCore/Formats/Bmp/BmpEncoderCore.cs

@ -5,7 +5,6 @@
namespace ImageProcessorCore.Formats namespace ImageProcessorCore.Formats
{ {
using System;
using System.IO; using System.IO;
using IO; using IO;
@ -21,7 +20,7 @@ namespace ImageProcessorCore.Formats
private BmpBitsPerPixel bmpBitsPerPixel; private BmpBitsPerPixel bmpBitsPerPixel;
/// <summary> /// <summary>
/// The amount to pad each row by.</param> /// The amount to pad each row by.
/// </summary> /// </summary>
private int padding; private int padding;
@ -44,7 +43,7 @@ namespace ImageProcessorCore.Formats
// Cast to int will get the bytes per pixel // Cast to int will get the bytes per pixel
short bpp = (short)(8 * (int)bitsPerPixel); short bpp = (short)(8 * (int)bitsPerPixel);
int bytesPerLine = 4 * ((image.Width * bpp + 31) / 32); int bytesPerLine = 4 * (((image.Width * bpp) + 31) / 32);
this.padding = bytesPerLine - (image.Width * (int)bitsPerPixel); this.padding = bytesPerLine - (image.Width * (int)bitsPerPixel);
// Do not use IDisposable pattern here as we want to preserve the stream. // Do not use IDisposable pattern here as we want to preserve the stream.
@ -121,9 +120,8 @@ namespace ImageProcessorCore.Formats
/// Writes the pixel data to the binary stream. /// Writes the pixel data to the binary stream.
/// </summary> /// </summary>
/// <typeparam name="T">The pixel format.</typeparam> /// <typeparam name="T">The pixel format.</typeparam>
/// <typeparam name="TP">The packed format. <example>long, float.</example></typeparam>/// <param name="writer"> /// <typeparam name="TP">The packed format. <example>long, float.</example></typeparam>
/// The <see cref="EndianBinaryWriter"/> containing the stream to write to. /// <param name="writer">The <see cref="EndianBinaryWriter"/> containing the stream to write to.</param>
/// </param>
/// <param name="image"> /// <param name="image">
/// The <see cref="ImageBase{T,TP}"/> containing pixel data. /// The <see cref="ImageBase{T,TP}"/> containing pixel data.
/// </param> /// </param>
@ -133,14 +131,14 @@ namespace ImageProcessorCore.Formats
{ {
using (IPixelAccessor<T, TP> pixels = image.Lock()) using (IPixelAccessor<T, TP> pixels = image.Lock())
{ {
switch (bmpBitsPerPixel) switch (this.bmpBitsPerPixel)
{ {
case BmpBitsPerPixel.Pixel32: case BmpBitsPerPixel.Pixel32:
this.Write32bit(writer, pixels); this.Write32Bit(writer, pixels);
break; break;
case BmpBitsPerPixel.Pixel24: case BmpBitsPerPixel.Pixel24:
this.Write24bit(writer, pixels); this.Write24Bit(writer, pixels);
break; break;
} }
} }
@ -153,7 +151,7 @@ namespace ImageProcessorCore.Formats
/// <typeparam name="TP">The packed format. <example>long, float.</example></typeparam> /// <typeparam name="TP">The packed format. <example>long, float.</example></typeparam>
/// <param name="writer">The <see cref="EndianBinaryWriter"/> containing the stream to write to.</param> /// <param name="writer">The <see cref="EndianBinaryWriter"/> containing the stream to write to.</param>
/// <param name="pixels">The <see cref="IPixelAccessor"/> containing pixel data.</param> /// <param name="pixels">The <see cref="IPixelAccessor"/> containing pixel data.</param>
private void Write32bit<T, TP>(EndianBinaryWriter writer, IPixelAccessor<T, TP> pixels) private void Write32Bit<T, TP>(EndianBinaryWriter writer, IPixelAccessor<T, TP> pixels)
where T : IPackedVector<TP> where T : IPackedVector<TP>
where TP : struct where TP : struct
{ {
@ -180,7 +178,7 @@ namespace ImageProcessorCore.Formats
/// <typeparam name="T">The pixel format.</typeparam> /// <typeparam name="T">The pixel format.</typeparam>
/// <typeparam name="TP">The packed format. <example>long, float.</example></typeparam>/// <param name="writer">The <see cref="EndianBinaryWriter"/> containing the stream to write to.</param> /// <typeparam name="TP">The packed format. <example>long, float.</example></typeparam>/// <param name="writer">The <see cref="EndianBinaryWriter"/> containing the stream to write to.</param>
/// <param name="pixels">The <see cref="IPixelAccessor"/> containing pixel data.</param> /// <param name="pixels">The <see cref="IPixelAccessor"/> containing pixel data.</param>
private void Write24bit<T, TP>(EndianBinaryWriter writer, IPixelAccessor<T, TP> pixels) private void Write24Bit<T, TP>(EndianBinaryWriter writer, IPixelAccessor<T, TP> pixels)
where T : IPackedVector<TP> where T : IPackedVector<TP>
where TP : struct where TP : struct
{ {

Loading…
Cancel
Save