Skip to content

Commit 4565fda

Browse files
ImageMaths => ImageMath
1 parent 216257a commit 4565fda

33 files changed

Lines changed: 261 additions & 262 deletions

src/ImageSharp/Color/Color.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@ namespace SixLabors.ImageSharp
2727
private Color(byte r, byte g, byte b, byte a)
2828
{
2929
this.data = new Rgba64(
30-
ImageMaths.UpscaleFrom8BitTo16Bit(r),
31-
ImageMaths.UpscaleFrom8BitTo16Bit(g),
32-
ImageMaths.UpscaleFrom8BitTo16Bit(b),
33-
ImageMaths.UpscaleFrom8BitTo16Bit(a));
30+
ImageMath.UpscaleFrom8BitTo16Bit(r),
31+
ImageMath.UpscaleFrom8BitTo16Bit(g),
32+
ImageMath.UpscaleFrom8BitTo16Bit(b),
33+
ImageMath.UpscaleFrom8BitTo16Bit(a));
3434
}
3535

3636
[MethodImpl(InliningOptions.ShortMethod)]
3737
private Color(byte r, byte g, byte b)
3838
{
3939
this.data = new Rgba64(
40-
ImageMaths.UpscaleFrom8BitTo16Bit(r),
41-
ImageMaths.UpscaleFrom8BitTo16Bit(g),
42-
ImageMaths.UpscaleFrom8BitTo16Bit(b),
40+
ImageMath.UpscaleFrom8BitTo16Bit(r),
41+
ImageMath.UpscaleFrom8BitTo16Bit(g),
42+
ImageMath.UpscaleFrom8BitTo16Bit(b),
4343
ushort.MaxValue);
4444
}
4545

src/ImageSharp/Common/Helpers/ImageMaths.cs renamed to src/ImageSharp/Common/Helpers/ImageMath.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp
1111
/// <summary>
1212
/// Provides common mathematical methods used for image processing.
1313
/// </summary>
14-
internal static class ImageMaths
14+
internal static class ImageMath
1515
{
1616
/// <summary>
1717
/// Vector for converting pixel to gray value as specified by ITU-R Recommendation BT.709.

src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,7 +1385,7 @@ private int ReadImageHeaders(BufferedReadStream stream, out bool inverted, out b
13851385
{
13861386
case BmpFileMarkerType.Bitmap:
13871387
colorMapSizeBytes = this.fileHeader.Offset - BmpFileHeader.Size - this.infoHeader.HeaderSize;
1388-
int colorCountForBitDepth = ImageMaths.GetColorCountForBitDepth(this.infoHeader.BitsPerPixel);
1388+
int colorCountForBitDepth = ImageMath.GetColorCountForBitDepth(this.infoHeader.BitsPerPixel);
13891389
bytesPerColorMapEntry = colorMapSizeBytes / colorCountForBitDepth;
13901390

13911391
// Edge case for less-than-full-sized palette: bytesPerColorMapEntry should be at least 3.
@@ -1399,7 +1399,7 @@ private int ReadImageHeaders(BufferedReadStream stream, out bool inverted, out b
13991399
case BmpFileMarkerType.Pointer:
14001400
// OS/2 bitmaps always have 3 colors per color palette entry.
14011401
bytesPerColorMapEntry = 3;
1402-
colorMapSizeBytes = ImageMaths.GetColorCountForBitDepth(this.infoHeader.BitsPerPixel) * bytesPerColorMapEntry;
1402+
colorMapSizeBytes = ImageMath.GetColorCountForBitDepth(this.infoHeader.BitsPerPixel) * bytesPerColorMapEntry;
14031403
break;
14041404
}
14051405
}

src/ImageSharp/Formats/Gif/GifEncoderCore.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream, CancellationToken
105105
}
106106

107107
// Get the number of bits.
108-
this.bitDepth = ImageMaths.GetBitsNeededForColorDepth(quantized.Palette.Length);
108+
this.bitDepth = ImageMath.GetBitsNeededForColorDepth(quantized.Palette.Length);
109109

110110
// Write the header.
111111
this.WriteHeader(stream);
@@ -212,7 +212,7 @@ private void EncodeLocal<TPixel>(Image<TPixel> image, IndexedImageFrame<TPixel>
212212
}
213213
}
214214

215-
this.bitDepth = ImageMaths.GetBitsNeededForColorDepth(quantized.Palette.Length);
215+
this.bitDepth = ImageMath.GetBitsNeededForColorDepth(quantized.Palette.Length);
216216
this.WriteGraphicalControlExtension(frameMetadata, this.GetTransparentIndex(quantized), stream);
217217
this.WriteImageDescriptor(frame, true, stream);
218218
this.WriteColorTable(quantized, stream);
@@ -468,7 +468,7 @@ private void WriteColorTable<TPixel>(IndexedImageFrame<TPixel> image, Stream str
468468
where TPixel : unmanaged, IPixel<TPixel>
469469
{
470470
// The maximum number of colors for the bit depth
471-
int colorTableLength = ImageMaths.GetColorCountForBitDepth(this.bitDepth) * Unsafe.SizeOf<Rgb24>();
471+
int colorTableLength = ImageMath.GetColorCountForBitDepth(this.bitDepth) * Unsafe.SizeOf<Rgb24>();
472472

473473
using IManagedByteBuffer colorTable = this.memoryAllocator.AllocateManagedByteBuffer(colorTableLength, AllocationOptions.Clean);
474474
PixelOperations<TPixel>.Instance.ToRgb24Bytes(

src/ImageSharp/Formats/Png/PngEncoderCore.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ private void CollectGrayscaleBytes<TPixel>(ReadOnlySpan<TPixel> rowSpan)
284284
rowSpan.Length,
285285
AllocationOptions.Clean))
286286
{
287-
int scaleFactor = 255 / (ImageMaths.GetColorCountForBitDepth(this.bitDepth) - 1);
287+
int scaleFactor = 255 / (ImageMath.GetColorCountForBitDepth(this.bitDepth) - 1);
288288
Span<byte> tempSpan = temp.GetSpan();
289289

290290
// We need to first create an array of luminance bytes then scale them down to the correct bit depth.
@@ -314,7 +314,7 @@ private void CollectGrayscaleBytes<TPixel>(ReadOnlySpan<TPixel> rowSpan)
314314
for (int x = 0, o = 0; x < rgbaSpan.Length; x++, o += 4)
315315
{
316316
Rgba64 rgba = Unsafe.Add(ref rgbaRef, x);
317-
ushort luminance = ImageMaths.Get16BitBT709Luminance(rgba.R, rgba.G, rgba.B);
317+
ushort luminance = ImageMath.Get16BitBT709Luminance(rgba.R, rgba.G, rgba.B);
318318
BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o, 2), luminance);
319319
BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o + 2, 2), rgba.A);
320320
}
@@ -329,7 +329,7 @@ private void CollectGrayscaleBytes<TPixel>(ReadOnlySpan<TPixel> rowSpan)
329329
{
330330
Unsafe.Add(ref rowSpanRef, x).ToRgba32(ref rgba);
331331
Unsafe.Add(ref rawScanlineSpanRef, o) =
332-
ImageMaths.Get8BitBT709Luminance(rgba.R, rgba.G, rgba.B);
332+
ImageMath.Get8BitBT709Luminance(rgba.R, rgba.G, rgba.B);
333333
Unsafe.Add(ref rawScanlineSpanRef, o + 1) = rgba.A;
334334
}
335335
}

src/ImageSharp/Formats/Png/PngEncoderOptionsHelpers.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public static IndexedImageFrame<TPixel> CreateQuantizedFrame<TPixel>(
7575
if (options.Quantizer is null)
7676
{
7777
byte bits = (byte)options.BitDepth;
78-
var maxColors = ImageMaths.GetColorCountForBitDepth(bits);
78+
var maxColors = ImageMath.GetColorCountForBitDepth(bits);
7979
options.Quantizer = new WuQuantizer(new QuantizerOptions { MaxColors = maxColors });
8080
}
8181

@@ -101,7 +101,7 @@ public static byte CalculateBitDepth<TPixel>(
101101
byte bitDepth;
102102
if (options.ColorType == PngColorType.Palette)
103103
{
104-
byte quantizedBits = (byte)ImageMaths.GetBitsNeededForColorDepth(quantizedFrame.Palette.Length).Clamp(1, 8);
104+
byte quantizedBits = (byte)ImageMath.GetBitsNeededForColorDepth(quantizedFrame.Palette.Length).Clamp(1, 8);
105105
byte bits = Math.Max((byte)options.BitDepth, quantizedBits);
106106

107107
// Png only supports in four pixel depths: 1, 2, 4, and 8 bits when using the PLTE chunk

src/ImageSharp/Formats/Png/PngScanlineProcessor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static void ProcessGrayscaleScanline<TPixel>(
2727
TPixel pixel = default;
2828
ref byte scanlineSpanRef = ref MemoryMarshal.GetReference(scanlineSpan);
2929
ref TPixel rowSpanRef = ref MemoryMarshal.GetReference(rowSpan);
30-
int scaleFactor = 255 / (ImageMaths.GetColorCountForBitDepth(header.BitDepth) - 1);
30+
int scaleFactor = 255 / (ImageMath.GetColorCountForBitDepth(header.BitDepth) - 1);
3131

3232
if (!hasTrans)
3333
{
@@ -96,7 +96,7 @@ public static void ProcessInterlacedGrayscaleScanline<TPixel>(
9696
TPixel pixel = default;
9797
ref byte scanlineSpanRef = ref MemoryMarshal.GetReference(scanlineSpan);
9898
ref TPixel rowSpanRef = ref MemoryMarshal.GetReference(rowSpan);
99-
int scaleFactor = 255 / (ImageMaths.GetColorCountForBitDepth(header.BitDepth) - 1);
99+
int scaleFactor = 255 / (ImageMath.GetColorCountForBitDepth(header.BitDepth) - 1);
100100

101101
if (!hasTrans)
102102
{

src/ImageSharp/Formats/Tga/TgaEncoderCore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ public static int GetLuminance<TPixel>(TPixel sourcePixel)
365365
where TPixel : unmanaged, IPixel<TPixel>
366366
{
367367
var vector = sourcePixel.ToVector4();
368-
return ImageMaths.GetBT709Luminance(ref vector, 256);
368+
return ImageMath.GetBT709Luminance(ref vector, 256);
369369
}
370370
}
371371
}

src/ImageSharp/PixelFormats/PixelImplementations/A8.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public partial struct A8 : IPixel<A8>, IPackedVector<byte>
105105

106106
/// <inheritdoc/>
107107
[MethodImpl(InliningOptions.ShortMethod)]
108-
public void FromLa32(La32 source) => this.PackedValue = ImageMaths.DownScaleFrom16BitTo8Bit(source.A);
108+
public void FromLa32(La32 source) => this.PackedValue = ImageMath.DownScaleFrom16BitTo8Bit(source.A);
109109

110110
/// <inheritdoc/>
111111
[MethodImpl(InliningOptions.ShortMethod)]

src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ public void FromL8(L8 source)
244244
[MethodImpl(InliningOptions.ShortMethod)]
245245
public void FromL16(L16 source)
246246
{
247-
byte rgb = ImageMaths.DownScaleFrom16BitTo8Bit(source.PackedValue);
247+
byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(source.PackedValue);
248248
this.R = rgb;
249249
this.G = rgb;
250250
this.B = rgb;
@@ -265,11 +265,11 @@ public void FromLa16(La16 source)
265265
[MethodImpl(InliningOptions.ShortMethod)]
266266
public void FromLa32(La32 source)
267267
{
268-
byte rgb = ImageMaths.DownScaleFrom16BitTo8Bit(source.L);
268+
byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(source.L);
269269
this.R = rgb;
270270
this.G = rgb;
271271
this.B = rgb;
272-
this.A = ImageMaths.DownScaleFrom16BitTo8Bit(source.A);
272+
this.A = ImageMath.DownScaleFrom16BitTo8Bit(source.A);
273273
}
274274

275275
/// <inheritdoc/>
@@ -306,20 +306,20 @@ public void ToRgba32(ref Rgba32 dest)
306306
[MethodImpl(InliningOptions.ShortMethod)]
307307
public void FromRgb48(Rgb48 source)
308308
{
309-
this.R = ImageMaths.DownScaleFrom16BitTo8Bit(source.R);
310-
this.G = ImageMaths.DownScaleFrom16BitTo8Bit(source.G);
311-
this.B = ImageMaths.DownScaleFrom16BitTo8Bit(source.B);
309+
this.R = ImageMath.DownScaleFrom16BitTo8Bit(source.R);
310+
this.G = ImageMath.DownScaleFrom16BitTo8Bit(source.G);
311+
this.B = ImageMath.DownScaleFrom16BitTo8Bit(source.B);
312312
this.A = byte.MaxValue;
313313
}
314314

315315
/// <inheritdoc/>
316316
[MethodImpl(InliningOptions.ShortMethod)]
317317
public void FromRgba64(Rgba64 source)
318318
{
319-
this.R = ImageMaths.DownScaleFrom16BitTo8Bit(source.R);
320-
this.G = ImageMaths.DownScaleFrom16BitTo8Bit(source.G);
321-
this.B = ImageMaths.DownScaleFrom16BitTo8Bit(source.B);
322-
this.A = ImageMaths.DownScaleFrom16BitTo8Bit(source.A);
319+
this.R = ImageMath.DownScaleFrom16BitTo8Bit(source.R);
320+
this.G = ImageMath.DownScaleFrom16BitTo8Bit(source.G);
321+
this.B = ImageMath.DownScaleFrom16BitTo8Bit(source.B);
322+
this.A = ImageMath.DownScaleFrom16BitTo8Bit(source.A);
323323
}
324324

325325
/// <inheritdoc/>

0 commit comments

Comments
 (0)