mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
Color values in love's APIs are now in the range of [0, 1] rather than [0, 255].
--HG-- branch : minor
This commit is contained in:
@@ -687,31 +687,11 @@ love::Vector ParticleSystem::getOffset() const
|
||||
void ParticleSystem::setColor(const std::vector<Colorf> &newColors)
|
||||
{
|
||||
colors = newColors;
|
||||
|
||||
for (Colorf &c : colors)
|
||||
{
|
||||
// We want to store the colors as [0, 1], rather than [0, 255].
|
||||
c.r /= 255.0f;
|
||||
c.g /= 255.0f;
|
||||
c.b /= 255.0f;
|
||||
c.a /= 255.0f;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<Colorf> ParticleSystem::getColor() const
|
||||
{
|
||||
// The particle system stores colors in the range of [0, 1]...
|
||||
std::vector<Colorf> ncolors(colors);
|
||||
|
||||
for (Colorf &c : ncolors)
|
||||
{
|
||||
c.r *= 255.0f;
|
||||
c.g *= 255.0f;
|
||||
c.b *= 255.0f;
|
||||
c.a *= 255.0f;
|
||||
}
|
||||
|
||||
return ncolors;
|
||||
return colors;
|
||||
}
|
||||
|
||||
void ParticleSystem::setQuads(const std::vector<Quad *> &newQuads)
|
||||
|
||||
@@ -388,7 +388,7 @@ void Font::getCodepointsFromString(const std::vector<ColoredString> &strs, Color
|
||||
{
|
||||
IndexedColor c = codepoints.colors[0];
|
||||
|
||||
if (c.index == 0 && c.color == Color(255, 255, 255, 255))
|
||||
if (c.index == 0 && c.color == Colorf(1.0f, 1.0f, 1.0f, 1.0f))
|
||||
codepoints.colors.pop_back();
|
||||
}
|
||||
}
|
||||
@@ -425,7 +425,13 @@ std::vector<Font::DrawCommand> Font::generateVertices(const ColoredCodepoints &c
|
||||
uint32 g = codepoints.cps[i];
|
||||
|
||||
if (curcolori + 1 < ncolors && codepoints.colors[curcolori + 1].index == i)
|
||||
curcolor = codepoints.colors[++curcolori].color;
|
||||
{
|
||||
const Colorf &c = codepoints.colors[++curcolori].color;
|
||||
curcolor.r = (unsigned char) (c.r * 255.0f);
|
||||
curcolor.g = (unsigned char) (c.g * 255.0f);
|
||||
curcolor.b = (unsigned char) (c.b * 255.0f);
|
||||
curcolor.a = (unsigned char) (c.a * 255.0f);
|
||||
}
|
||||
|
||||
if (g == '\n')
|
||||
{
|
||||
@@ -763,7 +769,7 @@ void Font::getWrap(const ColoredCodepoints &codepoints, float wraplimit, std::ve
|
||||
// Keeping the indexed colors "in sync" is a bit tricky, since we split
|
||||
// things up and we might skip some glyphs but we don't want to skip any
|
||||
// color which starts at those indices.
|
||||
Color curcolor(255, 255, 255, 255);
|
||||
Colorf curcolor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
bool addcurcolor = false;
|
||||
int curcolori = -1;
|
||||
int endcolori = (int) codepoints.colors.size() - 1;
|
||||
|
||||
@@ -64,12 +64,12 @@ public:
|
||||
struct ColoredString
|
||||
{
|
||||
std::string str;
|
||||
Color color;
|
||||
Colorf color;
|
||||
};
|
||||
|
||||
struct IndexedColor
|
||||
{
|
||||
Color color;
|
||||
Colorf color;
|
||||
int index;
|
||||
};
|
||||
|
||||
|
||||
@@ -440,11 +440,9 @@ void Graphics::reset()
|
||||
|
||||
void Graphics::clear(Colorf c)
|
||||
{
|
||||
Colorf nc = Colorf(c.r/255.0f, c.g/255.0f, c.b/255.0f, c.a/255.0f);
|
||||
gammaCorrectColor(c);
|
||||
|
||||
gammaCorrectColor(nc);
|
||||
|
||||
glClearColor(nc.r, nc.g, nc.b, nc.a);
|
||||
glClearColor(c.r, c.g, c.b, c.a);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
if (gl.bugs.clearRequiresDriverTextureStateUpdate && Shader::current)
|
||||
@@ -479,7 +477,7 @@ void Graphics::clear(const std::vector<OptionalColorf> &colors)
|
||||
if (!colors[i].enabled)
|
||||
continue;
|
||||
|
||||
GLfloat c[] = {colors[i].r/255.f, colors[i].g/255.f, colors[i].b/255.f, colors[i].a/255.f};
|
||||
GLfloat c[] = {colors[i].r, colors[i].g, colors[i].b, colors[i].a};
|
||||
|
||||
// TODO: Investigate a potential bug on AMD drivers in Windows/Linux
|
||||
// which apparently causes the clear color to be incorrect when mixed
|
||||
@@ -943,11 +941,10 @@ bool Graphics::isGammaCorrect() const
|
||||
|
||||
void Graphics::setColor(Colorf c)
|
||||
{
|
||||
Colorf nc = Colorf(c.r/255.0f, c.g/255.0f, c.b/255.0f, c.a/255.0f);
|
||||
|
||||
Colorf nc = c;
|
||||
gammaCorrectColor(nc);
|
||||
|
||||
glVertexAttrib4f(ATTRIB_CONSTANTCOLOR, nc.r, nc.g, nc.b, nc.a);
|
||||
|
||||
states.back().color = c;
|
||||
}
|
||||
|
||||
|
||||
@@ -442,7 +442,7 @@ public:
|
||||
/**
|
||||
* Creates a screenshot of the view and saves it to the default folder.
|
||||
* @param image The love.image module.
|
||||
* @param copyAlpha If the alpha channel should be copied or set to full opacity (255).
|
||||
* @param copyAlpha If the alpha channel should be copied or set to full opacity (1.0).
|
||||
**/
|
||||
love::image::ImageData *newScreenshot(love::image::Image *image, bool copyAlpha = true);
|
||||
|
||||
@@ -481,8 +481,8 @@ private:
|
||||
|
||||
struct DisplayState
|
||||
{
|
||||
Colorf color = Colorf(255.0, 255.0, 255.0, 255.0);
|
||||
Colorf backgroundColor = Colorf(0.0, 0.0, 0.0, 255.0);
|
||||
Colorf color = Colorf(1.0, 1.0, 1.0, 1.0);
|
||||
Colorf backgroundColor = Colorf(0.0, 0.0, 0.0, 1.0);
|
||||
|
||||
BlendMode blendMode = BLEND_ALPHA;
|
||||
BlendAlpha blendAlphaMode = BLENDALPHA_MULTIPLY;
|
||||
|
||||
@@ -58,7 +58,7 @@ int w_clear(lua_State *L)
|
||||
Colorf color;
|
||||
|
||||
if (lua_isnoneornil(L, 1))
|
||||
color.set(0, 0, 0, 0);
|
||||
color.set(0.0, 0.0, 0.0, 0.0);
|
||||
else if (lua_istable(L, 1))
|
||||
{
|
||||
std::vector<Graphics::OptionalColorf> colors((size_t) lua_gettop(L));
|
||||
@@ -78,7 +78,7 @@ int w_clear(lua_State *L)
|
||||
colors[i].r = (float) luaL_checknumber(L, -4);
|
||||
colors[i].g = (float) luaL_checknumber(L, -3);
|
||||
colors[i].b = (float) luaL_checknumber(L, -2);
|
||||
colors[i].a = (float) luaL_optnumber(L, -1, 255);
|
||||
colors[i].a = (float) luaL_optnumber(L, -1, 1.0);
|
||||
|
||||
lua_pop(L, 4);
|
||||
}
|
||||
@@ -91,7 +91,7 @@ int w_clear(lua_State *L)
|
||||
color.r = (float) luaL_checknumber(L, 1);
|
||||
color.g = (float) luaL_checknumber(L, 2);
|
||||
color.b = (float) luaL_checknumber(L, 3);
|
||||
color.a = (float) luaL_optnumber(L, 4, 255);
|
||||
color.a = (float) luaL_optnumber(L, 4, 1.0);
|
||||
}
|
||||
|
||||
luax_catchexcept(L, [&]() { instance()->clear(color); });
|
||||
@@ -706,10 +706,10 @@ static Mesh *newStandardMesh(lua_State *L)
|
||||
v.s = (float) luaL_optnumber(L, -6, 0.0);
|
||||
v.t = (float) luaL_optnumber(L, -5, 0.0);
|
||||
|
||||
v.r = (unsigned char) luaL_optnumber(L, -4, 255);
|
||||
v.g = (unsigned char) luaL_optnumber(L, -3, 255);
|
||||
v.b = (unsigned char) luaL_optnumber(L, -2, 255);
|
||||
v.a = (unsigned char) luaL_optnumber(L, -1, 255);
|
||||
v.r = (unsigned char) (luaL_optnumber(L, -4, 1.0) * 255.0);
|
||||
v.g = (unsigned char) (luaL_optnumber(L, -3, 1.0) * 255.0);
|
||||
v.b = (unsigned char) (luaL_optnumber(L, -2, 1.0) * 255.0);
|
||||
v.a = (unsigned char) (luaL_optnumber(L, -1, 1.0) * 255.0);
|
||||
|
||||
lua_pop(L, 9);
|
||||
vertices.push_back(v);
|
||||
@@ -911,7 +911,7 @@ int w_setColor(lua_State *L)
|
||||
c.r = (float) luaL_checknumber(L, -4);
|
||||
c.g = (float) luaL_checknumber(L, -3);
|
||||
c.b = (float) luaL_checknumber(L, -2);
|
||||
c.a = (float) luaL_optnumber(L, -1, 255);
|
||||
c.a = (float) luaL_optnumber(L, -1, 1.0);
|
||||
|
||||
lua_pop(L, 4);
|
||||
}
|
||||
@@ -920,7 +920,7 @@ int w_setColor(lua_State *L)
|
||||
c.r = (float) luaL_checknumber(L, 1);
|
||||
c.g = (float) luaL_checknumber(L, 2);
|
||||
c.b = (float) luaL_checknumber(L, 3);
|
||||
c.a = (float) luaL_optnumber(L, 4, 255);
|
||||
c.a = (float) luaL_optnumber(L, 4, 1.0);
|
||||
}
|
||||
instance()->setColor(c);
|
||||
return 0;
|
||||
@@ -947,7 +947,7 @@ int w_setBackgroundColor(lua_State *L)
|
||||
c.r = (float) luaL_checknumber(L, -4);
|
||||
c.g = (float) luaL_checknumber(L, -3);
|
||||
c.b = (float) luaL_checknumber(L, -2);
|
||||
c.a = (float) luaL_optnumber(L, -1, 255);
|
||||
c.a = (float) luaL_optnumber(L, -1, 1.0);
|
||||
|
||||
lua_pop(L, 4);
|
||||
}
|
||||
@@ -956,7 +956,7 @@ int w_setBackgroundColor(lua_State *L)
|
||||
c.r = (float) luaL_checknumber(L, 1);
|
||||
c.g = (float) luaL_checknumber(L, 2);
|
||||
c.b = (float) luaL_checknumber(L, 3);
|
||||
c.a = (float) luaL_optnumber(L, 4, 255);
|
||||
c.a = (float) luaL_optnumber(L, 4, 1.0);
|
||||
}
|
||||
instance()->setBackgroundColor(c);
|
||||
return 0;
|
||||
@@ -1635,10 +1635,10 @@ int w_points(lua_State *L)
|
||||
coords[i * 2 + 0] = luax_tofloat(L, -6);
|
||||
coords[i * 2 + 1] = luax_tofloat(L, -5);
|
||||
|
||||
colors[i * 4 + 0] = (uint8) luaL_optnumber(L, -4, 255);
|
||||
colors[i * 4 + 1] = (uint8) luaL_optnumber(L, -3, 255);
|
||||
colors[i * 4 + 2] = (uint8) luaL_optnumber(L, -2, 255);
|
||||
colors[i * 4 + 3] = (uint8) luaL_optnumber(L, -1, 255);
|
||||
colors[i * 4 + 0] = (uint8) (luaL_optnumber(L, -4, 1.0) * 255.0);
|
||||
colors[i * 4 + 1] = (uint8) (luaL_optnumber(L, -3, 1.0) * 255.0);
|
||||
colors[i * 4 + 2] = (uint8) (luaL_optnumber(L, -2, 1.0) * 255.0);
|
||||
colors[i * 4 + 3] = (uint8) (luaL_optnumber(L, -1, 1.0) * 255.0);
|
||||
|
||||
lua_pop(L, 7);
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ static inline size_t writeByteData(lua_State *L, int startidx, int components, c
|
||||
uint8 *componentdata = (uint8 *) data;
|
||||
|
||||
for (int i = 0; i < components; i++)
|
||||
componentdata[i] = (uint8) luaL_optnumber(L, startidx + i, 255);
|
||||
componentdata[i] = (uint8) (luaL_optnumber(L, startidx + i, 1.0) * 255.0);
|
||||
|
||||
return sizeof(uint8) * components;
|
||||
}
|
||||
@@ -78,7 +78,7 @@ static inline size_t readByteData(lua_State *L, int components, const char *data
|
||||
const uint8 *componentdata = (const uint8 *) data;
|
||||
|
||||
for (int i = 0; i < components; i++)
|
||||
lua_pushnumber(L, (lua_Number) componentdata[i]);
|
||||
lua_pushnumber(L, (lua_Number) componentdata[i] / 255.0);
|
||||
|
||||
return sizeof(uint8) * components;
|
||||
}
|
||||
|
||||
@@ -515,7 +515,7 @@ int w_ParticleSystem_setColors(lua_State *L)
|
||||
colors[i].r = (float) luaL_checknumber(L, -4);
|
||||
colors[i].g = (float) luaL_checknumber(L, -3);
|
||||
colors[i].b = (float) luaL_checknumber(L, -2);
|
||||
colors[i].a = (float) luaL_optnumber(L, -1, 255);
|
||||
colors[i].a = (float) luaL_optnumber(L, -1, 1.0);
|
||||
|
||||
// pop the color components from the stack
|
||||
lua_pop(L, 4);
|
||||
|
||||
@@ -174,21 +174,16 @@ static int w__Shader_sendFloat(lua_State *L, bool colors)
|
||||
if (!values)
|
||||
return luaL_error(L, "Error in arguments.");
|
||||
|
||||
if (colors)
|
||||
if (colors && love::graphics::isGammaCorrect())
|
||||
{
|
||||
bool gammacorrect = love::graphics::isGammaCorrect();
|
||||
// the fourth component (alpha) is always already linear, if it exists.
|
||||
int ncomponents = std::min((int) dimension, 3);
|
||||
const auto &m = love::math::Math::instance;
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
for (int j = 0; j < (int) dimension; j++)
|
||||
{
|
||||
// the fourth component (alpha) is always already linear, if it exists.
|
||||
if (gammacorrect && j < 3)
|
||||
values[i * dimension + j] = m.gammaToLinear(values[i * dimension + j] / 255.0f);
|
||||
else
|
||||
values[i * dimension + j] /= 255.0f;
|
||||
}
|
||||
for (int j = 0; j < ncomponents; j++)
|
||||
values[i * dimension + j] = m.gammaToLinear(values[i * dimension + j]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -144,19 +144,19 @@ int w_SpriteBatch_setColor(lua_State *L)
|
||||
for (int i = 1; i <= 4; i++)
|
||||
lua_rawgeti(L, 2, i);
|
||||
|
||||
c.r = (unsigned char) luaL_checknumber(L, -4);
|
||||
c.g = (unsigned char) luaL_checknumber(L, -3);
|
||||
c.b = (unsigned char) luaL_checknumber(L, -2);
|
||||
c.a = (unsigned char) luaL_optnumber(L, -1, 255);
|
||||
c.r = (unsigned char) (luaL_checknumber(L, -4) * 255.0);
|
||||
c.g = (unsigned char) (luaL_checknumber(L, -3) * 255.0);
|
||||
c.b = (unsigned char) (luaL_checknumber(L, -2) * 255.0);
|
||||
c.a = (unsigned char) (luaL_optnumber(L, -1, 1.0) * 255.0);
|
||||
|
||||
lua_pop(L, 4);
|
||||
}
|
||||
else
|
||||
{
|
||||
c.r = (unsigned char) luaL_checknumber(L, 2);
|
||||
c.g = (unsigned char) luaL_checknumber(L, 3);
|
||||
c.b = (unsigned char) luaL_checknumber(L, 4);
|
||||
c.a = (unsigned char) luaL_optnumber(L, 5, 255);
|
||||
c.r = (unsigned char) (luaL_checknumber(L, 2) * 255.0);
|
||||
c.g = (unsigned char) (luaL_checknumber(L, 3) * 255.0);
|
||||
c.b = (unsigned char) (luaL_checknumber(L, 4) * 255.0);
|
||||
c.a = (unsigned char) (luaL_optnumber(L, 5, 1.0) * 255.0);
|
||||
}
|
||||
|
||||
t->setColor(c);
|
||||
@@ -173,10 +173,10 @@ int w_SpriteBatch_getColor(lua_State *L)
|
||||
if (!color)
|
||||
return 0;
|
||||
|
||||
lua_pushnumber(L, color->r);
|
||||
lua_pushnumber(L, color->g);
|
||||
lua_pushnumber(L, color->b);
|
||||
lua_pushnumber(L, color->a);
|
||||
lua_pushnumber(L, (lua_Number) color->r / 255.0);
|
||||
lua_pushnumber(L, (lua_Number) color->g / 255.0);
|
||||
lua_pushnumber(L, (lua_Number) color->b / 255.0);
|
||||
lua_pushnumber(L, (lua_Number) color->a / 255.0);
|
||||
|
||||
return 4;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ Text *luax_checktext(lua_State *L, int idx)
|
||||
void luax_checkcoloredstring(lua_State *L, int idx, std::vector<Font::ColoredString> &strings)
|
||||
{
|
||||
Font::ColoredString coloredstr;
|
||||
coloredstr.color = Color(255, 255, 255, 255);
|
||||
coloredstr.color = Colorf(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
|
||||
if (lua_istable(L, idx))
|
||||
{
|
||||
@@ -50,10 +50,10 @@ void luax_checkcoloredstring(lua_State *L, int idx, std::vector<Font::ColoredStr
|
||||
for (int j = 1; j <= 4; j++)
|
||||
lua_rawgeti(L, -j, j);
|
||||
|
||||
coloredstr.color.r = (unsigned char) luaL_checknumber(L, -4);
|
||||
coloredstr.color.g = (unsigned char) luaL_checknumber(L, -3);
|
||||
coloredstr.color.b = (unsigned char) luaL_checknumber(L, -2);
|
||||
coloredstr.color.a = (unsigned char) luaL_optnumber(L, -1, 255);
|
||||
coloredstr.color.r = (float) luaL_checknumber(L, -4);
|
||||
coloredstr.color.g = (float) luaL_checknumber(L, -3);
|
||||
coloredstr.color.b = (float) luaL_checknumber(L, -2);
|
||||
coloredstr.color.a = (float) luaL_optnumber(L, -1, 1.0);
|
||||
|
||||
lua_pop(L, 4);
|
||||
}
|
||||
|
||||
@@ -74,10 +74,10 @@ int w_ImageData_getPixel(lua_State *L)
|
||||
|
||||
luax_catchexcept(L, [&](){ c = t->getPixel(x, y); });
|
||||
|
||||
lua_pushnumber(L, c.r);
|
||||
lua_pushnumber(L, c.g);
|
||||
lua_pushnumber(L, c.b);
|
||||
lua_pushnumber(L, c.a);
|
||||
lua_pushnumber(L, (lua_Number) c.r / 255.0);
|
||||
lua_pushnumber(L, (lua_Number) c.g / 255.0);
|
||||
lua_pushnumber(L, (lua_Number) c.b / 255.0);
|
||||
lua_pushnumber(L, (lua_Number) c.a / 255.0);
|
||||
return 4;
|
||||
}
|
||||
|
||||
@@ -93,19 +93,19 @@ int w_ImageData_setPixel(lua_State *L)
|
||||
for (int i = 1; i <= 4; i++)
|
||||
lua_rawgeti(L, 4, i);
|
||||
|
||||
c.r = (unsigned char)luaL_checkinteger(L, -4);
|
||||
c.g = (unsigned char)luaL_checkinteger(L, -3);
|
||||
c.b = (unsigned char)luaL_checkinteger(L, -2);
|
||||
c.a = (unsigned char)luaL_optinteger(L, -1, 255);
|
||||
c.r = (unsigned char) (luaL_checknumber(L, -4) * 255.0);
|
||||
c.g = (unsigned char) (luaL_checknumber(L, -3) * 255.0);
|
||||
c.b = (unsigned char) (luaL_checknumber(L, -2) * 255.0);
|
||||
c.a = (unsigned char) (luaL_optnumber(L, -1, 1.0) * 255.0);
|
||||
|
||||
lua_pop(L, 4);
|
||||
}
|
||||
else
|
||||
{
|
||||
c.r = (unsigned char)luaL_checkinteger(L, 4);
|
||||
c.g = (unsigned char)luaL_checkinteger(L, 5);
|
||||
c.b = (unsigned char)luaL_checkinteger(L, 6);
|
||||
c.a = (unsigned char)luaL_optinteger(L, 7, 255);
|
||||
c.r = (unsigned char) (luaL_checknumber(L, 4) * 255.0);
|
||||
c.g = (unsigned char) (luaL_checknumber(L, 5) * 255.0);
|
||||
c.b = (unsigned char) (luaL_checknumber(L, 6) * 255.0);
|
||||
c.a = (unsigned char) (luaL_optnumber(L, 7, 1.0) * 255.0);
|
||||
}
|
||||
|
||||
luax_catchexcept(L, [&](){ t->setPixel(x, y, c); });
|
||||
@@ -182,7 +182,7 @@ int w_ImageData__mapPixelUnsafe(lua_State *L)
|
||||
int ttype = lua_type(L, -4 + i);
|
||||
|
||||
if (ttype == LUA_TNUMBER)
|
||||
parray[i] = (unsigned char) lua_tonumber(L, -4 + i);
|
||||
parray[i] = (unsigned char) (lua_tonumber(L, -4 + i) * 255.0);
|
||||
else if (i == 3 && (ttype == LUA_TNONE || ttype == LUA_TNIL))
|
||||
parray[i] = 255; // Alpha component defaults to 255.
|
||||
else
|
||||
|
||||
@@ -132,10 +132,10 @@ function ImageData:_mapPixelUnsafe(func, ix, iy, iw, ih)
|
||||
for x=ix, ix+iw-1 do
|
||||
local p = pixels[y*idw+x]
|
||||
local r, g, b, a = func(x, y, tonumber(p.r), tonumber(p.g), tonumber(p.b), tonumber(p.a))
|
||||
pixels[y*idw+x].r = r
|
||||
pixels[y*idw+x].g = g
|
||||
pixels[y*idw+x].b = b
|
||||
pixels[y*idw+x].a = a == nil and 255 or a
|
||||
pixels[y*idw+x].r = r * 255
|
||||
pixels[y*idw+x].g = g * 255
|
||||
pixels[y*idw+x].b = b * 255
|
||||
pixels[y*idw+x].a = a == nil and 255 or (a*255)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -152,7 +152,7 @@ function ImageData:getPixel(x, y)
|
||||
local r, g, b, a = tonumber(pixel.r), tonumber(pixel.g), tonumber(pixel.b), tonumber(pixel.a)
|
||||
ffifuncs.unlockMutex(self)
|
||||
|
||||
return r, g, b, a
|
||||
return r / 255, g / 255, b / 255, a / 255
|
||||
end
|
||||
|
||||
local temppixel = ffi.new("ImageData_Pixel")
|
||||
@@ -174,10 +174,10 @@ function ImageData:setPixel(x, y, r, g, b, a)
|
||||
local p = objectcache[self]
|
||||
if not inside(x, y, p.width, p.height) then error("Attempt to set out-of-range pixel!", 2) end
|
||||
|
||||
temppixel.r = r
|
||||
temppixel.g = g
|
||||
temppixel.b = b
|
||||
temppixel.a = a == nil and 255 or a
|
||||
temppixel.r = r * 255
|
||||
temppixel.g = g * 255
|
||||
temppixel.b = b * 255
|
||||
temppixel.a = a == nil and 255 or a * 255
|
||||
|
||||
ffifuncs.lockMutex(self)
|
||||
p.pointer[y * p.width + x] = temppixel
|
||||
|
||||
@@ -234,7 +234,7 @@ static int getGammaArgs(lua_State *L, float color[4])
|
||||
for (int i = 1; i <= n && i <= 4; i++)
|
||||
{
|
||||
lua_rawgeti(L, 1, i);
|
||||
color[i - 1] = (float) luaL_checknumber(L, -1) / 255.0f;
|
||||
color[i - 1] = (float) luaL_checknumber(L, -1);
|
||||
numcomponents++;
|
||||
}
|
||||
|
||||
@@ -245,7 +245,7 @@ static int getGammaArgs(lua_State *L, float color[4])
|
||||
int n = lua_gettop(L);
|
||||
for (int i = 1; i <= n && i <= 4; i++)
|
||||
{
|
||||
color[i - 1] = (float) luaL_checknumber(L, i) / 255.0f;
|
||||
color[i - 1] = (float) luaL_checknumber(L, i);
|
||||
numcomponents++;
|
||||
}
|
||||
}
|
||||
@@ -266,7 +266,7 @@ int w_gammaToLinear(lua_State *L)
|
||||
// Alpha should always be linear.
|
||||
if (i < 3)
|
||||
color[i] = Math::instance.gammaToLinear(color[i]);
|
||||
lua_pushnumber(L, color[i] * 255);
|
||||
lua_pushnumber(L, color[i]);
|
||||
}
|
||||
|
||||
return numcomponents;
|
||||
@@ -282,7 +282,7 @@ int w_linearToGamma(lua_State *L)
|
||||
// Alpha should always be linear.
|
||||
if (i < 3)
|
||||
color[i] = Math::instance.linearToGamma(color[i]);
|
||||
lua_pushnumber(L, color[i] * 255);
|
||||
lua_pushnumber(L, color[i]);
|
||||
}
|
||||
|
||||
return numcomponents;
|
||||
|
||||
@@ -95,7 +95,7 @@ end
|
||||
|
||||
local function gammaToLinear(c)
|
||||
if c ~= nil then
|
||||
return tonumber(ffifuncs.gammaToLinear(c / 255)) * 255
|
||||
return tonumber(ffifuncs.gammaToLinear(c))
|
||||
end
|
||||
return c
|
||||
end
|
||||
@@ -110,7 +110,7 @@ end
|
||||
|
||||
local function linearToGamma(c)
|
||||
if c ~= nil then
|
||||
return tonumber(ffifuncs.linearToGamma(c / 255)) * 255
|
||||
return tonumber(ffifuncs.linearToGamma(c))
|
||||
end
|
||||
return c
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user