Added SLADE3's colourise and tint translations.

Includes support for ACS.
Added tokens for '#' and '@' in sc_man_scanner.re.
This commit is contained in:
Gaerzi 2017-03-05 21:03:36 +01:00 committed by Christoph Oelckers
parent b4079b9915
commit ad89d3eea0
5 changed files with 135 additions and 12 deletions

View file

@ -9088,6 +9088,35 @@ scriptwait:
}
break;
case PCD_TRANSLATIONRANGE4:
{ // Colourise translation
int start = STACK(5);
int end = STACK(4);
int r = STACK(3);
int g = STACK(2);
int b = STACK(1);
sp -= 5;
if (translation != NULL)
translation->AddColourisation(start, end, r, g, b);
}
break;
case PCD_TRANSLATIONRANGE5:
{ // Tint translation
int start = STACK(6);
int end = STACK(5);
int a = STACK(4);
int r = STACK(3);
int g = STACK(2);
int b = STACK(1);
sp -= 6;
if (translation != NULL)
translation->AddTint(start, end, r, g, b, a);
}
break;
case PCD_ENDTRANSLATION:
if (translation != NULL)
{

View file

@ -779,6 +779,8 @@ public:
/*380*/ PCD_STRCPYTOSCRIPTCHRANGE,
PCD_LSPEC5EX,
PCD_LSPEC5EXRESULT,
PCD_TRANSLATIONRANGE4,
PCD_TRANSLATIONRANGE5,
/*381*/ PCODE_COMMAND_COUNT
};

View file

@ -487,6 +487,56 @@ void FRemapTable::AddDesaturation(int start, int end, double r1, double g1, doub
//
//----------------------------------------------------------------------------
void FRemapTable::AddColourisation(int start, int end, int r, int g, int b)
{
for (int i = start; i < end; ++i)
{
float br = GPalette.BaseColors[i].r;
float bg = GPalette.BaseColors[i].g;
float bb = GPalette.BaseColors[i].b;
float grey = (br * 0.299 + bg * 0.587 + bb * 0.114) / 255.0f;
if (grey > 1.0) grey = 1.0;
br = r * grey;
bg = g * grey;
bb = b * grey;
int j = GPalette.Remap[i];
Palette[j] = PalEntry(j == 0 ? 0 : 255, int(br), int(bg), int(bb));
Remap[j] = ColorMatcher.Pick(Palette[j]);
}
}
//----------------------------------------------------------------------------
//
//
//
//----------------------------------------------------------------------------
void FRemapTable::AddTint(int start, int end, int r, int g, int b, int amount)
{
for (int i = start; i < end; ++i)
{
float br = GPalette.BaseColors[i].r;
float bg = GPalette.BaseColors[i].g;
float bb = GPalette.BaseColors[i].b;
float a = amount * 0.01f;
float ia = 1.0f - a;
br = br * ia + r * a;
bg = bg * ia + g * a;
bb = bb * ia + b * a;
int j = GPalette.Remap[i];
Palette[j] = PalEntry(j == 0 ? 0 : 255, int(br), int(bg), int(bb));
Remap[j] = ColorMatcher.Pick(Palette[j]);
}
}
//----------------------------------------------------------------------------
//
//
//
//----------------------------------------------------------------------------
void FRemapTable::AddToTranslation(const char *range)
{
int start,end;
@ -511,19 +561,9 @@ void FRemapTable::AddToTranslation(const char *range)
}
sc.MustGetAnyToken();
Printf(0, "token type: %d", sc.TokenType);
if (sc.TokenType != '[' && sc.TokenType != '%')
{
int pal1,pal2;
sc.TokenMustBe(TK_IntConst);
pal1 = sc.Number;
sc.MustGetToken(':');
sc.MustGetToken(TK_IntConst);
pal2 = sc.Number;
AddIndexRange(start, end, pal1, pal2);
}
else if (sc.TokenType == '[')
if (sc.TokenType == '[')
{
// translation using RGB values
int r1,g1,b1,r2,g2,b2;
@ -596,6 +636,54 @@ void FRemapTable::AddToTranslation(const char *range)
AddDesaturation(start, end, r1, g1, b1, r2, g2, b2);
}
else if (sc.TokenType == '#')
{
// Colourise translation
int r, g, b;
sc.MustGetToken('[');
sc.MustGetToken(TK_IntConst);
r = sc.Number;
sc.MustGetToken(',');
sc.MustGetToken(TK_IntConst);
g = sc.Number;
sc.MustGetToken(',');
sc.MustGetToken(TK_IntConst);
b = sc.Number;
sc.MustGetToken(']');
AddColourisation(start, end, r, g, b);
}
else if (sc.TokenType == '@')
{
// Tint translation
int a, r, g, b;
sc.MustGetToken(TK_IntConst);
a = sc.Number;
sc.MustGetToken('[');
sc.MustGetToken(TK_IntConst);
r = sc.Number;
sc.MustGetToken(',');
sc.MustGetToken(TK_IntConst);
g = sc.Number;
sc.MustGetToken(',');
sc.MustGetToken(TK_IntConst);
b = sc.Number;
sc.MustGetToken(']');
AddTint(start, end, r, g, b, a);
}
else
{
int pal1, pal2;
sc.TokenMustBe(TK_IntConst);
pal1 = sc.Number;
sc.MustGetToken(':');
sc.MustGetToken(TK_IntConst);
pal2 = sc.Number;
AddIndexRange(start, end, pal1, pal2);
}
}
catch (CRecoverableError &err)
{

View file

@ -42,6 +42,8 @@ struct FRemapTable
void AddIndexRange(int start, int end, int pal1, int pal2);
void AddColorRange(int start, int end, int r1,int g1, int b1, int r2, int g2, int b2);
void AddDesaturation(int start, int end, double r1, double g1, double b1, double r2, double g2, double b2);
void AddColourisation(int start, int end, int r, int g, int b);
void AddTint(int start, int end, int r, int g, int b, int amount);
void AddToTranslation(const char * range);
int StoreTranslation(int slot);

View file

@ -255,6 +255,8 @@ std2:
"^" { RET('^'); }
"|" { RET('|'); }
"?" { RET('?'); }
"#" { RET('#'); }
"@" { RET('@'); }
[ \t\v\f\r]+ { goto std1; }
"\n" { goto newline; }