Bitmap to Vector +Trace

A forum to share your demonstrations stacks, fun stacks, games, etc.
Post Reply
xAction
Posts: 285
Joined: Thu Sep 16, 2021 1:40 pm
Contact:

Bitmap to Vector +Trace

Post by xAction »

BitmapVectorTracer.livecode
(449.34 KiB) Downloaded 6 times
16x16Import011a10a02a.gif
16x16Import011a10a02a.gif (153.99 KiB) Viewed 276 times
You can doodle, convert to vector grid, and trace.

I started with the doodle thing but realized I didn't want highly grid-ified content for 3D extrusion, so spent many hours trying to figure out how to remove the extra griding, with no solution.

Then I found Bern Niggeman's trace alpha stack and adjusted it to make white the alpha so I could trace anything I doodled.
Then I figured I have all this data over in the BitFontMaker2-Like, I'll get that into this app and make sure the importer works.
So ...I exported all that data as images and imported it in this app and covered it to vector grids and tracings
Then I remembered I had all that data over there in the first place and binary compressed, doh!

And now Feel kind of silly because I know there's an SVG version of this same process , isn't there?

oh the command Prop.AutoBuildHistory
isn't actually exposed to the interface because I was importing thousands of files and didn't want someone else doing that until I get things working, but it's pretty safe on thousands of files, so let 'er rip.
OH oh!

Be sure you have your grid size right before import, I had mine set to 32x32 for thouasnds of files and that was way more data density than I wanted. Not reall sure what the use of those grids are, I wanted a cleaner coversion but always got mangled graphics....and special effects...

When I started out with this I had a whole bunch of crazy mistakes that did really cool "video effects' on the data. A bunch of the scripts are still in the stack. Have to figure out how to make them fit somewhere. They'd be neat to trigger in a game with like blasting things to bits...literally.

Well I'm tired and this has been some distraction.
Oh yeah, 2292 of files:
atlas4.png
atlas4.png (30.78 KiB) Viewed 273 times
While I was waiting for that to generate from the stored data, i found this 1-bit pack from Kenney
User avatar
richmond62
Posts: 2776
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: Bitmap to Vector +Trace

Post by richmond62 »

I wonder if Potrace (Open Source) cannot be rolled into OXT?

I do believe that is what is behind the f*cking wonderful bitmap to vector 'thing' in Inkscape, which I use quite a lot:

https://inkscape.org/

Come to think of things; that's the only thing I use Inkscape for. :D

https://potrace.sourceforge.net/

Mind you "precompiled distributions" is a load of old cack, as what you get is a load of files in a folder, and instructions on how to build the thing which are far from 'intuitive'. So: I'll stick with Inkscape.

AND 2019 is slightly 'old hat'.

Being my usual warped self, when I heard of 'Potrace' I analysed the name as Pot + Race and imagined a load of people with their brains addled with weed running a marathon. 8-)
https://richmondmathewson.owlstown.net/
xAction
Posts: 285
Joined: Thu Sep 16, 2021 1:40 pm
Contact:

Re: Bitmap to Vector +Trace

Post by xAction »

Well it is GPL and just requires it to be installed, then flagged at compile time.
How to access it via script is another story. And since there's no Windows build of OpenXTalk to the point is entirely moot.

But if you want to get started here's a high level guide on how to do it:
Creating a language wrapper to integrate the Potrace library with Livecode via Livecode Builder language
  • ]Understand the Potrace Library: The Potrace library provides core functionality for tracing bitmaps1. You need to understand the functions provided by this library and how they can be used.
  • Create C Wrappers: If the Potrace library is written in C or C++, you may need to create C wrappers for the functions you want to use2. This involves writing C functions that internally call the Potrace functions and expose a C-compatible API.
  • Integrate with Livecode Builder: Livecode Builder allows you to create extensions for Livecode. You’ll need to write Livecode Builder code that calls your C wrapper functions. This will likely involve using Livecode Builder’s foreign function interface (FFI), which allows it to call C functions in external libraries.
  • Compile and Link: Once you’ve written your C wrappers and Livecode Builder code, you’ll need to compile them and link against the Potrace library. This will create a Livecode extension that can be loaded into Livecode projects.
  • Test Your Extension: Finally, create a test Livecode project that uses your new extension. Call the Potrace functions through the extension and verify that they work correctly.
Please note that this is a high-level guide and the exact steps may vary depending on the specifics of the Potrace library and Livecode Builder. You may also need to consult the documentation for both Potrace and Livecode Builder to understand how to use them effectively.

Remember, when integrating libraries written in different languages, it’s important to understand how data types are represented and passed between languages3
This process, known as marshalling, can be complex but is crucial for the correct operation of your wrapper3.
.
Or ...just copy/paste someone else's code, change the bits you need to change, boop, done. xTalk style

Can't believe it's been 14 years since I last used Potrace and 3 yeas since I last opened Inkscape. Time flies.
User avatar
OpenXTalkPaul
Posts: 1574
Joined: Sat Sep 11, 2021 4:19 pm
Contact:

Re: Bitmap to Vector +Trace

Post by OpenXTalkPaul »

Nice! Thanks for sharing!

If there's a command line build of this library then you could use that from shell() or using 'open process'.
If it's a C/C++ library then I'm sure that could be wrapped with Extension Builder FFI bindings to use it from script.
I'm not sure how that could be useful without also including some path editing with handles and Bezier control for curved path editing too. Extension Builder's Widget canvas (libSkia) does have sub-pixel rendering capabilities so it could be capable of building such a thing (lot of work), the exact same library is used in many web browsers to render SVGs.
xAction
Posts: 285
Joined: Thu Sep 16, 2021 1:40 pm
Contact:

Re: Bitmap to Vector +Trace

Post by xAction »

Certainaly could roll potrace and mkbitmap in as 'externals' if I knew how, it's just a tiny c library.
Maybe a useful tutorial example.

The goal here was to simply be able to draw bitmaps in engine and convert to graphics for graphics based things like games.

I started out just wanting a little animated guy to move around, but things quickly escalated into building a whole universe of graphics.

Then I realized when i grabbed the trace alpha stack from Bern Niggeman that his code could actually be used
as the method described in the path finding thread.

Essentially:
  1. identify direction to target
  2. lock screen
  3. isolate list of blocking objects
  4. reproduce blocking objects as a 'mask" of solid black (or whatever your chosen color of mask is)
  5. add an outline buffer amount to the line size (so that your game objects don't slide along the walls like blind mice)
  6. convert mask to imageData
  7. Trace imagedata to a point list
  8. use that point list to get to the target without bumping into or sliding along walls
The image can be shrunk to make the trace faster, you only need enough detail to get the job done.

Oh boy this script needs some work:
65355 points
tooManyPoints.png
tooManyPoints.png (6.39 KiB) Viewed 239 times
User avatar
OpenXTalkPaul
Posts: 1574
Joined: Sat Sep 11, 2021 4:19 pm
Contact:

Re: Bitmap to Vector +Trace

Post by OpenXTalkPaul »

There are several ports of Potrace to other scripting languages.
Here's a javascript version, which could probably be made to work inside a Browser Widget, and could definitely be used from the Emscripten Engine or HyperSim running inside a web browser (or html/js based app engine such as Electron)
https://github.com/kilobtye/potrace

Swift version:
https://github.com/pcolton/potrace
xAction
Posts: 285
Joined: Thu Sep 16, 2021 1:40 pm
Contact:

Re: Bitmap to Vector +Trace

Post by xAction »

I was easily able to reduce the points and time it takes to make them by shrinking the trace image, which was still a bit of delay at 64x64 pixels. Once resized I've been trying to get a little something to follow the path to the target which was working okay, then I moved everything to the stack script and I'm suddenly I'm getting "Does not have this property" on something I can clearly see the property on.

Tomorrows another day.
Post Reply

Who is online

Users browsing this forum: No registered users and 22 guests