plutovg/surface
surface-create
(surface-create [width :int height :int] :ptr<void>)
allocate a new premultiplied-ARGB pixel buffer.
| width | surface width in pixels | |
| height | surface height in pixels |
(ok handle) on success; (err 0) if plutovg refuses the dimensions. Free with surface-destroy when done.
(let [r (surface-create 256 256)]
(if (ok? r) (let [s (ok-val r)] ...) (println "create failed")))
Since: PV0
surface-create-from-data
(surface-create-from-data [data :cstr width :int height :int stride :int] :ptr<void>)
wrap an existing pixel buffer as a surface.
| data | pointer to existing premultiplied-ARGB bytes (:cstr) | |
| width | surface width in pixels | |
| height | surface height in pixels | |
| stride | bytes per row (typically width * 4) |
(ok handle) on success; (err 0) on failure. The buffer is NOT owned by the returned surface; the caller must keep it alive until the surface is destroyed.
(surface-create-from-data buf 64 64 (* 64 4))
Since: PV0
surface-destroy
(surface-destroy [s :int] :void)
release a surface allocated by surface-create.
| s | surface handle (ok-val from surface-create) |
void
(surface-destroy s)
Since: PV0
surface-width
(surface-width [s :int] :int)
return the width of a surface in pixels.
| s | surface handle |
Width as :int.
(println (surface-width s))
Since: PV0
surface-height
(surface-height [s :int] :int)
return the height of a surface in pixels.
| s | surface handle |
Height as :int.
(println (surface-height s))
Since: PV0
surface-stride
(surface-stride [s :int] :int)
return the row stride of a surface in bytes.
| s | surface handle |
Bytes per row as :int. For surfaces allocated by surface-create this is always width * 4.
(println (surface-stride s))
Since: PV0
surface-data
(surface-data [s :int] :cstr)
return a raw pointer to the surface pixel buffer.
| s | surface handle |
Pointer to the pixel buffer as :cstr. Pixels are stored as 32-bit premultiplied ARGB (0xAARRGGBB); on a little-endian host the byte order in memory is B, G, R, A.
(let [buf (surface-data s)] ...)
Since: PV0
surface-write-png
(surface-write-png [s :int path :cstr] :ptr<void>)
write the surface to a PNG file.
| s | surface handle | |
| path | destination filesystem path |
(ok 0) on success; (err 0) if plutovg could not write the file.
(let [r (surface-write-png s "out.png")]
(if (ok? r) (println "written") (println "failed")))
Since: PV6
surface-write-jpeg
(surface-write-jpeg [s :int path :cstr quality :int] :ptr<void>)
write the surface to a JPEG file.
| s | surface handle | |
| path | destination filesystem path | |
| quality | JPEG quality in [0, 100]; 90 is a good default |
(ok 0) on success; (err 0) on failure.
(surface-write-jpeg s "out.jpg" 90)
Since: PV6
Internal definitions
__ok-- create an ok result wrapping integer value v.__err-- create an err result wrapping integer error value e.