Potrace to xTalk wrapper

Organizing tasks to work on, New Features Ideas, Building LCS & LCB Libraries & Widgets, Redecorating and Modifying the IDE, Hacking / Editing Tools, Compiling the Engine from Source, etc.
Post Reply
xAction
Posts: 285
Joined: Thu Sep 16, 2021 1:40 pm
Contact:

Potrace to xTalk wrapper

Post by xAction »

ChatGPT
To create a simple wrapper for the Potrace C library to interface with the Livecode IDE using Livecode Builder language, you'll need to follow these step-by-step instructions:
  1. Install Potrace:
    Make sure you have Potrace installed on your system. You can download it from the Potrace website and follow the installation instructions provided.
  2. Understand Builder:
    Familiarize yourself with Builder (LCB), which is the language used for extending Livecode's capabilities. You can find documentation and tutorials on Livecode's website. sigh
  3. Create a New Stack:
    Open IDE and create a new Stack, save as Potrace_Project or some other meaningful label.
  4. Create a Livecode Builder Script:
    In your Livecode project, create a new Livecode Builder script file (.lcb).
  5. Include Potrace Library:
    In your Livecode Builder script, include the Potrace library by specifying its location and necessary header files.
  6. Write Wrapper Functions:
    Write wrapper functions in Livecode Builder that map to the functionalities provided by Potrace. These functions should call the corresponding functions in the Potrace library.
  7. Compile the Livecode Builder Script:
    Compile the Livecode Builder script to ensure there are no syntax errors.
  8. Test the Wrapper Functions:
    Write test cases in Livecode IDE to test the wrapper functions. Make sure they produce the expected results.
  9. Handle Errors and Exceptions:
    Implement error handling in your Livecode Builder wrapper functions to handle potential errors gracefully.
  10. Document Your Wrapper:
    Document your wrapper functions thoroughly, including parameters, return types, and any potential side effects.
  11. Package Your Extension:
    Package your Livecode Builder script along with any necessary files (such as the Potrace library) into a distributable package.
  12. Distribute or Use Your Extension:
    Share your Livecode Builder extension with others or use it in your own Livecode projects as needed.
Here's a basic example of what your Livecode Builder script might look like:
// Wrapper for Potrace Library

// Include Potrace Library
// Note: This is just a placeholder, replace it with actual inclusion code foreign handler potrace_includeLib

// Wrapper Function to Trace Bitmap
function traceBitmap pBitmapPath, pOptions
// Call Potrace function to trace bitmap
// Note: Replace the function call with the actual Potrace function call
return foreign handler potrace_traceBitmap pBitmapPath, pOptions
end traceBitmap
Replace potrace_includeLib and potrace_traceBitmap with actual function names and include statements as per your Potrace library integration.

This is a simplified guide to get you started. Depending on the complexity of Potrace and the requirements of your project, you may need to adjust and expand these steps accordingly.
Just leaving this here, will try to fill in the blanks later.
User avatar
OpenXTalkPaul
Posts: 1574
Joined: Sat Sep 11, 2021 4:19 pm
Contact:

Re: Potrace to xTalk wrapper

Post by OpenXTalkPaul »

I gave it a quick look see.
There's both a command-line version and as a code library (which we can wrap).

Here's the API doc:
https://potrace.sourceforge.net/potracelib.pdf

It has a parameter called 'turdsize' :lol:
xAction
Posts: 285
Joined: Thu Sep 16, 2021 1:40 pm
Contact:

Re: Potrace to xTalk wrapper

Post by xAction »

Yeah using the command line version seems like the optimal option, but I'll never learn Builder without some small useful thing to adapt. Today Potrace, tomorrow Blender.

About:
Include Potrace Library:
In your Livecode Builder script, include the Potrace library by specifying its location and necessary header files.
How do i identify the library, is it just all the files in the 'src' folder?

ChatGPT
Identifying the necessary files from the Potrace library depends on how you obtained it and the structure of the distribution. Typically, when you download Potrace, you'll find the source code, which includes header files (.h) and source files (.c), along with any necessary build scripts or configuration files.

In the case of Potrace, the src folder often contains the source files (.c) and header files (.h) necessary to build the library. Here's what you can do to identify the required files:
  1. Explore the Potrace Source Distribution: Open the Potrace source distribution folder and navigate through its contents. Look for files with extensions .h and .c, which are likely the header files and source files, respectively.
  2. Check for Build Instructions: Potrace might include instructions on how to build the library for your system. These instructions often specify which files are essential for building the library and how to compile them.
  3. Identify Core Functionality Files: Potrace is a relatively small library, so you can usually identify the core functionality files by their names. Look for files that contain the main algorithms and functionalities provided by Potrace.
  4. Ensure Compatibility: Make sure the Potrace version you're using is compatible with your platform and intended use. Check the documentation or any accompanying README files for specific instructions or compatibility notes.
Once you've identified the necessary files, you'll typically include them in your Livecode Builder script by specifying their paths or by directly including their contents if your Livecode environment allows it. Here's a basic example of how you might include a C header file in Livecode Builder:
// Include Potrace Header File
foreign handler potrace_includeHeader pHeaderPath

// Include Potrace Library
on potrace_includeLib
put "/path/to/potrace.h" into tHeaderPath
potrace_includeHeader tHeaderPath
end potrace_includeLib
Replace "/path/to/potrace.h" with the actual path to the Potrace header file in your system. Repeat this process for any additional header files or source files required by Potrace. Remember to adjust paths and filenames according to your specific setup.

If Potrace requires additional dependencies or configuration, make sure to handle those as well during the integration process.

This hilights something: have to download the libraries for all platforms you want your thing to work on!
User avatar
OpenXTalkPaul
Posts: 1574
Joined: Sat Sep 11, 2021 4:19 pm
Contact:

Re: Potrace to xTalk wrapper

Post by OpenXTalkPaul »

How do i identify the library, is it just all the files in the 'src' folder?
!
I usually look for a version called libWhatever.dll (.dynlib, .so) on 'whatever's website, or see if it turns up in a package manager, or google search something like 'whatever' + dynamic library and see what turns up. SO if it's CURL for example, I would search for libcurl, sometimes it doesn't follow that pattern, for example 'HIDAPI' (as opposed to libHID) or 'GIFLib'.

This hilights something: have to download the libraries for all platforms you want your thing to work on
Correct, binary version of libWhatever library that you want to wrap for each and every platform that you want to support should go into 'Code' folder in your extension builder project, each in their own subfolders labeled by platform+architecture. Then the appropriate one gets loaded by the engine or is included with a standalone build that uses it. Some libraries have dependencies on other libraries too, so those can be included to ensure they're available at runtime.

If it's a library that you're certain will be available as part of the OS (like for example curl on macOS and most Linux) then you don't need to include a the binary, it will (hopefully ) find and load that library from the normal OS libraries.

On macOS or Linux there's 'DLOpen' which we could actually wrap with FFI and then script the loading of libraries!

The FluidSynth wrapper supports all three desktop OS and Android, it also includes dependency libraries for things like reading .ogg files and Glib (FluidSynth creates its own threads).

I agree that its a good idea to start with a small simple library that's going to be useful to you to keep your motivation up.
Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests