gcode2image 2.3.2__tar.gz → 2.4.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: gcode2image
3
- Version: 2.3.2
3
+ Version: 2.4.1
4
4
  Summary: gcode2image: convert gcode to image.
5
5
  Keywords: engraving,laser,image,laser engraving,PWM,gcode
6
6
  Author-email: Johannes Noordanus <mailjohannes.mailnoordanus@gmail.com>
@@ -9,15 +9,14 @@ Description-Content-Type: text/markdown
9
9
  Classifier: License :: OSI Approved :: MIT License
10
10
  Requires-Dist: numpy >= 1.24.3
11
11
  Requires-Dist: Pillow >= 9.5.0
12
- Requires-Dist: scikit-image >= 0.20.0
13
12
  Project-URL: Home, https://github.com/johannesnoordanus/gcode2image
14
13
 
15
14
  # gcode2image
16
15
 
17
16
  Commanline tool to convert gcode to pixel exact image files.
18
17
 
19
- This 2D viewer - images are 2D (so no Z coordinates) - has as strong points that it shows gray levels and thus is able to show a realistic representation of laser engravings. Images can be viewed while converting and the exact placing and size of the gcode can be shown.
20
- It is also possible to show movement *G0* code.
18
+ This 2D viewer - images are 2D (no Z coordinates) - has as strong points that it shows gray levels and thus is able to show a realistic representation of laser engravings. Images can be viewed while converting gcode and the exact placing and size of the gcode can be shown. Since version 2.4.0 repeated writes to the same pixel locations are shown. This means that the simulated engraving is pretty close to actual laser engraving.
19
+ It is also possible to show speed movement *G0* code.
21
20
 
22
21
  A typical command:
23
22
  ```gcode2image --showimage --flip test.gc test.png```
@@ -35,7 +34,7 @@ This generates a 1 cm (per axis) grid and shows the origin X0Y0.
35
34
  Please consider supporting me, so I can make this application better and add new functionality to it: <http://paypal.me/johannesnoordanus/5,00>
36
35
 
37
36
  ### Install:
38
- Depends on python libraries numpy, PIL and skimage.
37
+ Depends on python libraries numpy and PIL.
39
38
  *pip install* takes care of that.
40
39
  ```
41
40
  > pip install gcode2image
@@ -2,8 +2,8 @@
2
2
 
3
3
  Commanline tool to convert gcode to pixel exact image files.
4
4
 
5
- This 2D viewer - images are 2D (so no Z coordinates) - has as strong points that it shows gray levels and thus is able to show a realistic representation of laser engravings. Images can be viewed while converting and the exact placing and size of the gcode can be shown.
6
- It is also possible to show movement *G0* code.
5
+ This 2D viewer - images are 2D (no Z coordinates) - has as strong points that it shows gray levels and thus is able to show a realistic representation of laser engravings. Images can be viewed while converting gcode and the exact placing and size of the gcode can be shown. Since version 2.4.0 repeated writes to the same pixel locations are shown. This means that the simulated engraving is pretty close to actual laser engraving.
6
+ It is also possible to show speed movement *G0* code.
7
7
 
8
8
  A typical command:
9
9
  ```gcode2image --showimage --flip test.gc test.png```
@@ -21,7 +21,7 @@ This generates a 1 cm (per axis) grid and shows the origin X0Y0.
21
21
  Please consider supporting me, so I can make this application better and add new functionality to it: <http://paypal.me/johannesnoordanus/5,00>
22
22
 
23
23
  ### Install:
24
- Depends on python libraries numpy, PIL and skimage.
24
+ Depends on python libraries numpy and PIL.
25
25
  *pip install* takes care of that.
26
26
  ```
27
27
  > pip install gcode2image
@@ -2,13 +2,12 @@
2
2
  """
3
3
  gcode2image: convert gcode to image.
4
4
  """
5
- __version__ = "2.3.2"
5
+ __version__ = "2.4.1"
6
6
 
7
7
  import sys
8
8
  import re
9
9
  import argparse
10
10
  from PIL import Image
11
- from skimage.draw import line as drawline
12
11
  import numpy as np
13
12
 
14
13
  # set to 10 pixels per mm
@@ -36,6 +35,63 @@ def gcode2image(args) -> np.array:
36
35
 
37
36
  invert_intensity = True
38
37
 
38
+ def line_slope(p1: (int,int), p2: (int,int)):
39
+ """Calculate the slope of the line p1p2"""
40
+ x1, y1 = p1[0], p1[1]
41
+ x2, y2 = p2[0], p2[1]
42
+
43
+ if x1 == x2:
44
+ return 1
45
+
46
+ return (y1 - y2) / (x1 - x2)
47
+
48
+ def line_offset(p1: (int,int), p2: (int,int)):
49
+ """Calculate the offset of the line p1p2 from the origin"""
50
+ x1, y1 = p1[0], p1[1]
51
+
52
+ return y1 - line_slope(p1, p2) * x1
53
+
54
+ def line(x, slope, offset):
55
+ y = slope * x + offset
56
+ return round(y)
57
+
58
+ def draw(img, start: (int,int), end: (int,int), color):
59
+ slope = line_slope(start, end)
60
+ offset = line_offset(start, end)
61
+
62
+ #print(f"DRAW: start {start}, end {end}, color {color}")
63
+ if slope == 1 and ((start[0] - end[0]) != (start[1] - end[1])):
64
+ # vertical line (not a 45 degrees line)
65
+ diy = 1 if end[1] > start[1] else -1
66
+ for y2 in range(start[1], end[1] + diy, diy):
67
+ if img[y2,start[0]] != 255:
68
+ img[y2,start[0]] = max(img[y2,start[0]] - color, 0)
69
+ else:
70
+ img[y2,start[0]] = color
71
+ else:
72
+ # non vertical line
73
+ dix = 1 if end[0] > start[0] else -1
74
+ prev = start
75
+ for x in range(start[0], end[0] + dix, dix):
76
+ y = line(x,slope,offset)
77
+ if abs(y - prev[1]) > 1:
78
+ di = 1 if y > prev[1] else -1
79
+ for y1 in range(prev[1], y, di):
80
+ #print("y1:",(x,y1))
81
+ if img[y1,x] != 255:
82
+ img[y1,x] = max(img[y1,x] - color, 0)
83
+ else:
84
+ img[y1,x] = color
85
+
86
+ if x != end[0]:
87
+ if img[y,x] != 255:
88
+ img[y,x] = max(img[y,x] - color, 0)
89
+ else:
90
+ img[y,x] = color
91
+ #print("draw:",(x,y))
92
+
93
+ prev = (x,y)
94
+
39
95
  def pixel_range(ra, dY, dX, pixelsize, img_height, img_width):
40
96
  """
41
97
  Make range fit within window
@@ -62,11 +118,7 @@ def gcode2image(args) -> np.array:
62
118
  if X != x or Y != y:
63
119
  if (G1_mode and (M3_mode or M4_mode)) or (G0_mode and G0_gray):
64
120
  # draw line
65
- yy, xx = drawline(y - Y_start,x - X_start, Y - Y_start, X - X_start)
66
- if X > x or Y > y:
67
- image[yy[:-1], xx[:-1]] = pixel_intensity(S if S is not None else G0_gray)
68
- else:
69
- image[yy[1:], xx[1:]] = pixel_intensity(S if S is not None else G0_gray)
121
+ draw(image, (x - X_start,y - Y_start),(X - X_start,Y - Y_start), pixel_intensity(S if S is not None else G0_gray))
70
122
  x = X
71
123
  y = Y
72
124
 
@@ -14,7 +14,6 @@ keywords = ["engraving", "laser", "image", "laser engraving", "PWM", "gcode"]
14
14
  dependencies = [
15
15
  "numpy >= 1.24.3",
16
16
  "Pillow >= 9.5.0",
17
- "scikit-image >= 0.20.0",
18
17
  ]
19
18
 
20
19
  requires-python = ">=3.7"
File without changes