-
-
Notifications
You must be signed in to change notification settings - Fork 852
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose Span methods on LoadPixelData and SavePixelData #567
Changes from 17 commits
92ab411
cddab85
54791bf
c6c9ae8
1653a93
ea38b24
bddc20a
1c79b08
5156890
15494b4
00af2df
eb318a3
fd766a5
017c7fb
fda2d1f
4f779ca
46e0a85
202e472
45e5d5b
09a77e4
a05b618
92f353b
1695b59
63dc698
93c44f4
05aa089
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -853,7 +853,7 @@ private void ProcessScanlineFromPalette<TPixel>(ReadOnlySpan<byte> defilteredSca | |
where TPixel : struct, IPixel<TPixel> | ||
{ | ||
ReadOnlySpan<byte> newScanline = ToArrayByBitsLength(defilteredScanline, this.bytesPerScanline, this.header.BitDepth); | ||
byte[] pal = this.palette; | ||
ReadOnlySpan<Rgb24> pal = MemoryMarshal.Cast<byte, Rgb24>(this.palette); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. won't this fail if note: not asking for a change just pointing it out incase someone else thinks its important. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should only throw if the we try indexing into the palette outside it's bounds. |
||
var color = default(TPixel); | ||
|
||
var rgba = default(Rgba32); | ||
|
@@ -865,10 +865,9 @@ private void ProcessScanlineFromPalette<TPixel>(ReadOnlySpan<byte> defilteredSca | |
for (int x = 0; x < this.header.Width; x++) | ||
{ | ||
int index = newScanline[x]; | ||
int pixelOffset = index * 3; | ||
|
||
rgba.A = this.paletteAlpha.Length > index ? this.paletteAlpha[index] : (byte)255; | ||
rgba.Rgb = pal.GetRgb24(pixelOffset); | ||
rgba.Rgb = pal[index]; | ||
|
||
color.PackFromRgba32(rgba); | ||
row[x] = color; | ||
|
@@ -881,9 +880,8 @@ private void ProcessScanlineFromPalette<TPixel>(ReadOnlySpan<byte> defilteredSca | |
for (int x = 0; x < this.header.Width; x++) | ||
{ | ||
int index = newScanline[x]; | ||
int pixelOffset = index * 3; | ||
|
||
rgba.Rgb = pal.GetRgb24(pixelOffset); | ||
rgba.Rgb = pal[index]; | ||
|
||
color.PackFromRgba32(rgba); | ||
row[x] = color; | ||
|
@@ -946,6 +944,7 @@ private void ProcessInterlacedDefilteredScanline<TPixel>(ReadOnlySpan<byte> defi | |
|
||
ReadOnlySpan<byte> newScanline = ToArrayByBitsLength(scanlineBuffer, this.bytesPerScanline, this.header.BitDepth); | ||
var rgba = default(Rgba32); | ||
Span<Rgb24> pal = MemoryMarshal.Cast<byte, Rgb24>(this.palette); | ||
|
||
if (this.paletteAlpha != null && this.paletteAlpha.Length > 0) | ||
{ | ||
|
@@ -954,10 +953,9 @@ private void ProcessInterlacedDefilteredScanline<TPixel>(ReadOnlySpan<byte> defi | |
for (int x = pixelOffset, o = 0; x < this.header.Width; x += increment, o++) | ||
{ | ||
int index = newScanline[o]; | ||
int offset = index * 3; | ||
|
||
rgba.A = this.paletteAlpha.Length > index ? this.paletteAlpha[index] : (byte)255; | ||
rgba.Rgb = this.palette.GetRgb24(offset); | ||
rgba.Rgb = pal[index]; | ||
|
||
color.PackFromRgba32(rgba); | ||
rowSpan[x] = color; | ||
|
@@ -970,10 +968,8 @@ private void ProcessInterlacedDefilteredScanline<TPixel>(ReadOnlySpan<byte> defi | |
for (int x = pixelOffset, o = 0; x < this.header.Width; x += increment, o++) | ||
{ | ||
int index = newScanline[o]; | ||
int offset = index * 3; | ||
|
||
rgba.Rgb = this.palette.GetRgb24(offset); | ||
|
||
rgba.Rgb = pal[index]; | ||
color.PackFromRgba32(rgba); | ||
rowSpan[x] = color; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ public static Image<TPixel> LoadPixelData<TPixel>(TPixel[] data, int width, int | |
/// <param name="height">The height of the final image.</param> | ||
/// <typeparam name="TPixel">The pixel format.</typeparam> | ||
/// <returns>A new <see cref="Image{TPixel}"/>.</returns> | ||
private static Image<TPixel> LoadPixelData<TPixel>(Span<TPixel> data, int width, int height) | ||
public static Image<TPixel> LoadPixelData<TPixel>(Span<TPixel> data, int width, int height) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should consume There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My mistake that I also forgot about this in #565 :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. I'll update the PR shortly. Also need to figure out why that test is failing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated. |
||
where TPixel : struct, IPixel<TPixel> | ||
=> LoadPixelData(Configuration.Default, data, width, height); | ||
|
||
|
@@ -57,7 +57,7 @@ public static Image<TPixel> LoadPixelData<TPixel>(byte[] data, int width, int he | |
/// <param name="height">The height of the final image.</param> | ||
/// <typeparam name="TPixel">The pixel format.</typeparam> | ||
/// <returns>A new <see cref="Image{TPixel}"/>.</returns> | ||
private static Image<TPixel> LoadPixelData<TPixel>(Span<byte> data, int width, int height) | ||
public static Image<TPixel> LoadPixelData<TPixel>(Span<byte> data, int width, int height) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
where TPixel : struct, IPixel<TPixel> | ||
=> LoadPixelData<TPixel>(Configuration.Default, data, width, height); | ||
|
||
|
@@ -83,7 +83,7 @@ public static Image<TPixel> LoadPixelData<TPixel>(Configuration config, byte[] d | |
/// <param name="height">The height of the final image.</param> | ||
/// <typeparam name="TPixel">The pixel format.</typeparam> | ||
/// <returns>A new <see cref="Image{TPixel}"/>.</returns> | ||
private static Image<TPixel> LoadPixelData<TPixel>(Configuration config, Span<byte> data, int width, int height) | ||
public static Image<TPixel> LoadPixelData<TPixel>(Configuration config, Span<byte> data, int width, int height) | ||
where TPixel : struct, IPixel<TPixel> | ||
=> LoadPixelData(config, MemoryMarshal.Cast<byte, TPixel>(data), width, height); | ||
|
||
|
@@ -111,7 +111,7 @@ public static Image<TPixel> LoadPixelData<TPixel>(Configuration config, TPixel[] | |
/// <param name="height">The height of the final image.</param> | ||
/// <typeparam name="TPixel">The pixel format.</typeparam> | ||
/// <returns>A new <see cref="Image{TPixel}"/>.</returns> | ||
private static Image<TPixel> LoadPixelData<TPixel>(Configuration config, Span<TPixel> data, int width, int height) | ||
public static Image<TPixel> LoadPixelData<TPixel>(Configuration config, Span<TPixel> data, int width, int height) | ||
where TPixel : struct, IPixel<TPixel> | ||
{ | ||
int count = width * height; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea!