2012-10-26 16:09:14 +02:00
|
|
|
// Copyright (c) 2012, Thomas Goyne <plorkyeran@aegisub.org>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice appear in all copies.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
|
|
|
#include "libaegisub/color.h"
|
|
|
|
|
2012-10-27 15:32:53 +02:00
|
|
|
#include "parser.h"
|
|
|
|
|
2012-10-26 16:09:14 +02:00
|
|
|
#include <boost/format.hpp>
|
|
|
|
|
|
|
|
namespace agi {
|
|
|
|
|
|
|
|
Color::Color(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
|
|
|
|
: r(r), g(g), b(b), a(a)
|
|
|
|
{ }
|
|
|
|
|
2013-12-12 01:29:48 +01:00
|
|
|
Color::Color(std::string const& str) {
|
2012-10-27 15:32:53 +02:00
|
|
|
parser::parse(*this, str);
|
2012-10-26 16:09:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string Color::GetAssStyleFormatted() const {
|
|
|
|
return str(boost::format("&H%02X%02X%02X%02X") % (int)a % (int)b % (int)g % (int)r);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Color::GetAssOverrideFormatted() const {
|
|
|
|
return str(boost::format("&H%02X%02X%02X&") % (int)b % (int)g % (int)r);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Color::GetSsaFormatted() const {
|
2014-05-26 00:03:01 +02:00
|
|
|
return std::to_string((a << 24) + (b << 16) + (g << 8) + r);
|
2012-10-26 16:09:14 +02:00
|
|
|
}
|
|
|
|
|
2014-03-02 16:24:06 +01:00
|
|
|
std::string Color::GetHexFormatted(bool rgba) const {
|
|
|
|
if (rgba)
|
|
|
|
return str(boost::format("#%02X%02X%02X%02X") % (int)r % (int)g % (int)b % (int)a);
|
2012-10-26 16:09:14 +02:00
|
|
|
return str(boost::format("#%02X%02X%02X") % (int)r % (int)g % (int)b);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Color::GetRgbFormatted() const {
|
|
|
|
return str(boost::format("rgb(%d, %d, %d)") % (int)r % (int)g % (int)b);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Color::operator==(Color const& col) const {
|
|
|
|
return r == col.r && g == col.g && b == col.b && a == col.a;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Color::operator!=(Color const& col) const {
|
|
|
|
return !(*this == col);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|