mirror of
https://github.com/riegera2412/UVtools.git
synced 2026-07-09 01:52:32 +02:00
b2bd1c41f1
* (Add) PrusaSlicer Printer: Elegoo Mars 2 Pro * (Add) PrusaSlicer Printer: Creality LD-002H * (Add) PrusaSlicer Printer: Voxelab Polaris * (Add) File Format: UVJ (#8) * (Add) Mutataor: Pixel Dimming * (Add) Pixel Editor tab with new drawing functions * (Add) Pixel Editor: Bursh area and shape * (Add) Pixel Editor: Supports * (Add) Pixel Editor: Drain holes * (Add) Settings for pixel editor * (Add) Setting: File open default directory * (Add) Setting: File save default directory * (Add) Setting: File extract default directory * (Add) Setting: File convert default directory * (Add) Setting: File save prompt for overwrite (#10) * (Add) Setting: File save preffix and suffix name * (Add) Setting: UVtools version to the title bar * (Improvement) Force same directory as input file on dialogs * (Improvement) Pattern: Better positioning when not using an anchor, now it's more center friendly * (Change) Setting: Start maximized defaults to true * (Fix) Pattern: Calculated volume was appending one margin width/height more * (Fix) When cancel a file load, some shortcuts can crash the program as it assume file is loaded * (Fix) pws: Encode using the same count-of-threshold method as CBDDLP (ezrec/uv3dp#79)
129 lines
4.4 KiB
C#
129 lines
4.4 KiB
C#
/*
|
|
* GNU AFFERO GENERAL PUBLIC LICENSE
|
|
* Version 3, 19 November 2007
|
|
* Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
|
* Everyone is permitted to copy and distribute verbatim copies
|
|
* of this license document, but changing it is not allowed.
|
|
*/
|
|
using System.Drawing;
|
|
|
|
namespace UVtools.Core.Operations
|
|
{
|
|
public class OperationPattern
|
|
{
|
|
public Anchor Anchor { get; set; }
|
|
public Rectangle SrcRoi { get; }
|
|
|
|
public uint ImageWidth { get; }
|
|
public uint ImageHeight { get; }
|
|
|
|
public ushort MarginCol { get; set; }
|
|
public ushort MarginRow { get; set; }
|
|
|
|
public ushort MaxMarginCol { get; }
|
|
public ushort MaxMarginRow { get; }
|
|
|
|
public ushort Cols { get; set; } = 1;
|
|
public ushort Rows { get; set; } = 1;
|
|
|
|
public ushort MaxCols { get; }
|
|
public ushort MaxRows { get; }
|
|
|
|
public Size GetPatternVolume => new Size(Cols * SrcRoi.Width + (Cols - 1) * MarginCol, Rows * SrcRoi.Height + (Rows - 1) * MarginRow);
|
|
|
|
|
|
public OperationPattern(Rectangle srcRoi, uint imageWidth, uint imageHeight)
|
|
{
|
|
SrcRoi = srcRoi;
|
|
ImageWidth = imageWidth;
|
|
ImageHeight = imageHeight;
|
|
|
|
MaxCols = (ushort) (imageWidth / srcRoi.Width);
|
|
MaxRows = (ushort) (imageHeight / srcRoi.Height);
|
|
|
|
MaxMarginCol = CalculateMarginCol(MaxCols);
|
|
MaxMarginRow = CalculateMarginRow(MaxRows);
|
|
}
|
|
|
|
|
|
/*public void CalculateDstRoi()
|
|
{
|
|
_dstRoi.Size = SrcRoi.Size;
|
|
|
|
switch (Anchor)
|
|
{
|
|
case Anchor.TopLeft:
|
|
_dstRoi.Location = new Point(0, 0);
|
|
break;
|
|
case Anchor.TopCenter:
|
|
_dstRoi.Location = new Point((int)(ImageWidth / 2 - SrcRoi.Width / 2), 0);
|
|
break;
|
|
case Anchor.TopRight:
|
|
_dstRoi.Location = new Point((int)(ImageWidth - SrcRoi.Width), 0);
|
|
break;
|
|
case Anchor.MiddleLeft:
|
|
_dstRoi.Location = new Point(0, (int)(ImageHeight / 2 - SrcRoi.Height / 2));
|
|
break;
|
|
case Anchor.MiddleCenter:
|
|
_dstRoi.Location = new Point((int)(ImageWidth / 2 - SrcRoi.Width / 2), (int)(ImageHeight / 2 - SrcRoi.Height / 2));
|
|
break;
|
|
case Anchor.MiddleRight:
|
|
_dstRoi.Location = new Point((int)(ImageWidth - SrcRoi.Width), (int)(ImageHeight / 2 - SrcRoi.Height / 2));
|
|
break;
|
|
case Anchor.BottomLeft:
|
|
_dstRoi.Location = new Point(0, (int)(ImageHeight - SrcRoi.Height));
|
|
break;
|
|
case Anchor.BottomCenter:
|
|
_dstRoi.Location = new Point((int)(ImageWidth / 2 - SrcRoi.Width / 2), (int)(ImageHeight - SrcRoi.Height));
|
|
break;
|
|
case Anchor.BottomRight:
|
|
_dstRoi.Location = new Point((int)(ImageWidth - SrcRoi.Width), (int)(ImageHeight - SrcRoi.Height));
|
|
break;
|
|
default:
|
|
throw new ArgumentOutOfRangeException();
|
|
}
|
|
|
|
_dstRoi.X += MarginLeft;
|
|
_dstRoi.X -= MarginRight;
|
|
_dstRoi.Y += MarginTop;
|
|
_dstRoi.Y -= MarginBottom;
|
|
}*/
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Fills the plate with maximum cols and rows
|
|
/// </summary>
|
|
public void Fill()
|
|
{
|
|
Cols = MaxCols;
|
|
MarginCol = MaxMarginCol;
|
|
|
|
Rows = MaxRows;
|
|
MarginRow = MaxMarginRow;
|
|
}
|
|
|
|
public ushort CalculateMarginCol(ushort cols)
|
|
{
|
|
if (cols <= 1) return 0;
|
|
return (ushort)((ImageWidth - SrcRoi.Width * cols) / cols);
|
|
}
|
|
|
|
public ushort CalculateMarginRow(ushort rows)
|
|
{
|
|
if (rows <= 1) return 0;
|
|
return (ushort)((ImageHeight - SrcRoi.Height * rows) / rows);
|
|
}
|
|
|
|
public Rectangle GetRoi(ushort col, ushort row)
|
|
{
|
|
var patternVolume = GetPatternVolume;
|
|
|
|
return new Rectangle(new Point(
|
|
(int) (col * SrcRoi.Width + col * MarginCol + (ImageWidth - patternVolume.Width) / 2),
|
|
(int) (row * SrcRoi.Height + row * MarginRow + (ImageHeight - patternVolume.Height) / 2)), SrcRoi.Size);
|
|
}
|
|
}
|
|
}
|