|
26 | 26 | using SixLabors.ImageSharp.Metadata.Profiles.Icc; |
27 | 27 | using SixLabors.ImageSharp.Metadata.Profiles.Xmp; |
28 | 28 | using SixLabors.ImageSharp.PixelFormats; |
| 29 | +using SixLabors.ImageSharp.Processing; |
29 | 30 |
|
30 | 31 | namespace SixLabors.ImageSharp.Formats.Png; |
31 | 32 |
|
@@ -328,7 +329,7 @@ protected override Image<TPixel> Decode<TPixel>(BufferedReadStream stream, Cance |
328 | 329 |
|
329 | 330 | if (this.Options.TryGetIccProfileForColorConversion(metadata.IccProfile, out IccProfile? iccProfile)) |
330 | 331 | { |
331 | | - ApplyIccProfile(image, iccProfile, CompactSrgbV4Profile.Profile); |
| 332 | + image.ApplyIccProfile(iccProfile, CompactSrgbV4Profile.Profile); |
332 | 333 | } |
333 | 334 |
|
334 | 335 | return image; |
@@ -2161,58 +2162,4 @@ private static bool IsXmpTextData(ReadOnlySpan<byte> keywordBytes) |
2161 | 2162 |
|
2162 | 2163 | private void SwapScanlineBuffers() |
2163 | 2164 | => (this.scanline, this.previousScanline) = (this.previousScanline, this.scanline); |
2164 | | - |
2165 | | - // FIXME: Maybe this could be a .Mutate(x => x.ApplyIccProfile(destinationProfile)) ? Nothing related to png here |
2166 | | - private static void ApplyIccProfile<TPixel>(Image<TPixel> image, IccProfile sourceProfile, IccProfile destinationProfile) |
2167 | | - where TPixel : unmanaged, IPixel<TPixel> |
2168 | | - { |
2169 | | - ColorConversionOptions options = new() |
2170 | | - { |
2171 | | - SourceIccProfile = sourceProfile, |
2172 | | - TargetIccProfile = destinationProfile, |
2173 | | - }; |
2174 | | - |
2175 | | - ColorProfileConverter converter = new(options); |
2176 | | - |
2177 | | - image.ProcessPixelRows(pixelAccessor => |
2178 | | - { |
2179 | | - using IMemoryOwner<float> rgbBuffer = image.Configuration.MemoryAllocator.Allocate<float>(pixelAccessor.Width * 3); |
2180 | | - using IMemoryOwner<float> alphaBuffer = image.Configuration.MemoryAllocator.Allocate<float>(pixelAccessor.Width); |
2181 | | - Span<float> rgbPacked = rgbBuffer.Memory.Span; |
2182 | | - ref float rgbPackedRef = ref MemoryMarshal.GetReference(rgbPacked); |
2183 | | - Span<float> alphaPacked = alphaBuffer.Memory.Span; |
2184 | | - ref float alphaPackedRef = ref MemoryMarshal.GetReference(alphaPacked); |
2185 | | - |
2186 | | - for (int y = 0; y < pixelAccessor.Height; y++) |
2187 | | - { |
2188 | | - Span<TPixel> pixelsRow = pixelAccessor.GetRowSpan(y); |
2189 | | - int rgbIdx = 0; |
2190 | | - for (int x = 0; x < pixelsRow.Length; x++, rgbIdx += 3) |
2191 | | - { |
2192 | | - Vector4 rgba = pixelsRow[x].ToScaledVector4(); |
2193 | | - Unsafe.Add(ref rgbPackedRef, rgbIdx) = rgba.X; |
2194 | | - Unsafe.Add(ref rgbPackedRef, rgbIdx + 1) = rgba.Y; |
2195 | | - Unsafe.Add(ref rgbPackedRef, rgbIdx + 2) = rgba.Z; |
2196 | | - Unsafe.Add(ref alphaPackedRef, x) = rgba.W; |
2197 | | - } |
2198 | | - |
2199 | | - Span<Rgb> source = MemoryMarshal.Cast<float, Rgb>(rgbPacked); |
2200 | | - Span<Rgb> destination = MemoryMarshal.Cast<float, Rgb>(rgbPacked); |
2201 | | - converter.Convert<Rgb, Rgb>(source, destination); |
2202 | | - |
2203 | | - rgbIdx = 0; |
2204 | | - for (int x = 0; x < pixelsRow.Length; x++, rgbIdx += 3) |
2205 | | - { |
2206 | | - float r = Unsafe.Add(ref rgbPackedRef, rgbIdx); |
2207 | | - float g = Unsafe.Add(ref rgbPackedRef, rgbIdx + 1); |
2208 | | - float b = Unsafe.Add(ref rgbPackedRef, rgbIdx + 2); |
2209 | | - float a = Unsafe.Add(ref alphaPackedRef, x); |
2210 | | - |
2211 | | - pixelsRow[x] = TPixel.FromScaledVector4(new Vector4(r, g, b, a)); |
2212 | | - } |
2213 | | - } |
2214 | | - } |
2215 | | - ); |
2216 | | - } |
2217 | | - |
2218 | 2165 | } |
0 commit comments