Cross-platform Graphics Package recommendation (mid 2023)

Is there any documented cross-platform graphics package that is recommended these days?

By cross-platform I mean all Apple platforms and Linux, potentially Windows, not just a variety of Apple sub-platforms.

By graphics package I mean a package (or a collection of packages) with the following functionality:

  • graphic context
  • bezier paths
  • at least some basic text
  • reading/writing of at least one of the common bitmap image formats
  • reading/writing of SVG or some other vector format

I am not looking for a UI library, I am looking for headless graphics.

I did a brief research on the Swift Package Index and what I found were packages claiming to be cross-platform, but in fact they were cross-Apple-subplatform or wrappers around existing Apple frameworks.

Any recommendations?

1 Like

You mean those using Swift API (to make this semi on topic)? I doubt anything like this exists that also works on Linux and/or Windows.

Yes, using Swift API.

It might be a Swift wrapper around a C/C++ library that is included within the package, not requiring an external installation dependency, and that will be build together with the package.

Reason against an external installation dependency: I would like the installation of an open-source package+tool to be as easy as possible for the users. Preferably just download + swift build → ready to use.

Take a look at this Swift Package, which use Anti-Grain Geometry(AGG) C++ rendering library.

2 Likes

Does something like this meet your requirements : GitHub - migueldeicaza/SkiaKit: Swift Bindings to the Skia 2D graphics Library ?

2 Likes

Then consider the API notes approach. This is how CoreGraphics C api is exposed to Swift in a nice swift form. A fragment:

# CGBitmapContext
- Name: CGBitmapContextCreateWithData
  SwiftName: CGContext.init(data:width:height:bitsPerComponent:bytesPerRow:space:bitmapInfo:releaseCallback:releaseInfo:)
- Name: CGBitmapContextCreate
  SwiftName: CGContext.init(data:width:height:bitsPerComponent:bytesPerRow:space:bitmapInfo:)
- Name: CGBitmapContextGetData
  SwiftName: getter:CGContext.data(self:)
- Name: CGBitmapContextGetWidth
  SwiftName: getter:CGContext.width(self:)
...
- Name: CGContextGetInterpolationQuality
  SwiftName: getter:CGContext.interpolationQuality(self:)
- Name: CGContextSetInterpolationQuality
  SwiftName: setter:CGContext.interpolationQuality(self:_:)

A couple more come to mind:

  • SwiftGTK: a full set of auto-generated Swift bindings for gtk-3 or gtk-4 that attempts to provide a more swifty wrapper around the GTK APIs (including the underlying layers such as Glib and Cairo-graphics,
  • Tokamak: a cross-platform, open-source SwiftUI-compatible framework that works natively (with using GTK on Linux) as well as in the browser (using WASM),
  • Swift Cross UI: another SwiftUI-like framework for creating cross-platform apps in Swift, using Gtk 4 as the backend
2 Likes

Just announced?

2 Likes

Thank you, this one looks promising. Will check it out.

Thanks, I might consider it when I will be building an interactive UI application.

This does not look like not what I was looking for. This is an UI library focusing on displaying the graphical output. I am looking to produce a graphical artefacts – raw image data or files to be stored/shared – without displaying them in my application ("headless").

1 Like

Thank you, nice selection of UI frameworks.

Similar to Meta's IGL mentioned in this thread, I might consider it when I will be building an interactive UI application, which is not the case for this particular project/phase of the project.

Moreover, they all require separate installation of a third-party library, which I still would like to avoid and have just one-stop "swift build" and/or "swift run" for the package I am creating.

I'll throw in swift-webgpu as well, though it sounds like you are looking for something more high-level.

for image loading you can try swift-png, it is written in pure swift and doesn’t wrap any system frameworks.

4 Likes