meerk40t 0.9.3001__py2.py3-none-any.whl → 0.9.7010__py2.py3-none-any.whl

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.
Files changed (445) hide show
  1. meerk40t/__init__.py +1 -1
  2. meerk40t/balormk/balor_params.py +167 -167
  3. meerk40t/balormk/clone_loader.py +457 -457
  4. meerk40t/balormk/controller.py +1566 -1512
  5. meerk40t/balormk/cylindermod.py +64 -0
  6. meerk40t/balormk/device.py +966 -1959
  7. meerk40t/balormk/driver.py +778 -591
  8. meerk40t/balormk/galvo_commands.py +1195 -0
  9. meerk40t/balormk/gui/balorconfig.py +237 -111
  10. meerk40t/balormk/gui/balorcontroller.py +191 -184
  11. meerk40t/balormk/gui/baloroperationproperties.py +116 -115
  12. meerk40t/balormk/gui/corscene.py +845 -0
  13. meerk40t/balormk/gui/gui.py +179 -147
  14. meerk40t/balormk/livelightjob.py +466 -382
  15. meerk40t/balormk/mock_connection.py +131 -109
  16. meerk40t/balormk/plugin.py +133 -135
  17. meerk40t/balormk/usb_connection.py +306 -301
  18. meerk40t/camera/__init__.py +1 -1
  19. meerk40t/camera/camera.py +514 -397
  20. meerk40t/camera/gui/camerapanel.py +1241 -1095
  21. meerk40t/camera/gui/gui.py +58 -58
  22. meerk40t/camera/plugin.py +441 -399
  23. meerk40t/ch341/__init__.py +27 -27
  24. meerk40t/ch341/ch341device.py +628 -628
  25. meerk40t/ch341/libusb.py +595 -589
  26. meerk40t/ch341/mock.py +171 -171
  27. meerk40t/ch341/windriver.py +157 -157
  28. meerk40t/constants.py +13 -0
  29. meerk40t/core/__init__.py +1 -1
  30. meerk40t/core/bindalias.py +550 -539
  31. meerk40t/core/core.py +47 -47
  32. meerk40t/core/cutcode/cubiccut.py +73 -73
  33. meerk40t/core/cutcode/cutcode.py +315 -312
  34. meerk40t/core/cutcode/cutgroup.py +141 -137
  35. meerk40t/core/cutcode/cutobject.py +192 -185
  36. meerk40t/core/cutcode/dwellcut.py +37 -37
  37. meerk40t/core/cutcode/gotocut.py +29 -29
  38. meerk40t/core/cutcode/homecut.py +29 -29
  39. meerk40t/core/cutcode/inputcut.py +34 -34
  40. meerk40t/core/cutcode/linecut.py +33 -33
  41. meerk40t/core/cutcode/outputcut.py +34 -34
  42. meerk40t/core/cutcode/plotcut.py +335 -335
  43. meerk40t/core/cutcode/quadcut.py +61 -61
  44. meerk40t/core/cutcode/rastercut.py +168 -148
  45. meerk40t/core/cutcode/waitcut.py +34 -34
  46. meerk40t/core/cutplan.py +1843 -1316
  47. meerk40t/core/drivers.py +330 -329
  48. meerk40t/core/elements/align.py +801 -669
  49. meerk40t/core/elements/branches.py +1844 -1507
  50. meerk40t/core/elements/clipboard.py +229 -219
  51. meerk40t/core/elements/element_treeops.py +4561 -2837
  52. meerk40t/core/elements/element_types.py +125 -105
  53. meerk40t/core/elements/elements.py +4329 -3617
  54. meerk40t/core/elements/files.py +117 -64
  55. meerk40t/core/elements/geometry.py +473 -224
  56. meerk40t/core/elements/grid.py +467 -316
  57. meerk40t/core/elements/materials.py +158 -94
  58. meerk40t/core/elements/notes.py +50 -38
  59. meerk40t/core/elements/offset_clpr.py +933 -912
  60. meerk40t/core/elements/offset_mk.py +963 -955
  61. meerk40t/core/elements/penbox.py +339 -267
  62. meerk40t/core/elements/placements.py +300 -83
  63. meerk40t/core/elements/render.py +785 -687
  64. meerk40t/core/elements/shapes.py +2618 -2092
  65. meerk40t/core/elements/trace.py +651 -563
  66. meerk40t/core/elements/tree_commands.py +415 -409
  67. meerk40t/core/elements/undo_redo.py +116 -58
  68. meerk40t/core/elements/wordlist.py +319 -200
  69. meerk40t/core/exceptions.py +9 -9
  70. meerk40t/core/laserjob.py +220 -220
  71. meerk40t/core/logging.py +63 -63
  72. meerk40t/core/node/blobnode.py +83 -86
  73. meerk40t/core/node/bootstrap.py +105 -103
  74. meerk40t/core/node/branch_elems.py +40 -31
  75. meerk40t/core/node/branch_ops.py +45 -38
  76. meerk40t/core/node/branch_regmark.py +48 -41
  77. meerk40t/core/node/cutnode.py +29 -32
  78. meerk40t/core/node/effect_hatch.py +375 -257
  79. meerk40t/core/node/effect_warp.py +398 -0
  80. meerk40t/core/node/effect_wobble.py +441 -309
  81. meerk40t/core/node/elem_ellipse.py +404 -309
  82. meerk40t/core/node/elem_image.py +1082 -801
  83. meerk40t/core/node/elem_line.py +358 -292
  84. meerk40t/core/node/elem_path.py +259 -201
  85. meerk40t/core/node/elem_point.py +129 -102
  86. meerk40t/core/node/elem_polyline.py +310 -246
  87. meerk40t/core/node/elem_rect.py +376 -286
  88. meerk40t/core/node/elem_text.py +445 -418
  89. meerk40t/core/node/filenode.py +59 -40
  90. meerk40t/core/node/groupnode.py +138 -74
  91. meerk40t/core/node/image_processed.py +777 -766
  92. meerk40t/core/node/image_raster.py +156 -113
  93. meerk40t/core/node/layernode.py +31 -31
  94. meerk40t/core/node/mixins.py +135 -107
  95. meerk40t/core/node/node.py +1427 -1304
  96. meerk40t/core/node/nutils.py +117 -114
  97. meerk40t/core/node/op_cut.py +462 -335
  98. meerk40t/core/node/op_dots.py +296 -251
  99. meerk40t/core/node/op_engrave.py +414 -311
  100. meerk40t/core/node/op_image.py +755 -369
  101. meerk40t/core/node/op_raster.py +787 -522
  102. meerk40t/core/node/place_current.py +37 -40
  103. meerk40t/core/node/place_point.py +329 -126
  104. meerk40t/core/node/refnode.py +58 -47
  105. meerk40t/core/node/rootnode.py +225 -219
  106. meerk40t/core/node/util_console.py +48 -48
  107. meerk40t/core/node/util_goto.py +84 -65
  108. meerk40t/core/node/util_home.py +61 -61
  109. meerk40t/core/node/util_input.py +102 -102
  110. meerk40t/core/node/util_output.py +102 -102
  111. meerk40t/core/node/util_wait.py +65 -65
  112. meerk40t/core/parameters.py +709 -707
  113. meerk40t/core/planner.py +875 -785
  114. meerk40t/core/plotplanner.py +656 -652
  115. meerk40t/core/space.py +120 -113
  116. meerk40t/core/spoolers.py +706 -705
  117. meerk40t/core/svg_io.py +1836 -1549
  118. meerk40t/core/treeop.py +534 -445
  119. meerk40t/core/undos.py +278 -124
  120. meerk40t/core/units.py +784 -680
  121. meerk40t/core/view.py +393 -322
  122. meerk40t/core/webhelp.py +62 -62
  123. meerk40t/core/wordlist.py +513 -504
  124. meerk40t/cylinder/cylinder.py +247 -0
  125. meerk40t/cylinder/gui/cylindersettings.py +41 -0
  126. meerk40t/cylinder/gui/gui.py +24 -0
  127. meerk40t/device/__init__.py +1 -1
  128. meerk40t/device/basedevice.py +322 -123
  129. meerk40t/device/devicechoices.py +50 -0
  130. meerk40t/device/dummydevice.py +163 -128
  131. meerk40t/device/gui/defaultactions.py +618 -602
  132. meerk40t/device/gui/effectspanel.py +114 -0
  133. meerk40t/device/gui/formatterpanel.py +253 -290
  134. meerk40t/device/gui/warningpanel.py +337 -260
  135. meerk40t/device/mixins.py +13 -13
  136. meerk40t/dxf/__init__.py +1 -1
  137. meerk40t/dxf/dxf_io.py +766 -554
  138. meerk40t/dxf/plugin.py +47 -35
  139. meerk40t/external_plugins.py +79 -79
  140. meerk40t/external_plugins_build.py +28 -28
  141. meerk40t/extra/cag.py +112 -116
  142. meerk40t/extra/coolant.py +403 -0
  143. meerk40t/extra/encode_detect.py +198 -0
  144. meerk40t/extra/ezd.py +1165 -1165
  145. meerk40t/extra/hershey.py +835 -340
  146. meerk40t/extra/imageactions.py +322 -316
  147. meerk40t/extra/inkscape.py +630 -622
  148. meerk40t/extra/lbrn.py +424 -424
  149. meerk40t/extra/outerworld.py +284 -0
  150. meerk40t/extra/param_functions.py +1542 -1556
  151. meerk40t/extra/potrace.py +257 -253
  152. meerk40t/extra/serial_exchange.py +118 -0
  153. meerk40t/extra/updater.py +602 -453
  154. meerk40t/extra/vectrace.py +147 -146
  155. meerk40t/extra/winsleep.py +83 -83
  156. meerk40t/extra/xcs_reader.py +597 -0
  157. meerk40t/fill/fills.py +781 -335
  158. meerk40t/fill/patternfill.py +1061 -1061
  159. meerk40t/fill/patterns.py +614 -567
  160. meerk40t/grbl/control.py +87 -87
  161. meerk40t/grbl/controller.py +990 -903
  162. meerk40t/grbl/device.py +1081 -768
  163. meerk40t/grbl/driver.py +989 -771
  164. meerk40t/grbl/emulator.py +532 -497
  165. meerk40t/grbl/gcodejob.py +783 -767
  166. meerk40t/grbl/gui/grblconfiguration.py +373 -298
  167. meerk40t/grbl/gui/grblcontroller.py +485 -271
  168. meerk40t/grbl/gui/grblhardwareconfig.py +269 -153
  169. meerk40t/grbl/gui/grbloperationconfig.py +105 -0
  170. meerk40t/grbl/gui/gui.py +147 -116
  171. meerk40t/grbl/interpreter.py +44 -44
  172. meerk40t/grbl/loader.py +22 -22
  173. meerk40t/grbl/mock_connection.py +56 -56
  174. meerk40t/grbl/plugin.py +294 -264
  175. meerk40t/grbl/serial_connection.py +93 -88
  176. meerk40t/grbl/tcp_connection.py +81 -79
  177. meerk40t/grbl/ws_connection.py +112 -0
  178. meerk40t/gui/__init__.py +1 -1
  179. meerk40t/gui/about.py +2042 -296
  180. meerk40t/gui/alignment.py +1644 -1608
  181. meerk40t/gui/autoexec.py +199 -0
  182. meerk40t/gui/basicops.py +791 -670
  183. meerk40t/gui/bufferview.py +77 -71
  184. meerk40t/gui/busy.py +170 -133
  185. meerk40t/gui/choicepropertypanel.py +1673 -1469
  186. meerk40t/gui/consolepanel.py +706 -542
  187. meerk40t/gui/devicepanel.py +687 -581
  188. meerk40t/gui/dialogoptions.py +110 -107
  189. meerk40t/gui/executejob.py +316 -306
  190. meerk40t/gui/fonts.py +90 -90
  191. meerk40t/gui/functionwrapper.py +252 -0
  192. meerk40t/gui/gui_mixins.py +729 -0
  193. meerk40t/gui/guicolors.py +205 -182
  194. meerk40t/gui/help_assets/help_assets.py +218 -201
  195. meerk40t/gui/helper.py +154 -0
  196. meerk40t/gui/hersheymanager.py +1430 -846
  197. meerk40t/gui/icons.py +3422 -2747
  198. meerk40t/gui/imagesplitter.py +555 -508
  199. meerk40t/gui/keymap.py +354 -344
  200. meerk40t/gui/laserpanel.py +892 -806
  201. meerk40t/gui/laserrender.py +1470 -1232
  202. meerk40t/gui/lasertoolpanel.py +805 -793
  203. meerk40t/gui/magnetoptions.py +436 -0
  204. meerk40t/gui/materialmanager.py +2917 -0
  205. meerk40t/gui/materialtest.py +1722 -1694
  206. meerk40t/gui/mkdebug.py +646 -359
  207. meerk40t/gui/mwindow.py +163 -140
  208. meerk40t/gui/navigationpanels.py +2605 -2467
  209. meerk40t/gui/notes.py +143 -142
  210. meerk40t/gui/opassignment.py +414 -410
  211. meerk40t/gui/operation_info.py +310 -299
  212. meerk40t/gui/plugin.py +494 -328
  213. meerk40t/gui/position.py +714 -669
  214. meerk40t/gui/preferences.py +901 -650
  215. meerk40t/gui/propertypanels/attributes.py +1461 -1131
  216. meerk40t/gui/propertypanels/blobproperty.py +117 -114
  217. meerk40t/gui/propertypanels/consoleproperty.py +83 -80
  218. meerk40t/gui/propertypanels/gotoproperty.py +77 -0
  219. meerk40t/gui/propertypanels/groupproperties.py +223 -217
  220. meerk40t/gui/propertypanels/hatchproperty.py +489 -469
  221. meerk40t/gui/propertypanels/imageproperty.py +2244 -1384
  222. meerk40t/gui/propertypanels/inputproperty.py +59 -58
  223. meerk40t/gui/propertypanels/opbranchproperties.py +82 -80
  224. meerk40t/gui/propertypanels/operationpropertymain.py +1890 -1638
  225. meerk40t/gui/propertypanels/outputproperty.py +59 -58
  226. meerk40t/gui/propertypanels/pathproperty.py +389 -380
  227. meerk40t/gui/propertypanels/placementproperty.py +1214 -383
  228. meerk40t/gui/propertypanels/pointproperty.py +140 -136
  229. meerk40t/gui/propertypanels/propertywindow.py +313 -181
  230. meerk40t/gui/propertypanels/rasterwizardpanels.py +996 -912
  231. meerk40t/gui/propertypanels/regbranchproperties.py +76 -0
  232. meerk40t/gui/propertypanels/textproperty.py +770 -755
  233. meerk40t/gui/propertypanels/waitproperty.py +56 -55
  234. meerk40t/gui/propertypanels/warpproperty.py +121 -0
  235. meerk40t/gui/propertypanels/wobbleproperty.py +255 -204
  236. meerk40t/gui/ribbon.py +2468 -2210
  237. meerk40t/gui/scene/scene.py +1100 -1051
  238. meerk40t/gui/scene/sceneconst.py +22 -22
  239. meerk40t/gui/scene/scenepanel.py +439 -349
  240. meerk40t/gui/scene/scenespacewidget.py +365 -365
  241. meerk40t/gui/scene/widget.py +518 -505
  242. meerk40t/gui/scenewidgets/affinemover.py +215 -215
  243. meerk40t/gui/scenewidgets/attractionwidget.py +315 -309
  244. meerk40t/gui/scenewidgets/bedwidget.py +120 -97
  245. meerk40t/gui/scenewidgets/elementswidget.py +137 -107
  246. meerk40t/gui/scenewidgets/gridwidget.py +785 -745
  247. meerk40t/gui/scenewidgets/guidewidget.py +765 -765
  248. meerk40t/gui/scenewidgets/laserpathwidget.py +66 -66
  249. meerk40t/gui/scenewidgets/machineoriginwidget.py +86 -86
  250. meerk40t/gui/scenewidgets/nodeselector.py +28 -28
  251. meerk40t/gui/scenewidgets/rectselectwidget.py +589 -346
  252. meerk40t/gui/scenewidgets/relocatewidget.py +33 -33
  253. meerk40t/gui/scenewidgets/reticlewidget.py +83 -83
  254. meerk40t/gui/scenewidgets/selectionwidget.py +2952 -2756
  255. meerk40t/gui/simpleui.py +357 -333
  256. meerk40t/gui/simulation.py +2431 -2094
  257. meerk40t/gui/snapoptions.py +208 -203
  258. meerk40t/gui/spoolerpanel.py +1227 -1180
  259. meerk40t/gui/statusbarwidgets/defaultoperations.py +480 -353
  260. meerk40t/gui/statusbarwidgets/infowidget.py +520 -483
  261. meerk40t/gui/statusbarwidgets/opassignwidget.py +356 -355
  262. meerk40t/gui/statusbarwidgets/selectionwidget.py +172 -171
  263. meerk40t/gui/statusbarwidgets/shapepropwidget.py +754 -236
  264. meerk40t/gui/statusbarwidgets/statusbar.py +272 -260
  265. meerk40t/gui/statusbarwidgets/statusbarwidget.py +268 -270
  266. meerk40t/gui/statusbarwidgets/strokewidget.py +267 -251
  267. meerk40t/gui/themes.py +200 -78
  268. meerk40t/gui/tips.py +591 -0
  269. meerk40t/gui/toolwidgets/circlebrush.py +35 -35
  270. meerk40t/gui/toolwidgets/toolcircle.py +248 -242
  271. meerk40t/gui/toolwidgets/toolcontainer.py +82 -77
  272. meerk40t/gui/toolwidgets/tooldraw.py +97 -90
  273. meerk40t/gui/toolwidgets/toolellipse.py +219 -212
  274. meerk40t/gui/toolwidgets/toolimagecut.py +25 -132
  275. meerk40t/gui/toolwidgets/toolline.py +39 -144
  276. meerk40t/gui/toolwidgets/toollinetext.py +79 -236
  277. meerk40t/gui/toolwidgets/toollinetext_inline.py +296 -0
  278. meerk40t/gui/toolwidgets/toolmeasure.py +160 -216
  279. meerk40t/gui/toolwidgets/toolnodeedit.py +2088 -2074
  280. meerk40t/gui/toolwidgets/toolnodemove.py +92 -94
  281. meerk40t/gui/toolwidgets/toolparameter.py +754 -668
  282. meerk40t/gui/toolwidgets/toolplacement.py +108 -108
  283. meerk40t/gui/toolwidgets/toolpoint.py +68 -59
  284. meerk40t/gui/toolwidgets/toolpointlistbuilder.py +294 -0
  285. meerk40t/gui/toolwidgets/toolpointmove.py +183 -0
  286. meerk40t/gui/toolwidgets/toolpolygon.py +288 -403
  287. meerk40t/gui/toolwidgets/toolpolyline.py +38 -196
  288. meerk40t/gui/toolwidgets/toolrect.py +211 -207
  289. meerk40t/gui/toolwidgets/toolrelocate.py +72 -72
  290. meerk40t/gui/toolwidgets/toolribbon.py +598 -113
  291. meerk40t/gui/toolwidgets/tooltabedit.py +546 -0
  292. meerk40t/gui/toolwidgets/tooltext.py +98 -89
  293. meerk40t/gui/toolwidgets/toolvector.py +213 -204
  294. meerk40t/gui/toolwidgets/toolwidget.py +39 -39
  295. meerk40t/gui/usbconnect.py +98 -91
  296. meerk40t/gui/utilitywidgets/buttonwidget.py +18 -18
  297. meerk40t/gui/utilitywidgets/checkboxwidget.py +90 -90
  298. meerk40t/gui/utilitywidgets/controlwidget.py +14 -14
  299. meerk40t/gui/utilitywidgets/cyclocycloidwidget.py +343 -340
  300. meerk40t/gui/utilitywidgets/debugwidgets.py +148 -0
  301. meerk40t/gui/utilitywidgets/handlewidget.py +27 -27
  302. meerk40t/gui/utilitywidgets/harmonograph.py +450 -447
  303. meerk40t/gui/utilitywidgets/openclosewidget.py +40 -40
  304. meerk40t/gui/utilitywidgets/rotationwidget.py +54 -54
  305. meerk40t/gui/utilitywidgets/scalewidget.py +75 -75
  306. meerk40t/gui/utilitywidgets/seekbarwidget.py +183 -183
  307. meerk40t/gui/utilitywidgets/togglewidget.py +142 -142
  308. meerk40t/gui/utilitywidgets/toolbarwidget.py +8 -8
  309. meerk40t/gui/wordlisteditor.py +985 -931
  310. meerk40t/gui/wxmeerk40t.py +1444 -1169
  311. meerk40t/gui/wxmmain.py +5578 -4112
  312. meerk40t/gui/wxmribbon.py +1591 -1076
  313. meerk40t/gui/wxmscene.py +1635 -1453
  314. meerk40t/gui/wxmtree.py +2410 -2089
  315. meerk40t/gui/wxutils.py +1769 -1099
  316. meerk40t/gui/zmatrix.py +102 -102
  317. meerk40t/image/__init__.py +1 -1
  318. meerk40t/image/dither.py +429 -0
  319. meerk40t/image/imagetools.py +2778 -2269
  320. meerk40t/internal_plugins.py +150 -130
  321. meerk40t/kernel/__init__.py +63 -12
  322. meerk40t/kernel/channel.py +259 -212
  323. meerk40t/kernel/context.py +538 -538
  324. meerk40t/kernel/exceptions.py +41 -41
  325. meerk40t/kernel/functions.py +463 -414
  326. meerk40t/kernel/jobs.py +100 -100
  327. meerk40t/kernel/kernel.py +3809 -3571
  328. meerk40t/kernel/lifecycles.py +71 -71
  329. meerk40t/kernel/module.py +49 -49
  330. meerk40t/kernel/service.py +147 -147
  331. meerk40t/kernel/settings.py +383 -343
  332. meerk40t/lihuiyu/controller.py +883 -876
  333. meerk40t/lihuiyu/device.py +1181 -1069
  334. meerk40t/lihuiyu/driver.py +1466 -1372
  335. meerk40t/lihuiyu/gui/gui.py +127 -106
  336. meerk40t/lihuiyu/gui/lhyaccelgui.py +377 -363
  337. meerk40t/lihuiyu/gui/lhycontrollergui.py +741 -651
  338. meerk40t/lihuiyu/gui/lhydrivergui.py +470 -446
  339. meerk40t/lihuiyu/gui/lhyoperationproperties.py +238 -237
  340. meerk40t/lihuiyu/gui/tcpcontroller.py +226 -190
  341. meerk40t/lihuiyu/interpreter.py +53 -53
  342. meerk40t/lihuiyu/laserspeed.py +450 -450
  343. meerk40t/lihuiyu/loader.py +90 -90
  344. meerk40t/lihuiyu/parser.py +404 -404
  345. meerk40t/lihuiyu/plugin.py +101 -102
  346. meerk40t/lihuiyu/tcp_connection.py +111 -109
  347. meerk40t/main.py +231 -165
  348. meerk40t/moshi/builder.py +788 -781
  349. meerk40t/moshi/controller.py +505 -499
  350. meerk40t/moshi/device.py +495 -442
  351. meerk40t/moshi/driver.py +862 -696
  352. meerk40t/moshi/gui/gui.py +78 -76
  353. meerk40t/moshi/gui/moshicontrollergui.py +538 -522
  354. meerk40t/moshi/gui/moshidrivergui.py +87 -75
  355. meerk40t/moshi/plugin.py +43 -43
  356. meerk40t/network/console_server.py +102 -57
  357. meerk40t/network/kernelserver.py +10 -9
  358. meerk40t/network/tcp_server.py +142 -140
  359. meerk40t/network/udp_server.py +103 -77
  360. meerk40t/network/web_server.py +390 -0
  361. meerk40t/newly/controller.py +1158 -1144
  362. meerk40t/newly/device.py +874 -732
  363. meerk40t/newly/driver.py +540 -412
  364. meerk40t/newly/gui/gui.py +219 -188
  365. meerk40t/newly/gui/newlyconfig.py +116 -101
  366. meerk40t/newly/gui/newlycontroller.py +193 -186
  367. meerk40t/newly/gui/operationproperties.py +51 -51
  368. meerk40t/newly/mock_connection.py +82 -82
  369. meerk40t/newly/newly_params.py +56 -56
  370. meerk40t/newly/plugin.py +1214 -1246
  371. meerk40t/newly/usb_connection.py +322 -322
  372. meerk40t/rotary/gui/gui.py +52 -46
  373. meerk40t/rotary/gui/rotarysettings.py +240 -232
  374. meerk40t/rotary/rotary.py +202 -98
  375. meerk40t/ruida/control.py +291 -91
  376. meerk40t/ruida/controller.py +138 -1088
  377. meerk40t/ruida/device.py +672 -231
  378. meerk40t/ruida/driver.py +534 -472
  379. meerk40t/ruida/emulator.py +1494 -1491
  380. meerk40t/ruida/exceptions.py +4 -4
  381. meerk40t/ruida/gui/gui.py +71 -76
  382. meerk40t/ruida/gui/ruidaconfig.py +239 -72
  383. meerk40t/ruida/gui/ruidacontroller.py +187 -184
  384. meerk40t/ruida/gui/ruidaoperationproperties.py +48 -47
  385. meerk40t/ruida/loader.py +54 -52
  386. meerk40t/ruida/mock_connection.py +57 -109
  387. meerk40t/ruida/plugin.py +124 -87
  388. meerk40t/ruida/rdjob.py +2084 -945
  389. meerk40t/ruida/serial_connection.py +116 -0
  390. meerk40t/ruida/tcp_connection.py +146 -0
  391. meerk40t/ruida/udp_connection.py +73 -0
  392. meerk40t/svgelements.py +9671 -9669
  393. meerk40t/tools/driver_to_path.py +584 -579
  394. meerk40t/tools/geomstr.py +5583 -4680
  395. meerk40t/tools/jhfparser.py +357 -292
  396. meerk40t/tools/kerftest.py +904 -890
  397. meerk40t/tools/livinghinges.py +1168 -1033
  398. meerk40t/tools/pathtools.py +987 -949
  399. meerk40t/tools/pmatrix.py +234 -0
  400. meerk40t/tools/pointfinder.py +942 -942
  401. meerk40t/tools/polybool.py +940 -940
  402. meerk40t/tools/rasterplotter.py +1660 -547
  403. meerk40t/tools/shxparser.py +989 -901
  404. meerk40t/tools/ttfparser.py +726 -446
  405. meerk40t/tools/zinglplotter.py +595 -593
  406. {meerk40t-0.9.3001.dist-info → meerk40t-0.9.7010.dist-info}/LICENSE +21 -21
  407. {meerk40t-0.9.3001.dist-info → meerk40t-0.9.7010.dist-info}/METADATA +150 -139
  408. meerk40t-0.9.7010.dist-info/RECORD +445 -0
  409. {meerk40t-0.9.3001.dist-info → meerk40t-0.9.7010.dist-info}/WHEEL +1 -1
  410. {meerk40t-0.9.3001.dist-info → meerk40t-0.9.7010.dist-info}/top_level.txt +0 -1
  411. {meerk40t-0.9.3001.dist-info → meerk40t-0.9.7010.dist-info}/zip-safe +1 -1
  412. meerk40t/balormk/elementlightjob.py +0 -159
  413. meerk40t-0.9.3001.dist-info/RECORD +0 -437
  414. test/bootstrap.py +0 -63
  415. test/test_cli.py +0 -12
  416. test/test_core_cutcode.py +0 -418
  417. test/test_core_elements.py +0 -144
  418. test/test_core_plotplanner.py +0 -397
  419. test/test_core_viewports.py +0 -312
  420. test/test_drivers_grbl.py +0 -108
  421. test/test_drivers_lihuiyu.py +0 -443
  422. test/test_drivers_newly.py +0 -113
  423. test/test_element_degenerate_points.py +0 -43
  424. test/test_elements_classify.py +0 -97
  425. test/test_elements_penbox.py +0 -22
  426. test/test_file_svg.py +0 -176
  427. test/test_fill.py +0 -155
  428. test/test_geomstr.py +0 -1523
  429. test/test_geomstr_nodes.py +0 -18
  430. test/test_imagetools_actualize.py +0 -306
  431. test/test_imagetools_wizard.py +0 -258
  432. test/test_kernel.py +0 -200
  433. test/test_laser_speeds.py +0 -3303
  434. test/test_length.py +0 -57
  435. test/test_lifecycle.py +0 -66
  436. test/test_operations.py +0 -251
  437. test/test_operations_hatch.py +0 -57
  438. test/test_ruida.py +0 -19
  439. test/test_spooler.py +0 -22
  440. test/test_tools_rasterplotter.py +0 -29
  441. test/test_wobble.py +0 -133
  442. test/test_zingl.py +0 -124
  443. {test → meerk40t/cylinder}/__init__.py +0 -0
  444. /meerk40t/{core/element_commands.py → cylinder/gui/__init__.py} +0 -0
  445. {meerk40t-0.9.3001.dist-info → meerk40t-0.9.7010.dist-info}/entry_points.txt +0 -0
@@ -1,801 +1,1082 @@
1
- import threading
2
- from copy import copy
3
- from math import ceil, floor
4
-
5
- from meerk40t.core.node.node import Node
6
- from meerk40t.core.units import UNITS_PER_INCH
7
- from meerk40t.image.imagetools import RasterScripts
8
- from meerk40t.svgelements import Matrix, Path, Polygon
9
-
10
-
11
- class ImageNode(Node):
12
- """
13
- ImageNode is the bootstrapped node type for the 'elem image' type.
14
-
15
- ImageNode contains a main matrix, main image. A processed image and a processed matrix.
16
- The processed matrix must be concatenated with the main matrix to be accurate.
17
- """
18
-
19
- def __init__(self, **kwargs):
20
- self.image = None
21
- self.matrix = None
22
- self.overscan = None
23
- self.direction = None
24
- self.dpi = 500
25
- self.operations = list()
26
- self.invert = None
27
- self.dither = True
28
- self.dither_type = "Floyd-Steinberg"
29
- self.red = 1.0
30
- self.green = 1.0
31
- self.blue = 1.0
32
- self.lightness = 1.0
33
- self.view_invert = False
34
- self.prevent_crop = False
35
-
36
- self.passthrough = False
37
- super().__init__(type="elem image", **kwargs)
38
- # kwargs can actually reset quite a lot of the properties to none
39
- # so we need to revert these changes...
40
- if self.red is None:
41
- self.red = 1.0
42
- if self.green is None:
43
- self.green = 1.0
44
- if self.blue is None:
45
- self.blue = 1.0
46
- if self.lightness is None:
47
- self.lightness = 1.0
48
- if self.operations is None:
49
- self.operations = list()
50
- if self.dither_type is None:
51
- self.dither_type = "Floyd-Steinberg"
52
-
53
- self.__formatter = "{element_type} {id} {width}x{height}"
54
- if self.matrix is None:
55
- self.matrix = Matrix()
56
- if hasattr(self, "href"):
57
- try:
58
- from PIL import Image as PILImage
59
-
60
- if not isinstance(self.href, str):
61
- # Error caused by href being int value
62
- raise ImportError
63
-
64
- self.image = PILImage.open(self.href)
65
- if hasattr(self, "x"):
66
- self.matrix.post_translate_x(self.x)
67
- if hasattr(self, "y"):
68
- self.matrix.post_translate_x(self.y)
69
- real_width, real_height = self.image.size
70
- declared_width, declared_height = real_width, real_height
71
- if hasattr(self, "width"):
72
- declared_width = self.width
73
- if hasattr(self, "height"):
74
- declared_height = self.height
75
- try:
76
- sx = declared_width / real_width
77
- sy = declared_height / real_height
78
- self.matrix.post_scale(sx, sy)
79
- except ZeroDivisionError:
80
- pass
81
- delattr(self, "href")
82
- delattr(self, "x")
83
- delattr(self, "y")
84
- delattr(self, "height")
85
- delattr(self, "width")
86
- except ImportError:
87
- self.image = None
88
-
89
- # Step_x/y is the step factor of the image, the reciprocal of the DPI.
90
- self.step_x = None
91
- self.step_y = None
92
-
93
- self._needs_update = False
94
- self._update_thread = None
95
- self._update_lock = threading.Lock()
96
- self._processed_image = None
97
- self._processed_matrix = None
98
- self._process_image_failed = False
99
- self.message = None
100
- if self.operations or self.dither or self.prevent_crop:
101
- step = UNITS_PER_INCH / self.dpi
102
- step_x = step
103
- step_y = step
104
- self.process_image(step_x, step_y, not self.prevent_crop)
105
-
106
- def __copy__(self):
107
- nd = self.node_dict
108
- nd["matrix"] = copy(self.matrix)
109
- nd["operations"] = copy(self.operations)
110
- return ImageNode(**nd)
111
-
112
- def __repr__(self):
113
- return f"{self.__class__.__name__}('{self.type}', {str(self.image)}, {str(self._parent)})"
114
-
115
- @property
116
- def active_image(self):
117
- if self._processed_image is None:
118
- step = UNITS_PER_INCH / self.dpi
119
- step_x = step
120
- step_y = step
121
- self.process_image(step_x, step_y, not self.prevent_crop)
122
- if self._processed_image is not None:
123
- return self._processed_image
124
- else:
125
- return self.image
126
-
127
- @property
128
- def active_matrix(self):
129
- if self._processed_matrix is None:
130
- return self.matrix
131
- return self._processed_matrix * self.matrix
132
-
133
- def preprocess(self, context, matrix, plan):
134
- """
135
- Preprocess step during the cut planning stages.
136
-
137
- We require a context to calculate the correct step values relative to the device
138
- """
139
- self.step_x, self.step_y = context.device.view.dpi_to_steps(self.dpi)
140
- self.matrix *= matrix
141
- self.set_dirty_bounds()
142
- self.process_image(self.step_x, self.step_y, not self.prevent_crop)
143
-
144
- def as_image(self):
145
- return self.active_image, self.bbox()
146
-
147
- def bbox(self, transformed=True, with_stroke=False):
148
- image_width, image_height = self.active_image.size
149
- matrix = self.active_matrix
150
- x0, y0 = matrix.point_in_matrix_space((0, 0))
151
- x1, y1 = matrix.point_in_matrix_space((image_width, image_height))
152
- x2, y2 = matrix.point_in_matrix_space((0, image_height))
153
- x3, y3 = matrix.point_in_matrix_space((image_width, 0))
154
- return (
155
- min(x0, x1, x2, x3),
156
- min(y0, y1, y2, y3),
157
- max(x0, x1, x2, x3),
158
- max(y0, y1, y2, y3),
159
- )
160
-
161
- def default_map(self, default_map=None):
162
- default_map = super().default_map(default_map=default_map)
163
- default_map.update(self.__dict__)
164
- image = self.active_image
165
- default_map["width"] = image.width
166
- default_map["height"] = image.height
167
- default_map["element_type"] = "Image"
168
- return default_map
169
-
170
- def drop(self, drag_node, modify=True):
171
- # Dragging element into element.
172
- if drag_node.type.startswith("elem"):
173
- if modify:
174
- self.insert_sibling(drag_node)
175
- return True
176
- elif drag_node.type.startswith("op"):
177
- # If we drag an operation to this node,
178
- # then we will reverse the game
179
- return drag_node.drop(self, modify=modify)
180
- return False
181
-
182
- def revalidate_points(self):
183
- bounds = self.bounds
184
- if bounds is None:
185
- return
186
- if len(self._points) < 9:
187
- self._points.extend([None] * (9 - len(self._points)))
188
- self._points[0] = [bounds[0], bounds[1], "bounds top_left"]
189
- self._points[1] = [bounds[2], bounds[1], "bounds top_right"]
190
- self._points[2] = [bounds[0], bounds[3], "bounds bottom_left"]
191
- self._points[3] = [bounds[2], bounds[3], "bounds bottom_right"]
192
- cx = (bounds[0] + bounds[2]) / 2
193
- cy = (bounds[1] + bounds[3]) / 2
194
- self._points[4] = [cx, cy, "bounds center_center"]
195
- self._points[5] = [cx, bounds[1], "bounds top_center"]
196
- self._points[6] = [cx, bounds[3], "bounds bottom_center"]
197
- self._points[7] = [bounds[0], cy, "bounds center_left"]
198
- self._points[8] = [bounds[2], cy, "bounds center_right"]
199
-
200
- def update_point(self, index, point):
201
- return False
202
-
203
- def add_point(self, point, index=None):
204
- return False
205
-
206
- def update(self, context):
207
- """
208
- Update kicks off the image processing thread, which performs RasterWizard script operations on the image node.
209
-
210
- The text should be displayed in the scene by the renderer. And any additional changes will be processed
211
- until the new processed image is completed.
212
-
213
- @param context:
214
- @return:
215
- """
216
- self._needs_update = True
217
- if context is not None:
218
- self.message = "Processing..."
219
- context.signal("refresh_scene", "Scene")
220
- if self._update_thread is None:
221
-
222
- def clear(result):
223
- self._needs_update = False
224
- self._update_thread = None
225
- if context is not None:
226
- if self._process_image_failed:
227
- self.message = "Process image could not exist in memory."
228
- else:
229
- self.message = None
230
- context.signal("refresh_scene", "Scene")
231
- context.signal("image_updated", self)
232
-
233
- self._processed_image = None
234
- # self.processed_matrix = None
235
- if context is None:
236
- # Direct execution
237
- self._needs_update = False
238
- # Calculate scene step_x, step_y values
239
- step = UNITS_PER_INCH / self.dpi
240
- step_x = step
241
- step_y = step
242
- self.process_image(step_x, step_y, not self.prevent_crop)
243
- # Unset cache.
244
- self._cache = None
245
- else:
246
- self._update_thread = context.threaded(
247
- self._process_image_thread, result=clear, daemon=True
248
- )
249
-
250
- def _process_image_thread(self):
251
- """
252
- The function deletes the caches and processes the image until it no longer needs updating.
253
-
254
- @return:
255
- """
256
- while self._needs_update:
257
- self._needs_update = False
258
- # Calculate scene step_x, step_y values
259
- step = UNITS_PER_INCH / self.dpi
260
- step_x = step
261
- step_y = step
262
- self.process_image(step_x, step_y, not self.prevent_crop)
263
- # Unset cache.
264
- self._cache = None
265
-
266
- def process_image(self, step_x=None, step_y=None, crop=True):
267
- """
268
- SVG matrices are defined as follows.
269
- [a c e]
270
- [b d f]
271
-
272
- Pil requires a, c, e, b, d, f accordingly.
273
-
274
- As of 0.7.2 this converts the image to "L" as part of the process.
275
-
276
- There is a small amount of slop at the edge of converted images sometimes, so it's essential
277
- to mark the image as inverted if black should be treated as empty pixels. The scaled down image
278
- cannot lose the edge pixels since they could be important, but also dim may not be a multiple
279
- of step level which requires an introduced empty edge pixel to be added.
280
- """
281
-
282
- from PIL import Image
283
-
284
- if step_x is None:
285
- step_x = self.step_x
286
- if step_y is None:
287
- step_y = self.step_y
288
- try:
289
- actualized_matrix, image = self._process_image(step_x, step_y, crop=crop)
290
- inverted_main_matrix = Matrix(self.matrix).inverse()
291
- self._processed_matrix = actualized_matrix * inverted_main_matrix
292
- self._processed_image = image
293
- self._process_image_failed = False
294
- bb = self.bbox()
295
- self._bounds = bb
296
- self._paint_bounds = bb
297
- except (
298
- MemoryError,
299
- Image.DecompressionBombError,
300
- ValueError,
301
- ZeroDivisionError,
302
- ):
303
- # Memory error if creating requires too much memory.
304
- # DecompressionBomb if over 272 megapixels.
305
- # ValueError if bounds are NaN.
306
- # ZeroDivide if inverting the processed matrix cannot happen because image is a line
307
- self._process_image_failed = True
308
- self.updated()
309
-
310
- @property
311
- def opaque_image(self):
312
- from PIL import Image
313
-
314
- img = self.image
315
- if img is not None:
316
- if img.mode == "RGBA":
317
- r, g, b, a = img.split()
318
- background = Image.new("RGB", img.size, "white")
319
- background.paste(img, mask=a)
320
- img = background
321
- return img
322
-
323
- def _convert_image_to_grayscale(self, image):
324
- # Convert image to L type.
325
- if image.mode != "L":
326
- # Precalculate RGB for L conversion.
327
- # if self.red is None:
328
- # self.red = 1
329
- if self.red is None or self.green is None or self.blue is None:
330
- r = 1
331
- g = 1
332
- b = 1
333
- else:
334
- r = self.red * 0.299
335
- g = self.green * 0.587
336
- b = self.blue * 0.114
337
- v = self.lightness
338
- c = r + g + b
339
- try:
340
- c /= v
341
- r = r / c
342
- g = g / c
343
- b = b / c
344
- except ZeroDivisionError:
345
- pass
346
- image = image.convert("RGB")
347
- image = image.convert("L", matrix=(r, g, b, 1.0))
348
- return image
349
-
350
- def _get_transparent_mask(self, image):
351
- """
352
- Create Transparency Mask.
353
- @param image:
354
- @return:
355
- """
356
- if image is None:
357
- return None
358
- if "transparency" in image.info:
359
- image = image.convert("RGBA")
360
- try:
361
- return image.getchannel("A").point(lambda e: 255 - e)
362
- except ValueError:
363
- return None
364
-
365
- def _apply_mask(self, image, mask, reject_color=None):
366
- """
367
- Fill in original image with reject pixels.
368
-
369
- @param image: Image to be masked off.
370
- @param mask: Mask to apply to image
371
- @param reject_color: Optional specified reject color override. Reject is usually "white" or black if inverted.
372
- @return: image with mask pixels filled in with reject pixels
373
- """
374
- if not mask:
375
- return image
376
- if reject_color is None:
377
- reject_color = "black" if self.invert else "white"
378
- from PIL import Image
379
-
380
- background = image.copy()
381
- reject = Image.new("L", image.size, reject_color)
382
- background.paste(reject, mask=mask)
383
- return background
384
-
385
- def _get_crop_box(self, image):
386
- """
387
- Get the bbox cutting off the reject edges. The reject edges depend on the image's invert setting.
388
- @param image: Image to get crop box for.
389
- @return:
390
- """
391
- try:
392
- if self.invert:
393
- return image.getbbox()
394
- else:
395
- return image.point(lambda e: 255 - e).getbbox()
396
- except ValueError:
397
- return None
398
-
399
- def _process_script(self, image):
400
- """
401
- Process actual raster script operations. Any required grayscale, inversion, and masking will already have
402
- occurred. If there were reject pixels before they will be masked off after this process.
403
-
404
- @param image: image to process with self.operation script.
405
-
406
- @return: processed image
407
- """
408
- from PIL import ImageEnhance, ImageFilter, ImageOps
409
-
410
- overall_left = 0
411
- overall_top = 0
412
- overall_right, overall_bottom = image.size
413
- for op in self.operations:
414
- name = op["name"]
415
- if name == "resample":
416
- # This is just a reminder, that while this may still appear in the scripts it is intentionally
417
- # ignored (or needs to be revised with the upcoming appearance of passthrough) as it is not
418
- # serving the purpose of the past
419
- continue
420
- if name == "crop":
421
- try:
422
- if op["enable"] and op["bounds"] is not None:
423
- crop = op["bounds"]
424
- left = int(crop[0])
425
- upper = int(crop[1])
426
- right = int(crop[2])
427
- lower = int(crop[3])
428
- w, h = image.size
429
- overall_left += left
430
- overall_top += upper
431
- overall_right -= w - right
432
- overall_bottom -= h - lower
433
- image = image.crop((left, upper, right, lower))
434
- except KeyError:
435
- pass
436
- elif name == "edge_enhance":
437
- try:
438
- if op["enable"]:
439
- if image.mode == "P":
440
- image = image.convert("L")
441
- image = image.filter(filter=ImageFilter.EDGE_ENHANCE)
442
- except KeyError:
443
- pass
444
- elif name == "auto_contrast":
445
- try:
446
- if op["enable"]:
447
- if image.mode not in ("RGB", "L"):
448
- # Auto-contrast raises NotImplementedError if P
449
- # Auto-contrast raises OSError if not RGB, L.
450
- image = image.convert("L")
451
- image = ImageOps.autocontrast(image, cutoff=op["cutoff"])
452
- except KeyError:
453
- pass
454
- elif name == "tone":
455
- try:
456
- if op["enable"] and op["values"] is not None:
457
- if image.mode == "L":
458
- image = image.convert("P")
459
- tone_values = op["values"]
460
- if op["type"] == "spline":
461
- spline = ImageNode.spline(tone_values)
462
- else:
463
- tone_values = [q for q in tone_values if q is not None]
464
- spline = ImageNode.line(tone_values)
465
- if len(spline) < 256:
466
- spline.extend([255] * (256 - len(spline)))
467
- if len(spline) > 256:
468
- spline = spline[:256]
469
- image = image.point(spline)
470
- if image.mode != "L":
471
- image = image.convert("L")
472
- except KeyError:
473
- pass
474
- elif name == "contrast":
475
- try:
476
- if op["enable"]:
477
- if op["contrast"] is not None and op["brightness"] is not None:
478
- contrast = ImageEnhance.Contrast(image)
479
- c = (op["contrast"] + 128.0) / 128.0
480
- image = contrast.enhance(c)
481
-
482
- brightness = ImageEnhance.Brightness(image)
483
- b = (op["brightness"] + 128.0) / 128.0
484
- image = brightness.enhance(b)
485
- except KeyError:
486
- pass
487
- elif name == "gamma":
488
- try:
489
- if op["enable"] and op["factor"] is not None:
490
- if image.mode == "L":
491
- gamma_factor = float(op["factor"])
492
-
493
- def crimp(px):
494
- px = int(round(px))
495
- if px < 0:
496
- return 0
497
- if px > 255:
498
- return 255
499
- return px
500
-
501
- if gamma_factor == 0:
502
- gamma_lut = [0] * 256
503
- else:
504
- gamma_lut = [
505
- crimp(pow(i / 255, (1.0 / gamma_factor)) * 255)
506
- for i in range(256)
507
- ]
508
- image = image.point(gamma_lut)
509
- if image.mode != "L":
510
- image = image.convert("L")
511
- except KeyError:
512
- pass
513
- elif name == "unsharp_mask":
514
- try:
515
- if (
516
- op["enable"]
517
- and op["percent"] is not None
518
- and op["radius"] is not None
519
- and op["threshold"] is not None
520
- ):
521
- unsharp = ImageFilter.UnsharpMask(
522
- radius=op["radius"],
523
- percent=op["percent"],
524
- threshold=op["threshold"],
525
- )
526
- image = image.filter(unsharp)
527
- except (KeyError, ValueError): # Value error if wrong type of image.
528
- pass
529
- elif name == "halftone":
530
- try:
531
- if op["enable"]:
532
- image = RasterScripts.halftone(
533
- image,
534
- sample=op["sample"],
535
- angle=op["angle"],
536
- oversample=op["oversample"],
537
- black=op["black"],
538
- )
539
- except KeyError:
540
- pass
541
- elif name == "dither":
542
- # Set dither
543
- try:
544
- if op["enable"] and op["type"] is not None:
545
- self.dither_type = op["type"]
546
- self.dither = True
547
- else:
548
- # Takes precedence
549
- self.dither = False
550
- # image = self._apply_dither(image)
551
- except KeyError:
552
- pass
553
- else:
554
- # print(f"Unknown operation in raster-script: {name}")
555
- continue
556
- return image, (overall_left, overall_top, overall_right, overall_bottom)
557
-
558
- def _apply_dither(self, image):
559
- """
560
- Dither image to 1 bit. Floyd-Steinberg is performed by Pillow, other dithers require custom code.
561
-
562
- @param image: grayscale image to dither.
563
- @return: 1 bit dithered image
564
- """
565
- from meerk40t.image.imagetools import dither
566
-
567
- if self.dither and self.dither_type is not None:
568
- if self.dither_type != "Floyd-Steinberg":
569
- image = dither(image, self.dither_type)
570
- image = image.convert("1")
571
- return image
572
-
573
- def _process_image(self, step_x, step_y, crop=True):
574
- """
575
- This core code replaces the older actualize and rasterwizard functionalities. It should convert the image to
576
- a post-processed form with resulting post-process matrix.
577
-
578
- @param crop: Should the unneeded edges be cropped as part of this process. The need for the edge is determined
579
- by the color and the state of the self.invert attribute.
580
- @return:
581
- """
582
- from PIL import Image, ImageOps
583
-
584
- try:
585
- from PIL.Image import Transform
586
-
587
- AFFINE = Transform.AFFINE
588
- except ImportError:
589
- AFFINE = Image.AFFINE
590
-
591
- try:
592
- from PIL.Image import Resampling
593
-
594
- BICUBIC = Resampling.BICUBIC
595
- except ImportError:
596
- BICUBIC = Image.BICUBIC
597
-
598
- image = self.image
599
-
600
- transparent_mask = self._get_transparent_mask(image)
601
-
602
- image = self._convert_image_to_grayscale(self.opaque_image)
603
-
604
- image = self._apply_mask(image, transparent_mask)
605
-
606
- # Calculate image box.
607
- box = None
608
- if crop:
609
- box = self._get_crop_box(image)
610
- if box is None:
611
- # If box is entirely white, bbox caused value error, or crop not set.
612
- box = (0, 0, image.width, image.height)
613
- orgbox = (box[0], box[1], box[2], box[3])
614
-
615
- transform_matrix = copy(self.matrix) # Prevent Knock-on effect.
616
-
617
- # Find the boundary points of the rotated box edges.
618
- boundary_points = [
619
- transform_matrix.point_in_matrix_space([box[0], box[1]]), # Top-left
620
- transform_matrix.point_in_matrix_space([box[2], box[1]]), # Top-right
621
- transform_matrix.point_in_matrix_space([box[0], box[3]]), # Bottom-left
622
- transform_matrix.point_in_matrix_space([box[2], box[3]]), # Bottom-right
623
- ]
624
- xs = [e[0] for e in boundary_points]
625
- ys = [e[1] for e in boundary_points]
626
-
627
- # bbox here is expanded matrix size of box.
628
- step_scale_x = 1 / float(step_x)
629
- step_scale_y = 1 / float(step_y)
630
-
631
- bbox = min(xs), min(ys), max(xs), max(ys)
632
-
633
- image_width = ceil(bbox[2] * step_scale_x) - floor(bbox[0] * step_scale_x)
634
- image_height = ceil(bbox[3] * step_scale_y) - floor(bbox[1] * step_scale_y)
635
- tx = bbox[0]
636
- ty = bbox[1]
637
- # Caveat: we move the picture backward, so that the non-white
638
- # image content aligns at 0 , 0 - but we don't crop the image
639
- transform_matrix.post_translate(-tx, -ty)
640
- transform_matrix.post_scale(step_scale_x, step_scale_y)
641
- if step_y < 0:
642
- # If step_y is negative, translate
643
- transform_matrix.post_translate(0, image_height)
644
- if step_x < 0:
645
- # If step_x is negative, translate
646
- transform_matrix.post_translate(image_width, 0)
647
-
648
- try:
649
- transform_matrix.inverse()
650
- except ZeroDivisionError:
651
- # malformed matrix, scale=0 or something.
652
- transform_matrix.reset()
653
-
654
- # Perform image transform if needed.
655
- if (
656
- self.matrix.a != step_x
657
- or self.matrix.b != 0.0
658
- or self.matrix.c != 0.0
659
- or self.matrix.d != step_y
660
- ):
661
- if image_height <= 0:
662
- image_height = 1
663
- if image_width <= 0:
664
- image_width = 1
665
- image = image.transform(
666
- (image_width, image_height),
667
- AFFINE,
668
- (
669
- transform_matrix.a,
670
- transform_matrix.c,
671
- transform_matrix.e,
672
- transform_matrix.b,
673
- transform_matrix.d,
674
- transform_matrix.f,
675
- ),
676
- resample=BICUBIC,
677
- fillcolor="black" if self.invert else "white",
678
- )
679
- actualized_matrix = Matrix()
680
-
681
- if step_y < 0:
682
- # if step_y is negative, translate.
683
- actualized_matrix.post_translate(0, -image_height)
684
- if step_x < 0:
685
- # if step_x is negative, translate.
686
- actualized_matrix.post_translate(-image_width, 0)
687
-
688
- # If crop applies, apply crop.
689
- if crop:
690
- cbox = self._get_crop_box(image)
691
- if cbox is not None:
692
- width = cbox[2] - cbox[0]
693
- height = cbox[3] - cbox[1]
694
- if width != image.width or height != image.height:
695
- image = image.crop(cbox)
696
- # TODO:
697
- # We did not crop the image so far, but we already applied
698
- # the cropped transformation! That may be faulty, and needs to
699
- # be corrected at a later stage, but this logic, even if clumsy
700
- # is good enough: don't shift things twice!
701
- if orgbox[0] == 0 and orgbox[1] == 0:
702
- actualized_matrix.post_translate(cbox[0], cbox[1])
703
-
704
- actualized_matrix.post_scale(step_x, step_y)
705
- actualized_matrix.post_translate(tx, ty)
706
-
707
- # Invert black to white if needed.
708
- if self.invert:
709
- image = ImageOps.invert(image)
710
-
711
- # Find rejection mask of white pixels. (already inverted)
712
- reject_mask = image.point(lambda e: 0 if e == 255 else 255)
713
-
714
- image, newbounds = self._process_script(image)
715
- # This may have again changed the size of the image (op crop)
716
- # so we need to adjust the reject mask...
717
- reject_mask = reject_mask.crop(newbounds)
718
-
719
- background = Image.new("L", image.size, "white")
720
- background.paste(image, mask=reject_mask)
721
- image = background
722
-
723
- image = self._apply_dither(image)
724
- return actualized_matrix, image
725
-
726
- @staticmethod
727
- def line(p):
728
- N = len(p) - 1
729
- try:
730
- m = [(p[i + 1][1] - p[i][1]) / (p[i + 1][0] - p[i][0]) for i in range(0, N)]
731
- except ZeroDivisionError:
732
- m = [1] * N
733
- # b = y - mx
734
- b = [p[i][1] - (m[i] * p[i][0]) for i in range(0, N)]
735
- r = list()
736
- for i in range(0, p[0][0]):
737
- r.append(0)
738
- for i in range(len(p) - 1):
739
- x0 = p[i][0]
740
- x1 = p[i + 1][0]
741
- range_list = [int(round((m[i] * x) + b[i])) for x in range(x0, x1)]
742
- r.extend(range_list)
743
- for i in range(p[-1][0], 256):
744
- r.append(255)
745
- r.append(round(int(p[-1][1])))
746
- return r
747
-
748
- @staticmethod
749
- def spline(p):
750
- """
751
- Spline interpreter.
752
-
753
- Returns all integer locations between different spline interpolation values
754
- @param p: points to be quad spline interpolated.
755
- @return: integer y values for given spline points.
756
- """
757
- try:
758
- N = len(p) - 1
759
- w = [(p[i + 1][0] - p[i][0]) for i in range(0, N)]
760
- h = [(p[i + 1][1] - p[i][1]) / w[i] for i in range(0, N)]
761
- ftt = (
762
- [0]
763
- + [3 * (h[i + 1] - h[i]) / (w[i + 1] + w[i]) for i in range(0, N - 1)]
764
- + [0]
765
- )
766
- A = [(ftt[i + 1] - ftt[i]) / (6 * w[i]) for i in range(0, N)]
767
- B = [ftt[i] / 2 for i in range(0, N)]
768
- C = [h[i] - w[i] * (ftt[i + 1] + 2 * ftt[i]) / 6 for i in range(0, N)]
769
- D = [p[i][1] for i in range(0, N)]
770
- except ZeroDivisionError:
771
- return list(range(256))
772
- r = list()
773
- for i in range(0, p[0][0]):
774
- r.append(0)
775
- for i in range(len(p) - 1):
776
- a = p[i][0]
777
- b = p[i + 1][0]
778
- r.extend(
779
- int(
780
- round(
781
- A[i] * (x - a) ** 3
782
- + B[i] * (x - a) ** 2
783
- + C[i] * (x - a)
784
- + D[i]
785
- )
786
- )
787
- for x in range(a, b)
788
- )
789
- for i in range(p[-1][0], 256):
790
- r.append(255)
791
- r.append(round(int(p[-1][1])))
792
- return r
793
-
794
- def as_path(self):
795
- image_width, image_height = self.active_image.size
796
- matrix = self.active_matrix
797
- x0, y0 = matrix.point_in_matrix_space((0, 0))
798
- x1, y1 = matrix.point_in_matrix_space((0, image_height))
799
- x2, y2 = matrix.point_in_matrix_space((image_width, image_height))
800
- x3, y3 = matrix.point_in_matrix_space((image_width, 0))
801
- return abs(Path(Polygon((x0, y0), (x1, y1), (x2, y2), (x3, y3), (x0, y0))))
1
+ """
2
+ ImageNode is the bootstrapped node type for handling image elements within the application.
3
+
4
+ This class manages the properties and behaviors associated with image nodes, including
5
+ image processing, transformations, and keyhole functionalities. It supports various
6
+ operations such as cropping, dither effects, and applying raster scripts, while also
7
+ maintaining the necessary metadata for rendering and manipulation.
8
+
9
+ Args:
10
+ **kwargs: Additional keyword arguments for node initialization.
11
+
12
+ Attributes:
13
+ image: The original image loaded into the node.
14
+ matrix: The transformation matrix applied to the image.
15
+ dpi: The resolution of the image in dots per inch.
16
+ operations: A list of operations to be applied to the image.
17
+ keyhole_reference: Reference for keyhole operations.
18
+ active_image: The processed image ready for rendering.
19
+ active_matrix: The matrix that combines the main matrix with the processed matrix.
20
+ convex_hull: The convex hull of the non-white pixels in the image.
21
+
22
+ Methods:
23
+ set_keyhole(keyhole_ref, geom=None): Sets the keyhole reference and geometry.
24
+ process_image(step_x=None, step_y=None, crop=True): Processes the image based on the specified steps and cropping options.
25
+ update(context): Initiates the image processing thread and updates the image.
26
+ as_image(): Returns the active image and its bounding box.
27
+ bbox(transformed=True, with_stroke=False): Returns the bounding box of the image.
28
+ """
29
+
30
+ import numpy as np
31
+ import threading
32
+ import time
33
+ from copy import copy
34
+ from math import ceil, floor
35
+
36
+ from meerk40t.core.node.node import Node
37
+ from meerk40t.core.node.mixins import LabelDisplay, Suppressable
38
+ from meerk40t.core.units import UNITS_PER_INCH, UNITS_PER_MM
39
+ from meerk40t.image.imagetools import RasterScripts
40
+ from meerk40t.svgelements import Matrix, Path, Polygon
41
+ from meerk40t.tools.geomstr import Geomstr
42
+
43
+ class ImageNode(Node, LabelDisplay, Suppressable):
44
+ """
45
+ ImageNode is the bootstrapped node type for the 'elem image' type.
46
+
47
+ ImageNode contains a main matrix, main image. A processed image and a processed matrix.
48
+ The processed matrix must be concatenated with the main matrix to be accurate.
49
+ """
50
+
51
+ def __init__(self, **kwargs):
52
+ self.image = None
53
+ self.matrix = None
54
+ self.overscan = None
55
+ self.direction = None
56
+ self.dpi = 500
57
+ self.operations = []
58
+ self.invert = None
59
+ self.dither = True
60
+ self.dither_type = "Floyd-Steinberg"
61
+ self.red = 1.0
62
+ self.green = 1.0
63
+ self.blue = 1.0
64
+ self.lightness = 1.0
65
+ self.view_invert = False
66
+ self.prevent_crop = False
67
+ self.is_depthmap = False
68
+ self.depth_resolution = 256
69
+ # Keyhole-Variables
70
+ self._keyhole_reference = None
71
+ self._keyhole_geometry = None
72
+ self._keyhole_image = None
73
+ self._processing = False
74
+ self._convex_hull = None
75
+ self._default_units = UNITS_PER_INCH
76
+ startup = True
77
+ if "comingfromcopy" in kwargs:
78
+ startup = False
79
+ del kwargs["comingfromcopy"]
80
+
81
+ self.passthrough = False
82
+ super().__init__(type="elem image", **kwargs)
83
+ if "hidden" in kwargs:
84
+ if isinstance(kwargs["hidden"], str):
85
+ if kwargs["hidden"].lower() == "true":
86
+ kwargs["hidden"] = True
87
+ else:
88
+ kwargs["hidden"] = False
89
+ self.hidden = kwargs["hidden"]
90
+ # kwargs can actually reset quite a lot of the properties to none
91
+ # so, we need to revert these changes...
92
+ if self.red is None:
93
+ self.red = 1.0
94
+ if self.green is None:
95
+ self.green = 1.0
96
+ if self.blue is None:
97
+ self.blue = 1.0
98
+ if self.lightness is None:
99
+ self.lightness = 1.0
100
+ if self.operations is None:
101
+ self.operations = list()
102
+ if self.dither_type is None:
103
+ self.dither_type = "Floyd-Steinberg"
104
+
105
+ self.__formatter = "{element_type} {id} {width}x{height}"
106
+ if self.matrix is None:
107
+ self.matrix = Matrix()
108
+ if hasattr(self, "href"):
109
+ try:
110
+ from PIL import Image as PILImage
111
+
112
+ if not isinstance(self.href, str):
113
+ # Error caused by href being int value
114
+ raise ImportError
115
+
116
+ self.image = PILImage.open(self.href)
117
+ if hasattr(self, "x"):
118
+ self.matrix.post_translate_x(self.x)
119
+ delattr(self, "x")
120
+ if hasattr(self, "y"):
121
+ self.matrix.post_translate_x(self.y)
122
+ delattr(self, "y")
123
+ real_width, real_height = self.image.size
124
+ declared_width, declared_height = real_width, real_height
125
+ if hasattr(self, "width"):
126
+ declared_width = self.width
127
+ delattr(self, "width")
128
+
129
+ if hasattr(self, "height"):
130
+ declared_height = self.height
131
+ delattr(self, "height")
132
+ try:
133
+ sx = declared_width / real_width
134
+ sy = declared_height / real_height
135
+ self.matrix.post_scale(sx, sy)
136
+ except ZeroDivisionError:
137
+ pass
138
+ delattr(self, "href")
139
+
140
+ except ImportError:
141
+ self.image = None
142
+
143
+ # Step_x/y is the step factor of the image, the reciprocal of the DPI.
144
+ self.step_x = None
145
+ self.step_y = None
146
+
147
+ self._needs_update = False
148
+ self._update_thread = None
149
+ self._update_lock = threading.Lock()
150
+ self._processed_image = None
151
+ self._processed_matrix = None
152
+ self._actualized_matrix = None
153
+ self._process_image_failed = False
154
+
155
+ self.message = None
156
+ if (self.operations or self.dither or self.prevent_crop or self.keyhole_reference) and startup:
157
+ step = self._default_units / self.dpi
158
+ step_x = step
159
+ step_y = step
160
+ self.process_image(step_x, step_y, not self.prevent_crop)
161
+
162
+ def __copy__(self):
163
+ nd = self.node_dict
164
+ nd["matrix"] = copy(self.matrix)
165
+ nd["operations"] = copy(self.operations)
166
+ nd["comingfromcopy"] = True
167
+ newnode = ImageNode(**nd)
168
+ if self._processed_image is not None:
169
+ newnode._processed_image = copy(self._processed_image)
170
+ newnode._processed_matrix = copy(self._processed_matrix)
171
+ newnode._actualized_matrix = copy(self._actualized_matrix)
172
+ g = None if self._keyhole_geometry is None else copy(self._keyhole_geometry)
173
+ newnode.set_keyhole(self.keyhole_reference, g)
174
+ return newnode
175
+
176
+ def __repr__(self):
177
+ return f"{self.__class__.__name__}('{self.type}', {str(self.image)}, {str(self._parent)})"
178
+
179
+ @property
180
+ def active_image(self):
181
+ # This may be called too quick, so the image is still processing.
182
+ # This would cause an immediate recalculation which would make
183
+ # things even worse, we wait max 1 second
184
+ counter = 0
185
+ while self._processing and counter < 20:
186
+ time.sleep(0.05)
187
+ counter += 1
188
+ if self._processed_image is None:
189
+
190
+ step = self._default_units / self.dpi
191
+ step_x = step
192
+ step_y = step
193
+ self.process_image(step_x, step_y, not self.prevent_crop)
194
+ return self._apply_keyhole()
195
+ # if self._processed_image is not None:
196
+ # return self._processed_image
197
+ # else:
198
+ # return self.image
199
+
200
+ @property
201
+ def active_matrix(self):
202
+ if self._processed_matrix is None:
203
+ return self.matrix
204
+ return self._processed_matrix * self.matrix
205
+
206
+ @property
207
+ def keyhole_reference(self):
208
+ return self._keyhole_reference
209
+
210
+ @keyhole_reference.setter
211
+ def keyhole_reference(self, value):
212
+ self._keyhole_reference = value
213
+ self._keyhole_geometry = None
214
+ self._bounds_dirty = True
215
+
216
+ def set_keyhole(self, keyhole_ref, geom=None):
217
+ # This is useful if we do want to set it after loading a file
218
+ # or when assigning the reference, as this does not need a context
219
+ # query the complete node tree
220
+ self._cache = None
221
+ self.keyhole_reference = keyhole_ref
222
+ self._keyhole_geometry = geom
223
+ self._keyhole_image = None
224
+
225
+ def convex_hull(self) -> Geomstr:
226
+ if self._convex_hull is not None:
227
+ return self._convex_hull
228
+ t0 = time.perf_counter()
229
+ image_np = np.array(self.active_image.convert("L"))
230
+ # print (image_np)
231
+ # Find non-white pixels
232
+ # Iterate over each row in the image
233
+ left_side = []
234
+ right_side = []
235
+ for y in range(image_np.shape[0]):
236
+ row = image_np[y]
237
+ non_white_indices = np.where(row < 255)[0]
238
+
239
+ if non_white_indices.size > 0:
240
+ leftmost = non_white_indices[0]
241
+ rightmost = non_white_indices[-1]
242
+ left_side.append((leftmost, y))
243
+ right_side.insert(0, (rightmost, y))
244
+ left_side.extend(right_side)
245
+ non_white_pixels = left_side
246
+ t1 = time.perf_counter()
247
+ # Compute the convex hull
248
+ """
249
+ After the introduction of the quickhull routine in geomstr
250
+ the ConvexHull routine from scipy provides only limited
251
+ advantages over our own routine
252
+
253
+ pts = None
254
+ try:
255
+ # The ConvexHull routine from scipy provides less points
256
+ # and is faster (plus it has fewer non-understood artifacts)
257
+ from scipy.spatial import ConvexHull
258
+ c_points = np.array(non_white_pixels)
259
+ hull = ConvexHull(c_points)
260
+ hpts = c_points[hull.vertices]
261
+ pts = list( ( p[0], p[1] ) for p in hpts)
262
+ # print (f"scipy Hull has {len(pts)} pts")
263
+ except ImportError:
264
+ pass
265
+ t1b = time.perf_counter()
266
+ if pts is None:
267
+ """
268
+ pts = list(Geomstr.convex_hull(None, non_white_pixels))
269
+ if pts:
270
+ pts.append(pts[0])
271
+ # print("convex hull done")
272
+ t2 = time.perf_counter()
273
+ # print (f"Hull has {len(pts)} pts")
274
+ self._convex_hull = Geomstr.lines(*pts)
275
+ # print (f"Hull dimension: {self._convex_hull.bbox()} (for reference: image is {self.active_image.width}x{self.active_image.height} pixels)")
276
+ self._convex_hull.transform(self.active_matrix)
277
+ # print (f"Final dimension: {self._convex_hull.bbox()}")
278
+ t3 = time.perf_counter()
279
+ # print (f"Time to get pixels: {t1-t0:.3f}s, geomstr: {t2-t1b:.3f}s, scipy: {t1b-t1:.3f}s, total: {t3-t0:.3f}s")
280
+ return self._convex_hull
281
+
282
+ def preprocess(self, context, matrix, plan):
283
+ """
284
+ Preprocess step during the cut planning stages.
285
+
286
+ We require a context to calculate the correct step values relative to the device
287
+ """
288
+
289
+ dev_x, dev_y = context.device.view.dpi_to_steps(1)
290
+ self._default_units = (dev_x + dev_y) / 2
291
+ self.step_x, self.step_y = context.device.view.dpi_to_steps(self.dpi)
292
+ self.matrix *= matrix
293
+ self.set_dirty_bounds()
294
+ self.process_image(self.step_x, self.step_y, not self.prevent_crop)
295
+
296
+ def as_image(self):
297
+ return self.active_image, self.bbox()
298
+
299
+ def bbox(self, transformed=True, with_stroke=False):
300
+ image_width, image_height = self.active_image.size
301
+ matrix = self.active_matrix
302
+ x0, y0 = matrix.point_in_matrix_space((0, 0))
303
+ x1, y1 = matrix.point_in_matrix_space((image_width, image_height))
304
+ x2, y2 = matrix.point_in_matrix_space((0, image_height))
305
+ x3, y3 = matrix.point_in_matrix_space((image_width, 0))
306
+ return (
307
+ min(x0, x1, x2, x3),
308
+ min(y0, y1, y2, y3),
309
+ max(x0, x1, x2, x3),
310
+ max(y0, y1, y2, y3),
311
+ )
312
+
313
+ def default_map(self, default_map=None):
314
+ default_map = super().default_map(default_map=default_map)
315
+ default_map.update(self.__dict__)
316
+ image = self.active_image
317
+ default_map["width"] = image.width
318
+ default_map["height"] = image.height
319
+ default_map["element_type"] = "Image"
320
+ return default_map
321
+
322
+ def can_drop(self, drag_node):
323
+ # Dragging element into element.
324
+ return bool(
325
+ hasattr(drag_node, "as_geometry") or
326
+ hasattr(drag_node, "as_image") or
327
+ drag_node.type in ("op image", "op raster", "file", "group")
328
+ )
329
+
330
+ def drop(self, drag_node, modify=True, flag=False):
331
+ # Dragging element into element.
332
+ if not self.can_drop(drag_node):
333
+ return False
334
+ if hasattr(drag_node, "as_geometry") or hasattr(drag_node, "as_image") or drag_node.type in ("file", "group"):
335
+ if modify:
336
+ self.insert_sibling(drag_node)
337
+ return True
338
+ elif drag_node.type.startswith("op"):
339
+ # If we drag an operation to this node,
340
+ # then we will reverse the game
341
+ old_references = list(self._references)
342
+ result = drag_node.drop(self, modify=modify, flag=flag)
343
+ if result and modify:
344
+ for ref in old_references:
345
+ ref.remove_node()
346
+ return result
347
+ return False
348
+
349
+ def revalidate_points(self):
350
+ bounds = self.bounds
351
+ if bounds is None:
352
+ return
353
+ if len(self._points) < 9:
354
+ self._points.extend([None] * (9 - len(self._points)))
355
+ self._points[0] = [bounds[0], bounds[1], "bounds top_left"]
356
+ self._points[1] = [bounds[2], bounds[1], "bounds top_right"]
357
+ self._points[2] = [bounds[0], bounds[3], "bounds bottom_left"]
358
+ self._points[3] = [bounds[2], bounds[3], "bounds bottom_right"]
359
+ cx = (bounds[0] + bounds[2]) / 2
360
+ cy = (bounds[1] + bounds[3]) / 2
361
+ self._points[4] = [cx, cy, "bounds center_center"]
362
+ self._points[5] = [cx, bounds[1], "bounds top_center"]
363
+ self._points[6] = [cx, bounds[3], "bounds bottom_center"]
364
+ self._points[7] = [bounds[0], cy, "bounds center_left"]
365
+ self._points[8] = [bounds[2], cy, "bounds center_right"]
366
+
367
+ def update_point(self, index, point):
368
+ return False
369
+
370
+ def add_point(self, point, index=None):
371
+ return False
372
+
373
+ def update(self, context):
374
+ """
375
+ Update kicks off the image processing thread, which performs RasterWizard script operations on the image node.
376
+
377
+ The text should be displayed in the scene by the renderer. And any additional changes will be processed
378
+ until the new processed image is completed.
379
+
380
+ @param context:
381
+ @return:
382
+ """
383
+ self._needs_update = True
384
+ if context is not None:
385
+ self.message = "Processing..."
386
+ context.signal("refresh_scene", "Scene")
387
+ if self._update_thread is None:
388
+
389
+ def clear(result):
390
+ self._needs_update = False
391
+ self._update_thread = None
392
+ if context is not None:
393
+ if self._process_image_failed:
394
+ self.message = "Process image could not exist in memory."
395
+ else:
396
+ self.message = None
397
+ context.signal("refresh_scene", "Scene")
398
+ context.signal("image_updated", self)
399
+
400
+ def get_keyhole_geometry():
401
+ self._keyhole_geometry = None
402
+ self._keyhole_image = None
403
+ refnode = context.elements.find_node(self.id)
404
+ if refnode is not None and hasattr(refnode, "as_geometry"):
405
+ self._keyhole_geometry = refnode.as_geometry()
406
+
407
+ self._processed_image = None
408
+ self._convex_hull = None
409
+ # self.processed_matrix = None
410
+ if context is None:
411
+ # Direct execution
412
+ self._needs_update = False
413
+ # Calculate scene step_x, step_y values
414
+ step = self._default_units / self.dpi
415
+ step_x = step
416
+ step_y = step
417
+ self.process_image(step_x, step_y, not self.prevent_crop)
418
+ # Unset cache.
419
+ self._cache = None
420
+ else:
421
+ if self._keyhole_reference is not None and self._keyhole_geometry is None:
422
+ get_keyhole_geometry()
423
+
424
+ # We need to have a thread per image, so we need to provide a node specific thread_name!
425
+ self._update_thread = context.threaded(
426
+ self._process_image_thread, result=clear, daemon=True, thread_name=f"image_update_{self.id}_{str(time.perf_counter())}"
427
+ )
428
+
429
+ def _process_image_thread(self):
430
+ """
431
+ The function deletes the caches and processes the image until it no longer needs updating.
432
+
433
+ @return:
434
+ """
435
+ while self._needs_update:
436
+ self._needs_update = False
437
+ # Calculate scene step_x, step_y values
438
+ step = self._default_units / self.dpi
439
+ step_x = step
440
+ step_y = step
441
+ with self._update_lock:
442
+ self.process_image(step_x, step_y, not self.prevent_crop)
443
+ # Unset cache.
444
+ self._cache = None
445
+
446
+ def process_image(self, step_x=None, step_y=None, crop=True):
447
+ """
448
+ SVG matrices are defined as follows.
449
+ [a c e]
450
+ [b d f]
451
+
452
+ Pil requires a, c, e, b, d, f accordingly.
453
+
454
+ As of 0.7.2 this converts the image to "L" as part of the process.
455
+
456
+ There is a small amount of slop at the edge of converted images sometimes, so it's essential
457
+ to mark the image as inverted if black should be treated as empty pixels. The scaled down image
458
+ not lose the edge pixels since they could be important, but also dim may not be a multiple
459
+ of step level which requires an introduced empty edge pixel to be added.
460
+ """
461
+
462
+ from PIL import Image, ImageDraw
463
+ while self._processing:
464
+ time.sleep(0.05)
465
+
466
+ if step_x is None:
467
+ step_x = self.step_x
468
+ if step_y is None:
469
+ step_y = self.step_y
470
+ # print (f"process called with step_x={step_x}, step_y={step_y} (node: {self.step_x}, {self.step_y})")
471
+ try:
472
+ actualized_matrix, image = self._process_image(step_x, step_y, crop=crop)
473
+ inverted_main_matrix = Matrix(self.matrix).inverse()
474
+ self._actualized_matrix = actualized_matrix
475
+ self._processed_matrix = actualized_matrix * inverted_main_matrix
476
+ self._processed_image = image
477
+ self._process_image_failed = False
478
+ bb = self.bbox()
479
+ self._bounds = bb
480
+ self._paint_bounds = bb
481
+ except Exception as e:
482
+ # Memory error if creating requires too much memory.
483
+ # DecompressionBomb if over 272 megapixels.
484
+ # ValueError if bounds are NaN.
485
+ # ZeroDivide if inverting the processed matrix cannot happen because image is a line
486
+ # print (f"Shit, crashed with {e}")
487
+ self._process_image_failed = True
488
+ self._processing = False
489
+ self.updated()
490
+
491
+ @property
492
+ def opaque_image(self):
493
+ from PIL import Image
494
+ img = self.image
495
+ if img is not None and img.mode == "RGBA":
496
+ r, g, b, a = img.split()
497
+ background = Image.new("RGB", img.size, "white")
498
+ background.paste(img, mask=a)
499
+ img = background
500
+ return img
501
+
502
+ def _convert_image_to_grayscale(self, image):
503
+ # Convert image to L type.
504
+ if image.mode == "I":
505
+ from PIL import Image
506
+ # Load the 32-bit signed grayscale image
507
+ img = np.array(image, dtype=np.int32)
508
+
509
+ # No need to reshape the image to its original dimensions
510
+ # img = img.reshape((image.width, image.height))
511
+
512
+ # Normalize the image to the range 0-255
513
+ img_normalized = ((img - img.min()) / (img.max() - img.min()) * 255).astype(np.uint8)
514
+
515
+ # Convert the NumPy array to a Pillow Image
516
+ img_pil = Image.fromarray(img_normalized)
517
+ image = img_pil.convert("L")
518
+ elif image.mode != "L":
519
+ # Precalculate RGB for L conversion.
520
+ # if self.red is None:
521
+ # self.red = 1
522
+ if self.red is None or self.green is None or self.blue is None:
523
+ r = 1
524
+ g = 1
525
+ b = 1
526
+ else:
527
+ r = self.red * 0.299
528
+ g = self.green * 0.587
529
+ b = self.blue * 0.114
530
+ v = self.lightness
531
+ if v == 0:
532
+ v = 0.000001
533
+ c = r + g + b
534
+ try:
535
+ c /= v
536
+ r = r / c
537
+ g = g / c
538
+ b = b / c
539
+ except ZeroDivisionError:
540
+ pass
541
+ image = image.convert("RGB")
542
+ image = image.convert("L", matrix=(r, g, b, 1.0))
543
+ return image
544
+
545
+ def _get_transparent_mask(self, image):
546
+ """
547
+ Create Transparency Mask.
548
+ @param image:
549
+ @return:
550
+ """
551
+ if image is None:
552
+ return None
553
+ if "transparency" in image.info:
554
+ image = image.convert("RGBA")
555
+ try:
556
+ return image.getchannel("A").point(lambda e: 255 - e)
557
+ except ValueError:
558
+ return None
559
+
560
+ def _apply_mask(self, image, mask, reject_color=None):
561
+ """
562
+ Fill in original image with reject pixels.
563
+
564
+ @param image: Image to be masked off.
565
+ @param mask: Mask to apply to image
566
+ @param reject_color: Optional specified reject color override. Reject is usually "white" or black if inverted.
567
+ @return: image with mask pixels filled in with reject pixels
568
+ """
569
+ if not mask:
570
+ return image
571
+ if reject_color is None:
572
+ reject_color = "black" if self.invert else "white"
573
+ from PIL import Image
574
+
575
+ background = image.copy()
576
+ reject = Image.new("L", image.size, reject_color)
577
+ background.paste(reject, mask=mask)
578
+ return background
579
+
580
+ def _get_crop_box(self, image):
581
+ """
582
+ Get the bbox cutting off the reject edges. The reject edges depend on the image's invert setting.
583
+ @param image: Image to get crop box for.
584
+ @return:
585
+ """
586
+ try:
587
+ if self.invert:
588
+ return image.getbbox()
589
+ else:
590
+ return image.point(lambda e: 255 - e).getbbox()
591
+ except ValueError:
592
+ return None
593
+
594
+ def _process_script(self, image):
595
+ """
596
+ Process actual raster script operations. Any required grayscale, inversion, and masking will already have
597
+ occurred. If there were reject pixels before they will be masked off after this process.
598
+
599
+ @param image: image to process with self.operation script.
600
+
601
+ @return: processed image
602
+ """
603
+ from PIL import ImageEnhance, ImageFilter, ImageOps
604
+
605
+ overall_left = 0
606
+ overall_top = 0
607
+ overall_right, overall_bottom = image.size
608
+ for op in self.operations:
609
+ name = op["name"]
610
+ if name == "resample":
611
+ # This is just a reminder, that while this may still appear in the scripts it is intentionally
612
+ # ignored (or needs to be revised with the upcoming appearance of passthrough) as it is not
613
+ # serving the purpose of the past
614
+ continue
615
+ if name == "crop":
616
+ try:
617
+ # The dimensions of the image could have already be changed,
618
+ # so we recalculate the edges based on the original image size
619
+ if op["enable"] and op["bounds"] is not None:
620
+ crop = op["bounds"]
621
+ left_gap = int(crop[0])
622
+ top_gap = int(crop[1])
623
+ right_gap = self.image.width - int(crop[2])
624
+ bottom_gap = self.image.height - int(crop[3])
625
+
626
+ w, h = image.size
627
+ left = left_gap
628
+ upper = top_gap
629
+ right = image.width - right_gap
630
+ lower = image.height - bottom_gap
631
+
632
+ if left >= w:
633
+ left = w - 1
634
+ if upper >= h:
635
+ upper = h
636
+ if right <= left:
637
+ right = left + 1
638
+ if lower <= upper:
639
+ lower = upper + 1
640
+
641
+ overall_left += left
642
+ overall_top += upper
643
+ overall_right -= w - right
644
+ overall_bottom -= h - lower
645
+ image = image.crop((left, upper, right, lower))
646
+ except KeyError:
647
+ pass
648
+ elif name == "edge_enhance":
649
+ try:
650
+ if op["enable"]:
651
+ if image.mode == "P":
652
+ image = image.convert("L")
653
+ image = image.filter(filter=ImageFilter.EDGE_ENHANCE)
654
+ except KeyError:
655
+ pass
656
+ elif name == "auto_contrast":
657
+ try:
658
+ if op["enable"]:
659
+ if image.mode not in ("RGB", "L"):
660
+ # Auto-contrast raises NotImplementedError if P
661
+ # Auto-contrast raises OSError if not RGB, L.
662
+ image = image.convert("L")
663
+ image = ImageOps.autocontrast(image, cutoff=op["cutoff"])
664
+ except KeyError:
665
+ pass
666
+ elif name == "tone":
667
+ try:
668
+ if op["enable"] and op["values"] is not None and image.mode == "L":
669
+ image = image.convert("P")
670
+ tone_values = op["values"]
671
+ if op["type"] == "spline":
672
+ spline = ImageNode.spline(tone_values)
673
+ else:
674
+ tone_values = [q for q in tone_values if q is not None]
675
+ spline = ImageNode.line(tone_values)
676
+ if len(spline) < 256:
677
+ spline.extend([255] * (256 - len(spline)))
678
+ if len(spline) > 256:
679
+ spline = spline[:256]
680
+ image = image.point(spline)
681
+ if image.mode != "L":
682
+ image = image.convert("L")
683
+ except KeyError:
684
+ pass
685
+ elif name == "contrast":
686
+ try:
687
+ if op["enable"] and (op["contrast"] is not None and op["brightness"] is not None):
688
+ contrast = ImageEnhance.Contrast(image)
689
+ c = (op["contrast"] + 128.0) / 128.0
690
+ image = contrast.enhance(c)
691
+
692
+ brightness = ImageEnhance.Brightness(image)
693
+ b = (op["brightness"] + 128.0) / 128.0
694
+ image = brightness.enhance(b)
695
+ except KeyError:
696
+ pass
697
+ elif name == "gamma":
698
+ try:
699
+ if op["enable"] and op["factor"] is not None:
700
+ if image.mode == "L":
701
+ gamma_factor = float(op["factor"])
702
+
703
+ def crimp(px):
704
+ px = int(round(px))
705
+ if px < 0:
706
+ return 0
707
+ if px > 255:
708
+ return 255
709
+ return px
710
+
711
+ if gamma_factor == 0:
712
+ gamma_lut = [0] * 256
713
+ else:
714
+ gamma_lut = [
715
+ crimp(pow(i / 255, (1.0 / gamma_factor)) * 255)
716
+ for i in range(256)
717
+ ]
718
+ image = image.point(gamma_lut)
719
+ if image.mode != "L":
720
+ image = image.convert("L")
721
+ except KeyError:
722
+ pass
723
+ elif name == "unsharp_mask":
724
+ try:
725
+ if (
726
+ op["enable"]
727
+ and op["percent"] is not None
728
+ and op["radius"] is not None
729
+ and op["threshold"] is not None
730
+ ):
731
+ unsharp = ImageFilter.UnsharpMask(
732
+ radius=op["radius"],
733
+ percent=op["percent"],
734
+ threshold=op["threshold"],
735
+ )
736
+ image = image.filter(unsharp)
737
+ except (KeyError, ValueError): # Value error if wrong type of image.
738
+ pass
739
+ elif name == "halftone":
740
+ try:
741
+ if op["enable"]:
742
+ image = RasterScripts.halftone(
743
+ image,
744
+ sample=op["sample"],
745
+ angle=op["angle"],
746
+ oversample=op["oversample"],
747
+ black=op["black"],
748
+ )
749
+ except KeyError:
750
+ pass
751
+ elif name == "dither":
752
+ # Set dither
753
+ try:
754
+ if op["enable"] and op["type"] is not None:
755
+ self.dither_type = op["type"]
756
+ self.dither = True
757
+ self.is_depthmap = False
758
+ else:
759
+ # Takes precedence
760
+ self.dither = False
761
+ # image = self._apply_dither(image)
762
+ except KeyError:
763
+ pass
764
+ else:
765
+ # print(f"Unknown operation in raster-script: {name}")
766
+ continue
767
+ return image, (overall_left, overall_top, overall_right, overall_bottom)
768
+
769
+ def _apply_dither(self, image):
770
+ """
771
+ Dither image to 1 bit. Floyd-Steinberg is performed by Pillow, other dithers require custom code.
772
+
773
+ @param image: grayscale image to dither.
774
+ @return: 1 bit dithered image
775
+ """
776
+ from meerk40t.image.imagetools import dither
777
+
778
+ if self.dither and self.dither_type is not None:
779
+ if self.dither_type != "Floyd-Steinberg":
780
+ image = dither(image, self.dither_type)
781
+ if image.mode != "1":
782
+ image = image.convert("1")
783
+ self.is_depthmap = False
784
+ return image
785
+
786
+ def _process_image(self, step_x, step_y, crop=True):
787
+ """
788
+ This core code replaces the older actualize and rasterwizard functionalities. It should convert the image to
789
+ a post-processed form with resulting post-process matrix.
790
+
791
+ @param crop: Should the unneeded edges be cropped as part of this process. The need for the edge is determined
792
+ by the color and the state of the self.invert attribute.
793
+ @return:
794
+ """
795
+ from PIL import Image, ImageOps
796
+
797
+ try:
798
+ from PIL.Image import Transform
799
+
800
+ AFFINE = Transform.AFFINE
801
+ except ImportError:
802
+ AFFINE = Image.AFFINE
803
+
804
+ try:
805
+ from PIL.Image import Resampling
806
+
807
+ BICUBIC = Resampling.BICUBIC
808
+ except ImportError:
809
+ BICUBIC = Image.BICUBIC
810
+ self._processing = True
811
+ image = self.image
812
+
813
+ transparent_mask = self._get_transparent_mask(image)
814
+ opaque = self.opaque_image
815
+ image = self._convert_image_to_grayscale(opaque)
816
+
817
+ image = self._apply_mask(image, transparent_mask)
818
+
819
+ # Calculate image box.
820
+ box = None
821
+ if crop:
822
+ box = self._get_crop_box(image)
823
+ if box is None:
824
+ # If box is entirely white, bbox caused value error, or crop not set.
825
+ box = (0, 0, image.width, image.height)
826
+ orgbox = (box[0], box[1], box[2], box[3])
827
+
828
+ transform_matrix = copy(self.matrix) # Prevent Knock-on effect.
829
+
830
+ # Find the boundary points of the rotated box edges.
831
+ boundary_points = [
832
+ transform_matrix.point_in_matrix_space([box[0], box[1]]), # Top-left
833
+ transform_matrix.point_in_matrix_space([box[2], box[1]]), # Top-right
834
+ transform_matrix.point_in_matrix_space([box[0], box[3]]), # Bottom-left
835
+ transform_matrix.point_in_matrix_space([box[2], box[3]]), # Bottom-right
836
+ ]
837
+ xs = [e[0] for e in boundary_points]
838
+ ys = [e[1] for e in boundary_points]
839
+
840
+ # bbox here is expanded matrix size of box.
841
+ step_scale_x = 1 / float(step_x)
842
+ step_scale_y = 1 / float(step_y)
843
+
844
+ bbox = min(xs), min(ys), max(xs), max(ys)
845
+
846
+ image_width = ceil(bbox[2] * step_scale_x) - floor(bbox[0] * step_scale_x)
847
+ image_height = ceil(bbox[3] * step_scale_y) - floor(bbox[1] * step_scale_y)
848
+ tx = bbox[0]
849
+ ty = bbox[1]
850
+ # Caveat: we move the picture backward, so that the non-white
851
+ # image content aligns at 0 , 0 - but we don't crop the image
852
+ transform_matrix.post_translate(-tx, -ty)
853
+ transform_matrix.post_scale(step_scale_x, step_scale_y)
854
+ if step_y < 0:
855
+ # If step_y is negative, translate
856
+ transform_matrix.post_translate(0, image_height)
857
+ if step_x < 0:
858
+ # If step_x is negative, translate
859
+ transform_matrix.post_translate(image_width, 0)
860
+
861
+ try:
862
+ transform_matrix.inverse()
863
+ except ZeroDivisionError:
864
+ # malformed matrix, scale=0 or something.
865
+ transform_matrix.reset()
866
+
867
+ # Perform image transform if needed.
868
+ if (
869
+ self.matrix.a != step_x
870
+ or self.matrix.b != 0.0
871
+ or self.matrix.c != 0.0
872
+ or self.matrix.d != step_y
873
+ ):
874
+ # print (f"another transform called while {image.width}x{image.height} - requested: {image_width}x{image_height}")
875
+ if image_height <= 0:
876
+ image_height = 1
877
+ if image_width <= 0:
878
+ image_width = 1
879
+ image = image.transform(
880
+ (image_width, image_height),
881
+ AFFINE,
882
+ (
883
+ transform_matrix.a,
884
+ transform_matrix.c,
885
+ transform_matrix.e,
886
+ transform_matrix.b,
887
+ transform_matrix.d,
888
+ transform_matrix.f,
889
+ ),
890
+ resample=BICUBIC,
891
+ fillcolor="black" if self.invert else "white",
892
+ )
893
+ # print (f"after transform {image.width}x{image.height}")
894
+ actualized_matrix = Matrix()
895
+
896
+ if step_y < 0:
897
+ # if step_y is negative, translate.
898
+ actualized_matrix.post_translate(0, -image_height)
899
+ if step_x < 0:
900
+ # if step_x is negative, translate.
901
+ actualized_matrix.post_translate(-image_width, 0)
902
+
903
+ # If crop applies, apply crop.
904
+ if crop:
905
+ cbox = self._get_crop_box(image)
906
+ if cbox is not None:
907
+ width = cbox[2] - cbox[0]
908
+ height = cbox[3] - cbox[1]
909
+ if width != image.width or height != image.height:
910
+ image = image.crop(cbox)
911
+ # TODO:
912
+ # We did not crop the image so far, but we already applied
913
+ # the cropped transformation! That may be faulty, and needs to
914
+ # be corrected at a later stage, but this logic, even if clumsy
915
+ # is good enough: don't shift things twice!
916
+ if orgbox[0] == 0 and orgbox[1] == 0:
917
+ actualized_matrix.post_translate(cbox[0], cbox[1])
918
+
919
+ actualized_matrix.post_scale(step_x, step_y)
920
+ actualized_matrix.post_translate(tx, ty)
921
+
922
+ # Invert black to white if needed.
923
+ if self.invert:
924
+ try:
925
+ image = ImageOps.invert(image)
926
+ except OSError as e:
927
+ print (f"Image inversion crashed: {e}\nMode: {image.mode}, {image.width}x{image.height} pixel")
928
+
929
+ # Find rejection mask of white pixels. (already inverted)
930
+ reject_mask = image.point(lambda e: 0 if e == 255 else 255)
931
+ image, newbounds = self._process_script(image)
932
+ # This may have again changed the size of the image (op crop)
933
+ # so we need to adjust the reject mask...
934
+ reject_mask = reject_mask.crop(newbounds)
935
+
936
+ background = Image.new("L", image.size, "white")
937
+ background.paste(image, mask=reject_mask)
938
+ image = background
939
+
940
+ image = self._apply_dither(image)
941
+
942
+ self._processing = False
943
+ return actualized_matrix, image
944
+
945
+ def _apply_keyhole(self):
946
+ from PIL import Image, ImageDraw
947
+
948
+ image = self._processed_image
949
+ if image is None:
950
+ image = self.image
951
+ if self._keyhole_geometry is not None:
952
+ # Let's check whether the keyhole dimensions match
953
+ if self._keyhole_image is not None and (self._keyhole_image.width != image.width or self._keyhole_image.height != image.height):
954
+ self._keyhole_image = None
955
+ if self._keyhole_image is None:
956
+ actualized_matrix = self._actualized_matrix
957
+ # We can't render something with the usual suspects ie laserrender.render
958
+ # as we do not have access to wxpython on the command line, so we stick
959
+ # to the polygon method of ImageDraw instead
960
+ maskimage = Image.new("L", image.size, "black")
961
+ draw = ImageDraw.Draw(maskimage)
962
+ inverted_main_matrix = Matrix(self.matrix).inverse()
963
+ matrix = actualized_matrix * inverted_main_matrix * self.matrix
964
+
965
+ x0, y0 = matrix.point_in_matrix_space((0, 0))
966
+ x2, y2 = matrix.point_in_matrix_space((image.width, image.height))
967
+ # print (x0, y0, x2, y2)
968
+ # Let's simplify things, if we don't have any overlap then the image is white...
969
+ i_wd = x2 - x0
970
+ i_ht = y2 - y0
971
+ gidx = 0
972
+ for geom in self._keyhole_geometry.as_subpaths():
973
+ # Let's simplify things, if we don't have any overlap then we don't need to do something
974
+ # if x0 > bounds[2] or x2 < bounds [0] or y0 > bounds[3] or y2 < bounds[1]:
975
+ # continue
976
+ geom_points = list(geom.as_interpolated_points(int(UNITS_PER_MM/10)))
977
+ points = list()
978
+ for pt in geom_points:
979
+ if pt is None:
980
+ continue
981
+ gx = pt.real
982
+ gy = pt.imag
983
+ x = int(maskimage.width * (gx - x0) / i_wd )
984
+ y = int(maskimage.height * (gy - y0) / i_ht )
985
+ points.append( (x, y) )
986
+
987
+ # print (points)
988
+ draw.polygon( points, fill="white", outline="white")
989
+ self._keyhole_image = maskimage
990
+ # For debug purposes...
991
+ # maskimage.save("C:\\temp\\maskimage.png")
992
+
993
+ background = Image.new("L", image.size, "white")
994
+ background.paste(image, mask=self._keyhole_image)
995
+ image = background
996
+ return image
997
+
998
+ @staticmethod
999
+ def line(p):
1000
+ N = len(p) - 1
1001
+ try:
1002
+ m = [(p[i + 1][1] - p[i][1]) / (p[i + 1][0] - p[i][0]) for i in range(0, N)]
1003
+ except ZeroDivisionError:
1004
+ m = [1] * N
1005
+ # b = y - mx
1006
+ b = [p[i][1] - (m[i] * p[i][0]) for i in range(N)]
1007
+ r = list()
1008
+ for i in range(p[0][0]):
1009
+ r.append(0)
1010
+ for i in range(len(p) - 1):
1011
+ x0 = p[i][0]
1012
+ x1 = p[i + 1][0]
1013
+ range_list = [int(round((m[i] * x) + b[i])) for x in range(x0, x1)]
1014
+ r.extend(range_list)
1015
+ for i in range(p[-1][0], 256):
1016
+ r.append(255)
1017
+ r.append(round(int(p[-1][1])))
1018
+ return r
1019
+
1020
+ @staticmethod
1021
+ def spline(p):
1022
+ """
1023
+ Spline interpreter.
1024
+
1025
+ Returns all integer locations between different spline interpolation values
1026
+ @param p: points to be quad spline interpolated.
1027
+ @return: integer y values for given spline points.
1028
+ """
1029
+ try:
1030
+ N = len(p) - 1
1031
+ w = [(p[i + 1][0] - p[i][0]) for i in range(N)]
1032
+ h = [(p[i + 1][1] - p[i][1]) / w[i] for i in range(N)]
1033
+ ftt = (
1034
+ [0]
1035
+ + [3 * (h[i + 1] - h[i]) / (w[i + 1] + w[i]) for i in range(N - 1)]
1036
+ + [0]
1037
+ )
1038
+ A = [(ftt[i + 1] - ftt[i]) / (6 * w[i]) for i in range(N)]
1039
+ B = [ftt[i] / 2 for i in range(N)]
1040
+ C = [h[i] - w[i] * (ftt[i + 1] + 2 * ftt[i]) / 6 for i in range(N)]
1041
+ D = [p[i][1] for i in range(N)]
1042
+ except ZeroDivisionError:
1043
+ return list(range(256))
1044
+ r = list()
1045
+ for i in range(p[0][0]):
1046
+ r.append(0)
1047
+ for i in range(len(p) - 1):
1048
+ a = p[i][0]
1049
+ b = p[i + 1][0]
1050
+ r.extend(
1051
+ int(
1052
+ round(
1053
+ A[i] * (x - a) ** 3
1054
+ + B[i] * (x - a) ** 2
1055
+ + C[i] * (x - a)
1056
+ + D[i]
1057
+ )
1058
+ )
1059
+ for x in range(a, b)
1060
+ )
1061
+ for i in range(p[-1][0], 256):
1062
+ r.append(255)
1063
+ r.append(round(int(p[-1][1])))
1064
+ return r
1065
+
1066
+ def as_path(self):
1067
+ image_width, image_height = self.active_image.size
1068
+ matrix = self.active_matrix
1069
+ x0, y0 = matrix.point_in_matrix_space((0, 0))
1070
+ x1, y1 = matrix.point_in_matrix_space((0, image_height))
1071
+ x2, y2 = matrix.point_in_matrix_space((image_width, image_height))
1072
+ x3, y3 = matrix.point_in_matrix_space((image_width, 0))
1073
+ return abs(Path(Polygon((x0, y0), (x1, y1), (x2, y2), (x3, y3), (x0, y0))))
1074
+
1075
+ def translated(self, dx, dy, interim=False):
1076
+ self._cache = None
1077
+ self._keyhole_image = None
1078
+ if self._actualized_matrix is not None:
1079
+ self._actualized_matrix.post_translate(dx, dy)
1080
+ if self._convex_hull is not None:
1081
+ self._convex_hull.translate(dx, dy)
1082
+ return super().translated(dx, dy)