Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/edadma/libpng
Scala Native bingins for libpng
https://github.com/edadma/libpng
Last synced: 2 months ago
JSON representation
Scala Native bingins for libpng
- Host: GitHub
- URL: https://github.com/edadma/libpng
- Owner: edadma
- License: isc
- Created: 2021-09-05T15:08:52.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-09-07T11:16:59.000Z (over 3 years ago)
- Last Synced: 2024-04-22T13:32:55.789Z (9 months ago)
- Language: C
- Size: 836 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-scala-native - libpng - Bindings for the [libpng](http://www.libpng.org/) C reference library for reading and writing PNGs. (Bindings)
README
libpng
======![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/edadma/libpng?include_prereleases) ![GitHub (Pre-)Release Date](https://img.shields.io/github/release-date-pre/edadma/libpng) ![GitHub last commit](https://img.shields.io/github/last-commit/edadma/libpng) ![GitHub](https://img.shields.io/github/license/edadma/libpng)
*libpng* provides Scala Native bindings for the [libpng](http://www.libpng.org/) C library for reading and writing PNGs.
Overview
--------The goal of this project is to provide an easy-to-use Scala Native facade for the majority *libpng*, the official PNG reference library. Currently, many of the functions needed to read and write PNGs are covered. Also, convenience methods are provided to read into and write from an image buffer. The simplified API offered by the C library has not yet been covered, but is planned.
The more "programmer friendly" part of this library is found in the `io.github.edadma.libpng` package. That's the only package you need to import from, as seen in the example below. The other package in the library is `io.github.edadma.libpng.extern` which provides for interaction with the libpng C library using Scala Native interoperability elements from the so-call `unsafe` namespace. There are no public declarations in the `io.github.edadma.libpng` package that use `unsafe` types in their parameter or return types, making it a pure Scala facade. Consequently, you never have to worry about memory allocation or type conversions.
Usage
-----To use this library, `libpng-dev` needs to be installed:
```shell
sudo apt install libpng-dev
```Include the following in your `project/plugins.sbt`:
```sbt
addSbtPlugin("com.codecommit" % "sbt-github-packages" % "0.5.2")
```Include the following in your `build.sbt`:
```sbt
resolvers += Resolver.githubPackages("edadma")libraryDependencies += "io.github.edadma" %%% "libpng" % "0.1.0"
```Use the following `import` in your code:
```scala
import io.github.edadma.libpng._
```Example
-------The following example shows the use of convenience methods to read and write a PNG file to and from an image buffer. The example reads a PNG image file `image.png`, and modifies it, pixel by pixel, to remove all the red from it and to make the amount of green at each pixel equal to the amount of blue. The image is then written to a new PNG file `new.png`.
```scala
import io.github.edadma.libpng._object Main extends App {
val image = read("image.png")
if (image.format != ImageFormat.RGBA)
sys.error("can only process RGBA type files")for (i <- 0 until image.width; j <- 0 until image.height) {
image.setRGBARed(i, j, 0)
image.setRGBAGreen(i, j, image.getRGBABlue(i, j))
}write("new.png", image)
}
```As to performance, if you use `nativeMode := "release-fast"` in your `build.sbt`, then this example runs as fast as the corresponding C program would.
Documentation
-------------API documentation is forthcoming, however documentation for the C library is found [here](http://www.libpng.org/pub/png/libpng-manual.txt).
License
-------[ISC](https://github.com/edadma/libpng/blob/main/LICENSE)