Update representation of RGBA
This commit is contained in:
parent
0b6ba2faee
commit
f7fa9774d6
@ -14,8 +14,10 @@ LuaCanvas::LuaCanvas(
|
||||
}
|
||||
|
||||
union RGBA {
|
||||
uint8_t rgba[4];
|
||||
uint32_t raw;
|
||||
struct {
|
||||
uint8_t r, g, b, a;
|
||||
};
|
||||
uint32_t rgba;
|
||||
};
|
||||
|
||||
static RGBA* get_at(const ImageData& data, uint index) {
|
||||
@ -41,7 +43,7 @@ static int l_at(State* L) {
|
||||
auto y = static_cast<uint>(tointeger(L, 3));
|
||||
|
||||
if (auto pixel = get_at(L, x, y)) {
|
||||
return pushinteger(L, pixel->raw);
|
||||
return pushinteger(L, pixel->rgba);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -54,19 +56,19 @@ static int l_set(State* L) {
|
||||
if (auto pixel = get_at(L, x, y)) {
|
||||
switch (gettop(L)) {
|
||||
case 4:
|
||||
pixel->raw = static_cast<uint>(tointeger(L, 4));
|
||||
pixel->rgba = static_cast<uint>(tointeger(L, 4));
|
||||
return 1;
|
||||
case 6:
|
||||
pixel->rgba[0] = static_cast<ubyte>(tointeger(L, 4));
|
||||
pixel->rgba[1] = static_cast<ubyte>(tointeger(L, 5));
|
||||
pixel->rgba[2] = static_cast<ubyte>(tointeger(L, 6));
|
||||
pixel->rgba[3] = 255;
|
||||
pixel->r = static_cast<ubyte>(tointeger(L, 4));
|
||||
pixel->g = static_cast<ubyte>(tointeger(L, 5));
|
||||
pixel->b = static_cast<ubyte>(tointeger(L, 6));
|
||||
pixel->a = 255;
|
||||
return 1;
|
||||
case 7:
|
||||
pixel->rgba[0] = static_cast<ubyte>(tointeger(L, 4));
|
||||
pixel->rgba[1] = static_cast<ubyte>(tointeger(L, 5));
|
||||
pixel->rgba[2] = static_cast<ubyte>(tointeger(L, 6));
|
||||
pixel->rgba[3] = static_cast<ubyte>(tointeger(L, 7));
|
||||
pixel->r = static_cast<ubyte>(tointeger(L, 4));
|
||||
pixel->g = static_cast<ubyte>(tointeger(L, 5));
|
||||
pixel->b = static_cast<ubyte>(tointeger(L, 6));
|
||||
pixel->a = static_cast<ubyte>(tointeger(L, 7));
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
@ -97,7 +99,7 @@ static int l_meta_index(State* L) {
|
||||
auto& data = texture->data();
|
||||
if (isnumber(L, 2)) {
|
||||
if (auto pixel = get_at(data, static_cast<uint>(tointeger(L, 2)))) {
|
||||
return pushinteger(L, pixel->raw);
|
||||
return pushinteger(L, pixel->rgba);
|
||||
}
|
||||
}
|
||||
if (isstring(L, 2)) {
|
||||
@ -123,7 +125,7 @@ static int l_meta_newindex(State* L) {
|
||||
auto& data = texture->data();
|
||||
if (isnumber(L, 2) && isnumber(L, 3)) {
|
||||
if (auto pixel = get_at(data, static_cast<uint>(tointeger(L, 2)))) {
|
||||
pixel->raw = static_cast<uint>(tointeger(L, 3));
|
||||
pixel->rgba = static_cast<uint>(tointeger(L, 3));
|
||||
return 1;
|
||||
}
|
||||
return 1;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user