diff --git a/src/MagicScaler/Magic/IndexedColorTransform.cs b/src/MagicScaler/Magic/IndexedColorTransform.cs index a0f1215..aa4b579 100644 --- a/src/MagicScaler/Magic/IndexedColorTransform.cs +++ b/src/MagicScaler/Magic/IndexedColorTransform.cs @@ -68,7 +68,7 @@ public IndexedColorTransform(PixelSource source) : base(source) public void SetPalette(ReadOnlySpan 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..]); @@ -85,7 +85,7 @@ public void SetPalette(ReadOnlySpan 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); diff --git a/src/MagicScaler/Magic/OverlayTransform.cs b/src/MagicScaler/Magic/OverlayTransform.cs index 09f0650..a862eb9 100644 --- a/src/MagicScaler/Magic/OverlayTransform.cs +++ b/src/MagicScaler/Magic/OverlayTransform.cs @@ -155,8 +155,7 @@ private static unsafe bool noAlphaBlend(uint* ip, uint* ipe) if (ip < ipe + Vector256.Count) { - nuint offs = UnsafeUtil.ByteOffset(ipe, ip); - ip = UnsafeUtil.SubtractOffset(ip, offs); + ip = ipe; goto LoopTop; } @@ -181,8 +180,7 @@ private static unsafe bool noAlphaBlend(uint* ip, uint* ipe) if (ip < ipe + Vector128.Count) { - nuint offs = UnsafeUtil.ByteOffset(ipe, ip); - ip = UnsafeUtil.SubtractOffset(ip, offs); + ip = ipe; goto LoopTop; } diff --git a/src/MagicScaler/Magic/Processors/Converters.cs b/src/MagicScaler/Magic/Processors/Converters.cs index 9b6aa3f..bccb36d 100644 --- a/src/MagicScaler/Magic/Processors/Converters.cs +++ b/src/MagicScaler/Magic/Processors/Converters.cs @@ -287,8 +287,7 @@ private static void convertIntrinsic(byte* ip, byte* ipe) if (ip < ipe + Vector256.Count) { - nuint offs = UnsafeUtil.ByteOffset(ipe, ip); - ip = UnsafeUtil.SubtractOffset(ip, offs); + ip = ipe; Avx.Store(ip, vlast); goto LoopTop; } @@ -311,8 +310,7 @@ private static void convertIntrinsic(byte* ip, byte* ipe) if (ip < ipe + Vector128.Count) { - nuint offs = UnsafeUtil.ByteOffset(ipe, ip); - ip = UnsafeUtil.SubtractOffset(ip, offs); + ip = ipe; Sse2.Store(ip, vlast); goto LoopTop; } diff --git a/src/MagicScaler/Magic/Processors/ConvertersFloat.cs b/src/MagicScaler/Magic/Processors/ConvertersFloat.cs index bf49261..eeb5f91 100644 --- a/src/MagicScaler/Magic/Processors/ConvertersFloat.cs +++ b/src/MagicScaler/Magic/Processors/ConvertersFloat.cs @@ -1112,8 +1112,7 @@ private static void convertFloatAvx2(float* ip, float* ipe, float* lp, int lutma if (ip < ipe + Vector256.Count) { - nuint offs = UnsafeUtil.ByteOffset(ipe, ip); - ip = UnsafeUtil.SubtractOffset(ip, offs); + ip = ipe; Avx.Store(ip, vlast); goto LoopTop; } @@ -1210,8 +1209,7 @@ private static void convertFloat3AAvx2(float* ip, float* ipe, float* lp, int lut if (ip < ipe + Vector256.Count) { - nuint offs = UnsafeUtil.ByteOffset(ipe, ip); - ip = UnsafeUtil.SubtractOffset(ip, offs); + ip = ipe; Avx.Store(ip, vlast); goto LoopTop; } diff --git a/src/MagicScaler/Magic/Processors/ConvertersVideo.cs b/src/MagicScaler/Magic/Processors/ConvertersVideo.cs index 776e87d..9f47bfc 100644 --- a/src/MagicScaler/Magic/Processors/ConvertersVideo.cs +++ b/src/MagicScaler/Magic/Processors/ConvertersVideo.cs @@ -93,8 +93,7 @@ private static void convertIntrinsic(byte* ip, byte* ipe) if (ip < ipe + Vector256.Count) { - nuint offs = UnsafeUtil.ByteOffset(ipe, ip); - ip = UnsafeUtil.SubtractOffset(ip, offs); + ip = ipe; Avx.Store(ip, vlast); goto LoopTop; } @@ -135,8 +134,7 @@ private static void convertIntrinsic(byte* ip, byte* ipe) if (ip < ipe + Vector128.Count) { - nuint offs = UnsafeUtil.ByteOffset(ipe, ip); - ip = UnsafeUtil.SubtractOffset(ip, offs); + ip = ipe; Sse2.Store(ip, vlast); goto LoopTop; } @@ -218,8 +216,7 @@ private static void convertIntrinsic(byte* ip, byte* ipe) if (ip < ipe + Vector256.Count) { - nuint offs = UnsafeUtil.ByteOffset(ipe, ip); - ip = UnsafeUtil.SubtractOffset(ip, offs); + ip = ipe; Avx.Store(ip, vlast); goto LoopTop; } @@ -255,8 +252,7 @@ private static void convertIntrinsic(byte* ip, byte* ipe) if (ip < ipe + Vector128.Count) { - nuint offs = UnsafeUtil.ByteOffset(ipe, ip); - ip = UnsafeUtil.SubtractOffset(ip, offs); + ip = ipe; Sse2.Store(ip, vlast); goto LoopTop; } @@ -357,8 +353,7 @@ private static void convertIntrinsic(byte* ip, byte* ipe) if (ip < ipe + Vector256.Count) { - nuint offs = UnsafeUtil.ByteOffset(ipe, ip); - ip = UnsafeUtil.SubtractOffset(ip, offs); + ip = ipe; Avx.Store(ip, vlast); goto LoopTop; } @@ -407,8 +402,7 @@ private static void convertIntrinsic(byte* ip, byte* ipe) if (ip < ipe + Vector128.Count) { - nuint offs = UnsafeUtil.ByteOffset(ipe, ip); - ip = UnsafeUtil.SubtractOffset(ip, offs); + ip = ipe; Sse2.Store(ip, vlast); goto LoopTop; } @@ -507,8 +501,7 @@ private static void convertIntrinsic(byte* ip, byte* ipe) if (ip < ipe + Vector256.Count) { - nuint offs = UnsafeUtil.ByteOffset(ipe, ip); - ip = UnsafeUtil.SubtractOffset(ip, offs); + ip = ipe; Avx.Store(ip, vlast); goto LoopTop; } @@ -559,8 +552,7 @@ private static void convertIntrinsic(byte* ip, byte* ipe) if (ip < ipe + Vector128.Count) { - nuint offs = UnsafeUtil.ByteOffset(ipe, ip); - ip = UnsafeUtil.SubtractOffset(ip, offs); + ip = ipe; Sse2.Store(ip, vlast); goto LoopTop; } diff --git a/src/MagicScaler/WIC/WicImageProcessor.cs b/src/MagicScaler/WIC/WicImageProcessor.cs index ba287da..4332456 100644 --- a/src/MagicScaler/WIC/WicImageProcessor.cs +++ b/src/MagicScaler/WIC/WicImageProcessor.cs @@ -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);