diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index e21c9b0..91c254f 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -3,10 +3,11 @@
+
+
-
@@ -18,10 +19,10 @@
-
-
+
+
-
+
@@ -39,25 +40,25 @@
-
+
-
+
-
+
-
+
@@ -67,8 +68,8 @@
-
-
+
+
@@ -79,69 +80,38 @@
-
-
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
@@ -149,6 +119,15 @@
+
+
+
+
+
+
+
+
+
@@ -160,36 +139,36 @@
- barrier
- intersection points for this
- intersect
- self.b
- addPoint
- addLine
- intersectionPointWithInfLine
- invertLine
- matchInfLine
- invertSlope
- moveToIncludePoint
- renderPECCommands
- lineFallsInValidProjection
- makeStitchLevels
- TYPE_JUMP
- encode
- color
- 1095499788
- a0
- scale
- seeking to
- print
- Stitch(
- endWithinStart
Stitch
<
Beep
0x9
- width
size
+ color
+ starting at coordin
+ starting at coordinate
+ 58
+ colors
+ Color change
+ colorIndex
+ FE
+ black
+ color cha
+ default
+ ColorChange
+ getClosest
+ image
+ fe
+ width
+ label
+ FF
+ End st
+ End
+ starting stitches at location
+ thumbnail
+ getCoordinate
+ encode
+ PECColors
@@ -208,9 +187,10 @@
+
-
+
@@ -254,12 +234,12 @@
-
+
-
+
@@ -319,6 +299,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -355,7 +357,7 @@
-
+
@@ -390,10 +392,12 @@
+
+
@@ -421,7 +425,7 @@
-
+
@@ -504,13 +508,6 @@
-
-
-
-
-
-
-
@@ -546,21 +543,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -568,16 +550,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -585,33 +557,10 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
@@ -629,14 +578,96 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/LOG.md b/LOG.md
index 84c4b52..e2bbe18 100644
--- a/LOG.md
+++ b/LOG.md
@@ -1,3 +1,135 @@
+# 12/3
+
+If I write my PES header with TrueSizer's PEC section, the embroidery machine recognizes it. That means I'm not writing the PEC section correctly. Time for some more reverse engineering.
+
+FINALLY got something to show up. Yesssss. It turns out there's a main icon and then one for each color. I forgot that detail.
+
+# 12/2
+
+Whoops, I was looking at a design that I found and embroidered, and the stitches don't just go from endpoint to endpoint. There are multiple intermediate stitches. I need to fix that in my program too. Wow, there's really too much to do.
+
+# 12/1
+
+Wilcom adds 12116 - 11369 = 747 extra bytes to my file. I think the machine needs the PES section. I tried loading a PEC file and the machine didn't even bother recognizing it. I'll add minimum PES section stuff and see if it helps.
+
+I think it needs a thumbnail. I figured out how their image system works from the documentation I found (it didn't explain it very well, but they literally use one bit per pixel.)
+
+Okay, nope, my machine straight up just doesn't want to recognize it. It's probably related to me missing the PES section?
+
+000000000000000000000000000000000000000000000000
+000001110111111101111111011111110111111101111000
+000010000000000000000000000000000000000000000100
+000100000000000000000011011000000000000000000010
+001000000000000000000100000110000000000000000001
+001000000000000000001000001110000000000000000001
+001000000000000000001000000001000000000000000001
+001000000000000000001010011001000000000000000001
+001000000000000000001111011101000000000000000001
+001000000000000000001111011101000000000000000001
+001000000000000000001111011101000000000000000001
+001000000000000000001100001101000000000000000001
+001000000000000000001110011100100000000000000001
+001000000000000000001111011101100000000000000001
+001000000000000000001110010110010000000000000001
+001000000000000000011011000011010000000000000001
+001000000000000000011000000011000000000000000001
+001000000000000000111000000011010100000000000001
+001000000000000001111000000001110100000000000001
+001000000000000001110000000000100010000000000001
+001000000000000000110000000000100010000000000001
+001000000000000000100000000000110001000000000001
+001000000000000101100000000000110001000000000001
+001000000000000101100000000000110001000000000001
+001000000000000101000000000000110001000000000001
+001000000000000101100000000001100001000000000001
+001000000000001101110000000001110111000000000001
+001000000000111000111000000001110101000000000001
+001000000001110000110100000001100001100000000001
+001000000001100000011100000011100000110000000001
+001000000001100000001100001111100000011000000001
+001000000001100000001111011101100001110000000001
+001000000001111100001110000101100111000000000001
+001000000000001101111111011011110100000000000001
+000100000000000001111000000000110000000000000010
+000010000000000000000000000000000000000000000100
+000001110111111101111111011111110111111101111000
+000000000000000000000000000000000000000000000000
+000000000000000000000000000000000000000000000000
+000001110111111101111111011111110111111101111000
+000010000000000000000000000000000000000000000100
+000100000000000000000000000000000000000000000010
+001000000000000000000000000000000000000000000001
+001000000000000000000000000000000000000000000001
+001000000000000000000000000000000000000000000001
+001000000000000000000000000000000000000000000001
+001000000000000000000000000000000000000000000001
+001000000000000000000000000000000000000000000001
+001000000000000000000011010000000000000000000001
+001000000000000000000111011100000000000000000001
+001000000000000000000011011100000000000000000001
+001000000000000000000011010000000000000000000001
+001000000000000000000000000000000000000000000001
+001000000000000000000000000000000000000000000001
+001000000000000000000000000000000000000000000001
+001000000000000000000000000000000000000000000001
+001000000000000000000000000000000000000000000001
+001000000000000000000000000000000000000000000001
+001000000000000000000000000000000000000000000001
+001000000000000000000000000000000000000000000001
+001000000000000000000000000000000000000000000001
+001000000000000000000000000000000000000000000001
+001000000000000000000000000000000000000000000001
+001000000000000100000000000000000000000000000001
+001000000000000101000000000000100011000000000001
+001000000000001101100000000000110111000000000001
+001000000000111101100000000000110111000000000001
+001000000000111101110000000000110111110000000001
+001000000000111101111000000000110111110000000001
+001000000000111101111000000000110111100000000001
+001000000000011101111000000000110110000000000001
+001000000000000001111000000000110000000000000001
+000100000000000000000000000000000000000000000010
+000010000000000000000000000000000000000000000100
+000001110111111101111111011111110111111101111000
+000000000000000000000000000000000000000000000000
+000000000000000000000000000000000000000000000000
+000001110111111101111111011111110111111101111000
+000010000000000000000000000000000000000000000100
+000100000000000000000011011000000000000000000010
+001000000000000000000111011110000000000000000001
+001000000000000000001111011110000000000000000001
+001000000000000000001111011111000000000000000001
+001000000000000000001111011111000000000000000001
+001000000000000000001101000111000000000000000001
+001000000000000000001111011111000000000000000001
+001000000000000000001110011111000000000000000001
+001000000000000000001100000111000000000000000001
+001000000000000000001100011111100000000000000001
+001000000000000000001111011111100000000000000001
+001000000000000000001011000011110000000000000001
+001000000000000000011001000001110000000000000001
+001000000000000000010000000001110000000000000001
+001000000000000000110000000001110100000000000001
+001000000000000001110000000000110100000000000001
+001000000000000001100000000000110110000000000001
+001000000000000001100000000000110110000000000001
+001000000000000001100000000000010111000000000001
+001000000000000101000000000000010111000000000001
+001000000000000101000000000000010111000000000001
+001000000000000101000000000000010111000000000001
+001000000000000001000000000000110111000000000001
+001000000000001000100000000001010110000000000001
+001000000000111000011000000001000001000000000001
+001000000001000000011100000001000000100000000001
+001000000001100000001100000001000000010000000001
+001000000001100000001000000011000000001000000001
+001000000001000000000111011111000000110000000001
+001000000001110000000111011111000011000000000001
+001000000000001101001111011011100100000000000001
+000100000000000001111000000000110000000000000010
+000010000000000000000000000000000000000000000100
+000001110111111101111111011111110111111101111000
+000000000000000000000000000000000000000000000000
# 11/30
diff --git a/PECRender/main.py b/PECRender/main.py
index 3d4f255..0f13665 100644
--- a/PECRender/main.py
+++ b/PECRender/main.py
@@ -14,10 +14,78 @@ pyglet.gl.glClearColor(0.4,0.4,0.4,1)
#filepath = "/Users/imaustyn/Documents/MiamiUniversity/ECE 487/Project/Understanding2/tux.pes"
#filepath = "/Users/imaustyn/Downloads/Circle embroidery designs/Circle.pes"
-filepath = "/Users/imaustyn/Documents/MiamiUniversity/ECE 487/Project/PES-Embroidery/TestOutput/simple.PES"
+#filepath = "/Users/imaustyn/Documents/MiamiUniversity/ECE 487/Project/PES-Embroidery/TestOutput/simple.PES"
+filepath = "/Users/imaustyn/Documents/MiamiUniversity/ECE 487/Project/PES-Embroidery/TestOutput/simpleTry.PES"
# Global variables
class Global:
+ colorLookup = [
+ ('None', 26, 10, 148),
+ ('Prussian Blue', 26, 10, 148),
+ ('Blue', 15, 117, 255),
+ ('Teal Green', 0, 147, 76),
+ ('Corn Flower Blue', 186, 189, 254),
+ ('Red', 236, 0, 0),
+ ('Reddish Brown', 228, 153, 90),
+ ('Magenta', 204, 72, 171),
+ ('Light Lilac', 253, 196, 250),
+ ('Lilac', 221, 132, 205),
+ ('Mint Green', 107, 211, 138),
+ ('Deep Gold', 228, 169, 69),
+ ('Orange', 255, 189, 66),
+ ('Yellow', 255, 230, 0),
+ ('Lime Green', 108, 217, 0),
+ ('Brass', 193, 169, 65),
+ ('Silver', 181, 173, 151),
+ ('Russet Brown', 186, 156, 95),
+ ('Cream Brown', 250, 245, 158),
+ ('Pewter', 128, 128, 128),
+ ('Black', 0, 0, 0),
+ ('Ultramarine', 0, 28, 223),
+ ('Royal Purple', 223, 0, 184),
+ ('Dark Gray', 98, 98, 98),
+ ('Dark Brown', 105, 38, 13),
+ ('Deep Rose', 255, 0, 96),
+ ('Light Brown', 191, 130, 0),
+ ('Salmon Pink', 243, 145, 120),
+ ('Vermilion', 255, 104, 5),
+ ('White', 240, 240, 240),
+ ('Violet', 200, 50, 205),
+ ('Seacrest', 176, 191, 155),
+ ('Sky Blue', 101, 191, 235),
+ ('Pumpkin', 255, 186, 4),
+ ('Cream Yellow', 255, 240, 108),
+ ('Khaki', 254, 202, 21),
+ ('Clay Brown', 243, 129, 1),
+ ('Leaf Green', 55, 169, 35),
+ ('Peacock Blue', 35, 70, 95),
+ ('Gray', 166, 166, 149),
+ ('Warm Gray', 206, 191, 166),
+ ('Dark Olive', 150, 170, 2),
+ ('Linen', 255, 227, 198),
+ ('Pink', 255, 153, 215),
+ ('Deep Green', 0, 112, 4),
+ ('Lavender', 237, 204, 251),
+ ('Wisteria Violet', 192, 137, 216),
+ ('Beige', 231, 217, 180),
+ ('Carmine', 233, 14, 134),
+ ('Amber Red', 207, 104, 41),
+ ('Olive Green', 64, 134, 21),
+ ('Dark Fuchsia', 219, 23, 151),
+ ('Tangerine', 255, 167, 4),
+ ('Light Blue', 185, 255, 255),
+ ('Emerald Green', 34, 137, 39),
+ ('Purple', 182, 18, 205),
+ ('Moss Green', 0, 170, 0),
+ ('Flesh Pink', 254, 169, 220),
+ ('Harvest Gold', 254, 213, 16),
+ ('Electric Blue', 0, 151, 223),
+ ('Lemon Yellow', 255, 255, 132),
+ ('Fresh Green', 207, 231, 116),
+ ('Applique Material', 255, 200, 100),
+ ('Applique Position', 255, 200, 200),
+ ('Applique', 255, 200, 200)]
+
pauseEmbroidery = False
batch = pyglet.graphics.Batch()
x = 0
@@ -57,7 +125,14 @@ class Global:
# Skip stuff
cls.label = f.read(20)
print("Label: {}".format(cls.label))
- f.read(28)
+ f.read(14)
+
+ # Read thumbnail width and height
+ thumbWidth = struct.unpack("B", f.read(1))[0]
+ thumbHeight = struct.unpack("B", f.read(1))[0]
+ print("Thumbnail dimensions: {} by {}".format(8 * thumbWidth, thumbHeight))
+
+ f.read(12)
cls.numberOfColors = struct.unpack("B", f.read(1))[0] + 1
print("Number of colors: {}".format(cls.numberOfColors))
@@ -73,8 +148,31 @@ class Global:
# if blank is not (0,0):
# print("nope: {}".format(blank) )
# sys.exit(0)
- f.read(8)
- width, height = struct.unpack("> (7-x)) & pixels) > 0:
+ c = "1"
+ else:
+ c = "0"
+ sys.stdout.write(c)
+ sys.stdout.write("\n")
+
+ f.seek(lastPosition)
+
+ f.read(4)
+ width, height = struct.unpack(" 0:
# Double length
c = struct.unpack(">H", Global.readBytes(f, 2))[0]
@@ -171,10 +271,10 @@ class Global:
for i in range(0,stepBy):
x = cls.getCoordinate(f)
- if x is None:
+ if x is None or isinstance(x, str):
continue
y = -cls.getCoordinate(f)
- if y is None:
+ if y is None or isinstance(y, str):
continue
if x is "End" or y is "End":
@@ -182,9 +282,9 @@ class Global:
print("({},{})".format(x,y))
cls.addLine(Global.x, Global.y, Global.x + x, Global.y + y,
- (Global.testColors[Global.colorIndex])[0],
- (Global.testColors[Global.colorIndex])[1],
- (Global.testColors[Global.colorIndex])[2])
+ (Global.colorLookup[Global.colors[Global.colorIndex]])[1],
+ (Global.colorLookup[Global.colors[Global.colorIndex]])[2],
+ (Global.colorLookup[Global.colors[Global.colorIndex]])[3])
diff --git a/PESDump/main.py b/PESDump/main.py
new file mode 100644
index 0000000..e81d892
--- /dev/null
+++ b/PESDump/main.py
@@ -0,0 +1,87 @@
+import argparse
+import struct
+
+parser = argparse.ArgumentParser(description="Converts an SVG file into a PES embroidery file.")
+
+parser.add_argument("-i", dest="inputFile", type=str, action='store', required=True)
+
+args = parser.parse_args()
+
+def read(file, amount, format):
+ bytes = file.read(amount)
+ if len(bytes) is not amount:
+ return None
+
+ return (struct.unpack(format, bytes), bytes)
+
+def printW(string, raw):
+ raw = bytearray(raw)
+ print("{} {}".format(string, " ".join(format(x, "02x") for x in raw) ))
+
+def assertContinue(f):
+ h1 = f.read(2)
+ h2 = f.read(2)
+ h1 = struct.unpack(" 2047 or coordinate < -2047:
+ raise Exception("Coordinate movement too big: {}".format(coordinate))
+
+ total = self.type + ( int(round(coordinate)) & 0xFFF )
b.extend([ ((total & 0xFF00) >> 8), total & 0xFF])
+ def encodeForCSewSeg(self, b):
+ b.extend(encodeS16(self.point.real))
+ b.extend(encodeS16(self.point.imag))
+
def length(self):
return self.line.length()
@@ -280,10 +377,11 @@ class ColorChange:
TYPE_COLOR_CHANGE_left = 0xFE
TYPE_COLOR_CHANGE_right = 0xB0
- def __init__(self, colorIndex):
+ def __init__(self, colorIndex, indexInColorList):
self.colorIndex = colorIndex
+ self.indexInColorList = indexInColorList
def encode(self, b):
b.extend([ ColorChange.TYPE_COLOR_CHANGE_left ])
b.extend([ ColorChange.TYPE_COLOR_CHANGE_right ])
- b.extend([ self.colorIndex & 0xFF ])
\ No newline at end of file
+ b.extend([ self.indexInColorList & 0xFF ])
\ No newline at end of file
diff --git a/src/PES.pyc b/src/PES.pyc
index ec83c15..7682dc7 100644
Binary files a/src/PES.pyc and b/src/PES.pyc differ
diff --git a/src/main.py b/src/main.py
index ff06d9d..7d2238b 100644
--- a/src/main.py
+++ b/src/main.py
@@ -26,7 +26,7 @@ paths, attributes = svg
if paths is None:
sys.exit(0)
-threadWidth = 0.5
+threadWidth = 3
# Enumerate the shapes in the SVG to find where stitches should go.
levelGroups = []
@@ -48,11 +48,14 @@ for i, shape in enumerate(paths):
# Make the stitches into a continuous set of commands
PECCommands = createStitchRoutine(levelGroups, fillColors=fillColors, threadWidth=threadWidth)
-# Render the PEC commands
-renderPECCommands(PECCommands)
+left, right, bottom, top = shape.bbox()
-pec = PEC(label="pec1", colors=PECColors, commands=PECCommands)
-pes = PES(PEC=pec)
+pec = PEC(label="simple", colors=PECColors, commands=PECCommands, size=complex(right - left, top - bottom))
+
+# Render the PEC commands
+renderPEC(pec)
+
+pes = PES(PEC=pec, shape=shape)
encodedPES = pes.encode()
with open(args.outputFile, "w") as f:
diff --git a/src/svgFunctions.py b/src/svgFunctions.py
index 4e28099..3d1dc63 100644
--- a/src/svgFunctions.py
+++ b/src/svgFunctions.py
@@ -301,12 +301,14 @@ def createStitchRoutine(levelGroups, fillColors, threadWidth=2):
fillColor = fillColors[i]
colorData = PES.getClosestColor(fillColor)
- colorChange = ColorChange(colorIndex=colorData[0])
- allStitches.append(colorChange)
+ # First color is automatically set.
+ if i != 0:
+ colorChange = ColorChange(colorIndex=colorData[0], indexInColorList=i )
+ allStitches.append(colorChange)
for singleLineGroup in shapeLineGroup:
# Was the last command a stitch?
- if isinstance(allStitches[-1], Stitch):
+ if len(allStitches) > 0 and isinstance(allStitches[-1], Stitch):
lastStitch = allStitches[-1]
# Is the distance greater than the minimum?
if pointWithinPoint(lastStitch.point, singleLineGroup[0].start, maxDist) is not True:
@@ -324,12 +326,15 @@ def createStitchRoutine(levelGroups, fillColors, threadWidth=2):
print("Created {} stitches.".format(len(allStitches)))
return allStitches
-def renderPECCommands(PECCommands):
+def renderPEC(pec):
+
+ PECCommands = pec.commands
+ colors = pec.colors
GenericRenderer.globalRenderer.clearAll()
lastPoint = (0+0j)
- currentColor = ("None", 0,0,0)
+ currentColor = colors[0][1:]
jumps = []
for command in PECCommands:
if isinstance(command, Stitch):
@@ -342,7 +347,7 @@ def renderPECCommands(PECCommands):
lastPoint = command.point
if isinstance(command, ColorChange):
- currentColor = PES.colors[command.colorIndex]
+ currentColor = colors[command.indexInColorList][1:]
# Render all the jumps on top
for jump in jumps:
diff --git a/src/svgFunctions.pyc b/src/svgFunctions.pyc
index eb99421..786a71c 100644
Binary files a/src/svgFunctions.pyc and b/src/svgFunctions.pyc differ