Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <vcl/outdev.hxx>
31 : : #include <vcl/bitmapex.hxx>
32 : : #include <vcl/alpha.hxx>
33 : : #include <vcl/window.hxx>
34 : : #include <vcl/bmpacc.hxx>
35 : : #include <vcl/virdev.hxx>
36 : : #include <vcl/image.hxx>
37 : :
38 : : #include <image.h>
39 : :
40 : : // -----------
41 : : // - Defines -
42 : : // -----------
43 : :
44 : : #define IMPSYSIMAGEITEM_MASK ( 0x01 )
45 : : #define IMPSYSIMAGEITEM_ALPHA ( 0x02 )
46 : :
47 : : // -----------------------------------------------------------------------
48 : :
49 : 0 : ImageAryData::ImageAryData( const ImageAryData& rData ) :
50 : : maName( rData.maName ),
51 : : mnId( rData.mnId ),
52 [ # # ]: 0 : maBitmapEx( rData.maBitmapEx )
53 : : {
54 : 0 : }
55 : :
56 : 49512 : ImageAryData::ImageAryData( const rtl::OUString &aName,
57 : : sal_uInt16 nId, const BitmapEx &aBitmap )
58 [ + - ]: 49512 : : maName( aName ), mnId( nId ), maBitmapEx( aBitmap )
59 : : {
60 : 49512 : }
61 : :
62 : : // -----------------------------------------------------------------------
63 : :
64 [ + - ]: 49392 : ImageAryData::~ImageAryData()
65 : : {
66 : 49392 : }
67 : :
68 : : // -----------------------------------------------------------------------
69 : :
70 : 0 : ImageAryData& ImageAryData::operator=( const ImageAryData& rData )
71 : : {
72 : 0 : maName = rData.maName;
73 : 0 : mnId = rData.mnId;
74 : 0 : maBitmapEx = rData.maBitmapEx;
75 : :
76 : 0 : return *this;
77 : : }
78 : :
79 : : // -----------------
80 : : // - ImplImageList -
81 : : // -----------------
82 : :
83 [ + - ]: 885 : ImplImageList::ImplImageList()
84 : : {
85 : 885 : }
86 : :
87 : 0 : ImplImageList::ImplImageList( const ImplImageList &aSrc ) :
88 : : maPrefix( aSrc.maPrefix ),
89 : : maImageSize( aSrc.maImageSize ),
90 [ # # ]: 0 : mnRefCount( 1 )
91 : : {
92 [ # # ]: 0 : maImages.reserve( aSrc.maImages.size() );
93 [ # # ][ # # ]: 0 : for ( ImageAryDataVec::const_iterator aIt = aSrc.maImages.begin(), aEnd = aSrc.maImages.end(); aIt != aEnd; ++aIt )
94 : : {
95 [ # # ][ # # ]: 0 : ImageAryData* pAryData = new ImageAryData( **aIt );
96 [ # # ]: 0 : maImages.push_back( pAryData );
97 [ # # ]: 0 : if( !pAryData->maName.isEmpty() )
98 [ # # ]: 0 : maNameHash [ pAryData->maName ] = pAryData;
99 : : }
100 : 0 : }
101 : :
102 [ + - ]: 861 : ImplImageList::~ImplImageList()
103 : : {
104 [ + - ][ + + ]: 50253 : for ( ImageAryDataVec::iterator aIt = maImages.begin(), aEnd = maImages.end(); aIt != aEnd; ++aIt )
105 [ + - ][ + - ]: 49392 : delete *aIt;
106 : 861 : }
107 : :
108 : 49512 : void ImplImageList::AddImage( const ::rtl::OUString &aName,
109 : : sal_uInt16 nId, const BitmapEx &aBitmapEx )
110 : : {
111 [ + - ][ + - ]: 49512 : ImageAryData *pImg = new ImageAryData( aName, nId, aBitmapEx );
112 [ + - ]: 49512 : maImages.push_back( pImg );
113 [ + + ]: 49512 : if( !aName.isEmpty() )
114 [ + - ]: 49200 : maNameHash [ aName ] = pImg;
115 : 49512 : }
116 : :
117 : 0 : void ImplImageList::RemoveImage( sal_uInt16 nPos )
118 : : {
119 : 0 : ImageAryData *pImg = maImages[ nPos ];
120 [ # # ]: 0 : if( !pImg->maName.isEmpty() )
121 : 0 : maNameHash.erase( pImg->maName );
122 [ # # ][ # # ]: 0 : maImages.erase( maImages.begin() + nPos );
123 : 0 : }
124 : :
125 : : // -----------------
126 : : // - ImplImageData -
127 : : // -----------------
128 : :
129 : 205919 : ImplImageData::ImplImageData( const BitmapEx& rBmpEx ) :
130 : : mpImageBitmap( NULL ),
131 : 205919 : maBmpEx( rBmpEx )
132 : : {
133 : 205919 : }
134 : :
135 : : // -----------------------------------------------------------------------
136 : :
137 : 205919 : ImplImageData::~ImplImageData()
138 : : {
139 [ + + ][ + - ]: 205919 : delete mpImageBitmap;
140 : 205919 : }
141 : :
142 : : // -----------------
143 : : // - ImplImageData -
144 : : // -----------------
145 : :
146 : 4 : sal_Bool ImplImageData::IsEqual( const ImplImageData& rData )
147 : : {
148 : 4 : return( maBmpEx == rData.maBmpEx );
149 : : }
150 : :
151 : : // -------------
152 : : // - ImplImage -
153 : : // -------------
154 : :
155 : 215896 : ImplImage::ImplImage()
156 : : {
157 : 215896 : }
158 : :
159 : : // ------------------------------------------------------------------------------
160 : :
161 : 215896 : ImplImage::~ImplImage()
162 : : {
163 [ + + - ]: 215896 : switch( meType )
164 : : {
165 : : case IMAGETYPE_BITMAP:
166 [ + - ]: 9977 : delete static_cast< Bitmap* >( mpData );
167 : 9977 : break;
168 : :
169 : : case IMAGETYPE_IMAGE:
170 [ + - ]: 205919 : delete static_cast< ImplImageData* >( mpData );
171 : 205919 : break;
172 : : }
173 : 215896 : }
174 : :
175 : : // ----------------
176 : : // - ImplImageBmp -
177 : : // ----------------
178 : :
179 : 61398 : ImplImageBmp::ImplImageBmp() :
180 : : mpDisplayBmp( NULL ),
181 : : mpInfoAry( NULL ),
182 [ + - ]: 61398 : mnSize( 0 )
183 : : {
184 : 61398 : }
185 : :
186 : : // -------------
187 : : // - ImplImage -
188 : : // -------------
189 : :
190 [ + - ]: 61398 : ImplImageBmp::~ImplImageBmp()
191 : : {
192 [ + - ]: 61398 : delete[] mpInfoAry;
193 [ + + ][ + - ]: 61398 : delete mpDisplayBmp;
194 : 61398 : }
195 : :
196 : : // -----------------------------------------------------------------------
197 : :
198 : 61398 : void ImplImageBmp::Create( const BitmapEx& rBmpEx, long nItemWidth, long nItemHeight, sal_uInt16 nInitSize )
199 : : {
200 : 61398 : maBmpEx = rBmpEx;
201 : 61398 : maDisabledBmpEx.SetEmpty();
202 : :
203 [ - + ]: 61398 : delete mpDisplayBmp;
204 : 61398 : mpDisplayBmp = NULL;
205 : :
206 : 61398 : maSize = Size( nItemWidth, nItemHeight );
207 : 61398 : mnSize = nInitSize;
208 : :
209 [ - + ]: 61398 : delete[] mpInfoAry;
210 : 61398 : mpInfoAry = new sal_uInt8[ mnSize ];
211 : : memset( mpInfoAry,
212 : 62787 : rBmpEx.IsAlpha() ? IMPSYSIMAGEITEM_ALPHA : ( rBmpEx.IsTransparent() ? IMPSYSIMAGEITEM_MASK : 0 ),
213 [ + + + - ]: 62787 : mnSize );
214 : 61398 : }
215 : :
216 : : // -----------------------------------------------------------------------
217 : :
218 : 119210 : void ImplImageBmp::Draw( sal_uInt16 nPos, OutputDevice* pOutDev,
219 : : const Point& rPos, sal_uInt16 nStyle,
220 : : const Size* pSize )
221 : : {
222 [ + + ]: 119210 : if( pOutDev->IsDeviceOutputNecessary() )
223 : : {
224 : 119208 : const Point aSrcPos( nPos * maSize.Width(), 0 );
225 : 119208 : Size aOutSize;
226 : :
227 [ + - ][ - + ]: 119208 : aOutSize = ( pSize ? *pSize : pOutDev->PixelToLogic( maSize ) );
228 : :
229 [ + + ]: 119208 : if( nStyle & IMAGE_DRAW_DISABLE )
230 : : {
231 [ + - ]: 12722 : ImplUpdateDisabledBmpEx( nPos);
232 [ + - ]: 12722 : pOutDev->DrawBitmapEx( rPos, aOutSize, aSrcPos, maSize, maDisabledBmpEx );
233 : : }
234 : : else
235 : : {
236 [ - + ]: 106486 : if( nStyle & ( IMAGE_DRAW_COLORTRANSFORM |
237 : : IMAGE_DRAW_HIGHLIGHT | IMAGE_DRAW_DEACTIVE | IMAGE_DRAW_SEMITRANSPARENT ) )
238 : : {
239 [ # # ]: 0 : BitmapEx aTmpBmpEx;
240 [ # # ]: 0 : const Rectangle aCropRect( aSrcPos, maSize );
241 : :
242 [ # # ]: 0 : if( mpInfoAry[ nPos ] & ( IMPSYSIMAGEITEM_MASK | IMPSYSIMAGEITEM_ALPHA ) )
243 [ # # ]: 0 : aTmpBmpEx = maBmpEx;
244 : : else
245 [ # # ][ # # ]: 0 : aTmpBmpEx = maBmpEx.GetBitmap();
[ # # ][ # # ]
[ # # ]
246 : :
247 [ # # ]: 0 : aTmpBmpEx.Crop( aCropRect );
248 : :
249 [ # # ]: 0 : Bitmap aTmpBmp( aTmpBmpEx.GetBitmap() );
250 : :
251 [ # # ]: 0 : if( nStyle & ( IMAGE_DRAW_HIGHLIGHT | IMAGE_DRAW_DEACTIVE ) )
252 : : {
253 [ # # ]: 0 : BitmapWriteAccess* pAcc = aTmpBmp.AcquireWriteAccess();
254 : :
255 [ # # ]: 0 : if( pAcc )
256 : : {
257 : 0 : const StyleSettings& rSettings = pOutDev->GetSettings().GetStyleSettings();
258 : 0 : Color aColor;
259 : 0 : BitmapColor aCol;
260 : 0 : const long nW = pAcc->Width();
261 : 0 : const long nH = pAcc->Height();
262 [ # # ]: 0 : sal_uInt8* pMapR = new sal_uInt8[ 256 ];
263 [ # # ]: 0 : sal_uInt8* pMapG = new sal_uInt8[ 256 ];
264 [ # # ]: 0 : sal_uInt8* pMapB = new sal_uInt8[ 256 ];
265 : : long nX, nY;
266 : :
267 [ # # ]: 0 : if( nStyle & IMAGE_DRAW_HIGHLIGHT )
268 : 0 : aColor = rSettings.GetHighlightColor();
269 : : else
270 : 0 : aColor = rSettings.GetDeactiveColor();
271 : :
272 : 0 : const sal_uInt8 cR = aColor.GetRed();
273 : 0 : const sal_uInt8 cG = aColor.GetGreen();
274 : 0 : const sal_uInt8 cB = aColor.GetBlue();
275 : :
276 [ # # ]: 0 : for( nX = 0L; nX < 256L; nX++ )
277 : : {
278 [ # # ]: 0 : pMapR[ nX ] = (sal_uInt8) ( ( ( nY = ( nX + cR ) >> 1 ) > 255 ) ? 255 : nY );
279 [ # # ]: 0 : pMapG[ nX ] = (sal_uInt8) ( ( ( nY = ( nX + cG ) >> 1 ) > 255 ) ? 255 : nY );
280 [ # # ]: 0 : pMapB[ nX ] = (sal_uInt8) ( ( ( nY = ( nX + cB ) >> 1 ) > 255 ) ? 255 : nY );
281 : : }
282 : :
283 [ # # ]: 0 : if( pAcc->HasPalette() )
284 : : {
285 [ # # ]: 0 : for( sal_uInt16 i = 0, nCount = pAcc->GetPaletteEntryCount(); i < nCount; i++ )
286 : : {
287 : 0 : const BitmapColor& rCol = pAcc->GetPaletteColor( i );
288 : 0 : aCol.SetRed( pMapR[ rCol.GetRed() ] );
289 : 0 : aCol.SetGreen( pMapG[ rCol.GetGreen() ] );
290 : 0 : aCol.SetBlue( pMapB[ rCol.GetBlue() ] );
291 : 0 : pAcc->SetPaletteColor( i, aCol );
292 : : }
293 : : }
294 [ # # ]: 0 : else if( pAcc->GetScanlineFormat() == BMP_FORMAT_24BIT_TC_BGR )
295 : : {
296 [ # # ]: 0 : for( nY = 0L; nY < nH; nY++ )
297 : : {
298 : 0 : Scanline pScan = pAcc->GetScanline( nY );
299 : :
300 [ # # ]: 0 : for( nX = 0L; nX < nW; nX++ )
301 : : {
302 : 0 : *pScan = pMapB[ *pScan ]; pScan++;
303 : 0 : *pScan = pMapG[ *pScan ]; pScan++;
304 : 0 : *pScan = pMapR[ *pScan ]; pScan++;
305 : : }
306 : : }
307 : : }
308 : : else
309 : : {
310 [ # # ]: 0 : for( nY = 0L; nY < nH; nY++ )
311 : : {
312 [ # # ]: 0 : for( nX = 0L; nX < nW; nX++ )
313 : : {
314 [ # # ]: 0 : aCol = pAcc->GetPixel( nY, nX );
315 : 0 : aCol.SetRed( pMapR[ aCol.GetRed() ] );
316 : 0 : aCol.SetGreen( pMapG[ aCol.GetGreen() ] );
317 : 0 : aCol.SetBlue( pMapB[ aCol.GetBlue() ] );
318 [ # # ]: 0 : pAcc->SetPixel( nY, nX, aCol );
319 : : }
320 : : }
321 : : }
322 : :
323 [ # # ]: 0 : delete[] pMapR;
324 [ # # ]: 0 : delete[] pMapG;
325 [ # # ]: 0 : delete[] pMapB;
326 [ # # ]: 0 : aTmpBmp.ReleaseAccess( pAcc );
327 : : }
328 : : }
329 : :
330 [ # # ]: 0 : if( nStyle & IMAGE_DRAW_SEMITRANSPARENT )
331 : : {
332 [ # # ][ # # ]: 0 : if( aTmpBmpEx.IsTransparent() )
333 : : {
334 [ # # ][ # # ]: 0 : Bitmap aAlphaBmp( aTmpBmpEx.GetAlpha().GetBitmap() );
[ # # ]
335 : :
336 [ # # ]: 0 : aAlphaBmp.Adjust( 50 );
337 [ # # ][ # # ]: 0 : aTmpBmpEx = BitmapEx( aTmpBmp, AlphaMask( aAlphaBmp ) );
[ # # ][ # # ]
[ # # ][ # # ]
338 : : }
339 : : else
340 : : {
341 : 0 : sal_uInt8 cErase = 128;
342 [ # # ][ # # ]: 0 : aTmpBmpEx = BitmapEx( aTmpBmp, AlphaMask( aTmpBmp.GetSizePixel(), &cErase ) );
[ # # ][ # # ]
[ # # ][ # # ]
343 : : }
344 : : }
345 : : else
346 : : {
347 [ # # ][ # # ]: 0 : if( aTmpBmpEx.IsAlpha() )
348 [ # # ][ # # ]: 0 : aTmpBmpEx = BitmapEx( aTmpBmp, aTmpBmpEx.GetAlpha() );
[ # # ][ # # ]
[ # # ]
349 [ # # ][ # # ]: 0 : else if( aTmpBmpEx.IsAlpha() )
350 [ # # ][ # # ]: 0 : aTmpBmpEx = BitmapEx( aTmpBmp, aTmpBmpEx.GetMask() );
[ # # ][ # # ]
[ # # ]
351 : : }
352 : :
353 [ # # ][ # # ]: 0 : pOutDev->DrawBitmapEx( rPos, aOutSize, aTmpBmpEx );
[ # # ]
354 : : }
355 : : else
356 : : {
357 : : const BitmapEx* pOutputBmp;
358 : :
359 [ + + ]: 106486 : if( pOutDev->GetOutDevType() == OUTDEV_WINDOW )
360 : : {
361 [ + - ]: 101406 : ImplUpdateDisplayBmp( pOutDev );
362 : 101406 : pOutputBmp = mpDisplayBmp;
363 : : }
364 : : else
365 : 5080 : pOutputBmp = &maBmpEx;
366 : :
367 [ + - ]: 106486 : if( pOutputBmp )
368 [ + - ]: 119208 : pOutDev->DrawBitmapEx( rPos, aOutSize, aSrcPos, maSize, *pOutputBmp );
369 : : }
370 : : }
371 : : }
372 : 119210 : }
373 : :
374 : : // -----------------------------------------------------------------------
375 : :
376 : 101406 : void ImplImageBmp::ImplUpdateDisplayBmp( OutputDevice*
377 : : #if defined WNT
378 : : pOutDev
379 : : #endif
380 : : )
381 : : {
382 [ + + ][ + - ]: 101406 : if( !mpDisplayBmp && !maBmpEx.IsEmpty() )
[ + + ]
383 : : {
384 : : #if defined WNT
385 : : if( maBmpEx.IsAlpha() )
386 : : mpDisplayBmp = new BitmapEx( maBmpEx );
387 : : else
388 : : {
389 : : const Bitmap aBmp( maBmpEx.GetBitmap().CreateDisplayBitmap( pOutDev ) );
390 : :
391 : : if( maBmpEx.IsTransparent() )
392 : : mpDisplayBmp = new BitmapEx( aBmp, maBmpEx.GetMask().CreateDisplayBitmap( pOutDev ) );
393 : : else
394 : : mpDisplayBmp = new BitmapEx( aBmp );
395 : : }
396 : : #else
397 [ + - ]: 60376 : mpDisplayBmp = new BitmapEx( maBmpEx );
398 : : #endif
399 : : }
400 : 101406 : }
401 : :
402 : : // -----------------------------------------------------------------------
403 : :
404 : 12722 : void ImplImageBmp::ImplUpdateDisabledBmpEx( int nPos )
405 : : {
406 : 12722 : const Size aTotalSize( maBmpEx.GetSizePixel() );
407 : :
408 [ + + ][ + - ]: 12722 : if( maDisabledBmpEx.IsEmpty() )
409 : : {
410 [ + - ][ + - ]: 7977 : Bitmap aGrey( aTotalSize, 8, &Bitmap::GetGreyPalette( 256 ) );
411 [ + - ]: 7977 : AlphaMask aGreyAlphaMask( aTotalSize );
412 : :
413 [ + - ][ + - ]: 7977 : maDisabledBmpEx = BitmapEx( aGrey, aGreyAlphaMask );
[ + - ]
414 [ + - ][ + - ]: 7977 : nPos = -1;
415 : : }
416 : :
417 [ + - ]: 12722 : Bitmap aBmp( maBmpEx.GetBitmap() );
418 [ + - ]: 12722 : BitmapReadAccess* pBmp( aBmp.AcquireReadAccess() );
419 [ + - ]: 12722 : AlphaMask aBmpAlphaMask( maBmpEx.GetAlpha() );
420 [ + - ]: 12722 : BitmapReadAccess* pBmpAlphaMask( aBmpAlphaMask.AcquireReadAccess() );
421 [ + - ]: 12722 : Bitmap aGrey( maDisabledBmpEx.GetBitmap() );
422 [ + - ]: 12722 : BitmapWriteAccess* pGrey( aGrey.AcquireWriteAccess() );
423 [ + - ]: 12722 : AlphaMask aGreyAlphaMask( maDisabledBmpEx.GetAlpha() );
424 [ + - ]: 12722 : BitmapWriteAccess* pGreyAlphaMask( aGreyAlphaMask.AcquireWriteAccess() );
425 : :
426 [ + - ][ + - ]: 12722 : if( pBmp && pBmpAlphaMask && pGrey && pGreyAlphaMask )
[ + - ][ + - ]
427 : : {
428 : 12722 : BitmapColor aGreyVal( 0 );
429 : 12722 : BitmapColor aGreyAlphaMaskVal( 0 );
430 [ + + ]: 12722 : const Point aPos( ( nPos < 0 ) ? 0 : ( nPos * maSize.Width() ), 0 );
431 [ + + ]: 12722 : const int nLeft = aPos.X(), nRight = nLeft + ( ( nPos < 0 ) ? aTotalSize.Width() : maSize.Width() );
432 : 12722 : const int nTop = aPos.Y(), nBottom = nTop + maSize.Height();
433 : :
434 [ + + ]: 216753 : for( int nY = nTop; nY < nBottom; ++nY )
435 : : {
436 [ + + ]: 3480648 : for( int nX = nLeft; nX < nRight; ++nX )
437 : : {
438 [ + - ]: 3276617 : aGreyVal.SetIndex( pBmp->GetLuminance( nY, nX ) );
439 [ + - ]: 3276617 : pGrey->SetPixel( nY, nX, aGreyVal );
440 : :
441 [ + - ]: 3276617 : const BitmapColor aBmpAlphaMaskVal( pBmpAlphaMask->GetPixel( nY, nX ) );
442 : :
443 [ + - ]: 3276617 : aGreyAlphaMaskVal.SetIndex( static_cast< sal_uInt8 >( ::std::min( aBmpAlphaMaskVal.GetIndex() + 178ul, 255ul ) ) );
444 [ + - ]: 3276617 : pGreyAlphaMask->SetPixel( nY, nX, aGreyAlphaMaskVal );
445 : 3276617 : }
446 : 12722 : }
447 : : }
448 : :
449 [ + - ]: 12722 : aBmp.ReleaseAccess( pBmp );
450 [ + - ]: 12722 : aBmpAlphaMask.ReleaseAccess( pBmpAlphaMask );
451 [ + - ]: 12722 : aGrey.ReleaseAccess( pGrey );
452 [ + - ]: 12722 : aGreyAlphaMask.ReleaseAccess( pGreyAlphaMask );
453 : :
454 [ + - ][ + - ]: 12722 : maDisabledBmpEx = BitmapEx( aGrey, aGreyAlphaMask );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
455 : 12722 : }
456 : :
457 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|