there was an attempt

This commit is contained in:
Maff 2019-10-03 00:28:27 +01:00
parent 4356367712
commit 191dcdafd6
8 changed files with 88 additions and 4 deletions

View File

@ -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;
}
}

View File

@ -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
}
}
}

8
libdither/IDither.cs Normal file
View File

@ -0,0 +1,8 @@
using System.Drawing;
namespace libdither {
public interface IDither {
uint BlackPoint { get; set; }
Bitmap Dither(Bitmap input);
}
}

View File

@ -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;
}
}
}

View File

@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Drawing.Common" Version="4.6.0" />
</ItemGroup>
</Project>

View File

@ -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

View File

@ -22,14 +22,14 @@
<Grid Margin="0">
<RadioButton x:Name="rbP1" Content="P1/P1S" Margin="10,10,10,0" Click="SetP1_Click" ToolTip="Paperang model P1 or P1S" GroupName="rbgModel" Height="15" VerticalAlignment="Top"/>
<RadioButton x:Name="rbP2" Content="P2/P2S" Margin="10,30,10,0" Click="SetP2_Click" VerticalAlignment="Top" GroupName="rbgModel" ToolTip="Paperang model P2 or P2S"/>
<RadioButton x:Name="rbT1" Content="T1" Margin="10,50,10,0" Click="SetT1_Click" VerticalAlignment="Top" IsChecked="True" ToolTip="Paperang model T1, a tape-esque label printer" GroupName="rbgModel"/>
<RadioButton x:Name="rbT1" Content="T1" Margin="10,50,10,0" Click="SetT1_Click" VerticalAlignment="Top" ToolTip="Paperang model T1, a tape-esque label printer" GroupName="rbgModel"/>
<Button x:Name="btInitUSB" Content="Initialise" MinWidth="75" Margin="10,0,10,36" IsDefault="True" Click="BtInitUSB_Click" Height="21" VerticalAlignment="Bottom"/>
<Button x:Name="btDeInitUSB" Content="Deinitialise" MinWidth="75" Margin="10,0,10,10" Click="BtDeInitUSB_Click" Height="21" VerticalAlignment="Bottom" IsEnabled="False"/>
</Grid>
</GroupBox>
<GroupBox x:Name="gbOtherFunc" Header="Other Functions" Margin="2,2,2,2" Grid.Column="1" IsEnabled="False">
<Grid Margin="0,0,0,0">
<Slider x:Name="slFeedTime" Margin="10,44,10,0" Maximum="500" Value="175" TickPlacement="Both" SmallChange="5" TickFrequency="5" LargeChange="25" ToolTip="Choose how long, in milliseconds, the printer should feed paper for" IsMoveToPointEnabled="True" IsSnapToTickEnabled="True" Height="33" VerticalAlignment="Top"/>
<Slider x:Name="slFeedTime" Margin="10,44,10,0" Maximum="500" Value="175" TickPlacement="Both" SmallChange="5" TickFrequency="5" LargeChange="25" IsMoveToPointEnabled="True" IsSnapToTickEnabled="True" Height="33" VerticalAlignment="Top"/>
<Button x:Name="btFeed" Content="Feed" VerticalAlignment="Top" MinWidth="75" Margin="0,13,12,0" Height="21" Click="BtFeed_Click" Width="73" HorizontalAlignment="Right"/>
<Label x:Name="label" Content="Feed (ms)" Margin="10,10,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="79"/>
</Grid>

View File

@ -15,10 +15,11 @@ namespace paperangapp {
public partial class MainWindow : Window {
private ILogTiny logger;
private BaseTypes.Connection mmjcx=BaseTypes.Connection.USB;
private BaseTypes.Model mmjmd=BaseTypes.Model.T1;
private IPrinter prtr=new USB(BaseTypes.Model.T1); // T1 used as a generic, prtr used soley for the PrinterAvailable attr. all paperang devices tested report the exact same USB identifiers.
private BaseTypes.Model mmjmd=BaseTypes.Model.None;
private IPrinter prtr=new USB(BaseTypes.Model.None); // T1 used as a generic, prtr used soley for the PrinterAvailable attr. all paperang devices tested report the exact same USB identifiers.
private Paperang mmj=null;
private System.Timers.Timer usbpoll;
private uint dThresh=127;
private enum AppState {
UnInitNoDev,
UnInitDev,