Skip to content

Commit a8ded01

Browse files
authored
Version 1.7.6.0
1 parent 6f5fb2e commit a8ded01

19 files changed

+9463
-1237
lines changed

GRBL-Plotter/GCodeCreation/CreateFromForm/GCodeFromImage.Designer.cs

Lines changed: 723 additions & 677 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

GRBL-Plotter/GCodeCreation/CreateFromForm/GCodeFromImage.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,6 +1298,23 @@ public void BtnGenerateClick(object sender, EventArgs e)
12981298
bool applyPixelArt = RbPixelArt.Checked;
12991299
if (applyPixelArt)
13001300
{
1301+
if (CbPixelArtLimit.Checked)
1302+
{
1303+
int maxA = (int)NuDPixelArtLimitCount.Value*1000;
1304+
int nowA = originalImage.Width * originalImage.Height;
1305+
if (nowA > maxA)
1306+
{
1307+
Logger.Trace("resize nowA:{0} maxA:{1}", nowA, maxA);
1308+
int nowX = originalImage.Width;
1309+
int nowY = originalImage.Height;
1310+
double ratio = (double)nowY / (double)nowX; // nowA=nowX*nowX*ratio
1311+
double maxX = Math.Sqrt(maxA / ratio);
1312+
double maxY = maxX * ratio;
1313+
Logger.Trace("resize old:{0} {1} new:{2} {3} ratio:{4:0.00}",nowX,nowY,(int)maxX,(int)maxY,ratio);
1314+
ResizeNearestNeighbor filterResize = new ResizeNearestNeighbor((int)maxX, (int)maxY);
1315+
originalImage = filterResize.Apply(originalImage);
1316+
}
1317+
}
13011318
UpdateSizeControls();
13021319
}
13031320
GetToolTableSettings();

GRBL-Plotter/GCodeCreation/CreateFromForm/GCodeFromImage.resx

Lines changed: 604 additions & 541 deletions
Large diffs are not rendered by default.

GRBL-Plotter/GCodeCreation/CreateFromForm/GCodeFromImageCreatePixel.cs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ You should have received a copy of the GNU General Public License
2020
* 2024-12-12 New routines to draw pixels dot by dot
2121
* 2024-12-18 Shape from script
2222
* 2025-04-08 add special function
23+
* 2025-06-07 fill specialCodexxx variables
2324
*/
2425

2526
using System;
@@ -42,10 +43,10 @@ public partial class GCodeFromImage
4243
private static double pixelArtPenRadius = 0.2;
4344
private static bool pixelArtFill = false;
4445

45-
private static string specialCodeBefore = "";
46-
private static string specialCodeValue1 = "";
47-
private static string specialCodeValue2 = "";
48-
private static string specialCodeAfter = "";
46+
private static string specialCodeBefore = "G90 G1 Z1 F1000";
47+
private static string specialCodeValue1 = "G91 A";
48+
private static string specialCodeValue2 = "F10000";
49+
private static string specialCodeAfter = "G90 G0 Z5";
4950

5051

5152
private static StringBuilder pixelArtShapeScript = new StringBuilder();
@@ -61,11 +62,13 @@ private void ConvertColorMapPixelArt()
6162
string pixelArtSource = "S";
6263
if (RbStartGrayZ.Checked)
6364
pixelArtSource = "Z";
64-
if (RbStartGraySpecial.Checked)
65+
specialCodeValue1 = tBCodeValue1.Text;
66+
if (RbStartGraySpecial.Checked && (specialCodeValue1.Length > 1))
67+
{
6568
pixelArtSource = specialCodeValue1.Substring(specialCodeValue1.Length - 1);
66-
69+
}
6770
Logger.Info("▼▼ ConvertColorMapPixelArt px-dist:{0} colorMapCount:{1}", pixelArtDistance, colorMap.Count);
68-
Gcode.Comment(finalString, string.Format("{0} Source=\"{1}\" />", XmlMarker.PixelArt, pixelArtSource));
71+
Gcode.Comment(finalString, string.Format("{0} Source=\"{1}\" Dot-count=\"{2}\"/>", XmlMarker.PixelArt, pixelArtSource, (resultImage.Width * resultImage.Height)));
6972
int toolNr, skipTooNr = 1;
7073
short key;
7174
PointF tmpP;
@@ -411,7 +414,7 @@ private long CreatePixelPatternHeight(int width, int height, bool useZnotS, bool
411414
drawType = 1;
412415

413416
int dotLineCount = 4;
414-
if (!special)
417+
if (!special)
415418
{
416419
if (useZnotS) { dotLineCount = 3; }
417420
else { dotLineCount = 5; }
@@ -448,14 +451,14 @@ void ApplyPixelValueHeight(int xx, int yy)
448451
return;
449452
}
450453
cncCoordLastZ = cncCoordZ = Gcode.GcodeZUp;
451-
452-
// move to xy position
454+
455+
// move to xy position
453456
if (drawShape)
454457
finalString.AppendFormat("G{0} X{1} Y{2}\r\n", Gcode.FrmtCode(0), Gcode.FrmtNum(pixelPosX - adaptRadius), Gcode.FrmtNum(pixelPosY));
455458
else
456459
finalString.AppendFormat("G{0} X{1} Y{2}\r\n", Gcode.FrmtCode(0), Gcode.FrmtNum(pixelPosX), Gcode.FrmtNum(pixelPosY));
457460

458-
// apply brightnes as Gcode value as Z, S or special
461+
// apply brightnes as Gcode value as Z, S or special
459462
SetPixelHeight(brightnes, useZnotS, special, false);
460463

461464
if (!special)
@@ -494,13 +497,13 @@ private void SetPixelHeight(int bright, bool useZnotS, bool special, bool relati
494497
{ // apply code for down and up
495498
float sval = (float)nUDSpecialTop.Value - height * (float)(nUDSpecialTop.Value - nUDSpecialBottom.Value) / 255;
496499
if (specialCodeBefore != "")
497-
{
498-
finalString.AppendFormat("{0}\r\n", specialCodeBefore);
499-
finalString.AppendFormat("{0}{1}{2} (PD DOT)\r\n", specialCodeValue1, Gcode.FrmtNum(sval), specialCodeValue2);
500-
}
501-
else
502-
finalString.AppendFormat("{0}{1}{2} (PD DOT)\r\n", specialCodeValue1, Gcode.FrmtNum(sval), specialCodeValue2);
503-
500+
{
501+
finalString.AppendFormat("{0}\r\n", specialCodeBefore);
502+
finalString.AppendFormat("{0}{1}{2} (PD DOT)\r\n", specialCodeValue1, Gcode.FrmtNum(sval), specialCodeValue2);
503+
}
504+
else
505+
finalString.AppendFormat("{0}{1}{2} (PD DOT)\r\n", specialCodeValue1, Gcode.FrmtNum(sval), specialCodeValue2);
506+
504507
finalString.AppendFormat("{0} (PU)\r\n", specialCodeAfter);
505508
}
506509
else
@@ -536,7 +539,6 @@ private void UpdateSizeControls()
536539
LbLSizeXCode.Text = w.ToString();
537540
LbLSizeYCode.Text = h.ToString();
538541
}
539-
540542
}
541543

542544
class PixelBox : PictureBox

0 commit comments

Comments
 (0)