Add project files.

This commit is contained in:
EugeneTes
2026-01-13 09:06:47 +01:00
parent dd935fe1fa
commit 7390693f50
187 changed files with 83457 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
namespace Inspectron.Epson.SOAP
{
public enum Font
{
A,
B,
C,
D,
E
}
public enum ErrorCorrection
{
LEVEL_1,
LEVEL_2,
LEVEL_3,
LEVEL_4,
LEVEL_5,
LEVEL_6,
LEVEL_7,
LEVEL_8,
LEVEL_L,
LEVEL_M,
LEVEL_Q,
LEVEL_H,
LEVEL_DEFAULT
}
public enum Symbol
{
PDF417_STANDARD,
PDF417_TRUNCATED,
QRCODE_MODEL_1,
QRCODE_MODEL_2,
QRCODE_MICRO,
MAXICODE_MODE_2,
MAXICODE_MODE_3,
MAXICODE_MODE_4,
MAXICODE_MODE_5,
MAXICODE_MODE_6,
GS1_DATABAR_STACKED,
GS1_DATABAR_STACKED_OMNIDIRECTIONAL,
GS1_DATABAR_EXPANDED_STACKED,
AZTECCODE_FULLRANGE,
AZTECCODE_COMPACT,
DATAMATRIX_SQUARE,
DATAMATRIX_RECTANGLE_8,
DATAMATRIX_RECTANGLE_12,
DATAMATRIX_RECTANGLE_16
}
}

View File

@@ -0,0 +1,503 @@
using System.Text;
namespace Inspectron.Epson.SOAP
{
public class SoapEpsonPrint
{
private StringBuilder message = new StringBuilder();
private int halftone = 0;
private double brightness = 1.0;
private bool force = false;
// Font constants
public const string FONT_A = "font_a";
public const string FONT_B = "font_b";
public const string FONT_C = "font_c";
public const string FONT_D = "font_d";
public const string FONT_E = "font_e";
public const string FONT_SPECIAL_A = "special_a";
public const string FONT_SPECIAL_B = "special_b";
// Alignment constants
public const string ALIGN_LEFT = "left";
public const string ALIGN_CENTER = "center";
public const string ALIGN_RIGHT = "right";
// Color constants
public const string COLOR_NONE = "none";
public const string COLOR_1 = "color_1";
public const string COLOR_2 = "color_2";
public const string COLOR_3 = "color_3";
public const string COLOR_4 = "color_4";
// Feed constants
public const string FEED_PEELING = "peeling";
public const string FEED_CUTTING = "cutting";
public const string FEED_CURRENT_TOF = "current_tof";
public const string FEED_NEXT_TOF = "next_tof";
// Mode constants
public const string MODE_MONO = "mono";
public const string MODE_GRAY16 = "gray16";
// Barcode constants
public const string BARCODE_UPC_A = "upc_a";
public const string BARCODE_UPC_E = "upc_e";
public const string BARCODE_EAN13 = "ean13";
public const string BARCODE_JAN13 = "jan13";
public const string BARCODE_EAN8 = "ean8";
public const string BARCODE_JAN8 = "jan8";
public const string BARCODE_CODE39 = "code39";
public const string BARCODE_ITF = "itf";
public const string BARCODE_CODABAR = "codabar";
public const string BARCODE_CODE93 = "code93";
public const string BARCODE_CODE128 = "code128";
public const string BARCODE_GS1_128 = "gs1_128";
public const string BARCODE_GS1_DATABAR_OMNIDIRECTIONAL = "gs1_databar_omnidirectional";
public const string BARCODE_GS1_DATABAR_TRUNCATED = "gs1_databar_truncated";
public const string BARCODE_GS1_DATABAR_LIMITED = "gs1_databar_limited";
public const string BARCODE_GS1_DATABAR_EXPANDED = "gs1_databar_expanded";
public const string BARCODE_CODE128_AUTO = "code128_auto";
// HRI constants
public const string HRI_NONE = "none";
public const string HRI_ABOVE = "above";
public const string HRI_BELOW = "below";
public const string HRI_BOTH = "both";
// Level constants
public const string LEVEL_0 = "level_0";
public const string LEVEL_1 = "level_1";
public const string LEVEL_2 = "level_2";
public const string LEVEL_3 = "level_3";
public const string LEVEL_4 = "level_4";
public const string LEVEL_5 = "level_5";
public const string LEVEL_6 = "level_6";
public const string LEVEL_7 = "level_7";
public const string LEVEL_8 = "level_8";
public const string LEVEL_L = "level_l";
public const string LEVEL_M = "level_m";
public const string LEVEL_Q = "level_q";
public const string LEVEL_H = "level_h";
public const string LEVEL_DEFAULT = "default";
// Line constants
public const string LINE_THIN = "thin";
public const string LINE_MEDIUM = "medium";
public const string LINE_THICK = "thick";
public const string LINE_THIN_DOUBLE = "thin_double";
public const string LINE_MEDIUM_DOUBLE = "medium_double";
public const string LINE_THICK_DOUBLE = "thick_double";
// Direction constants
public const string DIRECTION_LEFT_TO_RIGHT = "left_to_right";
public const string DIRECTION_BOTTOM_TO_TOP = "bottom_to_top";
public const string DIRECTION_RIGHT_TO_LEFT = "right_to_left";
public const string DIRECTION_TOP_TO_BOTTOM = "top_to_bottom";
// Cut constants
public const string CUT_NO_FEED = "no_feed";
public const string CUT_FEED = "feed";
public const string CUT_RESERVE = "reserve";
public const string FULL_CUT_NO_FEED = "no_feed_fullcut";
public const string FULL_CUT_FEED = "feed_fullcut";
public const string FULL_CUT_RESERVE = "reserve_fullcut";
// Drawer constants
public const string DRAWER_1 = "drawer_1";
public const string DRAWER_2 = "drawer_2";
// Pulse constants
public const string PULSE_100 = "pulse_100";
public const string PULSE_200 = "pulse_200";
public const string PULSE_300 = "pulse_300";
public const string PULSE_400 = "pulse_400";
public const string PULSE_500 = "pulse_500";
// Pattern constants
public const string PATTERN_NONE = "none";
public const string PATTERN_0 = "pattern_0";
public const string PATTERN_1 = "pattern_1";
public const string PATTERN_2 = "pattern_2";
public const string PATTERN_3 = "pattern_3";
public const string PATTERN_4 = "pattern_4";
public const string PATTERN_5 = "pattern_5";
public const string PATTERN_6 = "pattern_6";
public const string PATTERN_7 = "pattern_7";
public const string PATTERN_8 = "pattern_8";
public const string PATTERN_9 = "pattern_9";
public const string PATTERN_10 = "pattern_10";
public const string PATTERN_A = "pattern_a";
public const string PATTERN_B = "pattern_b";
public const string PATTERN_C = "pattern_c";
public const string PATTERN_D = "pattern_d";
public const string PATTERN_E = "pattern_e";
public const string PATTERN_ERROR = "error";
public const string PATTERN_PAPER_END = "paper_end";
// Layout constants
public const string LAYOUT_RECEIPT = "receipt";
public const string LAYOUT_RECEIPT_BM = "receipt_bm";
public const string LAYOUT_LABEL = "label";
public const string LAYOUT_LABEL_BM = "label_bm";
// Halftone constants
public const int HALFTONE_DITHER = 0;
public const int HALFTONE_ERROR_DIFFUSION = 1;
public const int HALFTONE_THRESHOLD = 2;
public SoapEpsonPrint AddText(string data)
{
AddRow("text", Utils.EscapeMarkup(data));
return this;
}
public SoapEpsonPrint AddTextLang(string lang)
{
message.Append($"<text lang=\"{lang}\"/>");
return this;
}
public SoapEpsonPrint AddTextAlign(string align)
{
AddRow("text", null, new Dictionary<string, object> { { "align", align } });
return this;
}
public SoapEpsonPrint AddTextRotate(string rotate)
{
var s = Utils.GetBoolAttr("rotate", rotate);
message.Append($"<text{s}/>");
return this;
}
public SoapEpsonPrint AddTextLineSpace(string linespc)
{
AddRow("text", null, new Dictionary<string, object> { { "linespc", linespc } });
return this;
}
public SoapEpsonPrint AddTextFont(string font)
{
AddRow("text", null, new Dictionary<string, object> { { "font", font } });
return this;
}
public SoapEpsonPrint AddTextSmooth(string smooth)
{
var s = Utils.GetBoolAttr("smooth", smooth);
message.Append($"<text{s}/>");
return this;
}
public SoapEpsonPrint AddTextDouble(string dw, string dh)
{
var s = new StringBuilder();
if (dw != null)
{
s.Append(Utils.GetBoolAttr("dw", dw));
}
if (dh != null)
{
s.Append(Utils.GetBoolAttr("dh", dh));
}
message.Append($"<text{s}/>");
return this;
}
public SoapEpsonPrint AddTextSize(int width, int height)
{
AddRow("text", null, new Dictionary<string, object>
{
{ "width", width },
{ "height", height }
});
return this;
}
public SoapEpsonPrint AddTextStyle(bool reverse, bool ul, bool em, string color)
{
AddRow("text", null, new Dictionary<string, object>
{
{ "reverse", reverse },
{ "ul", ul },
{ "em", em },
{ "color", color }
});
return this;
}
public SoapEpsonPrint AddTextPosition(int x)
{
AddRow("text", null, new Dictionary<string, object> { { "x", x } });
return this;
}
public SoapEpsonPrint AddTextVPosition(int y)
{
AddRow("text", null, new Dictionary<string, object> { { "y", y } });
return this;
}
public SoapEpsonPrint AddSymbol(string data, Symbol type, SymbolOptions options = null)
{
var attrs = new Dictionary<string, object>
{
{ "type", GetSymbolTypeString(type) }
};
if (options != null)
{
if (options.ErrorCorrectionLevel.HasValue)
attrs["level"] = options.ErrorCorrectionLevel.Value;
if (options.Width.HasValue)
attrs["width"] = options.Width.Value;
if (options.Height.HasValue)
attrs["height"] = options.Height.Value;
if (options.Size.HasValue)
attrs["size"] = options.Size.Value;
}
AddRow("symbol", Utils.EscapeControl(Utils.EscapeMarkup(data)), attrs);
return this;
}
public SoapEpsonPrint AddQRCode(string data, QRCodeOptions options = null)
{
var attrs = new Dictionary<string, object>
{
{ "type", GetSymbolTypeString(Symbol.QRCODE_MODEL_2) }
};
if (options != null)
{
if (options.ErrorCorrectionLevel.HasValue)
attrs["level"] = options.ErrorCorrectionLevel.Value;
if (options.Size.HasValue)
attrs["width"] = options.Size.Value;
}
AddRow("symbol", Utils.EscapeMarkup(data), attrs);
return this;
}
public SoapEpsonPrint AddFeedUnit(string unit)
{
message.Append($"<feed unit=\"{unit}\"/>");
return this;
}
public SoapEpsonPrint AddFeedLine(int line)
{
AddRow("feed", null, new Dictionary<string, object> { { "line", line } });
return this;
}
public SoapEpsonPrint AddFeed()
{
message.Append("<feed/>");
return this;
}
public SoapEpsonPrint AddFeedPosition(string pos)
{
AddRow("feed", null, new Dictionary<string, object> { { "pos", pos } });
return this;
}
public SoapEpsonPrint AddImage(string base64ImageData, string width, string height)
{
AddRow("image", base64ImageData, new Dictionary<string, object>
{
{ "height", height },
{ "width", width },
{ "color", "color_1" },
{ "mode", "mono" }
});
return this;
}
public SoapEpsonPrint AddLogo(string key1, string key2)
{
AddRow("logo", null, new Dictionary<string, object>
{
{ "key1", key1 },
{ "key2", key2 }
});
return this;
}
public SoapEpsonPrint AddBarcode(string data, string type, int hri, string font, int width, int height)
{
AddRow("barcode", Utils.EscapeControl(Utils.EscapeMarkup(data)), new Dictionary<string, object>
{
{ "type", type },
{ "hri", hri },
{ "font", font },
{ "width", width },
{ "height", height }
});
return this;
}
public SoapEpsonPrint AddHLine(int x1, int x2, string style)
{
AddRow("hline", null, new Dictionary<string, object>
{
{ "x1", x1 },
{ "x2", x2 },
{ "style", style }
});
return this;
}
public SoapEpsonPrint AddVLineBegin(int x, string style)
{
AddRow("vline", null, new Dictionary<string, object>
{
{ "x", x },
{ "style", style }
});
return this;
}
public SoapEpsonPrint AddVLineEnd(int x, string style)
{
AddRow("vline", null, new Dictionary<string, object>
{
{ "x", x },
{ "style", style }
});
return this;
}
public SoapEpsonPrint AddRotateBegin()
{
message.Append("<rotate-begin/>");
return this;
}
public SoapEpsonPrint AddRotateEnd()
{
message.Append("<rotate-end/>");
return this;
}
public SoapEpsonPrint AddCut(string type)
{
AddRow("cut", null, new Dictionary<string, object> { { "type", type } });
return this;
}
public SoapEpsonPrint AddSound(object pattern, object repeat, string cycle)
{
AddRow("sound", null, new Dictionary<string, object>
{
{ "pattern", pattern },
{ "repeat", repeat },
{ "cycle", cycle }
});
return this;
}
public SoapEpsonPrint AddRecovery()
{
AddRow("recovery");
return this;
}
public SoapEpsonPrint AddReset()
{
AddRow("reset");
return this;
}
public SoapEpsonPrint AddCommand(string data)
{
message.Append($"<command>{Utils.ToHexBinary(data)}</command>");
return this;
}
public SoapEpsonPrint KickOutDrawer(string drawer = DRAWER_1, string pulse = PULSE_100)
{
AddRow("pulse", null, new Dictionary<string, object>
{
{ "drawer", drawer },
{ "time", pulse }
});
return this;
}
public override string ToString()
{
var s = force ? " force=\"true\"" : "";
return $"<epos-print xmlns=\"http://www.epson-pos.com/schemas/2011/03/epos-print\"{s}>{message}</epos-print>";
}
public void AddRow(string field, string value = null, Dictionary<string, object> fields = null)
{
message.Append($"<{field}");
if (fields != null)
{
foreach (var kvp in fields)
{
if (kvp.Value == null)
continue;
message.Append($" {kvp.Key}=\"{kvp.Value}\"");
}
}
if (string.IsNullOrEmpty(value))
{
message.Append("/>");
}
else
{
message.Append($">{value}</{field}>");
}
}
private string GetSymbolTypeString(Symbol symbol)
{
return symbol switch
{
Symbol.PDF417_STANDARD => "pdf417_standard",
Symbol.PDF417_TRUNCATED => "pdf417_truncated",
Symbol.QRCODE_MODEL_1 => "qrcode_model_1",
Symbol.QRCODE_MODEL_2 => "qrcode_model_2",
Symbol.QRCODE_MICRO => "qrcode_micro",
Symbol.MAXICODE_MODE_2 => "maxicode_mode_2",
Symbol.MAXICODE_MODE_3 => "maxicode_mode_3",
Symbol.MAXICODE_MODE_4 => "maxicode_mode_4",
Symbol.MAXICODE_MODE_5 => "maxicode_mode_5",
Symbol.MAXICODE_MODE_6 => "maxicode_mode_6",
Symbol.GS1_DATABAR_STACKED => "gs1_databar_stacked",
Symbol.GS1_DATABAR_STACKED_OMNIDIRECTIONAL => "gs1_databar_stacked_omnidirectional",
Symbol.GS1_DATABAR_EXPANDED_STACKED => "gs1_databar_expanded_stacked",
Symbol.AZTECCODE_FULLRANGE => "azteccode_fullrange",
Symbol.AZTECCODE_COMPACT => "azteccode_compact",
Symbol.DATAMATRIX_SQUARE => "datamatrix_square",
Symbol.DATAMATRIX_RECTANGLE_8 => "datamatrix_rectangle_8",
Symbol.DATAMATRIX_RECTANGLE_12 => "datamatrix_rectangle_12",
Symbol.DATAMATRIX_RECTANGLE_16 => "datamatrix_rectangle_16",
_ => throw new ArgumentException($"Invalid symbol type: {symbol}")
};
}
}
public class SymbolOptions
{
public int? ErrorCorrectionLevel { get; set; }
public int? Width { get; set; }
public int? Height { get; set; }
public int? Size { get; set; }
}
public class QRCodeOptions
{
public int? Size { get; set; }
public int? ErrorCorrectionLevel { get; set; }
}
}

View File

@@ -0,0 +1,152 @@
using System.Text;
using System.Xml.Linq;
namespace Inspectron.Epson.SOAP
{
public class SoapEpsonPrinter
{
private readonly string url;
private static readonly HttpClient httpClient = new HttpClient(new HttpClientHandler
{
ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true
});
private const string EPSON_XML_HEADER =
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
"<s:Header>" +
"<parameter xmlns=\"http://www.epson-pos.com/schemas/2011/03/epos-print\" />" +
"</s:Header>" +
"<s:Body>";
public SoapEpsonPrinter(string ip)
{
url = $"https://{ip}/cgi-bin/epos/service.cgi?devid=local_printer&timeout=10000";
}
public async Task<XElement> Send(SoapEpsonPrint print)
{
var data = print.ToString();
Console.WriteLine(data.ToString());
var xml = await Request(data);
Console.WriteLine(xml.ToString());
var response = xml.Descendants(XName.Get("response", "http://www.epson-pos.com/schemas/2011/03/epos-print"))
.FirstOrDefault();
if (response == null)
{
throw new Exception("INVALID_RESPONSE");
}
var successAttr = response.Attribute("success");
var success = successAttr?.Value == "true";
var codeAttr = response.Attribute("code");
var code = codeAttr?.Value ?? "";
if (!success)
{
throw new Exception(code);
}
return response;
}
public async Task<PrinterStatus> GetStatus(SoapEpsonPrint print)
{
var data = print.ToString();
var xml = await Request(data);
Console.WriteLine(xml.ToString());
var response = xml.Descendants(XName.Get("response", "http://www.epson-pos.com/schemas/2011/03/epos-print"))
.FirstOrDefault();
if (response == null)
{
throw new Exception("INVALID_RESPONSE");
}
var statusAttr = response.Attribute("status");
var status = int.Parse(statusAttr?.Value ?? "0");
var statuses = new PrinterStatus
{
IsResponsive = true,
DrawerIsOpen = true,
CoverIsOpen = false,
IsOffline = false,
PaperNearEmpty = false,
PaperEmpty = false
};
if ((status & 0x00000001) != 0)
{
statuses.IsResponsive = false;
}
if ((status & 0x00000004) != 0)
{
statuses.DrawerIsOpen = false;
}
if ((status & 0x00000008) != 0)
{
statuses.IsOffline = true;
}
if ((status & 0x00000020) != 0)
{
statuses.CoverIsOpen = true;
}
if ((status & 0x00020000) != 0)
{
statuses.PaperNearEmpty = true;
}
if ((status & 0x00080000) != 0)
{
statuses.PaperEmpty = true;
}
return statuses;
}
private async Task<XDocument> Request(string data)
{
var body = $"{EPSON_XML_HEADER}{data}</s:Body></s:Envelope>";
var content = new StringContent(body, Encoding.UTF8, "text/xml");
using (var request = new HttpRequestMessage(HttpMethod.Post, url))
{
request.Content = content;
//request.Headers.Add("If-Modified-Since", "Thu, 01 Jun 1970 00:00:00 GMT");
//request.Headers.Add("SOAPAction", "\"\"");
var response = await httpClient.SendAsync(request);
response.EnsureSuccessStatusCode();
var responseText = await response.Content.ReadAsStringAsync();
return XDocument.Parse(responseText);
}
}
}
public class PrinterStatus
{
public bool IsResponsive { get; set; }
public bool DrawerIsOpen { get; set; }
public bool CoverIsOpen { get; set; }
public bool IsOffline { get; set; }
public bool PaperNearEmpty { get; set; }
public bool PaperEmpty { get; set; }
public override string ToString()
{
return $"IsResponsive: {IsResponsive}, DrawerIsOpen: {DrawerIsOpen}, CoverIsOpen: {CoverIsOpen}, IsOffline: {IsOffline}, PaperNearEmpty: {PaperNearEmpty}, PaperEmpty: {PaperEmpty}";
}
}
}

View File

@@ -0,0 +1,242 @@
using System.Text;
using System.Text.RegularExpressions;
namespace Inspectron.Epson.SOAP
{
public static class Utils
{
public static string GetEnumAttr(string name, string value, Regex regex)
{
if (!regex.IsMatch(value))
{
throw new ArgumentException($"Parameter \"{name}\" is invalid");
}
return $" {name}=\"{value}\"";
}
public static string GetBoolAttr(string name, string value)
{
return $" {name}=\"{!string.IsNullOrEmpty(value)}\"";
}
public static string GetIntAttr(string name, int value, int min, int max)
{
if (value < min || value > max)
{
throw new ArgumentException($"Parameter \"{name}\" is invalid");
}
return $" {name}=\"{value}\"";
}
public static string GetUByteAttr(string name, int value)
{
return GetIntAttr(name, value, 0, 255);
}
public static string GetUShortAttr(string name, int value)
{
return GetIntAttr(name, value, 0, 65535);
}
public static string GetShortAttr(string name, int value)
{
return GetIntAttr(name, value, -32768, 32767);
}
public static string ToHexBinary(string s)
{
var result = new StringBuilder(s.Length * 2);
foreach (char c in s)
{
result.Append(((int)c).ToString("x2"));
}
return result.ToString();
}
public static string EscapeMarkup(string s)
{
if (string.IsNullOrEmpty(s))
return s;
var markup = new Regex(@"[<>&'""\t\n\r]");
if (markup.IsMatch(s))
{
s = markup.Replace(s, match =>
{
return match.Value switch
{
"<" => "&lt;",
">" => "&gt;",
"&" => "&amp;",
"'" => "&apos;",
"\"" => "&quot;",
"\t" => "&#9;",
"\n" => "&#10;",
"\r" => "&#13;",
_ => match.Value
};
});
}
return s;
}
public static string EscapeControl(string s)
{
if (string.IsNullOrEmpty(s))
return s;
var control = new Regex(@"[\\\x00-\x1f\x7f-\xff]");
if (control.IsMatch(s))
{
s = control.Replace(s, match =>
{
char c = match.Value[0];
if (c == '\\')
return "\\\\";
else
return $"\\x{((int)c):x2}";
});
}
return s;
}
public static string ToMonoImage(ImageData imgdata, int s, double g)
{
var x = new Func<int, char>(code => (char)code);
var m8 = new int[8][]
{
new int[] { 2, 130, 34, 162, 10, 138, 42, 170 },
new int[] { 194, 66, 226, 98, 202, 74, 234, 106 },
new int[] { 50, 178, 18, 146, 58, 186, 26, 154 },
new int[] { 242, 114, 210, 82, 250, 122, 218, 90 },
new int[] { 14, 142, 46, 174, 6, 134, 38, 166 },
new int[] { 206, 78, 238, 110, 198, 70, 230, 102 },
new int[] { 62, 190, 30, 158, 54, 182, 22, 150 },
new int[] { 254, 126, 222, 94, 246, 118, 214, 86 }
};
var d = imgdata.Data;
var w = imgdata.Width;
var h = imgdata.Height;
var r = new StringBuilder(((w + 7) >> 3) * h);
int n = 0;
int p = 0;
int t = 128;
var e = new int[w];
for (int j = 0; j < h; j++)
{
int e1 = 0;
int e2 = 0;
int i = 0;
while (i < w)
{
int b = i & 7;
if (s == 0)
{
t = m8[j & 7][b];
}
int v = (int)(Math.Pow(
(((d[p++] * 0.29891 + d[p++] * 0.58661 + d[p++] * 0.11448) * d[p]) / 255 +
255 - d[p++]) / 255,
1 / g) * 255);
if (s == 1)
{
v += (e[i] + e1) >> 4;
int f = v - (v < t ? 0 : 255);
if (i > 0)
{
e[i - 1] += f;
}
e[i] = f * 7 + e2;
e1 = f * 5;
e2 = f * 3;
}
if (v < t)
{
n |= 128 >> b;
}
i++;
if (b == 7 || i == w)
{
r.Append(x(n == 16 ? 32 : n));
n = 0;
}
}
}
return r.ToString();
}
public static string ToGrayImage(int[] data, int width, int height, double g)
{
var x = new Func<int, char>(code => (char)code);
var m4 = new int[4][]
{
new int[] { 0, 9, 2, 11 },
new int[] { 13, 4, 15, 6 },
new int[] { 3, 12, 1, 10 },
new int[] { 16, 7, 14, 5 }
};
var thermal = new int[]
{
0, 7, 13, 19, 23, 27, 31, 35, 40, 44, 49, 52, 54, 55, 57, 59, 61, 62, 64, 66, 67, 69, 70, 70,
71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 83, 84, 85, 86, 86, 87, 88, 88, 89, 90,
90, 91, 91, 92, 93, 93, 94, 94, 95, 96, 96, 97, 98, 98, 99, 99, 100, 101, 101, 102, 102, 103,
103, 104, 104, 105, 105, 106, 106, 107, 107, 108, 108, 109, 109, 110, 110, 111, 111, 112, 112,
112, 113, 113, 114, 114, 115, 115, 116, 116, 117, 117, 118, 118, 119, 119, 120, 120, 120, 121,
121, 122, 122, 123, 123, 123, 124, 124, 125, 125, 125, 126, 126, 127, 127, 127, 128, 128, 129,
129, 130, 130, 130, 131, 131, 132, 132, 132, 133, 133, 134, 134, 135, 135, 135, 136, 136, 137,
137, 137, 138, 138, 139, 139, 139, 140, 140, 141, 141, 141, 142, 142, 143, 143, 143, 144, 144,
145, 145, 146, 146, 146, 147, 147, 148, 148, 148, 149, 149, 150, 150, 150, 151, 151, 152, 152,
152, 153, 153, 154, 154, 155, 155, 155, 156, 156, 157, 157, 158, 158, 159, 159, 160, 160, 161,
161, 161, 162, 162, 163, 163, 164, 164, 165, 165, 166, 166, 166, 167, 167, 168, 168, 169, 169,
170, 170, 171, 171, 172, 173, 173, 174, 175, 175, 176, 177, 178, 178, 179, 180, 180, 181, 182,
182, 183, 184, 184, 185, 186, 186, 187, 189, 191, 193, 195, 198, 200, 202, 255
};
var r = new StringBuilder(((width + 1) >> 1) * height);
int n = 0;
int p = 0;
for (int j = 0; j < height; j++)
{
int i = 0;
while (i < width)
{
int b = i & 1;
int v = thermal[(int)(Math.Pow(
(((data[p++] * 0.29891 + data[p++] * 0.58661 + data[p++] * 0.11448) * data[p]) / 255 +
255 - data[p++]) / 255,
1 / g) * 255)];
int v1 = v / 17;
if (m4[j & 3][i & 3] < v % 17)
{
v1++;
}
n |= v1 << ((1 - b) << 2);
i++;
if (b == 1 || i == width)
{
r.Append(x(n));
n = 0;
}
}
}
return r.ToString();
}
}
public class ImageData
{
public int[] Data { get; set; }
public int Width { get; set; }
public int Height { get; set; }
}
}