diff --git a/libdither/Algorithms/Base.cs b/libdither/Algorithms/Base.cs new file mode 100644 index 0000000..a67255f --- /dev/null +++ b/libdither/Algorithms/Base.cs @@ -0,0 +1,13 @@ +using System.Drawing; + +namespace libdither.Algorithms { + internal abstract class Base : IDither { + private uint bwThresh; + public uint BlackPoint { get => bwThresh; set => bwThresh = value; } + //Do nothing for the dither method because it's a dummy + public abstract Bitmap Dither(Bitmap input); + internal static int Clamp(int input) => Clamp(input, 0, 255); + internal static int Clamp(int input, int min, int max) => (input < min) ? min : (input > max) ? max : input; + + } +} diff --git a/libdither/Algorithms/Ordered.cs b/libdither/Algorithms/Ordered.cs new file mode 100644 index 0000000..4624ace --- /dev/null +++ b/libdither/Algorithms/Ordered.cs @@ -0,0 +1,23 @@ +using System.Drawing; + +namespace libdither.Algorithms { + internal abstract class Ordered : Base { + private readonly byte[,] matrix; + private readonly byte hSzMx; + private readonly byte wSzMx; + internal protected Ordered(byte[,] input) { + hSzMx = (byte)(input.GetUpperBound(1) + 1); + wSzMx = (byte)(input.GetUpperBound(0) + 1); + int maxMx=wSzMx*hSzMx; + int scMx=255/maxMx; + matrix = new byte[hSzMx, wSzMx]; + for(int x = 0; x < wSzMx; x++) + for(int y = 0; y < hSzMx; y++) + matrix[x, y] = (byte)Clamp(input[x, y] * scMx); + } + public override Bitmap Dither(Bitmap input) { + int rC; int cC; byte tC; + cC + } + } +} diff --git a/libdither/IDither.cs b/libdither/IDither.cs new file mode 100644 index 0000000..8316e9c --- /dev/null +++ b/libdither/IDither.cs @@ -0,0 +1,8 @@ +using System.Drawing; + +namespace libdither { + public interface IDither { + uint BlackPoint { get; set; } + Bitmap Dither(Bitmap input); + } +} diff --git a/libdither/ImageTransforms.cs b/libdither/ImageTransforms.cs new file mode 100644 index 0000000..6ebf744 --- /dev/null +++ b/libdither/ImageTransforms.cs @@ -0,0 +1,27 @@ +using System.Drawing; +using System.Drawing.Imaging; +using System.IO; + +namespace libdither { + public static class ImageTransforms { + public static Bitmap ConvertTo1Bit(Bitmap input) => input; + public static byte[] Convert1BitToByteArray(Bitmap input) { + int hSz=input.Height; int wSz=input.Width; + byte[] intermed; + using(MemoryStream ms = new MemoryStream()) { + input.Save(ms, ImageFormat.Bmp); + input.Dispose(); + intermed = ms.ToArray(); + } + byte[] output=new byte[hSz*wSz]; + int hdrOffset=intermed.Length-output.Length; + for(int h = 0; h < hSz; h++) { + for(int w = 0; w < wSz; w++) { + output[(wSz * (hSz - 1 - h)) + (wSz - 1 - w)] = + (byte)~intermed[hdrOffset + (wSz * h) + (wSz - 1 - w)]; + } + } + return output; + } + } +} diff --git a/libdither/libdither.csproj b/libdither/libdither.csproj new file mode 100644 index 0000000..3732759 --- /dev/null +++ b/libdither/libdither.csproj @@ -0,0 +1,11 @@ + + + + netstandard2.0 + + + + + + + diff --git a/libpaperang/IPrinter.cs b/libpaperang/IPrinter.cs index 641f0e9..c4a994f 100644 --- a/libpaperang/IPrinter.cs +++ b/libpaperang/IPrinter.cs @@ -14,6 +14,7 @@ namespace libpaperang { public byte End; } public enum Model { + None, P1, // Original model; 57mm feed, 48-byte lines (200DPI), LiPo battery (1Ah) P1S,// Original "special edition" model; identical to P1 but in different colours T1, // Label printer model; 15mm feed, unknown-byte lines, 4xAAA battery diff --git a/paperangapp/MainWindow.xaml b/paperangapp/MainWindow.xaml index 18b6420..fbc1e86 100644 --- a/paperangapp/MainWindow.xaml +++ b/paperangapp/MainWindow.xaml @@ -22,14 +22,14 @@ - +