| Title: | Read and Write AVIF Images |
|---|---|
| Description: | Functions to read and write AV1 Image File Format. It can read and write both files and in-memory raw vectors. |
| Authors: | Zhichao Huang [aut, cre] |
| Maintainer: | Zhichao Huang <[email protected]> |
| License: | BSD_3_clause + file LICENSE |
| Version: | 0.0.1 |
| Built: | 2026-05-20 06:58:08 UTC |
| Source: | https://github.com/r-zon/avif |
Read an AVIF image from a file or a raw vector into an RGB array.
read_avif( source, ..., ptype = raw(), normalize = FALSE, native_raster = FALSE, codec = NULL, jobs = NULL )read_avif( source, ..., ptype = raw(), normalize = FALSE, native_raster = FALSE, codec = NULL, jobs = NULL )
source |
A file path or a raw vector. |
... |
Unused. |
ptype |
Prototype like raw(), 0L or 0.0 that defines the output type. |
normalize |
If |
native_raster |
If |
codec |
Codec for decoding, automatic if |
jobs |
Number of decoder threads, must be greater than 0, or |
An RGB array.
if (file.exists("8bpc.avif")) { read_avif("8bpc.avif") } if (file.exists("10bpc.avif")) { read_avif("10bpc.avif", ptype = 0L, native_raster = TRUE) } if (file.exists("12bpc.avif")) { read_avif( readBin("12bpc.avif", "raw", file.size("12bpc.avif")), ptype = 0., normalize = TRUE ) }if (file.exists("8bpc.avif")) { read_avif("8bpc.avif") } if (file.exists("10bpc.avif")) { read_avif("10bpc.avif", ptype = 0L, native_raster = TRUE) } if (file.exists("12bpc.avif")) { read_avif( readBin("12bpc.avif", "raw", file.size("12bpc.avif")), ptype = 0., normalize = TRUE ) }
Create an AVIF image from an RGB array into a file or return a raw vector.
write_avif( image, target = NULL, ..., speed = 6L, quality = 60L, alpha_quality = 60L, format = 444L, codec = NULL, jobs = NULL )write_avif( image, target = NULL, ..., speed = 6L, quality = 60L, alpha_quality = 60L, format = 444L, codec = NULL, jobs = NULL )
image |
A raw or integer vector with dimensions (height, width, channel). |
target |
A file path, or |
... |
Unused. |
speed |
Encoder speed in [0, 10] where 0 is the slowest, 10 is the fastest. |
quality |
Color quality in [0, 100] where 100 is lossless. |
alpha_quality |
Alpha quality in [0, 100] where 100 is lossless. |
format |
YUV format, must be one of 444, 422, 420 or 400. |
codec |
Codec for encoding, automatic if |
jobs |
Number of encoder threads, must be greater than 0, or |
NULL if target is a file path, otherwise a raw vector.
rgb_array <- hcl.colors(700) |> col2rgb() |> as.raw() |> array(c(3, 700, 100)) |> aperm() save_path <- file.path(tempdir(), "8bpc.avif") write_avif(rgb_array, save_path, speed = 0L, quality = 100L) writeBin(write_avif(rgb_array), save_path)rgb_array <- hcl.colors(700) |> col2rgb() |> as.raw() |> array(c(3, 700, 100)) |> aperm() save_path <- file.path(tempdir(), "8bpc.avif") write_avif(rgb_array, save_path, speed = 0L, quality = 100L) writeBin(write_avif(rgb_array), save_path)