1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Changed ColorPutter in preparation for Bloodlust & Petrify effects

This commit is contained in:
Ivan Savenko 2022-12-14 15:17:38 +02:00
parent 3693184e51
commit 7e35a96055
3 changed files with 47 additions and 22 deletions

View File

@ -628,7 +628,7 @@ void FadingAnimation::nextFrame()
uint8_t blue = stack->cloned ? 128 : 0;
uint8_t alpha = CSDL_Ext::lerp(from, dest, progress);
ColorShifterMultiplyAndAdd shifterFade ({factor, factor, factor, alpha}, {0, 0, blue, 0});
ColorShifterRange shifterFade ({0, 0, blue, 0}, {factor, factor, 255, alpha});
stackAnimation(stack)->shiftColor(&shifterFade);
if (progress == 1.0f)

View File

@ -76,10 +76,10 @@ BattleStacksController::BattleStacksController(BattleInterface & owner):
amountNegative = IImage::createFromFile("CMNUMWIN.BMP");
amountEffNeutral = IImage::createFromFile("CMNUMWIN.BMP");
static const ColorShifterMultiplyAndAddExcept shifterNormal ({150, 50, 255, 255}, {0,0,0,0}, {255, 231, 132, 255});
static const ColorShifterMultiplyAndAddExcept shifterPositive({ 50, 255, 50, 255}, {0,0,0,0}, {255, 231, 132, 255});
static const ColorShifterMultiplyAndAddExcept shifterNegative({255, 50, 50, 255}, {0,0,0,0}, {255, 231, 132, 255});
static const ColorShifterMultiplyAndAddExcept shifterNeutral ({255, 255, 50, 255}, {0,0,0,0}, {255, 231, 132, 255});
static const ColorShifterRangeExcept shifterNormal ({0,0,0,0}, {150, 50, 255, 255}, {255, 231, 132, 255});
static const ColorShifterRangeExcept shifterPositive({0,0,0,0}, { 50, 255, 50, 255}, {255, 231, 132, 255});
static const ColorShifterRangeExcept shifterNegative({0,0,0,0}, {255, 50, 50, 255}, {255, 231, 132, 255});
static const ColorShifterRangeExcept shifterNeutral ({0,0,0,0}, {255, 255, 50, 255}, {255, 231, 132, 255});
amountNormal->adjustPalette(&shifterNormal);
amountPositive->adjustPalette(&shifterPositive);
@ -213,7 +213,7 @@ void BattleStacksController::stackAdded(const CStack * stack, bool instant)
if (!instant)
{
ColorShifterMultiplyAndAdd shifterFade ({255, 255, 255, 0}, {0, 0, 0, 0});
ColorShifterRange shifterFade ({0, 0, 0, 0}, {255, 255, 255, 0});
stackAnimation[stack->ID]->shiftColor(&shifterFade);
owner.executeOnAnimationCondition(EAnimationEvents::HIT, true, [=]()

View File

@ -167,37 +167,44 @@ public:
};
/// Generic class for palette transformation
/// formula:
/// result = input * factor + added
class ColorShifterMultiplyAndAdd : public ColorShifter
/// Applies linear transformation to move all colors into range (min, max)
class ColorShifterRange : public ColorShifter
{
SDL_Color added;
SDL_Color base;
SDL_Color factor;
public:
ColorShifterMultiplyAndAdd(SDL_Color factor, SDL_Color added) :
factor(factor),
added(added)
{}
ColorShifterRange(SDL_Color min, SDL_Color max) :
base(min)
{
assert(max.r >= min.r);
assert(max.g >= min.g);
assert(max.b >= min.b);
assert(max.a >= min.a);
factor.r = max.r - min.r;
factor.g = max.g - min.g;
factor.b = max.b - min.b;
factor.a = max.a - min.a;
}
SDL_Color shiftColor(SDL_Color input) const override
{
return {
uint8_t(std::min(255.f, std::round(input.r * float(factor.r) / 255.f + added.r))),
uint8_t(std::min(255.f, std::round(input.g * float(factor.g) / 255.f + added.g))),
uint8_t(std::min(255.f, std::round(input.b * float(factor.b) / 255.f + added.b))),
uint8_t(std::min(255.f, std::round(input.a * float(factor.a) / 255.f + added.a)))
uint8_t(base.r + input.r * factor.r / 255),
uint8_t(base.g + input.g * factor.g / 255),
uint8_t(base.b + input.b * factor.b / 255),
uint8_t(base.a + input.a * factor.a / 255),
};
}
};
/// Color shifter that allows to specify color to be excempt from changes
class ColorShifterMultiplyAndAddExcept : public ColorShifterMultiplyAndAdd
class ColorShifterRangeExcept : public ColorShifterRange
{
SDL_Color ignored;
public:
ColorShifterMultiplyAndAddExcept(SDL_Color factor, SDL_Color added, SDL_Color ignored) :
ColorShifterMultiplyAndAdd(factor, added),
ColorShifterRangeExcept(SDL_Color min, SDL_Color max, SDL_Color ignored) :
ColorShifterRange(min, max),
ignored(ignored)
{}
@ -205,7 +212,25 @@ public:
{
if ( input.r == ignored.r && input.g == ignored.g && input.b == ignored.b && input.a == ignored.a)
return input;
return ColorShifterMultiplyAndAdd::shiftColor(input);
return ColorShifterRange::shiftColor(input);
}
};
class ColorShifterGrayscale : public ColorShifter
{
public:
SDL_Color shiftColor(SDL_Color input) const override
{
// Apply grayscale conversion according to human eye perception values
uint32_t gray = static_cast<uint32_t>(0.299 * input.r + 0.587 * input.g + 0.114 * input.b);
assert(gray < 256);
return {
uint8_t(gray),
uint8_t(gray),
uint8_t(gray),
input.a
};
}
};