Compare commits
No commits in common. "6208711292926ef53632c3adefd03fe58c4f5e12" and "47eb3ff9076469c5815f2ada32ff375fac80b825" have entirely different histories.
6208711292
...
47eb3ff907
8
.gitmodules
vendored
8
.gitmodules
vendored
@ -1,7 +1,15 @@
|
|||||||
|
[submodule "lib/raylib.c3l"]
|
||||||
|
path = lib/raylib.c3l
|
||||||
|
url = https://github.com/NexushasTaken/raylib.c3l
|
||||||
|
ignore = dirty
|
||||||
[submodule "lib/grapheme.c3l/thirdparty/libgrapheme"]
|
[submodule "lib/grapheme.c3l/thirdparty/libgrapheme"]
|
||||||
path = lib/grapheme.c3l/thirdparty/libgrapheme
|
path = lib/grapheme.c3l/thirdparty/libgrapheme
|
||||||
url = git://git.suckless.org/libgrapheme
|
url = git://git.suckless.org/libgrapheme
|
||||||
ignore = dirty
|
ignore = dirty
|
||||||
|
[submodule "lib/mini-qoi.c3l/thirdparty/mini-qoi"]
|
||||||
|
path = lib/mini-qoi.c3l/thirdparty/mini-qoi
|
||||||
|
url = https://github.com/shraiwi/mini-qoi
|
||||||
|
ignore = dirty
|
||||||
[submodule "lib/schrift.c3l/thirdparty/libschrift"]
|
[submodule "lib/schrift.c3l/thirdparty/libschrift"]
|
||||||
path = lib/schrift.c3l/thirdparty/libschrift
|
path = lib/schrift.c3l/thirdparty/libschrift
|
||||||
url = https://github.com/tomolt/libschrift
|
url = https://github.com/tomolt/libschrift
|
||||||
|
7
lib/mini-qoi.c3l/Makefile
Normal file
7
lib/mini-qoi.c3l/Makefile
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
all: thirdparty/mini-qoi/mqoi.a
|
||||||
|
mkdir -p linux-x64
|
||||||
|
cp thirdparty/mini-qoi/mqoi.a linux-x64/libmqoi.a
|
||||||
|
|
||||||
|
thirdparty/mini-qoi/mqoi.a:
|
||||||
|
gcc -O2 -c -o thirdparty/mini-qoi/mqoi.o thirdparty/mini-qoi/src/mini_qoi.c
|
||||||
|
ar -rc thirdparty/mini-qoi/mqoi.a thirdparty/mini-qoi/mqoi.o
|
122
lib/mini-qoi.c3l/libmqoi.c3i
Normal file
122
lib/mini-qoi.c3l/libmqoi.c3i
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
module mqoi;
|
||||||
|
|
||||||
|
macro rgb_hash(Rgb px) => ((px.r * 3 + px.g * 5 + px.b * 7) & 0b00111111);
|
||||||
|
macro mqoi_rgba_hash(Rgba px) => ((px.r * 3 + px.g * 5 + px.b * 7 + px.a * 11) & 0b00111111);
|
||||||
|
|
||||||
|
const uint MQOI_HEADER_SIZE = 14;
|
||||||
|
|
||||||
|
const char MQOI_MASK_OP_2B = 0b11000000;
|
||||||
|
const char MQOI_MASK_OP_8B = 0b11111111;
|
||||||
|
|
||||||
|
const char MQOI_MASK_OP_LUMA_DG = 0b00111111;
|
||||||
|
const char MQOI_MASK_OP_RUN = 0b00111111;
|
||||||
|
|
||||||
|
// basic types
|
||||||
|
|
||||||
|
enum DescErr : uint (uint value) {
|
||||||
|
MQOI_DESC_OK = 0, // The descriptor is valid
|
||||||
|
MQOI_DESC_INVALID_MAGIC = 1, // The magic value isn't correct
|
||||||
|
MQOI_DESC_INVALID_CHANNELS = 2, // The channel number isn't valid
|
||||||
|
MQOI_DESC_INVALID_COLORSPACE = 3, // The colorspace isn't valid
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Op : char (char value) {
|
||||||
|
MQOI_OP2_INDEX = (0b00 << 6),
|
||||||
|
MQOI_OP2_DIFF = (0b01 << 6),
|
||||||
|
MQOI_OP2_LUMA = (0b10 << 6),
|
||||||
|
MQOI_OP2_RUN = (0b11 << 6),
|
||||||
|
MQOI_OP8_RUN_RGB = (0b11111110),
|
||||||
|
MQOI_OP8_RUN_RGBA = (0b11111111),
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Channels : char (char value) {
|
||||||
|
MQOI_CHANNELS_RGB = 3,
|
||||||
|
MQOI_CHANNELS_RGBA = 4,
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Colorspace : char (char value) {
|
||||||
|
MQOI_COLORSPACE_SRGB = 0,
|
||||||
|
MQOI_COLORSPACE_LINEAR = 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
union Rgb {
|
||||||
|
struct { char r, g, b; }
|
||||||
|
char[3] value;
|
||||||
|
}
|
||||||
|
|
||||||
|
union Rgba{
|
||||||
|
struct { char r, g, b, a; }
|
||||||
|
char[4] value;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Desc {
|
||||||
|
char head;
|
||||||
|
|
||||||
|
char[4] magic;
|
||||||
|
char[4] width; // big-endian width
|
||||||
|
char[4] height; // big-endian height
|
||||||
|
char channels;
|
||||||
|
char colorspace;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==== chunks ====
|
||||||
|
|
||||||
|
union Chunk {
|
||||||
|
struct {
|
||||||
|
char head;
|
||||||
|
union {
|
||||||
|
Rgb rgb;
|
||||||
|
Rgba rgba;
|
||||||
|
char drdb;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
char[5] value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==== codecs ====
|
||||||
|
|
||||||
|
struct Encoding {
|
||||||
|
Rgba[64] hashtable;
|
||||||
|
Rgba prev_px;
|
||||||
|
Chunk working_chunk;
|
||||||
|
char working_chunk_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Dec {
|
||||||
|
Rgba[64] hashtable;
|
||||||
|
Rgba prev_px;
|
||||||
|
Chunk curr_chunk;
|
||||||
|
bitstruct : char {
|
||||||
|
char curr_chunk_head : 0..3;
|
||||||
|
char curr_chunk_size : 4..7;
|
||||||
|
}
|
||||||
|
uint pix_left;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==== utilities ====
|
||||||
|
|
||||||
|
fn void u32_write(uint * n, char * dest) @extern("mqoi_u32_write");
|
||||||
|
fn void u32_read(char * src, uint * n) @extern("mqoi_u32_read");
|
||||||
|
|
||||||
|
// ==== Desc ====
|
||||||
|
|
||||||
|
fn void desc_init(Desc* desc) @extern("mqoi_desc_init");
|
||||||
|
fn void desc_push(Desc* desc, char byte) @extern("mqoi_desc_push");
|
||||||
|
fn char* desc_pop(Desc* desc) @extern("mqoi_desc_pop");
|
||||||
|
fn char desc_verify(Desc* desc, uint* w, uint* h) @extern("mqoi_desc_verify");
|
||||||
|
fn bool desc_done(Desc* desc) @extern("mqoi_desc_done");
|
||||||
|
|
||||||
|
/* the encoder is still WIP
|
||||||
|
void mqoi_enc_init(mqoi_enc_t * enc);
|
||||||
|
void mqoi_enc_push(mqoi_enc_t * enc, Rgba * pix)
|
||||||
|
Chunk * mqoi_enc_pop(mqoi_enc_t * enc, char * size);
|
||||||
|
*/
|
||||||
|
|
||||||
|
// ==== Dec ====
|
||||||
|
|
||||||
|
fn void dec_init(Dec* dec, uint n_pix) @extern("mqoi_dec_init");
|
||||||
|
fn void dec_push(Dec* dec, char byte) @extern("mqoi_dec_push");
|
||||||
|
fn char dec_take(Dec* dec, char* bytes) @extern("mqoi_dec_take");
|
||||||
|
fn Rgba* dec_pop(Dec* dec) @extern("mqoi_dec_pop");
|
||||||
|
fn bool dec_done(Dec* dec) @extern("mqoi_dec_done");
|
||||||
|
|
9
lib/mini-qoi.c3l/manifest.json
Normal file
9
lib/mini-qoi.c3l/manifest.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"provides" : "mqoi",
|
||||||
|
"targets" : {
|
||||||
|
"linux-x64" : {
|
||||||
|
"dependencies" : [],
|
||||||
|
"linked-libraries" : ["mqoi", "c"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
14
lib/mini-qoi.c3l/project.json
Normal file
14
lib/mini-qoi.c3l/project.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"langrev": "1",
|
||||||
|
"warnings": [ "no-unused" ],
|
||||||
|
"dependency-search-paths": [ ".." ],
|
||||||
|
"dependencies": [ "mqoi" ],
|
||||||
|
"authors": [ "Alessandro Mauri <alemauri001@gmail.com>", "Shranav Palakurthi"],
|
||||||
|
"version": "0.1.0",
|
||||||
|
"sources": [ ],
|
||||||
|
"output": "build",
|
||||||
|
"target": "linux-x64",
|
||||||
|
"features": [],
|
||||||
|
"cpu": "generic",
|
||||||
|
"opt": "O0",
|
||||||
|
}
|
1
lib/mini-qoi.c3l/thirdparty/mini-qoi
vendored
Submodule
1
lib/mini-qoi.c3l/thirdparty/mini-qoi
vendored
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit f8b5a8a4d2eeee68b52e143060b7412ba78b5077
|
@ -3,7 +3,7 @@ module ugui;
|
|||||||
import std::core::mem::allocator;
|
import std::core::mem::allocator;
|
||||||
import std::collections::map;
|
import std::collections::map;
|
||||||
import std::io;
|
import std::io;
|
||||||
import std::compression::qoi;
|
import mqoi;
|
||||||
|
|
||||||
const usz SRITES_PER_ATLAS = 64;
|
const usz SRITES_PER_ATLAS = 64;
|
||||||
|
|
||||||
@ -102,12 +102,37 @@ fn void? Ctx.import_sprite_memory(&ctx, String name, char[] pixels, ushort w, us
|
|||||||
|
|
||||||
fn void? Ctx.import_sprite_file_qoi(&ctx, String name, String path, SpriteType type = SPRITE_NORMAL)
|
fn void? Ctx.import_sprite_file_qoi(&ctx, String name, String path, SpriteType type = SPRITE_NORMAL)
|
||||||
{
|
{
|
||||||
QOIDesc desc;
|
mqoi::Desc image_desc;
|
||||||
|
uint w, h;
|
||||||
|
|
||||||
char[] pixels = qoi::read(allocator::heap(), path, &desc, QOIChannels.RGBA)!;
|
File file = file::open(path, "rb")!;
|
||||||
|
defer (void) file.close();
|
||||||
|
|
||||||
|
while (!mqoi::desc_done(&image_desc)) {
|
||||||
|
mqoi::desc_push(&image_desc, file.read_byte()!);
|
||||||
|
}
|
||||||
|
if (mqoi::desc_verify(&image_desc, &w, &h) != 0) {
|
||||||
|
return io::FILE_NOT_VALID?;
|
||||||
|
}
|
||||||
|
|
||||||
|
mqoi::Dec dec;
|
||||||
|
mqoi::Rgba* px;
|
||||||
|
|
||||||
|
usz idx;
|
||||||
|
char[] pixels = mem::new_array(char, (usz)w*h*4);
|
||||||
defer mem::free(pixels);
|
defer mem::free(pixels);
|
||||||
|
|
||||||
ctx.sprite_atlas.insert(name, type, pixels, (ushort)desc.width, (ushort)desc.height, (ushort)desc.width)!;
|
mqoi::dec_init(&dec, w*h);
|
||||||
|
while (!mqoi::dec_done(&dec)) {
|
||||||
|
mqoi::dec_push(&dec, file.read_byte()!);
|
||||||
|
|
||||||
|
while ((px = mqoi::dec_pop(&dec)) != null) {
|
||||||
|
pixels[idx..idx+3] = px.value[..];
|
||||||
|
idx += 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.sprite_atlas.insert(name, type, pixels, (ushort)w, (ushort)h, (ushort)w)!;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn void? Ctx.draw_sprite(&ctx, String label, String name, Point off = {0,0})
|
fn void? Ctx.draw_sprite(&ctx, String label, String name, Point off = {0,0})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user