/*
This file is part of Ingen.
Copyright 2007-2016 David Robillard
Ingen is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free
Software Foundation, either version 3 of the License, or any later version.
Ingen is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU Affero General Public License for details.
You should have received a copy of the GNU Affero General Public License
along with Ingen. If not, see .
*/
#ifndef INGEN_GUI_RGBA_HPP
#define INGEN_GUI_RGBA_HPP
#include
#include
namespace ingen {
namespace gui {
inline uint32_t
rgba_to_uint(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
{
return ((static_cast(r) << 24) |
(static_cast(g) << 16) |
(static_cast(b) << 8) |
(static_cast(a)));
}
inline uint8_t
mono_interpolate(uint8_t v1, uint8_t v2, float f)
{
return static_cast(rintf((v2) * (f) + (v1) * (1 - (f))));
}
#define RGBA_R(x) (static_cast(x) >> 24)
#define RGBA_G(x) ((static_cast(x) >> 16) & 0xFF)
#define RGBA_B(x) ((static_cast(x) >> 8) & 0xFF)
#define RGBA_A(x) (static_cast(x) & 0xFF)
inline uint32_t
rgba_interpolate(uint32_t c1, uint32_t c2, float f)
{
return rgba_to_uint(
mono_interpolate(RGBA_R(c1), RGBA_R(c2), f),
mono_interpolate(RGBA_G(c1), RGBA_G(c2), f),
mono_interpolate(RGBA_B(c1), RGBA_B(c2), f),
mono_interpolate(RGBA_A(c1), RGBA_A(c2), f));
}
} // namespace gui
} // namespace ingen
#endif // INGEN_GUI_RGBA_HPP