189b56da7SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
389b56da7SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
489b56da7SAndrew Rist * or more contributor license agreements. See the NOTICE file
589b56da7SAndrew Rist * distributed with this work for additional information
689b56da7SAndrew Rist * regarding copyright ownership. The ASF licenses this file
789b56da7SAndrew Rist * to you under the Apache License, Version 2.0 (the
889b56da7SAndrew Rist * "License"); you may not use this file except in compliance
989b56da7SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
1189b56da7SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
1389b56da7SAndrew Rist * Unless required by applicable law or agreed to in writing,
1489b56da7SAndrew Rist * software distributed under the License is distributed on an
1589b56da7SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1689b56da7SAndrew Rist * KIND, either express or implied. See the License for the
1789b56da7SAndrew Rist * specific language governing permissions and limitations
1889b56da7SAndrew Rist * under the License.
19cdf0e10cSrcweir *
2089b56da7SAndrew Rist *************************************************************/
2189b56da7SAndrew Rist
2289b56da7SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_tools.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <stdlib.h>
28cdf0e10cSrcweir #include <vos/macros.hxx>
29cdf0e10cSrcweir #include <tools/color.hxx>
30cdf0e10cSrcweir #include <tools/debug.hxx>
31cdf0e10cSrcweir #include <tools/stream.hxx>
32cdf0e10cSrcweir #include <tools/rc.hxx>
33cdf0e10cSrcweir #include <tools/rcid.h>
34cdf0e10cSrcweir #include <tools/resid.hxx>
35cdf0e10cSrcweir #ifndef _SV_RC_H
36cdf0e10cSrcweir #include <tools/rc.h>
37cdf0e10cSrcweir #endif
38cdf0e10cSrcweir
39cdf0e10cSrcweir // -----------
40cdf0e10cSrcweir // - Inlines -
41cdf0e10cSrcweir // -----------
42cdf0e10cSrcweir
_FRound(double fVal)43cdf0e10cSrcweir static inline long _FRound( double fVal )
44cdf0e10cSrcweir {
45cdf0e10cSrcweir return( fVal > 0.0 ? (long) ( fVal + 0.5 ) : -(long) ( -fVal + 0.5 ) );
46cdf0e10cSrcweir }
47cdf0e10cSrcweir
48cdf0e10cSrcweir // ---------
49cdf0e10cSrcweir // - Color -
50cdf0e10cSrcweir // ---------
51cdf0e10cSrcweir
Color(const ResId & rResId)52cdf0e10cSrcweir Color::Color( const ResId& rResId )
53cdf0e10cSrcweir {
54cdf0e10cSrcweir rResId.SetRT( RSC_COLOR );
55cdf0e10cSrcweir ResMgr* pResMgr = rResId.GetResMgr();
56cdf0e10cSrcweir if ( pResMgr && pResMgr->GetResource( rResId ) )
57cdf0e10cSrcweir {
58cdf0e10cSrcweir // Header ueberspringen
59cdf0e10cSrcweir pResMgr->Increment( sizeof( RSHEADER_TYPE ) );
60cdf0e10cSrcweir
61cdf0e10cSrcweir // Daten laden
62cdf0e10cSrcweir sal_uInt16 nRed = pResMgr->ReadShort();
63cdf0e10cSrcweir sal_uInt16 nGreen = pResMgr->ReadShort();
64cdf0e10cSrcweir sal_uInt16 nBlue = pResMgr->ReadShort();
65cdf0e10cSrcweir // one more historical sal_uIntPtr
66cdf0e10cSrcweir pResMgr->ReadLong();
67cdf0e10cSrcweir
68cdf0e10cSrcweir // RGB-Farbe
69cdf0e10cSrcweir mnColor = RGB_COLORDATA( nRed>>8, nGreen>>8, nBlue>>8 );
70cdf0e10cSrcweir }
71cdf0e10cSrcweir else
72cdf0e10cSrcweir {
73cdf0e10cSrcweir mnColor = RGB_COLORDATA( 0, 0, 0 );
74cdf0e10cSrcweir }
75cdf0e10cSrcweir }
GetColorError(const Color & rCompareColor) const76cdf0e10cSrcweir sal_uInt8 Color::GetColorError( const Color& rCompareColor ) const
77cdf0e10cSrcweir {
78cdf0e10cSrcweir const long nErrAbs = labs( (long) rCompareColor.GetRed() - GetRed() ) +
79cdf0e10cSrcweir labs( (long) rCompareColor.GetGreen() - GetGreen() ) +
80cdf0e10cSrcweir labs( (long) rCompareColor.GetBlue() - GetBlue() );
81cdf0e10cSrcweir
82cdf0e10cSrcweir return (sal_uInt8) _FRound( nErrAbs * 0.3333333333 );
83cdf0e10cSrcweir }
84cdf0e10cSrcweir
85cdf0e10cSrcweir // -----------------------------------------------------------------------
86cdf0e10cSrcweir
IncreaseLuminance(sal_uInt8 cLumInc)87cdf0e10cSrcweir void Color::IncreaseLuminance( sal_uInt8 cLumInc )
88cdf0e10cSrcweir {
89cdf0e10cSrcweir SetRed( (sal_uInt8) VOS_BOUND( (long) COLORDATA_RED( mnColor ) + cLumInc, 0L, 255L ) );
90cdf0e10cSrcweir SetGreen( (sal_uInt8) VOS_BOUND( (long) COLORDATA_GREEN( mnColor ) + cLumInc, 0L, 255L ) );
91cdf0e10cSrcweir SetBlue( (sal_uInt8) VOS_BOUND( (long) COLORDATA_BLUE( mnColor ) + cLumInc, 0L, 255L ) );
92cdf0e10cSrcweir }
93cdf0e10cSrcweir
94cdf0e10cSrcweir // -----------------------------------------------------------------------
95cdf0e10cSrcweir
DecreaseLuminance(sal_uInt8 cLumDec)96cdf0e10cSrcweir void Color::DecreaseLuminance( sal_uInt8 cLumDec )
97cdf0e10cSrcweir {
98cdf0e10cSrcweir SetRed( (sal_uInt8) VOS_BOUND( (long) COLORDATA_RED( mnColor ) - cLumDec, 0L, 255L ) );
99cdf0e10cSrcweir SetGreen( (sal_uInt8) VOS_BOUND( (long) COLORDATA_GREEN( mnColor ) - cLumDec, 0L, 255L ) );
100cdf0e10cSrcweir SetBlue( (sal_uInt8) VOS_BOUND( (long) COLORDATA_BLUE( mnColor ) - cLumDec, 0L, 255L ) );
101cdf0e10cSrcweir }
102cdf0e10cSrcweir
103cdf0e10cSrcweir // -----------------------------------------------------------------------
104cdf0e10cSrcweir
IncreaseContrast(sal_uInt8 cContInc)105cdf0e10cSrcweir void Color::IncreaseContrast( sal_uInt8 cContInc )
106cdf0e10cSrcweir {
107cdf0e10cSrcweir if( cContInc)
108cdf0e10cSrcweir {
109cdf0e10cSrcweir const double fM = 128.0 / ( 128.0 - 0.4985 * cContInc );
110cdf0e10cSrcweir const double fOff = 128.0 - fM * 128.0;
111cdf0e10cSrcweir
112cdf0e10cSrcweir SetRed( (sal_uInt8) VOS_BOUND( _FRound( COLORDATA_RED( mnColor ) * fM + fOff ), 0L, 255L ) );
113cdf0e10cSrcweir SetGreen( (sal_uInt8) VOS_BOUND( _FRound( COLORDATA_GREEN( mnColor ) * fM + fOff ), 0L, 255L ) );
114cdf0e10cSrcweir SetBlue( (sal_uInt8) VOS_BOUND( _FRound( COLORDATA_BLUE( mnColor ) * fM + fOff ), 0L, 255L ) );
115cdf0e10cSrcweir }
116cdf0e10cSrcweir }
117cdf0e10cSrcweir
118cdf0e10cSrcweir // -----------------------------------------------------------------------
119cdf0e10cSrcweir
DecreaseContrast(sal_uInt8 cContDec)120cdf0e10cSrcweir void Color::DecreaseContrast( sal_uInt8 cContDec )
121cdf0e10cSrcweir {
122cdf0e10cSrcweir if( cContDec )
123cdf0e10cSrcweir {
124cdf0e10cSrcweir const double fM = ( 128.0 - 0.4985 * cContDec ) / 128.0;
125cdf0e10cSrcweir const double fOff = 128.0 - fM * 128.0;
126cdf0e10cSrcweir
127cdf0e10cSrcweir SetRed( (sal_uInt8) VOS_BOUND( _FRound( COLORDATA_RED( mnColor ) * fM + fOff ), 0L, 255L ) );
128cdf0e10cSrcweir SetGreen( (sal_uInt8) VOS_BOUND( _FRound( COLORDATA_GREEN( mnColor ) * fM + fOff ), 0L, 255L ) );
129cdf0e10cSrcweir SetBlue( (sal_uInt8) VOS_BOUND( _FRound( COLORDATA_BLUE( mnColor ) * fM + fOff ), 0L, 255L ) );
130cdf0e10cSrcweir }
131cdf0e10cSrcweir }
132cdf0e10cSrcweir
133cdf0e10cSrcweir // -----------------------------------------------------------------------
134cdf0e10cSrcweir
Invert()135cdf0e10cSrcweir void Color::Invert()
136cdf0e10cSrcweir {
137cdf0e10cSrcweir SetRed( ~COLORDATA_RED( mnColor ) );
138cdf0e10cSrcweir SetGreen( ~COLORDATA_GREEN( mnColor ) );
139cdf0e10cSrcweir SetBlue( ~COLORDATA_BLUE( mnColor ) );
140cdf0e10cSrcweir }
141cdf0e10cSrcweir
142cdf0e10cSrcweir // -----------------------------------------------------------------------
143cdf0e10cSrcweir
IsDark() const144cdf0e10cSrcweir sal_Bool Color::IsDark() const
145cdf0e10cSrcweir {
146*1bd631beSOliver-Rainer Wittmann return GetLuminance() <= 55;
147cdf0e10cSrcweir }
148cdf0e10cSrcweir
149cdf0e10cSrcweir // -----------------------------------------------------------------------
150cdf0e10cSrcweir
IsBright() const151cdf0e10cSrcweir sal_Bool Color::IsBright() const
152cdf0e10cSrcweir {
153cdf0e10cSrcweir return GetLuminance() >= 245;
154cdf0e10cSrcweir }
155cdf0e10cSrcweir
156cdf0e10cSrcweir // -----------------------------------------------------------------------
157cdf0e10cSrcweir // color space conversion
158cdf0e10cSrcweir // -----------------------------------------------------------------------
159cdf0e10cSrcweir
RGBtoHSB(sal_uInt16 & nHue,sal_uInt16 & nSat,sal_uInt16 & nBri) const160cdf0e10cSrcweir void Color::RGBtoHSB( sal_uInt16& nHue, sal_uInt16& nSat, sal_uInt16& nBri ) const
161cdf0e10cSrcweir {
162cdf0e10cSrcweir sal_uInt8 c[3];
163cdf0e10cSrcweir sal_uInt8 cMax, cMin;
164cdf0e10cSrcweir
165cdf0e10cSrcweir c[0] = GetRed();
166cdf0e10cSrcweir c[1] = GetGreen();
167cdf0e10cSrcweir c[2] = GetBlue();
168cdf0e10cSrcweir
169cdf0e10cSrcweir cMax = c[0];
170cdf0e10cSrcweir if( c[1] > cMax )
171cdf0e10cSrcweir cMax = c[1];
172cdf0e10cSrcweir if( c[2] > cMax )
173cdf0e10cSrcweir cMax = c[2];
174cdf0e10cSrcweir
175cdf0e10cSrcweir // Brightness = max(R, G, B);
176cdf0e10cSrcweir nBri = cMax * 100 / 255;
177cdf0e10cSrcweir
178cdf0e10cSrcweir cMin = c[0];
179cdf0e10cSrcweir if( c[1] < cMin )
180cdf0e10cSrcweir cMin = c[1];
181cdf0e10cSrcweir if( c[2] < cMin )
182cdf0e10cSrcweir cMin = c[2];
183cdf0e10cSrcweir
184cdf0e10cSrcweir sal_uInt8 cDelta = cMax - cMin;
185cdf0e10cSrcweir
186cdf0e10cSrcweir // Saturation = max - min / max
187cdf0e10cSrcweir if( nBri > 0 )
188cdf0e10cSrcweir nSat = cDelta * 100 / cMax;
189cdf0e10cSrcweir else
190cdf0e10cSrcweir nSat = 0;
191cdf0e10cSrcweir
192cdf0e10cSrcweir if( nSat == 0 )
193cdf0e10cSrcweir nHue = 0; // Default = undefined
194cdf0e10cSrcweir else
195cdf0e10cSrcweir {
196cdf0e10cSrcweir double dHue = 0.0;
197cdf0e10cSrcweir
198cdf0e10cSrcweir if( c[0] == cMax )
199cdf0e10cSrcweir {
200cdf0e10cSrcweir dHue = (double)( c[1] - c[2] ) / (double)cDelta;
201cdf0e10cSrcweir }
202cdf0e10cSrcweir else if( c[1] == cMax )
203cdf0e10cSrcweir {
204cdf0e10cSrcweir dHue = 2.0 + (double)( c[2] - c[0] ) / (double)cDelta;
205cdf0e10cSrcweir }
206cdf0e10cSrcweir else if ( c[2] == cMax )
207cdf0e10cSrcweir {
208cdf0e10cSrcweir dHue = 4.0 + (double)( c[0] - c[1] ) / (double)cDelta;
209cdf0e10cSrcweir }
210cdf0e10cSrcweir dHue *= 60.0;
211cdf0e10cSrcweir
212cdf0e10cSrcweir if( dHue < 0.0 )
213cdf0e10cSrcweir dHue += 360.0;
214cdf0e10cSrcweir
215cdf0e10cSrcweir nHue = (sal_uInt16) dHue;
216cdf0e10cSrcweir }
217cdf0e10cSrcweir }
218cdf0e10cSrcweir
HSBtoRGB(sal_uInt16 nHue,sal_uInt16 nSat,sal_uInt16 nBri)219cdf0e10cSrcweir ColorData Color::HSBtoRGB( sal_uInt16 nHue, sal_uInt16 nSat, sal_uInt16 nBri )
220cdf0e10cSrcweir {
221cdf0e10cSrcweir sal_uInt8 cR=0,cG=0,cB=0;
222cdf0e10cSrcweir sal_uInt8 nB = (sal_uInt8) ( nBri * 255 / 100 );
223cdf0e10cSrcweir
224cdf0e10cSrcweir if( nSat == 0 )
225cdf0e10cSrcweir {
226cdf0e10cSrcweir cR = nB;
227cdf0e10cSrcweir cG = nB;
228cdf0e10cSrcweir cB = nB;
229cdf0e10cSrcweir }
230cdf0e10cSrcweir else
231cdf0e10cSrcweir {
232cdf0e10cSrcweir double dH = nHue;
233cdf0e10cSrcweir double f;
234cdf0e10cSrcweir sal_uInt16 n;
235cdf0e10cSrcweir if( dH == 360.0 )
236cdf0e10cSrcweir dH = 0.0;
237cdf0e10cSrcweir
238cdf0e10cSrcweir dH /= 60.0;
239cdf0e10cSrcweir n = (sal_uInt16) dH;
240cdf0e10cSrcweir f = dH - n;
241cdf0e10cSrcweir
242cdf0e10cSrcweir sal_uInt8 a = (sal_uInt8) ( nB * ( 100 - nSat ) / 100 );
243cdf0e10cSrcweir sal_uInt8 b = (sal_uInt8) ( nB * ( 100 - ( (double)nSat * f ) ) / 100 );
244cdf0e10cSrcweir sal_uInt8 c = (sal_uInt8) ( nB * ( 100 - ( (double)nSat * ( 1.0 - f ) ) ) / 100 );
245cdf0e10cSrcweir
246cdf0e10cSrcweir switch( n )
247cdf0e10cSrcweir {
248cdf0e10cSrcweir case 0: cR = nB; cG = c; cB = a; break;
249cdf0e10cSrcweir case 1: cR = b; cG = nB; cB = a; break;
250cdf0e10cSrcweir case 2: cR = a; cG = nB; cB = c; break;
251cdf0e10cSrcweir case 3: cR = a; cG = b; cB = nB; break;
252cdf0e10cSrcweir case 4: cR = c; cG = a; cB = nB; break;
253cdf0e10cSrcweir case 5: cR = nB; cG = a; cB = b; break;
254cdf0e10cSrcweir }
255cdf0e10cSrcweir }
256cdf0e10cSrcweir
257cdf0e10cSrcweir return RGB_COLORDATA( cR, cG, cB );
258cdf0e10cSrcweir }
259cdf0e10cSrcweir
260cdf0e10cSrcweir // -----------------------------------------------------------------------
261cdf0e10cSrcweir
262b2b569f2SArmin Le Grand // CMYK values from 0 to 1
CMYKtoRGB(double fCyan,double fMagenta,double fYellow,double fKey)263b2b569f2SArmin Le Grand ColorData Color::CMYKtoRGB( double fCyan, double fMagenta, double fYellow, double fKey )
264b2b569f2SArmin Le Grand {
265b2b569f2SArmin Le Grand fCyan = (fCyan * ( 1.0 - fKey )) + fKey;
266b2b569f2SArmin Le Grand fMagenta = (fMagenta * ( 1.0 - fKey )) + fKey;
267b2b569f2SArmin Le Grand fYellow = (fYellow * ( 1.0 - fKey )) + fKey;
268b2b569f2SArmin Le Grand
269b2b569f2SArmin Le Grand sal_uInt8 nRed = static_cast< sal_uInt8 >( std::max( std::min( ( 1.0 - fCyan ) * 255.0, 255.0), 0.0 ) );
270b2b569f2SArmin Le Grand sal_uInt8 nGreen = static_cast< sal_uInt8 >( std::max( std::min( ( 1.0 - fMagenta ) * 255.0, 255.0), 0.0 ) );
271b2b569f2SArmin Le Grand sal_uInt8 nBlue = static_cast< sal_uInt8 >( std::max( std::min( ( 1.0 - fYellow ) * 255.0, 255.0), 0.0 ) );
272b2b569f2SArmin Le Grand
273b2b569f2SArmin Le Grand return RGB_COLORDATA( nRed, nGreen, nBlue );
274b2b569f2SArmin Le Grand }
275b2b569f2SArmin Le Grand
276b2b569f2SArmin Le Grand // -----------------------------------------------------------------------
277b2b569f2SArmin Le Grand
278b2b569f2SArmin Le Grand // RGB values from 0 to 255
279b2b569f2SArmin Le Grand // CMY results from 0 to 1
RGBtoCMYK(double & fCyan,double & fMagenta,double & fYellow,double & fKey)280b2b569f2SArmin Le Grand void Color::RGBtoCMYK( double& fCyan, double& fMagenta, double& fYellow, double& fKey )
281b2b569f2SArmin Le Grand {
282b2b569f2SArmin Le Grand fCyan = 1 - ( GetRed() / 255.0 );
283b2b569f2SArmin Le Grand fMagenta = 1 - ( GetGreen() / 255.0 );
284b2b569f2SArmin Le Grand fYellow = 1 - ( GetBlue() / 255.0 );
285b2b569f2SArmin Le Grand
286b2b569f2SArmin Le Grand //CMYK and CMY values from 0 to 1
287b2b569f2SArmin Le Grand fKey = 1.0;
288b2b569f2SArmin Le Grand if( fCyan < fKey ) fKey = fCyan;
289b2b569f2SArmin Le Grand if( fMagenta < fKey ) fKey = fMagenta;
290b2b569f2SArmin Le Grand if( fYellow < fKey ) fKey = fYellow;
291b2b569f2SArmin Le Grand
292b2b569f2SArmin Le Grand if ( fKey == 1.0 )
293b2b569f2SArmin Le Grand {
294b2b569f2SArmin Le Grand //Black
295b2b569f2SArmin Le Grand fCyan = 0.0;
296b2b569f2SArmin Le Grand fMagenta = 0.0;
297b2b569f2SArmin Le Grand fYellow = 0.0;
298b2b569f2SArmin Le Grand }
299b2b569f2SArmin Le Grand else
300b2b569f2SArmin Le Grand {
301b2b569f2SArmin Le Grand fCyan = ( fCyan - fKey ) / ( 1.0 - fKey );
302b2b569f2SArmin Le Grand fMagenta = ( fMagenta - fKey ) / ( 1.0 - fKey );
303b2b569f2SArmin Le Grand fYellow = ( fYellow - fKey ) / ( 1.0 - fKey );
304b2b569f2SArmin Le Grand }
305b2b569f2SArmin Le Grand }
306b2b569f2SArmin Le Grand
307b2b569f2SArmin Le Grand // -----------------------------------------------------------------------
308b2b569f2SArmin Le Grand
Read(SvStream & rIStm,sal_Bool bNewFormat)309cdf0e10cSrcweir SvStream& Color::Read( SvStream& rIStm, sal_Bool bNewFormat )
310cdf0e10cSrcweir {
311cdf0e10cSrcweir if ( bNewFormat )
312cdf0e10cSrcweir rIStm >> mnColor;
313cdf0e10cSrcweir else
314cdf0e10cSrcweir rIStm >> *this;
315cdf0e10cSrcweir
316cdf0e10cSrcweir return rIStm;
317cdf0e10cSrcweir }
318cdf0e10cSrcweir
319cdf0e10cSrcweir // -----------------------------------------------------------------------
320cdf0e10cSrcweir
Write(SvStream & rOStm,sal_Bool bNewFormat)321cdf0e10cSrcweir SvStream& Color::Write( SvStream& rOStm, sal_Bool bNewFormat )
322cdf0e10cSrcweir {
323cdf0e10cSrcweir if ( bNewFormat )
324cdf0e10cSrcweir rOStm << mnColor;
325cdf0e10cSrcweir else
326cdf0e10cSrcweir rOStm << *this;
327cdf0e10cSrcweir
328cdf0e10cSrcweir return rOStm;
329cdf0e10cSrcweir }
330cdf0e10cSrcweir
331cdf0e10cSrcweir // -----------------------------------------------------------------------
332cdf0e10cSrcweir
333cdf0e10cSrcweir #define COL_NAME_USER ((sal_uInt16)0x8000)
334cdf0e10cSrcweir #define COL_RED_1B ((sal_uInt16)0x0001)
335cdf0e10cSrcweir #define COL_RED_2B ((sal_uInt16)0x0002)
336cdf0e10cSrcweir #define COL_GREEN_1B ((sal_uInt16)0x0010)
337cdf0e10cSrcweir #define COL_GREEN_2B ((sal_uInt16)0x0020)
338cdf0e10cSrcweir #define COL_BLUE_1B ((sal_uInt16)0x0100)
339cdf0e10cSrcweir #define COL_BLUE_2B ((sal_uInt16)0x0200)
340cdf0e10cSrcweir
341cdf0e10cSrcweir // -----------------------------------------------------------------------
342cdf0e10cSrcweir
operator >>(SvStream & rIStream,Color & rColor)343cdf0e10cSrcweir SvStream& operator>>( SvStream& rIStream, Color& rColor )
344cdf0e10cSrcweir {
345cdf0e10cSrcweir DBG_ASSERTWARNING( rIStream.GetVersion(), "Color::>> - Solar-Version not set on rIStream" );
346cdf0e10cSrcweir
347cdf0e10cSrcweir sal_uInt16 nColorName;
348cdf0e10cSrcweir sal_uInt16 nRed;
349cdf0e10cSrcweir sal_uInt16 nGreen;
350cdf0e10cSrcweir sal_uInt16 nBlue;
351cdf0e10cSrcweir
352cdf0e10cSrcweir rIStream >> nColorName;
353cdf0e10cSrcweir
354cdf0e10cSrcweir if ( nColorName & COL_NAME_USER )
355cdf0e10cSrcweir {
356cdf0e10cSrcweir if ( rIStream.GetCompressMode() == COMPRESSMODE_FULL )
357cdf0e10cSrcweir {
358cdf0e10cSrcweir unsigned char cAry[6];
359cdf0e10cSrcweir sal_uInt16 i = 0;
360cdf0e10cSrcweir
361cdf0e10cSrcweir nRed = 0;
362cdf0e10cSrcweir nGreen = 0;
363cdf0e10cSrcweir nBlue = 0;
364cdf0e10cSrcweir
365cdf0e10cSrcweir if ( nColorName & COL_RED_2B )
366cdf0e10cSrcweir i += 2;
367cdf0e10cSrcweir else if ( nColorName & COL_RED_1B )
368cdf0e10cSrcweir i++;
369cdf0e10cSrcweir if ( nColorName & COL_GREEN_2B )
370cdf0e10cSrcweir i += 2;
371cdf0e10cSrcweir else if ( nColorName & COL_GREEN_1B )
372cdf0e10cSrcweir i++;
373cdf0e10cSrcweir if ( nColorName & COL_BLUE_2B )
374cdf0e10cSrcweir i += 2;
375cdf0e10cSrcweir else if ( nColorName & COL_BLUE_1B )
376cdf0e10cSrcweir i++;
377cdf0e10cSrcweir
378cdf0e10cSrcweir rIStream.Read( cAry, i );
379cdf0e10cSrcweir i = 0;
380cdf0e10cSrcweir
381cdf0e10cSrcweir if ( nColorName & COL_RED_2B )
382cdf0e10cSrcweir {
383cdf0e10cSrcweir nRed = cAry[i];
384cdf0e10cSrcweir nRed <<= 8;
385cdf0e10cSrcweir i++;
386cdf0e10cSrcweir nRed |= cAry[i];
387cdf0e10cSrcweir i++;
388cdf0e10cSrcweir }
389cdf0e10cSrcweir else if ( nColorName & COL_RED_1B )
390cdf0e10cSrcweir {
391cdf0e10cSrcweir nRed = cAry[i];
392cdf0e10cSrcweir nRed <<= 8;
393cdf0e10cSrcweir i++;
394cdf0e10cSrcweir }
395cdf0e10cSrcweir if ( nColorName & COL_GREEN_2B )
396cdf0e10cSrcweir {
397cdf0e10cSrcweir nGreen = cAry[i];
398cdf0e10cSrcweir nGreen <<= 8;
399cdf0e10cSrcweir i++;
400cdf0e10cSrcweir nGreen |= cAry[i];
401cdf0e10cSrcweir i++;
402cdf0e10cSrcweir }
403cdf0e10cSrcweir else if ( nColorName & COL_GREEN_1B )
404cdf0e10cSrcweir {
405cdf0e10cSrcweir nGreen = cAry[i];
406cdf0e10cSrcweir nGreen <<= 8;
407cdf0e10cSrcweir i++;
408cdf0e10cSrcweir }
409cdf0e10cSrcweir if ( nColorName & COL_BLUE_2B )
410cdf0e10cSrcweir {
411cdf0e10cSrcweir nBlue = cAry[i];
412cdf0e10cSrcweir nBlue <<= 8;
413cdf0e10cSrcweir i++;
414cdf0e10cSrcweir nBlue |= cAry[i];
415cdf0e10cSrcweir i++;
416cdf0e10cSrcweir }
417cdf0e10cSrcweir else if ( nColorName & COL_BLUE_1B )
418cdf0e10cSrcweir {
419cdf0e10cSrcweir nBlue = cAry[i];
420cdf0e10cSrcweir nBlue <<= 8;
421cdf0e10cSrcweir i++;
422cdf0e10cSrcweir }
423cdf0e10cSrcweir }
424cdf0e10cSrcweir else
425cdf0e10cSrcweir {
426cdf0e10cSrcweir rIStream >> nRed;
427cdf0e10cSrcweir rIStream >> nGreen;
428cdf0e10cSrcweir rIStream >> nBlue;
429cdf0e10cSrcweir }
430cdf0e10cSrcweir
431cdf0e10cSrcweir rColor.mnColor = RGB_COLORDATA( nRed>>8, nGreen>>8, nBlue>>8 );
432cdf0e10cSrcweir }
433cdf0e10cSrcweir else
434cdf0e10cSrcweir {
435cdf0e10cSrcweir static ColorData aColAry[] =
436cdf0e10cSrcweir {
437cdf0e10cSrcweir COL_BLACK, // COL_BLACK
438cdf0e10cSrcweir COL_BLUE, // COL_BLUE
439cdf0e10cSrcweir COL_GREEN, // COL_GREEN
440cdf0e10cSrcweir COL_CYAN, // COL_CYAN
441cdf0e10cSrcweir COL_RED, // COL_RED
442cdf0e10cSrcweir COL_MAGENTA, // COL_MAGENTA
443cdf0e10cSrcweir COL_BROWN, // COL_BROWN
444cdf0e10cSrcweir COL_GRAY, // COL_GRAY
445cdf0e10cSrcweir COL_LIGHTGRAY, // COL_LIGHTGRAY
446cdf0e10cSrcweir COL_LIGHTBLUE, // COL_LIGHTBLUE
447cdf0e10cSrcweir COL_LIGHTGREEN, // COL_LIGHTGREEN
448cdf0e10cSrcweir COL_LIGHTCYAN, // COL_LIGHTCYAN
449cdf0e10cSrcweir COL_LIGHTRED, // COL_LIGHTRED
450cdf0e10cSrcweir COL_LIGHTMAGENTA, // COL_LIGHTMAGENTA
451cdf0e10cSrcweir COL_YELLOW, // COL_YELLOW
452cdf0e10cSrcweir COL_WHITE, // COL_WHITE
453cdf0e10cSrcweir COL_WHITE, // COL_MENUBAR
454cdf0e10cSrcweir COL_BLACK, // COL_MENUBARTEXT
455cdf0e10cSrcweir COL_WHITE, // COL_POPUPMENU
456cdf0e10cSrcweir COL_BLACK, // COL_POPUPMENUTEXT
457cdf0e10cSrcweir COL_BLACK, // COL_WINDOWTEXT
458cdf0e10cSrcweir COL_WHITE, // COL_WINDOWWORKSPACE
459cdf0e10cSrcweir COL_BLACK, // COL_HIGHLIGHT
460cdf0e10cSrcweir COL_WHITE, // COL_HIGHLIGHTTEXT
461cdf0e10cSrcweir COL_BLACK, // COL_3DTEXT
462cdf0e10cSrcweir COL_LIGHTGRAY, // COL_3DFACE
463cdf0e10cSrcweir COL_WHITE, // COL_3DLIGHT
464cdf0e10cSrcweir COL_GRAY, // COL_3DSHADOW
465cdf0e10cSrcweir COL_LIGHTGRAY, // COL_SCROLLBAR
466cdf0e10cSrcweir COL_WHITE, // COL_FIELD
467cdf0e10cSrcweir COL_BLACK // COL_FIELDTEXT
468cdf0e10cSrcweir };
469cdf0e10cSrcweir
470cdf0e10cSrcweir if ( nColorName < (sizeof( aColAry )/sizeof(ColorData)) )
471cdf0e10cSrcweir rColor.mnColor = aColAry[nColorName];
472cdf0e10cSrcweir else
473cdf0e10cSrcweir rColor.mnColor = COL_BLACK;
474cdf0e10cSrcweir }
475cdf0e10cSrcweir
476cdf0e10cSrcweir return rIStream;
477cdf0e10cSrcweir }
478cdf0e10cSrcweir
479cdf0e10cSrcweir // -----------------------------------------------------------------------
480cdf0e10cSrcweir
operator <<(SvStream & rOStream,const Color & rColor)481cdf0e10cSrcweir SvStream& operator<<( SvStream& rOStream, const Color& rColor )
482cdf0e10cSrcweir {
483cdf0e10cSrcweir DBG_ASSERTWARNING( rOStream.GetVersion(), "Color::<< - Solar-Version not set on rOStream" );
484cdf0e10cSrcweir
485cdf0e10cSrcweir sal_uInt16 nColorName = COL_NAME_USER;
486cdf0e10cSrcweir sal_uInt16 nRed = rColor.GetRed();
487cdf0e10cSrcweir sal_uInt16 nGreen = rColor.GetGreen();
488cdf0e10cSrcweir sal_uInt16 nBlue = rColor.GetBlue();
489cdf0e10cSrcweir nRed = (nRed<<8) + nRed;
490cdf0e10cSrcweir nGreen = (nGreen<<8) + nGreen;
491cdf0e10cSrcweir nBlue = (nBlue<<8) + nBlue;
492cdf0e10cSrcweir
493cdf0e10cSrcweir if ( rOStream.GetCompressMode() == COMPRESSMODE_FULL )
494cdf0e10cSrcweir {
495cdf0e10cSrcweir unsigned char cAry[6];
496cdf0e10cSrcweir sal_uInt16 i = 0;
497cdf0e10cSrcweir
498cdf0e10cSrcweir if ( nRed & 0x00FF )
499cdf0e10cSrcweir {
500cdf0e10cSrcweir nColorName |= COL_RED_2B;
501cdf0e10cSrcweir cAry[i] = (unsigned char)(nRed & 0xFF);
502cdf0e10cSrcweir i++;
503cdf0e10cSrcweir cAry[i] = (unsigned char)((nRed >> 8) & 0xFF);
504cdf0e10cSrcweir i++;
505cdf0e10cSrcweir }
506cdf0e10cSrcweir else if ( nRed & 0xFF00 )
507cdf0e10cSrcweir {
508cdf0e10cSrcweir nColorName |= COL_RED_1B;
509cdf0e10cSrcweir cAry[i] = (unsigned char)((nRed >> 8) & 0xFF);
510cdf0e10cSrcweir i++;
511cdf0e10cSrcweir }
512cdf0e10cSrcweir if ( nGreen & 0x00FF )
513cdf0e10cSrcweir {
514cdf0e10cSrcweir nColorName |= COL_GREEN_2B;
515cdf0e10cSrcweir cAry[i] = (unsigned char)(nGreen & 0xFF);
516cdf0e10cSrcweir i++;
517cdf0e10cSrcweir cAry[i] = (unsigned char)((nGreen >> 8) & 0xFF);
518cdf0e10cSrcweir i++;
519cdf0e10cSrcweir }
520cdf0e10cSrcweir else if ( nGreen & 0xFF00 )
521cdf0e10cSrcweir {
522cdf0e10cSrcweir nColorName |= COL_GREEN_1B;
523cdf0e10cSrcweir cAry[i] = (unsigned char)((nGreen >> 8) & 0xFF);
524cdf0e10cSrcweir i++;
525cdf0e10cSrcweir }
526cdf0e10cSrcweir if ( nBlue & 0x00FF )
527cdf0e10cSrcweir {
528cdf0e10cSrcweir nColorName |= COL_BLUE_2B;
529cdf0e10cSrcweir cAry[i] = (unsigned char)(nBlue & 0xFF);
530cdf0e10cSrcweir i++;
531cdf0e10cSrcweir cAry[i] = (unsigned char)((nBlue >> 8) & 0xFF);
532cdf0e10cSrcweir i++;
533cdf0e10cSrcweir }
534cdf0e10cSrcweir else if ( nBlue & 0xFF00 )
535cdf0e10cSrcweir {
536cdf0e10cSrcweir nColorName |= COL_BLUE_1B;
537cdf0e10cSrcweir cAry[i] = (unsigned char)((nBlue >> 8) & 0xFF);
538cdf0e10cSrcweir i++;
539cdf0e10cSrcweir }
540cdf0e10cSrcweir
541cdf0e10cSrcweir rOStream << nColorName;
542cdf0e10cSrcweir rOStream.Write( cAry, i );
543cdf0e10cSrcweir }
544cdf0e10cSrcweir else
545cdf0e10cSrcweir {
546cdf0e10cSrcweir rOStream << nColorName;
547cdf0e10cSrcweir rOStream << nRed;
548cdf0e10cSrcweir rOStream << nGreen;
549cdf0e10cSrcweir rOStream << nBlue;
550cdf0e10cSrcweir }
551cdf0e10cSrcweir
552cdf0e10cSrcweir return rOStream;
553cdf0e10cSrcweir }
554