Browse Source

Color values in love's APIs are now in the range of [0, 1] rather than [0, 255].

--HG--
branch : minor
Alex Szpakowski 9 years ago
parent
commit
ed933847f8

+ 1 - 21
src/modules/graphics/ParticleSystem.cpp

@@ -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)

+ 9 - 3
src/modules/graphics/opengl/Font.cpp

@@ -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;

+ 2 - 2
src/modules/graphics/opengl/Font.h

@@ -64,12 +64,12 @@ public:
 	struct ColoredString
 	{
 		std::string str;
-		Color color;
+		Colorf color;
 	};
 
 	struct IndexedColor
 	{
-		Color color;
+		Colorf color;
 		int index;
 	};
 

+ 5 - 8
src/modules/graphics/opengl/Graphics.cpp

@@ -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;
 }
 

+ 3 - 3
src/modules/graphics/opengl/Graphics.h

@@ -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;

+ 15 - 15
src/modules/graphics/opengl/wrap_Graphics.cpp

@@ -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);
 			}

+ 2 - 2
src/modules/graphics/opengl/wrap_Mesh.cpp

@@ -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;
 }

+ 1 - 1
src/modules/graphics/opengl/wrap_ParticleSystem.cpp

@@ -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);

+ 5 - 10
src/modules/graphics/opengl/wrap_Shader.cpp

@@ -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]);
 		}
 	}
 

+ 12 - 12
src/modules/graphics/opengl/wrap_SpriteBatch.cpp

@@ -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;
 }

+ 5 - 5
src/modules/graphics/opengl/wrap_Text.cpp

@@ -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);
 			}

+ 13 - 13
src/modules/image/wrap_ImageData.cpp

@@ -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

+ 9 - 9
src/modules/image/wrap_ImageData.lua

@@ -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

+ 4 - 4
src/modules/math/wrap_Math.cpp

@@ -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;

+ 2 - 2
src/modules/math/wrap_Math.lua

@@ -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

+ 2 - 2
src/scripts/boot.lua

@@ -600,8 +600,8 @@ function love.errhand(msg)
 	love.graphics.reset()
 	local font = love.graphics.setNewFont(math.floor(love.window.toPixels(14)))
 
-	love.graphics.setBackgroundColor(89, 157, 220)
-	love.graphics.setColor(255, 255, 255, 255)
+	love.graphics.setBackgroundColor(89/255, 157/255, 220/255)
+	love.graphics.setColor(1, 1, 1, 1)
 
 	local trace = debug.traceback()
 

+ 3 - 3
src/scripts/boot.lua.h

@@ -1101,10 +1101,10 @@ const unsigned char boot_lua[] =
 	0x34, 0x29, 0x29, 0x29, 0x0a,
 	0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x73, 0x2e, 0x73, 0x65, 0x74, 
 	0x42, 0x61, 0x63, 0x6b, 0x67, 0x72, 0x6f, 0x75, 0x6e, 0x64, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x38, 0x39, 
-	0x2c, 0x20, 0x31, 0x35, 0x37, 0x2c, 0x20, 0x32, 0x32, 0x30, 0x29, 0x0a,
+	0x2f, 0x32, 0x35, 0x35, 0x2c, 0x20, 0x31, 0x35, 0x37, 0x2f, 0x32, 0x35, 0x35, 0x2c, 0x20, 0x32, 0x32, 0x30, 
+	0x2f, 0x32, 0x35, 0x35, 0x29, 0x0a,
 	0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x73, 0x2e, 0x73, 0x65, 0x74, 
-	0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x32, 0x35, 0x35, 0x2c, 0x20, 0x32, 0x35, 0x35, 0x2c, 0x20, 0x32, 0x35, 
-	0x35, 0x2c, 0x20, 0x32, 0x35, 0x35, 0x29, 0x0a,
+	0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x31, 0x2c, 0x20, 0x31, 0x2c, 0x20, 0x31, 0x2c, 0x20, 0x31, 0x29, 0x0a,
 	0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x72, 0x61, 0x63, 0x65, 0x20, 0x3d, 0x20, 0x64, 0x65, 0x62, 
 	0x75, 0x67, 0x2e, 0x74, 0x72, 0x61, 0x63, 0x65, 0x62, 0x61, 0x63, 0x6b, 0x28, 0x29, 0x0a,
 	0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x73, 0x2e, 0x63, 0x6c, 0x65, 

+ 10 - 10
src/scripts/nogame.lua

@@ -746,17 +746,17 @@ function love.nogame()
 		local COLORS = {}
 
 		for _,color in ipairs({
-			{ 240, 240, 240 }, -- WHITE (ish)
-			{ 232, 104, 162}, -- PINK
-			{ 69, 155, 168 }, -- BLUE
-			{ 67, 93, 119 }, -- DARK BLUE
+			{ 15/16, 15/16, 15/16 }, -- WHITE (ish)
+			{ 232/255, 104/255, 162/255 }, -- PINK
+			{ 69/255, 155/255, 168/255 }, -- BLUE
+			{ 67/255, 93/255, 119/255 }, -- DARK BLUE
 		}) do
 			table.insert(COLORS, color)
 			table.insert(COLORS, color)
 		end
 
 		-- Insert only once. This way it appears half as often.
-		table.insert(COLORS, { 220, 239, 113 }) -- LIME
+		table.insert(COLORS, { 220/255, 239/255, 113/255 }) -- LIME
 
 		-- When using the higher-res mosaic sprite sheet, we want to draw its
 		-- sprites at the same scale as the regular-resolution one, because
@@ -859,7 +859,7 @@ function love.nogame()
 			T = love.graphics.newQuad(96, 64, 32, 32, sw, sh),
 		}
 
-		local INITIAL_TEXT_COLOR = { 240, 240, 240 }
+		local INITIAL_TEXT_COLOR = { 15/16, 15/16, 15/16 }
 
 		local put_text = function(str, offset, x, y)
 			local idx = offset + SIZE_X * y + x
@@ -916,7 +916,7 @@ function love.nogame()
 
 	function Mosaic:draw()
 		self.batch:clear()
-		love.graphics.setColor(255, 255, 255, 64)
+		love.graphics.setColor(1, 1, 1, 0.25)
 		for idx,piece in ipairs(self.pieces) do
 			local ct = 1 - self.color_t
 			local c0 = piece.color.prev
@@ -928,12 +928,12 @@ function love.nogame()
 			self.batch:setColor(r, g, b)
 			self.batch:add(piece.quad, piece.x, piece.y, piece.r, 1, 1, 16, 16)
 		end
-		love.graphics.setColor(255, 255, 255, 255)
+		love.graphics.setColor(1, 1, 1, 1)
 		love.graphics.draw(self.batch, 0, 0)
 	end
 
 	function love.load()
-		love.graphics.setBackgroundColor(136, 193, 206)
+		love.graphics.setBackgroundColor(136/255, 193/255, 206/255)
 
 		local function load_image(file, name)
 			return love.graphics.newImage(love.filesystem.newFileData(file, name:gsub("_", "."), "base64"))
@@ -964,7 +964,7 @@ function love.nogame()
 	end
 
 	function love.draw()
-		love.graphics.setColor(255, 255, 255)
+		love.graphics.setColor(1, 1, 1)
 		love.graphics.push()
 		love.graphics.scale(love.window.getPixelScale())
 		g_entities.mosaic:draw()

+ 23 - 19
src/scripts/nogame.lua.h

@@ -3161,14 +3161,18 @@ const unsigned char nogame_lua[] =
 	0x7d, 0x0a,
 	0x09, 0x09, 0x66, 0x6f, 0x72, 0x20, 0x5f, 0x2c, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x69, 0x6e, 0x20, 0x69, 
 	0x70, 0x61, 0x69, 0x72, 0x73, 0x28, 0x7b, 0x0a,
-	0x09, 0x09, 0x09, 0x7b, 0x20, 0x32, 0x34, 0x30, 0x2c, 0x20, 0x32, 0x34, 0x30, 0x2c, 0x20, 0x32, 0x34, 0x30, 
-	0x20, 0x7d, 0x2c, 0x20, 0x2d, 0x2d, 0x20, 0x57, 0x48, 0x49, 0x54, 0x45, 0x20, 0x28, 0x69, 0x73, 0x68, 0x29, 0x0a,
-	0x09, 0x09, 0x09, 0x7b, 0x20, 0x32, 0x33, 0x32, 0x2c, 0x20, 0x31, 0x30, 0x34, 0x2c, 0x20, 0x31, 0x36, 0x32, 
-	0x7d, 0x2c, 0x20, 0x2d, 0x2d, 0x20, 0x50, 0x49, 0x4e, 0x4b, 0x0a,
-	0x09, 0x09, 0x09, 0x7b, 0x20, 0x36, 0x39, 0x2c, 0x20, 0x31, 0x35, 0x35, 0x2c, 0x20, 0x31, 0x36, 0x38, 0x20, 
-	0x7d, 0x2c, 0x20, 0x2d, 0x2d, 0x20, 0x42, 0x4c, 0x55, 0x45, 0x0a,
-	0x09, 0x09, 0x09, 0x7b, 0x20, 0x36, 0x37, 0x2c, 0x20, 0x39, 0x33, 0x2c, 0x20, 0x31, 0x31, 0x39, 0x20, 0x7d, 
-	0x2c, 0x20, 0x2d, 0x2d, 0x20, 0x44, 0x41, 0x52, 0x4b, 0x20, 0x42, 0x4c, 0x55, 0x45, 0x0a,
+	0x09, 0x09, 0x09, 0x7b, 0x20, 0x31, 0x35, 0x2f, 0x31, 0x36, 0x2c, 0x20, 0x31, 0x35, 0x2f, 0x31, 0x36, 0x2c, 
+	0x20, 0x31, 0x35, 0x2f, 0x31, 0x36, 0x20, 0x7d, 0x2c, 0x20, 0x2d, 0x2d, 0x20, 0x57, 0x48, 0x49, 0x54, 0x45, 
+	0x20, 0x28, 0x69, 0x73, 0x68, 0x29, 0x0a,
+	0x09, 0x09, 0x09, 0x7b, 0x20, 0x32, 0x33, 0x32, 0x2f, 0x32, 0x35, 0x35, 0x2c, 0x20, 0x31, 0x30, 0x34, 0x2f, 
+	0x32, 0x35, 0x35, 0x2c, 0x20, 0x31, 0x36, 0x32, 0x2f, 0x32, 0x35, 0x35, 0x20, 0x7d, 0x2c, 0x20, 0x2d, 0x2d, 
+	0x20, 0x50, 0x49, 0x4e, 0x4b, 0x0a,
+	0x09, 0x09, 0x09, 0x7b, 0x20, 0x36, 0x39, 0x2f, 0x32, 0x35, 0x35, 0x2c, 0x20, 0x31, 0x35, 0x35, 0x2f, 0x32, 
+	0x35, 0x35, 0x2c, 0x20, 0x31, 0x36, 0x38, 0x2f, 0x32, 0x35, 0x35, 0x20, 0x7d, 0x2c, 0x20, 0x2d, 0x2d, 0x20, 
+	0x42, 0x4c, 0x55, 0x45, 0x0a,
+	0x09, 0x09, 0x09, 0x7b, 0x20, 0x36, 0x37, 0x2f, 0x32, 0x35, 0x35, 0x2c, 0x20, 0x39, 0x33, 0x2f, 0x32, 0x35, 
+	0x35, 0x2c, 0x20, 0x31, 0x31, 0x39, 0x2f, 0x32, 0x35, 0x35, 0x20, 0x7d, 0x2c, 0x20, 0x2d, 0x2d, 0x20, 0x44, 
+	0x41, 0x52, 0x4b, 0x20, 0x42, 0x4c, 0x55, 0x45, 0x0a,
 	0x09, 0x09, 0x7d, 0x29, 0x20, 0x64, 0x6f, 0x0a,
 	0x09, 0x09, 0x09, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x2e, 0x69, 0x6e, 0x73, 0x65, 0x72, 0x74, 0x28, 0x43, 0x4f, 
 	0x4c, 0x4f, 0x52, 0x53, 0x2c, 0x20, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x29, 0x0a,
@@ -3180,8 +3184,9 @@ const unsigned char nogame_lua[] =
 	0x70, 0x70, 0x65, 0x61, 0x72, 0x73, 0x20, 0x68, 0x61, 0x6c, 0x66, 0x20, 0x61, 0x73, 0x20, 0x6f, 0x66, 0x74, 
 	0x65, 0x6e, 0x2e, 0x0a,
 	0x09, 0x09, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x2e, 0x69, 0x6e, 0x73, 0x65, 0x72, 0x74, 0x28, 0x43, 0x4f, 0x4c, 
-	0x4f, 0x52, 0x53, 0x2c, 0x20, 0x7b, 0x20, 0x32, 0x32, 0x30, 0x2c, 0x20, 0x32, 0x33, 0x39, 0x2c, 0x20, 0x31, 
-	0x31, 0x33, 0x20, 0x7d, 0x29, 0x20, 0x2d, 0x2d, 0x20, 0x4c, 0x49, 0x4d, 0x45, 0x0a,
+	0x4f, 0x52, 0x53, 0x2c, 0x20, 0x7b, 0x20, 0x32, 0x32, 0x30, 0x2f, 0x32, 0x35, 0x35, 0x2c, 0x20, 0x32, 0x33, 
+	0x39, 0x2f, 0x32, 0x35, 0x35, 0x2c, 0x20, 0x31, 0x31, 0x33, 0x2f, 0x32, 0x35, 0x35, 0x20, 0x7d, 0x29, 0x20, 
+	0x2d, 0x2d, 0x20, 0x4c, 0x49, 0x4d, 0x45, 0x0a,
 	0x09, 0x09, 0x2d, 0x2d, 0x20, 0x57, 0x68, 0x65, 0x6e, 0x20, 0x75, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x68, 
 	0x65, 0x20, 0x68, 0x69, 0x67, 0x68, 0x65, 0x72, 0x2d, 0x72, 0x65, 0x73, 0x20, 0x6d, 0x6f, 0x73, 0x61, 0x69, 
 	0x63, 0x20, 0x73, 0x70, 0x72, 0x69, 0x74, 0x65, 0x20, 0x73, 0x68, 0x65, 0x65, 0x74, 0x2c, 0x20, 0x77, 0x65, 
@@ -3417,8 +3422,8 @@ const unsigned char nogame_lua[] =
 	0x20, 0x33, 0x32, 0x2c, 0x20, 0x33, 0x32, 0x2c, 0x20, 0x73, 0x77, 0x2c, 0x20, 0x73, 0x68, 0x29, 0x2c, 0x0a,
 	0x09, 0x09, 0x7d, 0x0a,
 	0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x49, 0x4e, 0x49, 0x54, 0x49, 0x41, 0x4c, 0x5f, 0x54, 0x45, 
-	0x58, 0x54, 0x5f, 0x43, 0x4f, 0x4c, 0x4f, 0x52, 0x20, 0x3d, 0x20, 0x7b, 0x20, 0x32, 0x34, 0x30, 0x2c, 0x20, 
-	0x32, 0x34, 0x30, 0x2c, 0x20, 0x32, 0x34, 0x30, 0x20, 0x7d, 0x0a,
+	0x58, 0x54, 0x5f, 0x43, 0x4f, 0x4c, 0x4f, 0x52, 0x20, 0x3d, 0x20, 0x7b, 0x20, 0x31, 0x35, 0x2f, 0x31, 0x36, 
+	0x2c, 0x20, 0x31, 0x35, 0x2f, 0x31, 0x36, 0x2c, 0x20, 0x31, 0x35, 0x2f, 0x31, 0x36, 0x20, 0x7d, 0x0a,
 	0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x70, 0x75, 0x74, 0x5f, 0x74, 0x65, 0x78, 0x74, 0x20, 0x3d, 
 	0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x73, 0x74, 0x72, 0x2c, 0x20, 0x6f, 0x66, 0x66, 
 	0x73, 0x65, 0x74, 0x2c, 0x20, 0x78, 0x2c, 0x20, 0x79, 0x29, 0x0a,
@@ -3525,8 +3530,8 @@ const unsigned char nogame_lua[] =
 	0x09, 0x09, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x62, 0x61, 0x74, 0x63, 0x68, 0x3a, 0x63, 0x6c, 0x65, 0x61, 0x72, 
 	0x28, 0x29, 0x0a,
 	0x09, 0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x73, 0x2e, 0x73, 0x65, 
-	0x74, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x32, 0x35, 0x35, 0x2c, 0x20, 0x32, 0x35, 0x35, 0x2c, 0x20, 0x32, 
-	0x35, 0x35, 0x2c, 0x20, 0x36, 0x34, 0x29, 0x0a,
+	0x74, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x31, 0x2c, 0x20, 0x31, 0x2c, 0x20, 0x31, 0x2c, 0x20, 0x30, 0x2e, 
+	0x32, 0x35, 0x29, 0x0a,
 	0x09, 0x09, 0x66, 0x6f, 0x72, 0x20, 0x69, 0x64, 0x78, 0x2c, 0x70, 0x69, 0x65, 0x63, 0x65, 0x20, 0x69, 0x6e, 
 	0x20, 0x69, 0x70, 0x61, 0x69, 0x72, 0x73, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x69, 0x65, 0x63, 0x65, 
 	0x73, 0x29, 0x20, 0x64, 0x6f, 0x0a,
@@ -3553,8 +3558,7 @@ const unsigned char nogame_lua[] =
 	0x72, 0x2c, 0x20, 0x31, 0x2c, 0x20, 0x31, 0x2c, 0x20, 0x31, 0x36, 0x2c, 0x20, 0x31, 0x36, 0x29, 0x0a,
 	0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
 	0x09, 0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x73, 0x2e, 0x73, 0x65, 
-	0x74, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x32, 0x35, 0x35, 0x2c, 0x20, 0x32, 0x35, 0x35, 0x2c, 0x20, 0x32, 
-	0x35, 0x35, 0x2c, 0x20, 0x32, 0x35, 0x35, 0x29, 0x0a,
+	0x74, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x31, 0x2c, 0x20, 0x31, 0x2c, 0x20, 0x31, 0x2c, 0x20, 0x31, 0x29, 0x0a,
 	0x09, 0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x73, 0x2e, 0x64, 0x72, 
 	0x61, 0x77, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x62, 0x61, 0x74, 0x63, 0x68, 0x2c, 0x20, 0x30, 0x2c, 0x20, 
 	0x30, 0x29, 0x0a,
@@ -3563,7 +3567,8 @@ const unsigned char nogame_lua[] =
 	0x64, 0x28, 0x29, 0x0a,
 	0x09, 0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x73, 0x2e, 0x73, 0x65, 
 	0x74, 0x42, 0x61, 0x63, 0x6b, 0x67, 0x72, 0x6f, 0x75, 0x6e, 0x64, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x31, 
-	0x33, 0x36, 0x2c, 0x20, 0x31, 0x39, 0x33, 0x2c, 0x20, 0x32, 0x30, 0x36, 0x29, 0x0a,
+	0x33, 0x36, 0x2f, 0x32, 0x35, 0x35, 0x2c, 0x20, 0x31, 0x39, 0x33, 0x2f, 0x32, 0x35, 0x35, 0x2c, 0x20, 0x32, 
+	0x30, 0x36, 0x2f, 0x32, 0x35, 0x35, 0x29, 0x0a,
 	0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6c, 
 	0x6f, 0x61, 0x64, 0x5f, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x28, 0x66, 0x69, 0x6c, 0x65, 0x2c, 0x20, 0x6e, 0x61, 
 	0x6d, 0x65, 0x29, 0x0a,
@@ -3629,8 +3634,7 @@ const unsigned char nogame_lua[] =
 	0x09, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x64, 0x72, 0x61, 
 	0x77, 0x28, 0x29, 0x0a,
 	0x09, 0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x73, 0x2e, 0x73, 0x65, 
-	0x74, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x32, 0x35, 0x35, 0x2c, 0x20, 0x32, 0x35, 0x35, 0x2c, 0x20, 0x32, 
-	0x35, 0x35, 0x29, 0x0a,
+	0x74, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x31, 0x2c, 0x20, 0x31, 0x2c, 0x20, 0x31, 0x29, 0x0a,
 	0x09, 0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x73, 0x2e, 0x70, 0x75, 
 	0x73, 0x68, 0x28, 0x29, 0x0a,
 	0x09, 0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x73, 0x2e, 0x73, 0x63,