[vlc-devel] [PATCH 2/3] win32: added helper function HtmlColor2RGB
Sergey Radionov
rsatom at gmail.com
Sat Jan 14 17:24:40 CET 2012
---
common/win32_fullscreen.cpp | 59 +++++++++++++++++++++++++++++++++++++++++++
common/win32_fullscreen.h | 8 ++++++
2 files changed, 67 insertions(+), 0 deletions(-)
diff --git a/common/win32_fullscreen.cpp b/common/win32_fullscreen.cpp
index 0943849..0b677cb 100644
--- a/common/win32_fullscreen.cpp
+++ b/common/win32_fullscreen.cpp
@@ -31,6 +31,65 @@
#include "win32_fullscreen.h"
////////////////////////////////////////////////////////////////////////////////
+//helper functions
+////////////////////////////////////////////////////////////////////////////////
+inline bool IsHexChar(std::string::value_type ch)
+{
+ if( (ch >= '0' && ch <= '9') ||
+ (ch >= 'a' && ch <= 'f') ||
+ (ch >= 'A' && ch <= 'F') )
+ {
+ return true;
+ }
+ return false;
+}
+
+inline BYTE HexToBYTE(std::string::value_type ch1, std::string::value_type ch2)
+{
+ BYTE r = 0;
+
+ if ( (ch1 >= '0' && ch1 <= '9')) {
+ r = (ch1-'0');
+ }
+ else if ( (ch1 >= 'a' && ch1 <= 'f') ) {
+ r = (ch1 - 'a' + 10);
+ }
+ else if ( (ch1 >= 'A' && ch1 <= 'F') ) {
+ r = (ch1 - 'A' + 10);
+ }
+ r <<= 4;
+
+ if ( (ch2 >= '0' && ch2 <= '9') ) {
+ r |= ch2-'0';
+ }
+ else if ( (ch2 >= 'a' && ch2 <= 'f') ) {
+ r |= ch2 - 'a' + 10;
+ }
+ else if ( (ch2 >= 'A' && ch2 <= 'F') ) {
+ r |= ch2 - 'A' + 10;
+ }
+
+ return r;
+}
+
+COLORREF HtmlColor2RGB( const std::string& HtmlColor,
+ COLORREF DefColor )
+{
+ /*#rrggbb*/
+ if(HtmlColor.size() != 7 || HtmlColor[0] != '#')
+ return DefColor;
+
+ for(int p = 1; p<7; ++p) {
+ if( !IsHexChar( HtmlColor[p] ) )
+ return DefColor;
+ }
+
+ return RGB( HexToBYTE(HtmlColor[1], HtmlColor[2]),
+ HexToBYTE(HtmlColor[3], HtmlColor[4]),
+ HexToBYTE(HtmlColor[5], HtmlColor[6]) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
//VLCControlsWnd members
////////////////////////////////////////////////////////////////////////////////
VLCControlsWnd*
diff --git a/common/win32_fullscreen.h b/common/win32_fullscreen.h
index 0024d1a..b0fd1e6 100644
--- a/common/win32_fullscreen.h
+++ b/common/win32_fullscreen.h
@@ -30,7 +30,15 @@
#include "win32_vlcwnd.h"
#include "vlc_player_options.h"
+////////////////////////////////////////////////////////////////////////////////
+//helper functions
+////////////////////////////////////////////////////////////////////////////////
+COLORREF HtmlColor2RGB( const std::string& HtmlColor,
+ COLORREF DefColor = RGB(0, 0, 0) );
+////////////////////////////////////////////////////////////////////////////////
+//class VLCViewResources
+////////////////////////////////////////////////////////////////////////////////
struct VLCViewResources
{
VLCViewResources()
--
1.7.7.1.msysgit.0
More information about the vlc-devel
mailing list