Skip to content

Commit

Permalink
tidying
Browse files Browse the repository at this point in the history
  • Loading branch information
saucecontrol committed Dec 4, 2024
1 parent 17937d8 commit 1a58f2b
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 31 deletions.
4 changes: 2 additions & 2 deletions src/MagicScaler/Magic/IndexedColorTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public IndexedColorTransform(PixelSource source) : base(source)

public void SetPalette(ReadOnlySpan<uint> pal, bool isExact)
{
if (pal.Length is < 2 or > maxPaletteSize) throw new ArgumentException($"Palette must have between 2 and {maxPaletteSize} entries.", nameof(pal));
if (pal.Length is < 1 or > maxPaletteSize) throw new ArgumentException($"Palette must have between 1 and {maxPaletteSize} entries.", nameof(pal));

pal.CopyTo(palBuff.Span);
pal.CopyTo(palBuff.Span[maxPaletteSize..]);
Expand All @@ -85,7 +85,7 @@ public void SetPalette(ReadOnlySpan<uint> pal, bool isExact)
protected override void CopyPixelsInternal(in PixelArea prc, int cbStride, int cbBufferSize, byte* pbBuffer)
{
if (palBuff.IsEmpty) ThrowHelper.ThrowObjectDisposed(nameof(IndexedColorTransform));
if (paletteColors is 0) throw new InvalidOperationException("No palette has been set.");
if (paletteLength is 0) throw new InvalidOperationException("No palette has been set.");

if (isFixedGrey)
copyPixelsDirect(prc, cbStride, cbBufferSize, pbBuffer);
Expand Down
6 changes: 2 additions & 4 deletions src/MagicScaler/Magic/OverlayTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ private static unsafe bool noAlphaBlend(uint* ip, uint* ipe)

if (ip < ipe + Vector256<uint>.Count)
{
nuint offs = UnsafeUtil.ByteOffset(ipe, ip);
ip = UnsafeUtil.SubtractOffset(ip, offs);
ip = ipe;
goto LoopTop;
}

Expand All @@ -181,8 +180,7 @@ private static unsafe bool noAlphaBlend(uint* ip, uint* ipe)

if (ip < ipe + Vector128<uint>.Count)
{
nuint offs = UnsafeUtil.ByteOffset(ipe, ip);
ip = UnsafeUtil.SubtractOffset(ip, offs);
ip = ipe;
goto LoopTop;
}

Expand Down
6 changes: 2 additions & 4 deletions src/MagicScaler/Magic/Processors/Converters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,7 @@ private static void convertIntrinsic(byte* ip, byte* ipe)

if (ip < ipe + Vector256<byte>.Count)
{
nuint offs = UnsafeUtil.ByteOffset(ipe, ip);
ip = UnsafeUtil.SubtractOffset(ip, offs);
ip = ipe;
Avx.Store(ip, vlast);
goto LoopTop;
}
Expand All @@ -311,8 +310,7 @@ private static void convertIntrinsic(byte* ip, byte* ipe)

if (ip < ipe + Vector128<byte>.Count)
{
nuint offs = UnsafeUtil.ByteOffset(ipe, ip);
ip = UnsafeUtil.SubtractOffset(ip, offs);
ip = ipe;
Sse2.Store(ip, vlast);
goto LoopTop;
}
Expand Down
6 changes: 2 additions & 4 deletions src/MagicScaler/Magic/Processors/ConvertersFloat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1112,8 +1112,7 @@ private static void convertFloatAvx2(float* ip, float* ipe, float* lp, int lutma

if (ip < ipe + Vector256<float>.Count)
{
nuint offs = UnsafeUtil.ByteOffset(ipe, ip);
ip = UnsafeUtil.SubtractOffset(ip, offs);
ip = ipe;
Avx.Store(ip, vlast);
goto LoopTop;
}
Expand Down Expand Up @@ -1210,8 +1209,7 @@ private static void convertFloat3AAvx2(float* ip, float* ipe, float* lp, int lut

if (ip < ipe + Vector256<float>.Count)
{
nuint offs = UnsafeUtil.ByteOffset(ipe, ip);
ip = UnsafeUtil.SubtractOffset(ip, offs);
ip = ipe;
Avx.Store(ip, vlast);
goto LoopTop;
}
Expand Down
24 changes: 8 additions & 16 deletions src/MagicScaler/Magic/Processors/ConvertersVideo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ private static void convertIntrinsic(byte* ip, byte* ipe)

if (ip < ipe + Vector256<byte>.Count)
{
nuint offs = UnsafeUtil.ByteOffset(ipe, ip);
ip = UnsafeUtil.SubtractOffset(ip, offs);
ip = ipe;
Avx.Store(ip, vlast);
goto LoopTop;
}
Expand Down Expand Up @@ -135,8 +134,7 @@ private static void convertIntrinsic(byte* ip, byte* ipe)

if (ip < ipe + Vector128<byte>.Count)
{
nuint offs = UnsafeUtil.ByteOffset(ipe, ip);
ip = UnsafeUtil.SubtractOffset(ip, offs);
ip = ipe;
Sse2.Store(ip, vlast);
goto LoopTop;
}
Expand Down Expand Up @@ -218,8 +216,7 @@ private static void convertIntrinsic(byte* ip, byte* ipe)

if (ip < ipe + Vector256<byte>.Count)
{
nuint offs = UnsafeUtil.ByteOffset(ipe, ip);
ip = UnsafeUtil.SubtractOffset(ip, offs);
ip = ipe;
Avx.Store(ip, vlast);
goto LoopTop;
}
Expand Down Expand Up @@ -255,8 +252,7 @@ private static void convertIntrinsic(byte* ip, byte* ipe)

if (ip < ipe + Vector128<byte>.Count)
{
nuint offs = UnsafeUtil.ByteOffset(ipe, ip);
ip = UnsafeUtil.SubtractOffset(ip, offs);
ip = ipe;
Sse2.Store(ip, vlast);
goto LoopTop;
}
Expand Down Expand Up @@ -357,8 +353,7 @@ private static void convertIntrinsic(byte* ip, byte* ipe)

if (ip < ipe + Vector256<byte>.Count)
{
nuint offs = UnsafeUtil.ByteOffset(ipe, ip);
ip = UnsafeUtil.SubtractOffset(ip, offs);
ip = ipe;
Avx.Store(ip, vlast);
goto LoopTop;
}
Expand Down Expand Up @@ -407,8 +402,7 @@ private static void convertIntrinsic(byte* ip, byte* ipe)

if (ip < ipe + Vector128<byte>.Count)
{
nuint offs = UnsafeUtil.ByteOffset(ipe, ip);
ip = UnsafeUtil.SubtractOffset(ip, offs);
ip = ipe;
Sse2.Store(ip, vlast);
goto LoopTop;
}
Expand Down Expand Up @@ -507,8 +501,7 @@ private static void convertIntrinsic(byte* ip, byte* ipe)

if (ip < ipe + Vector256<byte>.Count)
{
nuint offs = UnsafeUtil.ByteOffset(ipe, ip);
ip = UnsafeUtil.SubtractOffset(ip, offs);
ip = ipe;
Avx.Store(ip, vlast);
goto LoopTop;
}
Expand Down Expand Up @@ -559,8 +552,7 @@ private static void convertIntrinsic(byte* ip, byte* ipe)

if (ip < ipe + Vector128<byte>.Count)
{
nuint offs = UnsafeUtil.ByteOffset(ipe, ip);
ip = UnsafeUtil.SubtractOffset(ip, offs);
ip = ipe;
Sse2.Store(ip, vlast);
goto LoopTop;
}
Expand Down
3 changes: 2 additions & 1 deletion src/MagicScaler/WIC/WicImageProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@ private static ProcessImageResult processImage(PipelineContext ctx, Stream ostm)
MagicTransforms.AddMatte(ctx);
MagicTransforms.AddPad(ctx);
WicTransforms.AddIndexedColorConverter(ctx);
MagicTransforms.AddExternalFormatConverter(ctx, true);

var codec = ctx.Settings.EncoderInfo!;
if (wicCodecs.TryGetEncoderForMimeType(codec.MimeTypes.First(), out var wicenc))
codec = wicenc;
else
MagicTransforms.AddExternalFormatConverter(ctx, true);

using var enc = codec.Factory(ostm, ctx.Settings.EncoderOptions);
enc.WriteFrame(ctx.Source, ctx.Metadata, PixelArea.Default);
Expand Down

0 comments on commit 1a58f2b

Please sign in to comment.