VERSIÓ: 1.6.0:

- [NEW] pal.mask() i pal.lut(), per a tocaments de paleta avançats.
This commit is contained in:
Raimon @ quifisraimon committed 2026-10-13 10:23:02 +02:00
1 parent 8ae82936dc
commit a35b7c1be5
5 files changed
+68 -1

No files matched your search

+27
View File
@@ -396,6 +396,31 @@ namespace mini
}
return 0;
}
static int lut(lua_State *L) {
const int index = luaL_checkinteger(L, 1);
if (index<0 || index>255) return 0;
uint8_t tabla[256];
for (int i = 0; i < 256; ++i) tabla[i] = i;
if (!lua_isnil(L, 2) && lua_gettop(L) >= 2) {
luaL_checktype(L, 2, LUA_TTABLE);
const int len = std::min(256, (int)lua_rawlen(L, 2));
for (int i=0;i<len; ++i) {
lua_rawgeti(L, 2, i+1);
if (lua_isinteger(L, -1)) tabla[i] = lua_tointeger(L, -1);
lua_pop(L, 1);
}
}
mini::pal::mask::lut(index, tabla);
return 0;
}
static int mask(lua_State *L) {
mini::pal::mask::apply();
return 0;
}
}
namespace view
@@ -1114,6 +1139,8 @@ namespace mini
lua_pushcfunction(L,wrappers::pal::color); lua_setfield(L, -2, "color");
lua_pushcfunction(L,wrappers::pal::trans); lua_setfield(L, -2, "trans");
lua_pushcfunction(L,wrappers::pal::subpal); lua_setfield(L, -2, "subpal");
lua_pushcfunction(L,wrappers::pal::lut); lua_setfield(L, -2, "lut");
lua_pushcfunction(L,wrappers::pal::mask); lua_setfield(L, -2, "mask");
lua_setglobal(L, "pal");
lua_newtable(L);
+24
View File
@@ -1,6 +1,7 @@
#include "pal.h"
#include "mini/file/file.h"
#include "mini/draw/draw.h"
#include "mini/surf/surf.h"
#include <stdlib.h>
@@ -81,5 +82,28 @@ namespace mini
for (int i=0;i<256;++i) draw::state.draw_palette[i]=i;
}
}
namespace mask {
uint8_t tables[256][256];
void apply() {
surf::surface_t& source = surf::state.surfaces[surf::state.source_surface];
surf::surface_t& dest = surf::state.surfaces[surf::state.dest_surface];
const int width = source.w < dest.w ? source.w : dest.w;
const int height = source.h < dest.h ? source.h : dest.h;
for (int y=0; y<height; ++y)
for (int x=0; x<width; ++x)
dest.p[x+y*dest.w] = tables[source.p[x+y*source.w]][dest.p[x+y*dest.w]];
}
void lut(uint8_t index, uint8_t *table) {
for (int i=0; i<256; ++i) {
tables[index][i] = table[i];
}
}
}
}
}
+4
View File
@@ -24,5 +24,9 @@ namespace mini
uint8_t set(uint8_t index, uint8_t color);
void reset();
}
namespace mask {
void apply();
void lut(uint8_t index, uint8_t *table);
}
}
}
+1 -1
View File
@@ -1,3 +1,3 @@
#pragma once
#define MINI_VERSION "1.5.15"
#define MINI_VERSION "1.6.0"
+12
View File
@@ -181,6 +181,18 @@ function pal.subpal(index, color) end
---Set the specified subpalette range to the specified palette index
function pal.subpal(index1, index2, color) end
---@param index number
---Set a 1:1 look up table (passthrough, no changes) for the specified mask value
function pal.lut(index) end
---@param index number
---@param table table
---Set the look up table for the specified mask value
function pal.lut(index, table) end
---Apply the look up tables, based on the source surface values, to the destination surface
function pal.mask() end
---@class view
view = {}