xref: /aoo41x/main/vcl/source/gdi/impbmp.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_vcl.hxx"
30 
31 #include <tools/debug.hxx>
32 
33 #include <vcl/bitmap.hxx>
34 
35 #include <svdata.hxx>
36 #include <salinst.hxx>
37 #include <salbmp.hxx>
38 #include <impbmp.hxx>
39 
40 // --------------
41 // - ImpBitmap	-
42 // --------------
43 
44 ImpBitmap::ImpBitmap() :
45 			mnRefCount	( 1UL ),
46 			mnChecksum	( 0UL ),
47 			mpSalBitmap ( ImplGetSVData()->mpDefInst->CreateSalBitmap() ),
48 			maSourceSize( 0, 0 )
49 {
50 }
51 
52 // -----------------------------------------------------------------------
53 
54 ImpBitmap::~ImpBitmap()
55 {
56 	delete mpSalBitmap;
57 }
58 
59 // -----------------------------------------------------------------------
60 void ImpBitmap::ImplSetSalBitmap( SalBitmap* pBitmap )
61 {
62 	delete mpSalBitmap, mpSalBitmap = pBitmap;
63 }
64 
65 // -----------------------------------------------------------------------
66 
67 sal_Bool ImpBitmap::ImplCreate( const Size& rSize, sal_uInt16 nBitCount, const BitmapPalette& rPal )
68 {
69 	maSourceSize = rSize;
70 	return mpSalBitmap->Create( rSize, nBitCount, rPal );
71 }
72 
73 // -----------------------------------------------------------------------
74 
75 sal_Bool ImpBitmap::ImplCreate( const ImpBitmap& rImpBitmap )
76 {
77 	maSourceSize = rImpBitmap.maSourceSize;
78 	mnChecksum = rImpBitmap.mnChecksum;
79 	return mpSalBitmap->Create( *rImpBitmap.mpSalBitmap );
80 }
81 
82 // -----------------------------------------------------------------------
83 
84 sal_Bool ImpBitmap::ImplCreate( const ImpBitmap& rImpBitmap, SalGraphics* pGraphics )
85 {
86 	return mpSalBitmap->Create( *rImpBitmap.mpSalBitmap, pGraphics );
87 }
88 
89 // -----------------------------------------------------------------------
90 
91 sal_Bool ImpBitmap::ImplCreate( const ImpBitmap& rImpBitmap, sal_uInt16 nNewBitCount )
92 {
93 	return mpSalBitmap->Create( *rImpBitmap.mpSalBitmap, nNewBitCount );
94 }
95 
96 // -----------------------------------------------------------------------
97 
98 void ImpBitmap::ImplDestroy()
99 {
100 	mpSalBitmap->Destroy();
101 }
102 
103 // -----------------------------------------------------------------------
104 
105 Size ImpBitmap::ImplGetSize() const
106 {
107 	return mpSalBitmap->GetSize();
108 }
109 
110 // -----------------------------------------------------------------------
111 
112 sal_uInt16 ImpBitmap::ImplGetBitCount() const
113 {
114 	sal_uInt16 nBitCount = mpSalBitmap->GetBitCount();
115 	return( ( nBitCount <= 1 ) ? 1 : ( nBitCount <= 4 ) ? 4 : ( nBitCount <= 8 ) ? 8 : 24 );
116 }
117 
118 // -----------------------------------------------------------------------
119 
120 BitmapBuffer* ImpBitmap::ImplAcquireBuffer( sal_Bool bReadOnly )
121 {
122 	return mpSalBitmap->AcquireBuffer( bReadOnly );
123 }
124 
125 // -----------------------------------------------------------------------
126 
127 void ImpBitmap::ImplReleaseBuffer( BitmapBuffer* pBuffer, sal_Bool bReadOnly )
128 {
129 	mpSalBitmap->ReleaseBuffer( pBuffer, bReadOnly );
130 
131 	if( !bReadOnly )
132 		mnChecksum = 0;
133 }
134