Created
December 6, 2015 09:20
-
-
Save yumetodo/dad352ffdc27c19cf825 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <stdexcept> | |
#include <cstdint> | |
#define CONSTEXPR_FUNCTION constexpr | |
void foo() noexcept(false) { | |
throw std::runtime_error("error test"); | |
} | |
namespace detail { | |
CONSTEXPR_FUNCTION uint8_t DxGetRValue(unsigned int X8R8G8B8) { return static_cast<uint8_t>((0x00FF0000 & X8R8G8B8) >> 16); } | |
CONSTEXPR_FUNCTION uint8_t DxGetGValue(unsigned int X8R8G8B8) { return static_cast<uint8_t>((0x0000FF00 & X8R8G8B8) >> 8); } | |
CONSTEXPR_FUNCTION uint8_t DxGetBValue(unsigned int X8R8G8B8) { return static_cast<uint8_t>(0x000000FF & X8R8G8B8); } | |
struct RGB_t { | |
RGB_t() = default; | |
CONSTEXPR_FUNCTION RGB_t(uint8_t i_r, uint8_t i_g, uint8_t i_b) : r(i_r), g(i_g), b(i_b) {} | |
explicit CONSTEXPR_FUNCTION RGB_t(unsigned int X8R8G8B8) : RGB_t(DxGetRValue(X8R8G8B8), DxGetGValue(X8R8G8B8), DxGetBValue(X8R8G8B8)) {}//C++11:delegating constructor | |
uint8_t r; | |
uint8_t g; | |
uint8_t b; | |
}; | |
RGB_t& operator+=(RGB_t& l, const RGB_t& r) { | |
l.r += r.r; | |
l.g += r.g; | |
l.b += r.b; | |
return l; | |
} | |
struct YPbPr {//ITU-R BT.709 cf.)http://koujinz.cocolog-nifty.com/blog/2009/03/rgbycbcr-a4a5.html | |
YPbPr() = default; | |
CONSTEXPR_FUNCTION YPbPr(uint8_t i_y, uint8_t i_pb, uint8_t i_pr) : y(i_y), pb(i_pb), pr(i_pr) {} | |
explicit CONSTEXPR_FUNCTION YPbPr(uint8_t i_y) : YPbPr(i_y, 0, 0) {}//C++11:delegating constructor | |
uint8_t y, pb, pr; | |
}; | |
CONSTEXPR_FUNCTION YPbPr to_YPbPr(RGB_t in) { | |
return YPbPr(static_cast<uint8_t>(0.2126 * in.r + 0.7152 * in.g + 0.0722 * in.b), static_cast<uint8_t>(-0.1146 * in.r - 0.3854 * in.g + 0.5 * in.b), static_cast<uint8_t>(0.5 * in.r - 0.4542 * in.g - 0.0458 * in.b)); | |
} | |
CONSTEXPR_FUNCTION RGB_t to_RGB_t(YPbPr in) { | |
return RGB_t(static_cast<uint8_t>(in.y + 1.5748 * in.pr), static_cast<uint8_t>(in.y - 0.1873 * in.pb - 0.4681 * in.pr), static_cast<uint8_t>(in.y + 1.8556 * in.pb)); | |
} | |
} | |
int main() { | |
constexpr auto c = detail::YPbPr(122); | |
constexpr auto c2 = detail::to_RGB_t(c); | |
std::cout << "arikitari_na_world!" | |
<< static_cast<unsigned int>(c2.r) << ", " | |
<< static_cast<unsigned int>(c2.g) << ", " | |
<< static_cast<unsigned int>(c2.b) << " " | |
<< _MSC_FULL_VER | |
<< std::endl; | |
try { | |
foo(); | |
} | |
catch (const std::exception& er) { | |
std::cerr << er.what() << std::endl; | |
} | |
system("pause"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment