|
|
|
@ -1,13 +1,14 @@ |
|
|
|
// Copyright (c) Six Labors and contributors.
|
|
|
|
// Licensed under the Apache License, Version 2.0.
|
|
|
|
|
|
|
|
using System; |
|
|
|
using SixLabors.ImageSharp.Memory; |
|
|
|
using SixLabors.ImageSharp.PixelFormats; |
|
|
|
|
|
|
|
namespace SixLabors.ImageSharp.Dithering.Base |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// The base class for performing ordered ditheroing using a 4x4 matrix.
|
|
|
|
/// The base class for performing ordered dithering using a 4x4 matrix.
|
|
|
|
/// </summary>
|
|
|
|
public abstract class OrderedDitherBase : IOrderedDither |
|
|
|
{ |
|
|
|
@ -30,7 +31,23 @@ namespace SixLabors.ImageSharp.Dithering.Base |
|
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
|
{ |
|
|
|
source.ToRgba32(ref rgba); |
|
|
|
image[x, y] = this.matrix[y % 3, x % 3] >= rgba[index] ? lower : upper; |
|
|
|
switch (index) |
|
|
|
{ |
|
|
|
case 0: |
|
|
|
image[x, y] = this.matrix[y % 3, x % 3] >= rgba.R ? lower : upper; |
|
|
|
return; |
|
|
|
case 1: |
|
|
|
image[x, y] = this.matrix[y % 3, x % 3] >= rgba.G ? lower : upper; |
|
|
|
return; |
|
|
|
case 2: |
|
|
|
image[x, y] = this.matrix[y % 3, x % 3] >= rgba.B ? lower : upper; |
|
|
|
return; |
|
|
|
case 3: |
|
|
|
image[x, y] = this.matrix[y % 3, x % 3] >= rgba.A ? lower : upper; |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(index), "Index should be between 0 and 3 inclusive."); |
|
|
|
} |
|
|
|
} |
|
|
|
} |