cginternals / libzeug

deprecated: C++ sanctuary for small but powerful and frequently required, stand alone features.
MIT License
16 stars 13 forks source link

Color asHex is faulty #110

Closed apopiak closed 9 years ago

apopiak commented 9 years ago

In Color.cpp:

std::string Color::asHex(bool alpha) const
{
    std::stringstream stream;
    stream << "#";

If rgba() returns 0 (for black) the hex is invalid. Because of setw(2) and setfill('0') the stringstream contains #00 instead of the expected #00000000.

    stream << std::hex << std::uppercase << std::setw(2) << std::setfill('0');

    if (alpha)
        stream << rgba();
    else
        stream << red() << green() << blue();

    return stream.str();
}