New raster colorizer modes linear-rgba and linear-bgra
This commit is contained in:
parent
ac19076f0b
commit
a74543a145
2 changed files with 34 additions and 1 deletions
|
@ -61,9 +61,11 @@ class raster;
|
|||
enum colorizer_mode_enum : std::uint8_t
|
||||
{
|
||||
COLORIZER_INHERIT = 0, //!< The stop inherits the mode from the colorizer
|
||||
COLORIZER_LINEAR = 1, //!< Linear interpolation between colors
|
||||
COLORIZER_LINEAR = 1, //!< Linear interpolation between colors, each channel separately
|
||||
COLORIZER_DISCRETE = 2, //!< Single color for stop
|
||||
COLORIZER_EXACT = 3, //!< Only the exact value specified for the stop gets translated, others use the default
|
||||
COLORIZER_LINEAR_RGBA = 4,//!< Linear interpolation between colors, all channels combined as RGBA value
|
||||
COLORIZER_LINEAR_BGRA = 5,//!< Linear interpolation between colors, all channels combined as BGRA value
|
||||
colorizer_mode_enum_MAX
|
||||
};
|
||||
|
||||
|
|
|
@ -42,6 +42,8 @@ static const char *colorizer_mode_strings[] = {
|
|||
"linear",
|
||||
"discrete",
|
||||
"exact",
|
||||
"linear-rgba",
|
||||
"linear-bgra",
|
||||
""
|
||||
};
|
||||
|
||||
|
@ -257,6 +259,35 @@ unsigned raster_colorizer::get_color(float val) const
|
|||
|
||||
}
|
||||
break;
|
||||
case COLORIZER_LINEAR_RGBA:
|
||||
{
|
||||
if(nextStopValue == stopValue)
|
||||
{
|
||||
return stopColor.rgba();
|
||||
}
|
||||
|
||||
double fraction = (val - stopValue) / (nextStopValue - stopValue);
|
||||
double colorStart = static_cast<double>(stopColor.rgba());
|
||||
double colorEnd = static_cast<double>(nextStopColor.rgba());
|
||||
outputColor = color(colorStart + fraction * (colorEnd - colorStart));
|
||||
}
|
||||
break;
|
||||
case COLORIZER_LINEAR_BGRA:
|
||||
{
|
||||
if(nextStopValue == stopValue)
|
||||
{
|
||||
return stopColor.rgba();
|
||||
}
|
||||
|
||||
double fraction = (val - stopValue) / (nextStopValue - stopValue);
|
||||
std::swap(stopColor.red_, stopColor.blue_);
|
||||
std::swap(nextStopColor.red_, nextStopColor.blue_);
|
||||
double colorStart = static_cast<double>(stopColor.rgba());
|
||||
double colorEnd = static_cast<double>(nextStopColor.rgba());
|
||||
outputColor = color(colorStart + fraction * (colorEnd - colorStart));
|
||||
std::swap(outputColor.red_, outputColor.blue_);
|
||||
}
|
||||
break;
|
||||
case COLORIZER_DISCRETE:
|
||||
outputColor = stopColor;
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue