R53 and R55

This commit is contained in:
2022-09-29 18:20:21 -07:00
parent e68df9c672
commit c1d2b619ee
5 changed files with 319 additions and 17 deletions

View File

@ -30,7 +30,7 @@ public class ProcessData : IProcessData
List<object> Shared.Properties.IProcessData.Details => _Details;
public ProcessData(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection, int startX, int startY, int endX, int endY, Size size, List<Tuple<string, Color[]>> colorCollections)
public ProcessData(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection, int startX, int startY, int endX, int endY, int offSetX, int offSetY, Size size, List<Tuple<string, Color[]>> colorCollections)
{
if (logistics is null)
{ }
@ -39,7 +39,25 @@ public class ProcessData : IProcessData
_Details = new List<object>();
MesEntity = logistics.MesEntity;
_Log = LogManager.GetLogger(typeof(ProcessData));
Parse(fileRead, fileInfoCollection, startX, startY, endX, endY, size, colorCollections);
Parse(fileRead, fileInfoCollection, startX, startY, endX, endY, offSetX, offSetY, size, colorCollections);
}
internal static (int, int) GetOffSet(string sourceDirectoryCloaking)
{
int offSetX;
int offSetY;
string[] offset = sourceDirectoryCloaking.Split('x');
if (offset.Length != 2 || !int.TryParse(offset[0], out int x) || !int.TryParse(offset[1], out int y))
{
offSetX = 0;
offSetY = 0;
}
else
{
offSetX = x;
offSetY = y;
}
return new(offSetX, offSetY);
}
private static string Get(string value, bool useSplitForMID)
@ -105,16 +123,20 @@ public class ProcessData : IProcessData
#nullable enable
#pragma warning disable CA1416
private static (Size, Color[]) Get(string reportFullPath, int startX, int startY, int endX, int endY)
private static (Size, Color[]) Get(string reportFullPath, int startX, int startY, int endX, int endY, int offSetX, int offSetY)
{
Color color;
List<Color> colors = new();
int startXValue = startX + offSetX;
int startYValue = startY + offSetY;
int endXValue = endX + offSetX;
int endYValue = endY + offSetY;
using Bitmap? bitmap = Image.FromFile(reportFullPath) as Bitmap;
if (bitmap is null)
throw new Exception($"Couldn't load image from <{reportFullPath}>");
for (int x = startX; x < endX; x++)
for (int x = startXValue; x < endXValue; x++)
{
for (int y = startY; y < endY; y++)
for (int y = startYValue; y < endYValue; y++)
{
color = bitmap.GetPixel(x, y);
colors.Add(color);
@ -138,12 +160,16 @@ public class ProcessData : IProcessData
return imageFormat;
}
private static (Color[], int, int) Get(IFileRead fileRead, List<FileInfo> fileInfoCollection, int startX, int startY, int endX, int endY, string extension, Size size)
private static (Color[], int, int) Get(IFileRead fileRead, List<FileInfo> fileInfoCollection, int startX, int startY, int endX, int endY, int offSetX, int offSetY, string extension, Size size)
{
Color color;
List<Color> colors = new();
MemoryStream memoryStream = new();
Bitmap selectedBitmap = new(endX - startX, endY - startY);
int startXValue = startX + offSetX;
int startYValue = startY + offSetY;
int endXValue = endX + offSetX;
int endYValue = endY + offSetY;
Bitmap selectedBitmap = new(endXValue - startXValue, endYValue - startYValue);
System.Drawing.Imaging.ImageFormat imageFormat = Get(extension);
using Bitmap? bitmap = Image.FromFile(fileRead.ReportFullPath) as Bitmap;
string saveFileName = Path.ChangeExtension(fileRead.ReportFullPath, extension);
@ -151,13 +177,13 @@ public class ProcessData : IProcessData
throw new Exception($"Couldn't load image from <{fileRead.ReportFullPath}>");
if (!size.Equals(bitmap.Size))
throw new Exception("Source size doesn't match master image size <http://10.95.154.28/set_output?input=0&output=0&venc_framerate=60&venc_gop=300&venc_width=640&venc_height=480&venc_bitrate=32000&http_ts_uri=/0.ts&http_flv_uri=/0.flv&rtsp_uri=/0&rtmp_enable=0&rtmp_uri=/0&rtmp_publish_uri=rtmp%3A%2F%2F192.168.1.169%2Flive%2F0&rtmp_publish_enable=0&http_ts_enable=1&http_flv_enable=1&rtsp_enable=1&venc_profile=0&http_hls_uri=/0.m3u8&http_hls_enable=0&venc_width_height_same_as_input=0&multicast_ip=238.0.0.1&multicast_port=1234&multicast_enable=0&venc_codec=265&srt_enable=0&srt_port=9000&srt_publish_enable=0&srt_publish_uri=srt%3A%2F%2F192.168.1.169%3A9000&srt_key=0123456789&srt_key_enable=0&max_qp=42&venc_rc_mode=0&ts_muxrate=0&_=1655307485097>");
for (int x = startX; x < endX; x++)
for (int x = startXValue; x < endXValue; x++)
{
for (int y = startY; y < endY; y++)
for (int y = startYValue; y < endYValue; y++)
{
color = bitmap.GetPixel(x, y);
colors.Add(color);
selectedBitmap.SetPixel(x - startX, y - startY, color);
selectedBitmap.SetPixel(x - startXValue, y - startYValue, color);
}
}
selectedBitmap.Save(memoryStream, imageFormat);
@ -166,7 +192,7 @@ public class ProcessData : IProcessData
fileInfoCollection.Add(new FileInfo(saveFileName));
SaveToFile(extension, saveFileName, memoryStream);
}
return new(colors.ToArray(), endX - startX, endY - startY);
return new(colors.ToArray(), endXValue - startXValue, endYValue - startYValue);
}
private static string Get(IFileRead fileRead, string extension, string extra)
@ -212,20 +238,20 @@ public class ProcessData : IProcessData
File.WriteAllLines(textFileName, lines);
}
internal static List<(string, Size, Color[])> GetColorCollections(int startX, int startY, int endX, int endY, string masterImageDirectory)
internal static List<(string, Size, Color[])> GetColorCollections(int startX, int startY, int endX, int endY, int offSetX, int offSetY, string masterImageDirectory)
{
List<(string, Size, Color[])> results = new();
(Size Size, Color[] Colors) result;
string[] files = Directory.GetFiles(masterImageDirectory, "*.jpeg", SearchOption.TopDirectoryOnly);
foreach (string file in files)
{
result = Get(file, startX, startY, endX, endY);
result = Get(file, startX, startY, endX, endY, offSetX, offSetY);
results.Add(new(file, result.Size, result.Colors));
}
return results;
}
private void Parse(IFileRead fileRead, List<FileInfo> fileInfoCollection, int startX, int startY, int endX, int endY, Size size, List<Tuple<string, Color[]>> colorCollections)
private void Parse(IFileRead fileRead, List<FileInfo> fileInfoCollection, int startX, int startY, int endX, int endY, int offSetX, int offSetY, Size size, List<Tuple<string, Color[]>> colorCollections)
{
Red = 0;
Green = 0;
@ -235,7 +261,7 @@ public class ProcessData : IProcessData
const int thresHold = 70;
const string extension = ".tiff";
List<(string File, int TotalDelta)> totalDeltaCollection = new();
(Color[] sourceColors, int width, int height) = Get(fileRead, fileInfoCollection, startX, startY, endX, endY, extension, size);
(Color[] sourceColors, int width, int height) = Get(fileRead, fileInfoCollection, startX, startY, endX, endY, offSetX, offSetY, extension, size);
foreach ((string file, Color[] colors) in colorCollections)
{
totalDelta = 0;