|
|
@ -373,22 +373,21 @@ namespace SixLabors.ImageSharp.Formats.Tga |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
using (IManagedByteBuffer row = this.memoryAllocator.AllocatePaddedPixelRowBuffer(width, 1, 0)) |
|
|
using IMemoryOwner<byte> row = this.memoryAllocator.AllocatePaddedPixelRowBuffer(width, 1, 0); |
|
|
{ |
|
|
Span<byte> rowSpan = row.GetSpan(); |
|
|
bool invertY = InvertY(origin); |
|
|
bool invertY = InvertY(origin); |
|
|
if (invertY) |
|
|
if (invertY) |
|
|
{ |
|
|
{ |
|
|
for (int y = height - 1; y >= 0; y--) |
|
|
for (int y = height - 1; y >= 0; y--) |
|
|
{ |
|
|
{ |
|
|
this.ReadL8Row(width, pixels, row, y); |
|
|
this.ReadL8Row(width, pixels, rowSpan, y); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
for (int y = 0; y < height; y++) |
|
|
for (int y = 0; y < height; y++) |
|
|
{ |
|
|
{ |
|
|
this.ReadL8Row(width, pixels, row, y); |
|
|
this.ReadL8Row(width, pixels, rowSpan, y); |
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -406,8 +405,9 @@ namespace SixLabors.ImageSharp.Formats.Tga |
|
|
{ |
|
|
{ |
|
|
TPixel color = default; |
|
|
TPixel color = default; |
|
|
bool invertX = InvertX(origin); |
|
|
bool invertX = InvertX(origin); |
|
|
using (IManagedByteBuffer row = this.memoryAllocator.AllocatePaddedPixelRowBuffer(width, 2, 0)) |
|
|
using IMemoryOwner<byte> row = this.memoryAllocator.AllocatePaddedPixelRowBuffer(width, 2, 0); |
|
|
{ |
|
|
Span<byte> rowSpan = row.GetSpan(); |
|
|
|
|
|
|
|
|
for (int y = 0; y < height; y++) |
|
|
for (int y = 0; y < height; y++) |
|
|
{ |
|
|
{ |
|
|
int newY = InvertY(y, height, origin); |
|
|
int newY = InvertY(y, height, origin); |
|
|
@ -437,8 +437,7 @@ namespace SixLabors.ImageSharp.Formats.Tga |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
this.currentStream.Read(row); |
|
|
this.currentStream.Read(rowSpan); |
|
|
Span<byte> rowSpan = row.GetSpan(); |
|
|
|
|
|
|
|
|
|
|
|
if (!this.hasAlpha) |
|
|
if (!this.hasAlpha) |
|
|
{ |
|
|
{ |
|
|
@ -460,7 +459,6 @@ namespace SixLabors.ImageSharp.Formats.Tga |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Reads a uncompressed TGA image where each pixels has 24 bit.
|
|
|
/// Reads a uncompressed TGA image where each pixels has 24 bit.
|
|
|
@ -490,23 +488,22 @@ namespace SixLabors.ImageSharp.Formats.Tga |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
using (IManagedByteBuffer row = this.memoryAllocator.AllocatePaddedPixelRowBuffer(width, 3, 0)) |
|
|
using IMemoryOwner<byte> row = this.memoryAllocator.AllocatePaddedPixelRowBuffer(width, 3, 0); |
|
|
{ |
|
|
Span<byte> rowSpan = row.GetSpan(); |
|
|
bool invertY = InvertY(origin); |
|
|
bool invertY = InvertY(origin); |
|
|
|
|
|
|
|
|
if (invertY) |
|
|
if (invertY) |
|
|
{ |
|
|
{ |
|
|
for (int y = height - 1; y >= 0; y--) |
|
|
for (int y = height - 1; y >= 0; y--) |
|
|
{ |
|
|
{ |
|
|
this.ReadBgr24Row(width, pixels, row, y); |
|
|
this.ReadBgr24Row(width, pixels, rowSpan, y); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
for (int y = 0; y < height; y++) |
|
|
for (int y = 0; y < height; y++) |
|
|
{ |
|
|
{ |
|
|
this.ReadBgr24Row(width, pixels, row, y); |
|
|
this.ReadBgr24Row(width, pixels, rowSpan, y); |
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -526,21 +523,21 @@ namespace SixLabors.ImageSharp.Formats.Tga |
|
|
bool invertX = InvertX(origin); |
|
|
bool invertX = InvertX(origin); |
|
|
if (this.tgaMetadata.AlphaChannelBits == 8 && !invertX) |
|
|
if (this.tgaMetadata.AlphaChannelBits == 8 && !invertX) |
|
|
{ |
|
|
{ |
|
|
using (IManagedByteBuffer row = this.memoryAllocator.AllocatePaddedPixelRowBuffer(width, 4, 0)) |
|
|
using IMemoryOwner<byte> row = this.memoryAllocator.AllocatePaddedPixelRowBuffer(width, 4, 0); |
|
|
{ |
|
|
Span<byte> rowSpan = row.GetSpan(); |
|
|
|
|
|
|
|
|
if (InvertY(origin)) |
|
|
if (InvertY(origin)) |
|
|
{ |
|
|
{ |
|
|
for (int y = height - 1; y >= 0; y--) |
|
|
for (int y = height - 1; y >= 0; y--) |
|
|
{ |
|
|
{ |
|
|
this.ReadBgra32Row(width, pixels, row, y); |
|
|
this.ReadBgra32Row(width, pixels, rowSpan, y); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
for (int y = 0; y < height; y++) |
|
|
for (int y = 0; y < height; y++) |
|
|
{ |
|
|
{ |
|
|
this.ReadBgra32Row(width, pixels, row, y); |
|
|
this.ReadBgra32Row(width, pixels, rowSpan, y); |
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -652,12 +649,12 @@ namespace SixLabors.ImageSharp.Formats.Tga |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
private void ReadL8Row<TPixel>(int width, Buffer2D<TPixel> pixels, IManagedByteBuffer row, int y) |
|
|
private void ReadL8Row<TPixel>(int width, Buffer2D<TPixel> pixels, Span<byte> row, int y) |
|
|
where TPixel : unmanaged, IPixel<TPixel> |
|
|
where TPixel : unmanaged, IPixel<TPixel> |
|
|
{ |
|
|
{ |
|
|
this.currentStream.Read(row); |
|
|
this.currentStream.Read(row); |
|
|
Span<TPixel> pixelSpan = pixels.GetRowSpan(y); |
|
|
Span<TPixel> pixelSpan = pixels.GetRowSpan(y); |
|
|
PixelOperations<TPixel>.Instance.FromL8Bytes(this.Configuration, row.GetSpan(), pixelSpan, width); |
|
|
PixelOperations<TPixel>.Instance.FromL8Bytes(this.Configuration, row, pixelSpan, width); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
@ -679,12 +676,12 @@ namespace SixLabors.ImageSharp.Formats.Tga |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
private void ReadBgr24Row<TPixel>(int width, Buffer2D<TPixel> pixels, IManagedByteBuffer row, int y) |
|
|
private void ReadBgr24Row<TPixel>(int width, Buffer2D<TPixel> pixels, Span<byte> row, int y) |
|
|
where TPixel : unmanaged, IPixel<TPixel> |
|
|
where TPixel : unmanaged, IPixel<TPixel> |
|
|
{ |
|
|
{ |
|
|
this.currentStream.Read(row); |
|
|
this.currentStream.Read(row); |
|
|
Span<TPixel> pixelSpan = pixels.GetRowSpan(y); |
|
|
Span<TPixel> pixelSpan = pixels.GetRowSpan(y); |
|
|
PixelOperations<TPixel>.Instance.FromBgr24Bytes(this.Configuration, row.GetSpan(), pixelSpan, width); |
|
|
PixelOperations<TPixel>.Instance.FromBgr24Bytes(this.Configuration, row, pixelSpan, width); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
@ -698,12 +695,12 @@ namespace SixLabors.ImageSharp.Formats.Tga |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
private void ReadBgra32Row<TPixel>(int width, Buffer2D<TPixel> pixels, IManagedByteBuffer row, int y) |
|
|
private void ReadBgra32Row<TPixel>(int width, Buffer2D<TPixel> pixels, Span<byte> row, int y) |
|
|
where TPixel : unmanaged, IPixel<TPixel> |
|
|
where TPixel : unmanaged, IPixel<TPixel> |
|
|
{ |
|
|
{ |
|
|
this.currentStream.Read(row); |
|
|
this.currentStream.Read(row); |
|
|
Span<TPixel> pixelSpan = pixels.GetRowSpan(y); |
|
|
Span<TPixel> pixelSpan = pixels.GetRowSpan(y); |
|
|
PixelOperations<TPixel>.Instance.FromBgra32Bytes(this.Configuration, row.GetSpan(), pixelSpan, width); |
|
|
PixelOperations<TPixel>.Instance.FromBgra32Bytes(this.Configuration, row, pixelSpan, width); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|