-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbrother.py
More file actions
408 lines (352 loc) · 17.3 KB
/
brother.py
File metadata and controls
408 lines (352 loc) · 17.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
import struct
from os.path import basename, splitext, getsize, join
from os import statvfs
from shutil import copyfile
from embroidery_thread import pecThreads
imageWithFrame = [
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
[0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
]
class BoundingBox:
# this is only used when calculating the conversion from pattern to PES files
def __init__(self, left=0, top=0, right=0, bottom=0):
self.left = left
self.top = top
self.right = right
self.bottom = bottom
@property
def width(self):
return self.right - self.left
@property
def height(self):
return self.bottom - self.top
def __str__(self):
return "width: %s, height: %s" % (self.width, self.height)
def __repr__(self):
return self.__str__()
def calc_bounding_box(blocks):
bounding_rect = BoundingBox()
for block in blocks:
stitches = block.stitches
for stitch in stitches:
if "TRIM" in stitch.tags:
continue
bounding_rect.left = min(bounding_rect.left, stitch.x*10.0)
bounding_rect.top = min(bounding_rect.top, stitch.y)
bounding_rect.right = max(bounding_rect.right, stitch.x)
bounding_rect.bottom = max(bounding_rect.bottom, stitch.y)
return bounding_rect
class BrotherEmbroideryFile():
def __init__(self, filename="output.pes", filehandle=None):
if filehandle is None:
self.fh = open(filename, "wb")
else:
self.fh = filehandle
self.filename = filename
self.verbose = False
self.output = ''
def write_pattern(self, pattern):
self.output += "#PES0001"
self.output += self.write_int(0x00, width=4)
for _ in range(3):
self.output += self.write_int(0x01)
self.output += self.write_int(0x00)
self.output += self.write_int(0x00)
self.output += self.write_int(0x07)
self.c_emb_one(pattern)
if self.verbose:
for b in pattern.blocks:
print(b)
self.c_sew_seg(pattern)
pec_location = len(self.output)
self.output = self.output[:0x08] + \
self.write_int(pec_location, width=4) + self.output[
0x08 + 4:]
self.write_pec_stitches(pattern)
self.fh.write(self.output)
self.fh.close()
def write_int(self, val, width=2, LE=True):
output = ''
val = int(round(val))
for i in range(width):
offset = i * 8 if LE else (width - i - 1) * 8
output += chr((val >> offset) & 0xFF)
return output
def write_float(self, val):
for b in bytearray(struct.pack("f", val)):
self.output += chr(b)
def write_stitch(self, stitch, bounds):
self.output += self.write_int(stitch.x - bounds.left)
self.output += self.write_int(stitch.y + bounds.top)
def write_image(self, image):
for i in range(38):
for j in range(6):
offset = j * 8
output = 0
for k in range(8):
output += (image[i][offset + k] != 0) << k
self.output += chr(output)
def encode_jump(self, x, tags):
outputVal = abs(x) & 0x7FF
orPart = 0x80
if "TRIM" in tags:
orPart |= 0x20
if "JUMP" in tags:
orPart |= 0x10
if x < 0:
outputVal = x + 0x1000 & 0x7FF
outputVal |= 0x800
self.output += chr(((outputVal >> 8) & 0x0F) | orPart)
self.output += chr(outputVal & 0xFF)
def c_emb_one(self, pattern):
self.output += "CEmbOne"
for _ in range(8):
self.output += self.write_int(0x00)
self.write_float(1.0)
self.write_float(0.0)
self.write_float(0.0)
self.write_float(1.0)
hoopHeight = 1800
hoopWidth = 1300
self.write_float((pattern.bounds.width - hoopWidth) / 2.0)
self.write_float((pattern.bounds.height + hoopHeight) / 2.0)
self.output += self.write_int(0x01)
self.output += self.write_int(0x00)
self.output += self.write_int(0x00)
self.output += self.write_int(pattern.bounds.width)
self.output += self.write_int(pattern.bounds.height)
for _ in range(8):
self.output += chr(0)
def c_sew_seg(self, pattern):
self.output += self.write_int(len(pattern.blocks))
self.output += self.write_int(0xFFFF)
self.output += self.write_int(0x00)
self.output += self.write_int(0x07)
self.output += "CSewSeg"
colorInfo = []
for i, block in enumerate(pattern.blocks):
self.output += self.write_int(block.stitch_type)
self.output += self.write_int(block.color)
if block.color not in [c[1] for c in colorInfo]:
colorInfo.append([i, block.color])
self.output += self.write_int(block.num_stitches)
for stitch_i in range(0, len(block.stitches)):
self.write_stitch(block.stitches[stitch_i], pattern.bounds)
if i < len(pattern.blocks) - 1:
self.output += self.write_int(0x8003)
self.output += self.write_int(len(colorInfo))
for i in range(len(colorInfo)):
self.output += self.write_int(colorInfo[i][0])
self.output += self.write_int(colorInfo[i][1])
self.output += self.write_int(0, width=4)
def write_pec_stitches(self, pattern):
self.output += "LA:"
pes_name = splitext(basename(self.filename))[0]
while len(pes_name) < 16:
pes_name = pes_name + chr(0x20)
pes_name = pes_name[0:16]
self.output += str(pes_name)
self.output += chr(0x0D)
for _ in range(12):
self.output += chr(0x20)
self.output += chr(0xFF)
self.output += chr(0x00)
self.output += chr(0x06)
self.output += chr(0x26)
for _ in range(12):
self.output += chr(0x20)
self.output += chr(pattern.thread_count - 1)
for color in pattern.thread_colors:
self.output += chr(color)
for _ in range(0x1cf - pattern.thread_count):
self.output += chr(0x20)
self.output += self.write_int(0x0)
graphics_offset_location = len(self.output)
self.output += chr(0x00)
self.output += chr(0x00)
self.output += chr(0x00)
self.output += chr(0x31)
self.output += chr(0xff)
self.output += chr(0xf0)
self.output += self.write_int(pattern.bounds.width)
self.output += self.write_int(pattern.bounds.height)
self.output += self.write_int(0x1e0)
self.output += self.write_int(0x1b0)
self.output += self.write_int(0x9000 | -int(round(pattern.bounds.left)), LE=False)
self.output += self.write_int(0x9000 | -int(round(pattern.bounds.top)), LE=False)
thisX = 0.0
thisY = 0.0
stope_code = 2
for block in pattern.blocks:
for stitch in block.stitches:
deltaX = int(round(stitch.x - thisX))
deltaY = int(round(stitch.y - thisY))
thisX += deltaX
thisY += deltaY
if "STOP" in stitch.tags or "COLOR" in stitch.tags:
self.output += chr(0xFE)
self.output += chr(0xB0)
self.output += chr(stope_code)
if stope_code == 2:
stope_code = 1
else:
stope_code = 2
elif "END" in stitch.tags:
self.output += chr(0xff)
break
elif -64 < deltaX < 63 and -64 < deltaY < 63 and not (
"TRIM" in stitch.tags or "JUMP" in stitch.tags):
self.output += chr(deltaX + 0x80 if deltaX < 0 else deltaX)
self.output += chr(deltaY + 0x80 if deltaY < 0 else deltaY)
else:
self.encode_jump(deltaX, stitch.tags)
self.encode_jump(deltaY, stitch.tags)
graphics_offset_value = len(self.output) - graphics_offset_location + 2
self.output = self.output[:graphics_offset_location] + \
chr(graphics_offset_value & 0xFF) + \
chr((graphics_offset_value >> 8) & 0xFF) + \
chr((graphics_offset_value >> 16) & 0xFF) + \
self.output[graphics_offset_location + 3:]
populate_image(pattern)
self.write_image(pattern.image)
for i in range(pattern.thread_count):
pattern.image = imageWithFrame
populate_image(pattern, index=i)
self.write_image(pattern.image)
def pattern_to_csv(pattern, filename):
def wrap_string_list(input_list):
output_list = []
for i in input_list:
output_list.append('"'+str(i)+'"')
return ",".join(output_list)+"\n"
if isinstance(filename, str) or isinstance(filename, unicode):
output_file = open(filename, "wb")
else:
output_file = filename
output_file.write(wrap_string_list(
["#", "[THREAD_NUMBER]", "[RED]", "[GREEN]", "[BLUE]", "[DESCRIPTION]",
"[CATALOG_NUMBER]"]))
for i, color in enumerate(pattern.thread_colors):
output_file.write(wrap_string_list(["$", str(i + 1)]+pecThreads[color][0]+["(null)", "(null)"]))
output_file.write(wrap_string_list(["#", "[STITCH_TYPE]", "[X]", '[Y]']))
for block in pattern.blocks:
for stitch in block.stitches:
output_file.write(wrap_string_list(["*", stitch.tags[0], stitch.x/10.0, 0.1*(pattern.bounds.height-stitch.y)]))
output_file.close()
def populate_image(pattern, index=None):
# this is Brother sewing machine specific
yFactor = 32.0
xFactor = 42.0
if pattern.bounds.height > 0:
yFactor /= pattern.bounds.height
if pattern.bounds.width > 0:
xFactor /= pattern.bounds.width
for i, block in enumerate(pattern.blocks):
for stitch in block.stitches:
if index is not None:
if i != index:
continue
x = int(round((stitch.x - pattern.bounds.left) * xFactor)) + 3
y = int(round((stitch.y - pattern.bounds.top) * yFactor)) + 3
pattern.image[y][x] = 1
def upload(pes_filename):
# since this library is sometimes used in web-environments, where subprocesses aren't
# allowed, move this import statement to only where it's actually used.
from subprocess import check_output
mount_points = {}
out = check_output(["df"]).split("\n")
for line in out:
if line.find("/media") >= 0:
mount_location = line.split("%")[-1]
line = line.split(" ")
mount_points[line[0]] = mount_location.strip()
mount_destination = None
for mount_point in mount_points:
out = check_output(
["udevadm", "info", "--name=" + mount_point, "--attribute-walk"])
if out.find('ATTRS{idVendor}=="04f9"') > 0:
print("found brother device, assuming embroidery machine")
mount_destination = mount_points[mount_point]
break
if mount_destination is None:
print("could not find brother embroidery machine to transfer to")
else:
_statvfs = statvfs(mount_destination)
if getsize(pes_filename) > _statvfs.f_frsize * _statvfs.f_bavail:
print("file cannot be transfered - not enough space on device")
else:
copyfile(pes_filename, join(mount_destination, basename(pes_filename)))