Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/9551-dev/luaqoi
QOI (Quite Okay Image) decoding and encoding library written in Lua
https://github.com/9551-dev/luaqoi
cc-tweaked cctweaked computercraft decoder encoder graphics graphics-programming lua qoi qoi-format
Last synced: 3 months ago
JSON representation
QOI (Quite Okay Image) decoding and encoding library written in Lua
- Host: GitHub
- URL: https://github.com/9551-dev/luaqoi
- Owner: 9551-Dev
- License: mit
- Created: 2024-09-11T06:27:04.000Z (4 months ago)
- Default Branch: master
- Last Pushed: 2024-09-15T19:13:40.000Z (4 months ago)
- Last Synced: 2024-09-29T15:22:31.348Z (4 months ago)
- Topics: cc-tweaked, cctweaked, computercraft, decoder, encoder, graphics, graphics-programming, lua, qoi, qoi-format
- Language: Lua
- Homepage:
- Size: 32.6 MB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# LuaQOI
Lua libary for decoding an encoding [.qoi](https://qoiformat.org) images on a similar level to FFMPEG/GIMP/IM.
#### Decoder arguments:
`qoid.decode(data_source,[no_alpha])` -> `[table]`
- data_source`[table]` list in some way representing data given to the decoder, can have 3 entries
- `data`: raw binary string of image data
- `file`: path to an image file
- `handle`: binary file handle (QOI_D closes this handle)
- no_alpha`[boolean]`: if an image has an alpha channel, this strips it (useful for easier handling of hexadecimal output data), defaults to `false`
#### Decoder result `[table]`
- width`[u32]`: Width of the decoded image
- height`[u32]`: Height of the decoded image
- pixels`[table]`: 2D array[y][x] storing all the pixel colors encoded as hex
- channels`[string]`: Either `"RGB"` or `"RGBA"`
- colorspace`[string]`: Either `"SRGB_LINEAR_ALPHA"` or `"SRGB_LINEAR"`---
#### Encoder arguments:
`qoie.encode(image_data,[width],[height],[alpha_channel],[output_file],[colorspace])` -> `[string]`
- image_data`[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)
- width`[u32]`: Desired width of the encoded image, defaults to the length of the first image row (`#image_data[1]`)
- height`[u32]`: Desired height of the encoded image, defualts to the row count of image_data (`#image_data`)
- alpha_channel`[boolean]`: Enables alpha channel encoding on the image, hex format: `0xRRGGBBAA`, defaults to `false`
- output_file`[string]`: Automatically saves the resulting binary string to a file given a path, defaults to no file saving.
- colorspace`[string]`: QOI image colorspace, defaults to SRGB_LINEAR_ALPHA.#### Encoder result `[string]`
- A binary string containing all of the image data, can be saved to a file via binary file handle.### Example [decoder](./qoi_d.lua) usage:
```lua
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
))
```### Example [encoder](./qoi_e.lua) usage
```lua
local qoie = require("qoi_e")local data = {
{0xFF0000,0x0000FF},
{0x00FFFF,0xFFFF00}
}local dat = qoie.encode(data)
```
or something like this
```lua
local qoie = require("qoi_e")local data = {
{0xFF0000,0x0000FF},
{0x00FFFF,0xFFFF00},
{0x0000FF,0xFF0000}
}qoie.encode(data,2,3,false,"epic_output.ppm")
```