Wickedlasers / laserdocklib

client library to connect to laserdock
GNU Lesser General Public License v3.0
28 stars 8 forks source link

Additional documentation #5

Open MrBlenny opened 6 years ago

MrBlenny commented 6 years ago

Hey,

I've got an inclination to build a HTML5 canvas -> laser dock converter. This would be a chrome extension which find the canvas on a webpage, load some simple game-specific config and start sampling it and converting the canvas shapes/paths to the laserdock format. This would allow for a variety of simple web based games to be played, for example:

Is there additional documentation?

My current thinking:

  1. Chrome extension modifies how the html5 canvas is rendered, removing background textures, changing shapes to outlines etc. Client side js is specific to each game and liable to break.
  2. toDataURL is used to convert canvas to an image
  3. Images are converted to svg using something like imagetracerjs
  4. Svgs are then sent to a python process to be encoded using svg2ild

I have not used these libs before so performance will be questionable. I suspect the bottleneck will be vectorising the rasters - this could be multi-threaded in node if need be. Does laserdocklib bring anything to the table here?

gavrushkin commented 6 years ago

David, please check another library, it has more high-level classes: https://github.com/Wickedlasers/libLaserdockCore

Using JS for image conversion in realtime looks not very cool for real-time conversion. For your task it would be better to use OpenCV - get contours from image and convert them to laserdock points directly.

Instead of: html -> image -> svg -> ild -> laserdock

You'll get html -> image -> opencv contours conversion -> laserdock

Disadvantage is that you need to have OpenCV installed - I don't know if Chrome extension allows it.

MrBlenny commented 6 years ago

Has the opencv contour -> laserdock conversion been done before? Can you outline the difference between the ild and laserdock formats?

PS: OpenCV can be installed as part of an electron app which is a good alternative to a chrome extension.

gavrushkin commented 6 years ago

1) Yes, it is used in laserdock app

2) We use liblzr library for ILD file parsing and openlase library for image generation/optimisation. I meant this conversion. https://github.com/brendan-w/lzr/blob/master/liblzr/liblzr.hpp https://github.com/marcan/openlase/blob/master/libol/libol.c