Implementation of sRGB image support. Overhauls the linearization setup to utilize the sRGB image types, as well as refactors the use of ColorF and ColorI to be properly internally consistent. ColorIs are used only for front-facing/editing/UI settings, and ColorFs, now renamed to LinearColorF to reduce confusion of purpose, are used for color info in the engine itself. This avoids confusing and expensive conversions back and forth between types and avoids botches with linearity. Majority work done by @rextimmy

This commit is contained in:
Areloch 2017-06-23 11:36:20 -05:00
parent 8780f83262
commit 25686ed4be
294 changed files with 3894 additions and 2813 deletions

View file

@ -1021,7 +1021,7 @@ DefineConsoleFunction( strrchrpos, S32, ( const char* str, const char* chr, S32
//----------------------------------------------------------------
DefineConsoleFunction(ColorFloatToInt, ColorI, (ColorF color), ,
DefineConsoleFunction(ColorFloatToInt, ColorI, (LinearColorF color), ,
"Convert from a float color to an integer color (0.0 - 1.0 to 0 to 255).\n"
"@param color Float color value to be converted in the form \"R G B A\", where R is red, G is green, B is blue, and A is alpha.\n"
"@return Converted color value (0 - 255)\n\n"
@ -1030,10 +1030,10 @@ DefineConsoleFunction(ColorFloatToInt, ColorI, (ColorF color), ,
"@endtsexample\n"
"@ingroup Strings")
{
return (ColorI)color;
return color.toColorI();
}
DefineConsoleFunction(ColorIntToFloat, ColorF, (ColorI color), ,
DefineConsoleFunction(ColorIntToFloat, LinearColorF, (ColorI color), ,
"Convert from a integer color to an float color (0 to 255 to 0.0 - 1.0).\n"
"@param color Integer color value to be converted in the form \"R G B A\", where R is red, G is green, B is blue, and A is alpha.\n"
"@return Converted color value (0.0 - 1.0)\n\n"
@ -1042,7 +1042,7 @@ DefineConsoleFunction(ColorIntToFloat, ColorF, (ColorI color), ,
"@endtsexample\n"
"@ingroup Strings")
{
return (ColorF)color;
return LinearColorF(color);
}
DefineConsoleFunction(ColorRGBToHEX, const char*, (ColorI color), ,
@ -1080,10 +1080,8 @@ DefineConsoleFunction(ColorHEXToRGB, ColorI, (const char* hex), ,
"@endtsexample\n"
"@ingroup Strings")
{
S32 rgb = dAtoui(hex, 16);
ColorI color;
color.set(rgb & 0x000000FF, (rgb & 0x0000FF00) >> 8, (rgb & 0x00FF0000) >> 16);
color.set(String(hex));
return color;
}

View file

@ -567,13 +567,13 @@ ConsoleSetType( TypeFlag )
//-----------------------------------------------------------------------------
// TypeColorF
//-----------------------------------------------------------------------------
ConsoleType(ColorF, TypeColorF, ColorF, "")
ImplementConsoleTypeCasters( TypeColorF, ColorF )
ConsoleType(LinearColorF, TypeColorF, LinearColorF, "")
ImplementConsoleTypeCasters( TypeColorF, LinearColorF )
ConsoleGetType( TypeColorF )
{
// Fetch color.
const ColorF* color = (ColorF*)dptr;
const LinearColorF* color = (LinearColorF*)dptr;
// Fetch stock color name.
StringTableEntry colorName = StockColor::name( *color );
@ -591,7 +591,7 @@ ConsoleGetType( TypeColorF )
ConsoleSetType( TypeColorF )
{
ColorF *tmpColor = (ColorF *) dptr;
LinearColorF *tmpColor = (LinearColorF *) dptr;
if(argc == 1)
{
// Is only a single argument passed?

View file

@ -122,7 +122,7 @@ DefineConsoleType( TypeParticleParameterString, const char * )
DefineConsoleType( TypeFlag, S32 )
DefineConsoleType( TypeColorI, ColorI )
DefineConsoleType( TypeColorF, ColorF )
DefineConsoleType( TypeColorF, LinearColorF )
DefineConsoleType( TypeSimObjectName, SimObject* )
DefineConsoleType( TypeShader, GFXShader * )

View file

@ -63,8 +63,8 @@ IMPLEMENT_STRUCT( ColorI,
END_IMPLEMENT_STRUCT;
IMPLEMENT_STRUCT( ColorF,
ColorF,,
IMPLEMENT_STRUCT( LinearColorF,
LinearColorF,,
"RGBA color quadruple in 32bit floating-point precision per channel." )
FIELD( red, red, 1, "Red channel value." )

View file

@ -38,7 +38,7 @@ namespace Torque {
}
class ColorI;
class ColorF;
class LinearColorF;
DECLARE_STRUCT_R(Vector< bool >);
@ -46,6 +46,6 @@ DECLARE_STRUCT_R(Vector< S32 >);
DECLARE_STRUCT_R(Vector< F32 >);
DECLARE_STRUCT_R(Torque::UUID);
DECLARE_STRUCT_R(ColorI);
DECLARE_STRUCT_R(ColorF);
DECLARE_STRUCT_R(LinearColorF);
#endif // !_ENGINESTRUCTS_H_

View file

@ -377,7 +377,7 @@ namespace PropertyInfo
//-----------------------------------------------------------------------------
// Colors
//-----------------------------------------------------------------------------
bool default_scan(const String &data, ColorF & result)
bool default_scan(const String &data, LinearColorF & result)
{
if(StringUnit::getUnitCount(data," ") == 3)
{
@ -389,7 +389,7 @@ namespace PropertyInfo
return true;
}
bool default_print(String & result, ColorF const & data)
bool default_print(String & result, LinearColorF const & data)
{
if(data.alpha == 1.0f)
result = String::ToString("%g %g %g",data.red,data.green,data.blue);

View file

@ -24,7 +24,7 @@
#define _PROPERTYPARSING_H_
class ColorI;
class ColorF;
class LinearColorF;
class Point2I;
class Point2F;
class Point3F;
@ -110,8 +110,8 @@ namespace PropertyInfo
bool default_print( String & result, const MatrixF & data );
// Colors
bool default_scan(const String &data, ColorF & result);
bool default_print(String & result, const ColorF & data);
bool default_scan(const String &data, LinearColorF & result);
bool default_print(String & result, const LinearColorF & data);
bool default_scan(const String &data, ColorI & result);
bool default_print(String & result, const ColorI & data);