QOI (Quite Okay Image) decoding and encoding library written in Lua
MIT License
Lua libary for decoding an encoding .qoi images on a similar level to FFMPEG/GIMP/IM.
qoid.decode(data_source,[no_alpha])
-> [table]
[table]
list in some way representing data given to the decoder, can have 3 entries
data
: raw binary string of image datafile
: path to an image filehandle
: binary file handle (QOI_D closes this handle)[boolean]
: if an image has an alpha channel, this strips it (useful for easier handling of hexadecimal output data), defaults to false
[table]
[u32]
: Width of the decoded image[u32]
: Height of the decoded image[table]
: 2D array[y][x] storing all the pixel colors encoded as hex[string]
: Either "RGB"
or "RGBA"
[string]
: Either "SRGB_LINEAR_ALPHA"
or "SRGB_LINEAR"
qoie.encode(image_data,[width],[height],[alpha_channel],[output_file],[colorspace])
-> [string]
[table]
: 2D array[y][x] containing all the pixels we want to encode into the QOI (either as hex or 3/4 entry tables, 4 entries used for alpha/transparency)[u32]
: Desired width of the encoded image, defaults to the length of the first image row (#image_data[1]
)[u32]
: Desired height of the encoded image, defualts to the row count of image_data (#image_data
)[boolean]
: Enables alpha channel encoding on the image, hex format: 0xRRGGBBAA
, defaults to false
[string]
: Automatically saves the resulting binary string to a file given a path, defaults to no file saving.[string]
: QOI image colorspace, defaults to SRGB_LINEAR_ALPHA.[string]
local img_src = select(1,...)
local pixel_x = tonumber(select(2,...))
local pixel_y = tonumber(select(3,...))
local qoid = require("qoi_d")
local decoded = qoid.decode({file=img_src})
local color_hex = decoded.pixels[pixel_y][pixel_x]
print(("Pixel at %s:%s is #%x"):format(
pixel_x,pixel_y,
color_hex
))
local qoie = require("qoi_e")
local data = {
{0xFF0000,0x0000FF},
{0x00FFFF,0xFFFF00}
}
local dat = qoie.encode(data)
or something like this
local qoie = require("qoi_e")
local data = {
{0xFF0000,0x0000FF},
{0x00FFFF,0xFFFF00},
{0x0000FF,0xFF0000}
}
qoie.encode(data,2,3,false,"epic_output.ppm")