Skip to content

Commit

Permalink
v4.2.2
Browse files Browse the repository at this point in the history
- **UI:**
  - (Add) Allow to drag and drop Gerber files into main window to open them in the PCB exposure tool (Hold SHIFT key to run the operation right away, without opening the tool dialog, it will run with the default settings)
  - (Improvement) Drag and drop invalid files that are not recognized no longer closes the current file nor open new instances when multiple files are passed or when SHIFT is held
- **Pixel editor:**
  - (Improvement) Line shape was producing one pixel more than required
  - (Improvement) Make the shape preview more accurate with the actual real output and when defining a shape thickness instead of a fill
  - (Improvement) Increase the accuracy of the shapes by passing float instead of int
  - (Improvement) Make the square shape to be exactly the input brush size
  - (Improvement) Dispose Skia drawing objects after draw the pixel editor shapes into the previewer
- (Improvement) Better performance and speed when rendering the layer image into the previewer
- (Improvement) Dispose cached data when layer changes into the previewer
- (Change) Layer image preview format from Bgr to Bgra (Added alpha channel, now 32 bits)
- (Fix) Calibration Blooming effect: All layers are being set with bottom exposure time (#481)
- (Upgrade) .NET from 6.0.26 to 6.0.27
- (Downgrade) AvaloniaUI from 11.0.9 to 11.0.7 (Fix #836 but may re-introduce others)
  • Loading branch information
sn4k3 committed Feb 17, 2024
1 parent 115ee06 commit 64971d3
Show file tree
Hide file tree
Showing 38 changed files with 501 additions and 390 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Changelog

## 17/02/2024 - v4.2.2

- **UI:**
- (Add) Allow to drag and drop Gerber files into main window to open them in the PCB exposure tool (Hold SHIFT key to run the operation right away, without opening the tool dialog, it will run with the default settings)
- (Improvement) Drag and drop invalid files that are not recognized no longer closes the current file nor open new instances when multiple files are passed or when SHIFT is held
- **Pixel editor:**
- (Improvement) Line shape was producing one pixel more than required
- (Improvement) Make the shape preview more accurate with the actual real output and when defining a shape thickness instead of a fill
- (Improvement) Increase the accuracy of the shapes by passing float instead of int
- (Improvement) Make the square shape to be exactly the input brush size
- (Improvement) Dispose Skia drawing objects after draw the pixel editor shapes into the previewer
- (Improvement) Better performance and speed when rendering the layer image into the previewer
- (Improvement) Dispose cached data when layer changes into the previewer
- (Change) Layer image preview format from Bgr to Bgra (Added alpha channel, now 32 bits)
- (Fix) Calibration Blooming effect: All layers are being set with bottom exposure time (#481)
- (Upgrade) .NET from 6.0.26 to 6.0.27
- (Downgrade) AvaloniaUI from 11.0.9 to 11.0.7 (Fix #836 but may re-introduce others)

## 10/02/2024 - v4.2.1

- **UI:**
Expand Down
2 changes: 2 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)build\UVtools.snk</AssemblyOriginatorKeyFile>

<PathMap>$(MSBuildProjectDirectory)=$(MSBuildProjectName)</PathMap>

<AvaloniaVersion>11.0.7</AvaloniaVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
30 changes: 14 additions & 16 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
- **UI:**
- **Pixel editor:**
- (Add) Shortcut: Ctrl/⌘+E to de/activate pixel editor
- (Add) Profiles (#604, #831)
- (Improvement) Use DataGrid row header to show the operation count instead of process and store indexes for the objects
- (Fix) Drawings and Text controls are not stretched to fill the available space to the right
- (Improvement) macOS: Shortcuts Ctrl+0, Ctrl+R, Ctrl+F changed to use command key(⌘) instead of control key
- (Improvement) Dynamic layer height, Lithophane, PCB exposure and Phased exposure: Use better performant `HasNonZero` instead of `CountNonZero` to check if there are any pixels to process
- (Improvement) Update demo file with the newest version of the format and use SL1S printer instead
- (Change) Extract file contents shortcut: From Ctrl+E to Ctrl+Shift+E
- (Fix) Files with different resolution information from empty layers were generating wrong image creation for such layers (#833)
- (Fix) Possible throw an exception about invalid roi when using Roi and/or masks under some tools
- (Fix) Skeletonize memory leak
- (Fix) System.NullReferenceException when accessing reallocated layers (#835)
- (Fix) Unable to save profiles for "Light bleed compensation", "Phased exposure"
- (Fix) PrusaSlicer printer "UVtools Prusa SL1S SPEED": Fix the display width and height, they were flipped
- (Upgrade) AvaloniaUI from 11.0.7 to 11.0.9
- (Add) Allow to drag and drop Gerber files into main window to open them in the PCB exposure tool (Hold SHIFT key to run the operation right away, without opening the tool dialog, it will run with the default settings)
- (Improvement) Drag and drop invalid files that are not recognized no longer closes the current file nor open new instances when multiple files are passed or when SHIFT is held
- **Pixel editor:**
- (Improvement) Line shape was producing one pixel more than required
- (Improvement) Make the shape preview more accurate with the actual real output and when defining a shape thickness instead of a fill
- (Improvement) Increase the accuracy of the shapes by passing float instead of int
- (Improvement) Make the square shape to be exactly the input brush size
- (Improvement) Dispose Skia drawing objects after draw the pixel editor shapes into the previewer
- (Improvement) Better performance and speed when rendering the layer image into the previewer
- (Improvement) Dispose cached data when layer changes into the previewer
- (Change) Layer image preview format from Bgr to Bgra (Added alpha channel, now 32 bits)
- (Fix) Calibration Blooming effect: All layers are being set with bottom exposure time (#481)
- (Upgrade) .NET from 6.0.26 to 6.0.27
- (Downgrade) AvaloniaUI from 11.0.9 to 11.0.7 (Fix #836 but may re-introduce others)

46 changes: 24 additions & 22 deletions UVtools.AvaloniaControls/AdvancedImageBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ public Rect SelectionRegion
TriggerRender();
RaisePropertyChanged(nameof(HaveSelection));
RaisePropertyChanged(nameof(SelectionRegionNet));
RaisePropertyChanged(nameof(SelectionPixelSize));
RaisePropertyChanged(nameof(SelectionRegionPixel));
}
}

Expand All @@ -1031,17 +1031,16 @@ public Rectangle SelectionRegionNet
get
{
var rect = SelectionRegion;
return new Rectangle((int) Math.Ceiling(rect.X), (int)Math.Ceiling(rect.Y),
(int)rect.Width, (int)rect.Height);
return new ((int) Math.Ceiling(rect.X), (int)Math.Ceiling(rect.Y), (int)rect.Width, (int)rect.Height);
}
}

public PixelSize SelectionPixelSize
public PixelRect SelectionRegionPixel
{
get
{
var rect = SelectionRegion;
return new PixelSize((int) rect.Width, (int) rect.Height);
return new ((int)Math.Ceiling(rect.X), (int)Math.Ceiling(rect.Y), (int)rect.Width, (int)rect.Height);
}
}

Expand Down Expand Up @@ -1191,8 +1190,7 @@ public override void Render(DrawingContext context)
var image = Image;
if (image is null) return;
var imageViewPort = GetImageViewPort();



// Draw image
context.DrawImage(image,
GetSourceImageRegion(),
Expand Down Expand Up @@ -2395,6 +2393,10 @@ public Rect GetImageViewPort()
#endregion

#region Image methods
/// <summary>
/// Loads the image from the specified path.
/// </summary>
/// <param name="path">Image path from disk</param>
public void LoadImage(string path)
{
Image = new Bitmap(path);
Expand All @@ -2405,31 +2407,31 @@ public void LoadImage(string path)
var image = ImageAsWriteableBitmap;
if (image is null || !HaveSelection) return null;

var selection = SelectionRegionNet;
var pixelSize = SelectionPixelSize;
using var frameBuffer = image.Lock();

var newBitmap = new WriteableBitmap(pixelSize, image.Dpi, frameBuffer.Format, AlphaFormat.Unpremul);
using var newFrameBuffer = newBitmap.Lock();
var selection = SelectionRegionPixel;

int i = 0;
using var srcBuffer = image.Lock();
var cropBitmap = new WriteableBitmap(selection.Size, image.Dpi, srcBuffer.Format, AlphaFormat.Unpremul);
using var dstBuffer = cropBitmap.Lock();

unsafe
{
var inputPixels = (uint*) (void*) frameBuffer.Address;
var targetPixels = (uint*) (void*) newFrameBuffer.Address;
var ySrc = srcBuffer.Address + srcBuffer.RowBytes * selection.Y + selection.X * (srcBuffer.Format.BitsPerPixel / 8);
var yDst = dstBuffer.Address;

for (int y = selection.Y; y < selection.Bottom; y++)
{
var thisY = y * frameBuffer.Size.Width;
for (int x = selection.X; x < selection.Right; x++)
{
targetPixels![i++] = inputPixels![thisY + x];
}
Buffer.MemoryCopy(
ySrc.ToPointer(),
yDst.ToPointer(),
dstBuffer.RowBytes,
dstBuffer.RowBytes);

ySrc += srcBuffer.RowBytes;
yDst += dstBuffer.RowBytes;
}
}

return newBitmap;
return cropBitmap;
}
#endregion

Expand Down
4 changes: 2 additions & 2 deletions UVtools.AvaloniaControls/UVtools.AvaloniaControls.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- ExtendedNumericUpDown: Initial value with a reset button and value unit label
- IndexSelector: Allow to choose an index from a collection count and display the selected number
- GroupBox: Similar to GroupBox of WinForms, it contain an Header and Content</Description>
<Version>3.0.2</Version>
<Version>3.0.3</Version>

<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/sn4k3/UVtools/tree/master/UVtools.AvaloniaControls</RepositoryUrl>
Expand All @@ -24,7 +24,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="11.0.9" />
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
</ItemGroup>

</Project>
67 changes: 34 additions & 33 deletions UVtools.Core/Extensions/DrawingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,54 +38,55 @@ public static double CalculatePolygonRadiusFromSideLength(double length, int sid
return length / (2 * Math.Cos((90 - theta / 2) * Math.PI / 180.0));
}

public static Point[] GetPolygonVertices(int sides, int radius, Point center, double startingAngle = 0, bool flipHorizontally = false, bool flipVertically = false)

public static Point[] GetPolygonVertices(int sides, double diameter, PointF center, double startingAngle = 0, bool flipHorizontally = false, bool flipVertically = false, MidpointRounding midpointRounding = MidpointRounding.AwayFromZero)
{
if (sides < 3)
throw new ArgumentException("Polygons can't have less than 3 sides...", nameof(sides));

var vertices = new Point[sides];
var radius = diameter / 2;

/*if (sides == 4)
if (sides == 4)
{
var rotatedRect = new RotatedRect(center, new SizeF(radius * 2, radius * 2), (float)startingAngle);
var rotatedRect = new RotatedRect(center, new SizeF((float)diameter - 1, (float)diameter - 1), (float)startingAngle);
var verticesF = rotatedRect.GetVertices();
for (var i = 0; i < verticesF.Length; i++)
{
vertices[i] = verticesF[i].ToPoint();
vertices[i] = verticesF[i].ToPoint(midpointRounding);
}
return vertices;
}*/



var deg = 360.0 / sides;//calculate the rotation angle
var rad = Math.PI / 180.0;
}
else
{
var angleIncrement = 360.0 / sides; //calculate the rotation angle
var rad = Math.PI / 180.0;

var x0 = center.X + radius * Math.Cos(-(((180 - deg) / 2) + startingAngle) * rad);
var y0 = center.Y - radius * Math.Sin(-(((180 - deg) / 2) + startingAngle) * rad);
var x0 = center.X + radius * Math.Cos(-(((180 - angleIncrement) / 2) + startingAngle) * rad);
var y0 = center.Y - radius * Math.Sin(-(((180 - angleIncrement) / 2) + startingAngle) * rad);

var x1 = center.X + radius * Math.Cos(-(((180 - deg) / 2) + deg + startingAngle) * rad);
var y1 = center.Y - radius * Math.Sin(-(((180 - deg) / 2) + deg + startingAngle) * rad);
var x1 = center.X + radius * Math.Cos(-(((180 - angleIncrement) / 2) + startingAngle + angleIncrement) * rad);
var y1 = center.Y - radius * Math.Sin(-(((180 - angleIncrement) / 2) + startingAngle + angleIncrement) * rad);

vertices[0] = new(
(int) Math.Round(x0, MidpointRounding.AwayFromZero),
(int) Math.Round(y0, MidpointRounding.AwayFromZero)
);
vertices[0] = new(
(int)Math.Round(x0, midpointRounding),
(int)Math.Round(y0, midpointRounding)
);

vertices[1] = new(
(int) Math.Round(x1, MidpointRounding.AwayFromZero),
(int) Math.Round(y1, MidpointRounding.AwayFromZero)
);
vertices[1] = new(
(int)Math.Round(x1, midpointRounding),
(int)Math.Round(y1, midpointRounding)
);

for (int i = 0; i < sides - 2; i++)
{
var dsinrot = Math.Sin(deg * (i + 1) * rad);
var dcosrot = Math.Cos(deg * (i + 1) * rad);
for (int i = 0; i < sides - 2; i++)
{
var dsinrot = Math.Sin(angleIncrement * (i + 1) * rad);
var dcosrot = Math.Cos(angleIncrement * (i + 1) * rad);

vertices[i + 2] = new(
(int)Math.Round(center.X + dcosrot * (x1 - center.X) - dsinrot * (y1 - center.Y), MidpointRounding.AwayFromZero),
(int)Math.Round(center.Y + dsinrot * (x1 - center.X) + dcosrot * (y1 - center.Y), MidpointRounding.AwayFromZero)
);
vertices[i + 2] = new(
(int)Math.Round(center.X + dcosrot * (x1 - center.X) - dsinrot * (y1 - center.Y), midpointRounding),
(int)Math.Round(center.Y + dsinrot * (x1 - center.X) + dcosrot * (y1 - center.Y), midpointRounding)
);
}
}

if (flipHorizontally)
Expand All @@ -94,7 +95,7 @@ public static Point[] GetPolygonVertices(int sides, int radius, Point center, do
var endX = center.X + radius;
for (int i = 0; i < sides; i++)
{
vertices[i].X = endX - (vertices[i].X - startX);
vertices[i].X = (int)Math.Round(endX - (vertices[i].X - startX), midpointRounding);
}
}

Expand All @@ -104,7 +105,7 @@ public static Point[] GetPolygonVertices(int sides, int radius, Point center, do
var endY = center.Y + radius;
for (int i = 0; i < sides; i++)
{
vertices[i].Y = endY - (vertices[i].Y - startY);
vertices[i].Y = (int)Math.Round(endY - (vertices[i].Y - startY), midpointRounding);
}
}

Expand Down
Loading

0 comments on commit 64971d3

Please sign in to comment.