Skip to content

Commit 0e127c4

Browse files
committed
[DW-34] optimize OpenTiffToImageSharp
1 parent 2d2f799 commit 0e127c4

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

  • IronSoftware.Drawing/IronSoftware.Drawing.Common

IronSoftware.Drawing/IronSoftware.Drawing.Common/AnyBitmap.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2547,11 +2547,27 @@ private Lazy<List<Image>> OpenTiffToImageSharp()
25472547
throw new NotSupportedException("Could not read image");
25482548
}
25492549

2550-
using Image<Rgba32> bmp = new(width, height);
2551-
2552-
var bits = PrepareByteArray(bmp, raster, width, height);
2553-
2554-
var image = Image.LoadPixelData<Rgba32>(bits, bmp.Width, bmp.Height);
2550+
var image = new Image<Rgba32>(width, height);
2551+
image.ProcessPixelRows(accessor =>
2552+
{
2553+
for (int y = 0; y < height; y++)
2554+
{
2555+
var pixelRow = accessor.GetRowSpan(y);
2556+
int tiffRow = height - 1 - y; // flip Y
2557+
2558+
for (int x = 0; x < width; x++)
2559+
{
2560+
int pixel = raster[tiffRow * width + x];
2561+
2562+
byte a = (byte)((pixel >> 24) & 0xFF);
2563+
byte b = (byte)((pixel >> 16) & 0xFF);
2564+
byte g = (byte)((pixel >> 8) & 0xFF);
2565+
byte r = (byte)(pixel & 0xFF);
2566+
2567+
pixelRow[x] = new Rgba32(r, g, b, a);
2568+
}
2569+
}
2570+
});
25552571
image.Metadata.HorizontalResolution = horizontalResolution;
25562572
image.Metadata.VerticalResolution = verticalResolution;
25572573
images.Add(image);

0 commit comments

Comments
 (0)