mirror of https://github.com/SixLabors/ImageSharp
6 changed files with 206 additions and 1 deletions
@ -0,0 +1,68 @@ |
|||||
|
// Copyright (c) Six Labors.
|
||||
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Formats.Jxl.Processing; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Base DCT AC coefficient image
|
||||
|
/// </summary>
|
||||
|
internal interface IJxlDctAcImage |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Gets the bit width of AC coefficients
|
||||
|
/// </summary>
|
||||
|
public JxlDctAcType Type { get; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the number of pixels per row.
|
||||
|
/// </summary>
|
||||
|
public int PixelsPerRow { get; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets a value indicating whether the image is empty and doesn't
|
||||
|
/// have anything within.
|
||||
|
/// </summary>
|
||||
|
public bool IsEmpty { get; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Returns a reference to the coefficients at the specified row.
|
||||
|
/// </summary>
|
||||
|
/// <param name="channel">The plane index (which channel).</param>
|
||||
|
/// <param name="y">The row index within plane specified by <paramref name="channel"/>.</param>
|
||||
|
/// <param name="xBase">The X offset at the specified row.</param>
|
||||
|
/// <returns>
|
||||
|
/// A reference to the coefficients inside the channel
|
||||
|
/// specified by index <paramref name="channel"/>, at index of
|
||||
|
/// the row specified by <paramref name="y"/>, with X offset
|
||||
|
/// specified by <paramref name="xBase"/>.
|
||||
|
/// </returns>
|
||||
|
public JxlDctAcPointer GetPlaneRow(int channel, int y, int xBase = 0); |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Returns a reference to the coefficients at the specified row.
|
||||
|
/// </summary>
|
||||
|
/// <param name="channel">The plane index (which channel).</param>
|
||||
|
/// <param name="y">The row index within plane specified by <paramref name="channel"/>.</param>
|
||||
|
/// <param name="xBase">The X offset at the specified row.</param>
|
||||
|
/// <returns>
|
||||
|
/// A reference to the coefficients inside the channel
|
||||
|
/// specified by index <paramref name="channel"/>, at index of
|
||||
|
/// the row specified by <paramref name="y"/>, with X offset
|
||||
|
/// specified by <paramref name="xBase"/>.
|
||||
|
/// </returns>
|
||||
|
/// <remarks>
|
||||
|
/// This is a read-only kind of <see cref="GetPlaneRow(int, int, int)"/>.
|
||||
|
/// </remarks>
|
||||
|
public JxlDctReadOnlyAcPointer GetReadOnlyPlaneRow(int channel, int y, int xBase = 0); |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Fills all planes with zero.
|
||||
|
/// </summary>
|
||||
|
public void Clear(); |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Fills everything within the specified plane with zero.
|
||||
|
/// </summary>
|
||||
|
/// <param name="plane">Desired index of the plane.</param>
|
||||
|
public void Clear(int plane = 0); |
||||
|
} |
||||
@ -0,0 +1,63 @@ |
|||||
|
// Copyright (c) Six Labors.
|
||||
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
|
using SixLabors.ImageSharp.Formats.Jxl.Memory; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Formats.Jxl.Processing; |
||||
|
|
||||
|
internal sealed class JxlDctAcImage<T> : IJxlDctAcImage, IDisposable |
||||
|
where T : unmanaged |
||||
|
{ |
||||
|
private readonly JxlImage3<T> image; |
||||
|
|
||||
|
public unsafe JxlDctAcImage(Configuration configuration, int width, int height) |
||||
|
{ |
||||
|
DebugGuard.IsTrue(sizeof(T) is 2 or 4, "The type must be 2 or 4 bytes"); |
||||
|
|
||||
|
this.image = JxlImage3<T>.Create(configuration, width, height); |
||||
|
} |
||||
|
|
||||
|
public unsafe JxlDctAcType Type => sizeof(T) == 4 ? JxlDctAcType.Ac32 : JxlDctAcType.Ac16; |
||||
|
|
||||
|
public int PixelsPerRow => this.image.PixelsPerRow; |
||||
|
|
||||
|
public bool IsEmpty => this.image.XSize == 0 || this.image.YSize == 0; |
||||
|
|
||||
|
public void Clear() => JxlImageOperations.ClearImage(this.image); |
||||
|
|
||||
|
public void Clear(int plane = 0) => JxlImageOperations.ClearImage(this.image); |
||||
|
|
||||
|
public unsafe JxlDctAcPointer GetPlaneRow(int channel, int y, int xBase = 0) |
||||
|
{ |
||||
|
if (sizeof(T) == 4) |
||||
|
{ |
||||
|
Span<int> span = (this.image as JxlImage3<int>)!.PlaneRow(channel, y)[xBase..]; |
||||
|
return new JxlDctAcPointer() { Pointer32 = span }; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
Span<short> span = (this.image as JxlImage3<short>)!.PlaneRow(channel, y)[xBase..]; |
||||
|
return new JxlDctAcPointer() { Pointer16 = span }; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public unsafe JxlDctReadOnlyAcPointer GetReadOnlyPlaneRow(int channel, int y, int xBase = 0) |
||||
|
{ |
||||
|
if (sizeof(T) == 4) |
||||
|
{ |
||||
|
ReadOnlySpan<int> span = (this.image as JxlImage3<int>)!.PlaneRow(channel, y)[xBase..]; |
||||
|
return new JxlDctReadOnlyAcPointer(span); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
ReadOnlySpan<short> span = (this.image as JxlImage3<short>)!.PlaneRow(channel, y)[xBase..]; |
||||
|
return new JxlDctReadOnlyAcPointer(span); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public void Dispose() |
||||
|
{ |
||||
|
this.image.Dispose(); |
||||
|
GC.SuppressFinalize(this); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
// Copyright (c) Six Labors.
|
||||
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Formats.Jxl.Processing; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Pointer to DCT AC coefficients
|
||||
|
/// </summary>
|
||||
|
internal ref struct JxlDctAcPointer() |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 16-bit pointer (if any)
|
||||
|
/// </summary>
|
||||
|
public Span<short> Pointer16 = []; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 32-bit pointer (if any)
|
||||
|
/// </summary>
|
||||
|
public Span<int> Pointer32 = []; |
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
// Copyright (c) Six Labors.
|
||||
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Formats.Jxl.Processing; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Bit size for DCT AC coefficient
|
||||
|
/// </summary>
|
||||
|
internal enum JxlDctAcType : byte |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 16-bit coefficient
|
||||
|
/// </summary>
|
||||
|
Ac16, |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 32-bit coefficient
|
||||
|
/// </summary>
|
||||
|
Ac32 |
||||
|
} |
||||
@ -0,0 +1,24 @@ |
|||||
|
// Copyright (c) Six Labors.
|
||||
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Formats.Jxl.Processing; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Pointer to DCT AC coefficients. (Read-only)
|
||||
|
/// </summary>
|
||||
|
internal readonly ref struct JxlDctReadOnlyAcPointer |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 16-bit pointer (if any)
|
||||
|
/// </summary>
|
||||
|
public readonly ReadOnlySpan<short> Pointer16; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 32-bit pointer (if any)
|
||||
|
/// </summary>
|
||||
|
public readonly ReadOnlySpan<int> Pointer32; |
||||
|
|
||||
|
internal JxlDctReadOnlyAcPointer(ReadOnlySpan<short> pointer16) => this.Pointer16 = pointer16; |
||||
|
|
||||
|
internal JxlDctReadOnlyAcPointer(ReadOnlySpan<int> pointer32) => this.Pointer32 = pointer32; |
||||
|
} |
||||
Loading…
Reference in new issue