summaryrefslogtreecommitdiff
path: root/tools/source/generic/color.cxx
diff options
context:
space:
mode:
authorChristian Lippka <cl@lippka.com>2011-05-06 16:11:58 +0200
committerJan Holesovsky <kendy@suse.cz>2011-05-06 17:55:29 +0200
commit58336f0066737161af99f5daad2cad8df2250941 (patch)
tree17ce73035aa07fb245bed9e8ea446f1ee74de562 /tools/source/generic/color.cxx
parent948c14eec1829e1191502db8a6fa5a4147a15592 (diff)
New color picker dialog for all applications.
Replaces the old color picker with a new one. Demo: http://www.youtube.com/watch?v=rPu6EmIxkIM
Diffstat (limited to 'tools/source/generic/color.cxx')
-rw-r--r--tools/source/generic/color.cxx47
1 files changed, 47 insertions, 0 deletions
diff --git a/tools/source/generic/color.cxx b/tools/source/generic/color.cxx
index 9a209b38f754..5560e631767a 100644
--- a/tools/source/generic/color.cxx
+++ b/tools/source/generic/color.cxx
@@ -261,6 +261,53 @@ ColorData Color::HSBtoRGB( sal_uInt16 nHue, sal_uInt16 nSat, sal_uInt16 nBri )
// -----------------------------------------------------------------------
+// CMYK values from 0 to 1
+ColorData Color::CMYKtoRGB( double fCyan, double fMagenta, double fYellow, double fKey )
+{
+ fCyan = (fCyan * ( 1.0 - fKey )) + fKey;
+ fMagenta = (fMagenta * ( 1.0 - fKey )) + fKey;
+ fYellow = (fYellow * ( 1.0 - fKey )) + fKey;
+
+ sal_uInt8 nRed = static_cast< sal_uInt8 >( std::max( std::min( ( 1.0 - fCyan ) * 255.0, 255.0), 0.0 ) );
+ sal_uInt8 nGreen = static_cast< sal_uInt8 >( std::max( std::min( ( 1.0 - fMagenta ) * 255.0, 255.0), 0.0 ) );
+ sal_uInt8 nBlue = static_cast< sal_uInt8 >( std::max( std::min( ( 1.0 - fYellow ) * 255.0, 255.0), 0.0 ) );
+
+ return RGB_COLORDATA( nRed, nGreen, nBlue );
+}
+
+// -----------------------------------------------------------------------
+
+// RGB values from 0 to 255
+// CMY results from 0 to 1
+void Color::RGBtoCMYK( double& fCyan, double& fMagenta, double& fYellow, double& fKey )
+{
+ fCyan = 1 - ( GetRed() / 255.0 );
+ fMagenta = 1 - ( GetGreen() / 255.0 );
+ fYellow = 1 - ( GetBlue() / 255.0 );
+
+ //CMYK and CMY values from 0 to 1
+ fKey = 1.0;
+ if( fCyan < fKey ) fKey = fCyan;
+ if( fMagenta < fKey ) fKey = fMagenta;
+ if( fYellow < fKey ) fKey = fYellow;
+
+ if ( fKey == 1.0 )
+ {
+ //Black
+ fCyan = 0.0;
+ fMagenta = 0.0;
+ fYellow = 0.0;
+ }
+ else
+ {
+ fCyan = ( fCyan - fKey ) / ( 1.0 - fKey );
+ fMagenta = ( fMagenta - fKey ) / ( 1.0 - fKey );
+ fYellow = ( fYellow - fKey ) / ( 1.0 - fKey );
+ }
+}
+
+// -----------------------------------------------------------------------
+
SvStream& Color::Read( SvStream& rIStm, sal_Bool bNewFormat )
{
if ( bNewFormat )