Browse Source

Add width and height as parameter for makeopaque, change currentPosition to pixelDataStart

pull/1026/head
Brian Popow 7 years ago
parent
commit
e8e1e528fc
  1. 18
      src/ImageSharp/Formats/Tga/TgaDecoderCore.cs

18
src/ImageSharp/Formats/Tga/TgaDecoderCore.cs

@ -366,7 +366,7 @@ namespace SixLabors.ImageSharp.Formats.Tga
{ {
Span<Bgra5551> bgraRowSpan = bgraRow.GetSpan(); Span<Bgra5551> bgraRowSpan = bgraRow.GetSpan();
long currentPosition = this.currentStream.Position; long currentPosition = this.currentStream.Position;
for (int y = 0; y < this.fileHeader.Height; y++) for (int y = 0; y < height; y++)
{ {
this.currentStream.Read(row); this.currentStream.Read(row);
int newY = Invert(y, height, inverted); int newY = Invert(y, height, inverted);
@ -379,7 +379,7 @@ namespace SixLabors.ImageSharp.Formats.Tga
} }
// We need to set each alpha component value to fully opaque. // We need to set each alpha component value to fully opaque.
this.MakeOpaque(pixels, currentPosition, row, bgraRowSpan); this.MakeOpaque(pixels, width, height, currentPosition, row, bgraRowSpan);
} }
} }
@ -551,15 +551,17 @@ namespace SixLabors.ImageSharp.Formats.Tga
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel type.</typeparam> /// <typeparam name="TPixel">The pixel type.</typeparam>
/// <param name="pixels">The destination pixel buffer.</param> /// <param name="pixels">The destination pixel buffer.</param>
/// <param name="currentPosition">The start position of pixel data.</param> /// <param name="width">The width of the image.</param>
/// <param name="height">The height of the image.</param>
/// <param name="pixelDataStart">The start position of pixel data.</param>
/// <param name="row">A byte array to store the read pixel data.</param> /// <param name="row">A byte array to store the read pixel data.</param>
/// <param name="bgraRowSpan">Bgra pixel row span.</param> /// <param name="bgraRowSpan">Bgra pixel row span.</param>
private void MakeOpaque<TPixel>(Buffer2D<TPixel> pixels, long currentPosition, IManagedByteBuffer row, Span<Bgra5551> bgraRowSpan) private void MakeOpaque<TPixel>(Buffer2D<TPixel> pixels, int width, int height, long pixelDataStart, IManagedByteBuffer row, Span<Bgra5551> bgraRowSpan)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
// Reset our stream for a second pass. // Reset our stream for a second pass.
this.currentStream.Position = currentPosition; this.currentStream.Position = pixelDataStart;
for (int y = 0; y < this.fileHeader.Height; y++) for (int y = 0; y < width; y++)
{ {
this.currentStream.Read(row); this.currentStream.Read(row);
PixelOperations<Bgra5551>.Instance.FromBgra5551Bytes( PixelOperations<Bgra5551>.Instance.FromBgra5551Bytes(
@ -567,9 +569,9 @@ namespace SixLabors.ImageSharp.Formats.Tga
row.GetSpan(), row.GetSpan(),
bgraRowSpan, bgraRowSpan,
this.fileHeader.Width); this.fileHeader.Width);
Span<TPixel> pixelSpan = pixels.GetRowSpan(this.fileHeader.Height - y - 1); Span<TPixel> pixelSpan = pixels.GetRowSpan(height - y - 1);
for (int x = 0; x < this.fileHeader.Width; x++) for (int x = 0; x < width; x++)
{ {
Bgra5551 bgra = bgraRowSpan[x]; Bgra5551 bgra = bgraRowSpan[x];
bgra.PackedValue = (ushort)(bgra.PackedValue | (1 << 15)); bgra.PackedValue = (ushort)(bgra.PackedValue | (1 << 15));

Loading…
Cancel
Save