10d63794cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
30d63794cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
40d63794cSAndrew Rist * or more contributor license agreements. See the NOTICE file
50d63794cSAndrew Rist * distributed with this work for additional information
60d63794cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
70d63794cSAndrew Rist * to you under the Apache License, Version 2.0 (the
80d63794cSAndrew Rist * "License"); you may not use this file except in compliance
90d63794cSAndrew Rist * with the License. You may obtain a copy of the License at
100d63794cSAndrew Rist *
110d63794cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
120d63794cSAndrew Rist *
130d63794cSAndrew Rist * Unless required by applicable law or agreed to in writing,
140d63794cSAndrew Rist * software distributed under the License is distributed on an
150d63794cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
160d63794cSAndrew Rist * KIND, either express or implied. See the License for the
170d63794cSAndrew Rist * specific language governing permissions and limitations
180d63794cSAndrew Rist * under the License.
190d63794cSAndrew Rist *
200d63794cSAndrew Rist *************************************************************/
210d63794cSAndrew Rist
220d63794cSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #ifndef _SV_BMPACC_HXX
25cdf0e10cSrcweir #define _SV_BMPACC_HXX
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <vcl/sv.h>
28cdf0e10cSrcweir #include <vcl/dllapi.h>
29cdf0e10cSrcweir #include <vcl/salbtype.hxx>
30cdf0e10cSrcweir #include <vcl/bitmap.hxx>
31cdf0e10cSrcweir
32cdf0e10cSrcweir //#if 0 // _SOLAR__PRIVATE
33cdf0e10cSrcweir
34cdf0e10cSrcweir // --------------------
35cdf0e10cSrcweir // - Access defines -
36cdf0e10cSrcweir // --------------------
37cdf0e10cSrcweir
38cdf0e10cSrcweir #define DECL_FORMAT_GETPIXEL( Format ) \
39cdf0e10cSrcweir static BitmapColor GetPixelFor##Format( ConstScanline pScanline, long nX, const ColorMask& rMask );
40cdf0e10cSrcweir
41cdf0e10cSrcweir #define DECL_FORMAT_SETPIXEL( Format ) \
42cdf0e10cSrcweir static void SetPixelFor##Format( Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask );
43cdf0e10cSrcweir
44cdf0e10cSrcweir #define DECL_FORMAT( Format ) \
45cdf0e10cSrcweir DECL_FORMAT_GETPIXEL( Format ) \
46cdf0e10cSrcweir DECL_FORMAT_SETPIXEL( Format )
47cdf0e10cSrcweir
48cdf0e10cSrcweir #define IMPL_FORMAT_GETPIXEL( Format ) \
49cdf0e10cSrcweir BitmapColor BitmapReadAccess::GetPixelFor##Format( ConstScanline pScanline, long nX, const ColorMask& rMask )
50cdf0e10cSrcweir
51cdf0e10cSrcweir #define IMPL_FORMAT_GETPIXEL_NOMASK( Format ) \
52cdf0e10cSrcweir BitmapColor BitmapReadAccess::GetPixelFor##Format( ConstScanline pScanline, long nX, const ColorMask& )
53cdf0e10cSrcweir
54cdf0e10cSrcweir #define IMPL_FORMAT_SETPIXEL( Format ) \
55cdf0e10cSrcweir void BitmapReadAccess::SetPixelFor##Format( Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask )
56cdf0e10cSrcweir
57cdf0e10cSrcweir #define IMPL_FORMAT_SETPIXEL_NOMASK( Format ) \
58cdf0e10cSrcweir void BitmapReadAccess::SetPixelFor##Format( Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& )
59cdf0e10cSrcweir
60cdf0e10cSrcweir #define CASE_FORMAT( Format ) \
61cdf0e10cSrcweir case( BMP_FORMAT##Format ): \
62cdf0e10cSrcweir { \
63cdf0e10cSrcweir mFncGetPixel = GetPixelFor##Format;\
64cdf0e10cSrcweir mFncSetPixel = SetPixelFor##Format;\
65cdf0e10cSrcweir } \
66cdf0e10cSrcweir break;
67cdf0e10cSrcweir
68cdf0e10cSrcweir //#endif // __PRIVATE
69cdf0e10cSrcweir
70cdf0e10cSrcweir // --------------------
71cdf0e10cSrcweir // - Access functions -
72cdf0e10cSrcweir // --------------------
73cdf0e10cSrcweir
74cdf0e10cSrcweir typedef BitmapColor (*FncGetPixel)( ConstScanline pScanline, long nX, const ColorMask& rMask );
75cdf0e10cSrcweir typedef void (*FncSetPixel)( Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask );
76cdf0e10cSrcweir
77cdf0e10cSrcweir // --------------------
78cdf0e10cSrcweir // - BitmapReadAccess -
79cdf0e10cSrcweir // --------------------
80cdf0e10cSrcweir
81cdf0e10cSrcweir class VCL_DLLPUBLIC BitmapReadAccess
82cdf0e10cSrcweir {
83cdf0e10cSrcweir friend class BitmapWriteAccess;
84cdf0e10cSrcweir
85cdf0e10cSrcweir private:
86cdf0e10cSrcweir
BitmapReadAccess()87cdf0e10cSrcweir BitmapReadAccess() {}
BitmapReadAccess(const BitmapReadAccess &)88cdf0e10cSrcweir BitmapReadAccess( const BitmapReadAccess& ) {}
operator =(const BitmapReadAccess &)89cdf0e10cSrcweir BitmapReadAccess& operator=( const BitmapReadAccess& ) { return *this; }
90cdf0e10cSrcweir
91cdf0e10cSrcweir protected:
92cdf0e10cSrcweir Bitmap maBitmap;
93cdf0e10cSrcweir BitmapBuffer* mpBuffer;
94cdf0e10cSrcweir Scanline* mpScanBuf;
95cdf0e10cSrcweir ColorMask maColorMask;
96cdf0e10cSrcweir FncGetPixel mFncGetPixel;
97cdf0e10cSrcweir FncSetPixel mFncSetPixel;
98cdf0e10cSrcweir sal_Bool mbModify;
99cdf0e10cSrcweir
100cdf0e10cSrcweir //#if 0 // _SOLAR__PRIVATE
101cdf0e10cSrcweir
102cdf0e10cSrcweir SAL_DLLPRIVATE void ImplCreate( Bitmap& rBitmap );
103cdf0e10cSrcweir SAL_DLLPRIVATE void ImplDestroy();
104cdf0e10cSrcweir SAL_DLLPRIVATE sal_Bool ImplSetAccessPointers( sal_uLong nFormat );
105cdf0e10cSrcweir
106cdf0e10cSrcweir public:
107cdf0e10cSrcweir
108cdf0e10cSrcweir SAL_DLLPRIVATE void ImplZeroInitUnusedBits();
ImplGetBitmapBuffer() const109cdf0e10cSrcweir SAL_DLLPRIVATE BitmapBuffer* ImplGetBitmapBuffer() const { return mpBuffer; }
110cdf0e10cSrcweir
111cdf0e10cSrcweir DECL_FORMAT( _1BIT_MSB_PAL )
112cdf0e10cSrcweir DECL_FORMAT( _1BIT_LSB_PAL )
113cdf0e10cSrcweir DECL_FORMAT( _4BIT_MSN_PAL )
114cdf0e10cSrcweir DECL_FORMAT( _4BIT_LSN_PAL )
115cdf0e10cSrcweir DECL_FORMAT( _8BIT_PAL )
116cdf0e10cSrcweir DECL_FORMAT( _8BIT_TC_MASK )
117cdf0e10cSrcweir DECL_FORMAT( _16BIT_TC_MSB_MASK )
118cdf0e10cSrcweir DECL_FORMAT( _16BIT_TC_LSB_MASK )
119cdf0e10cSrcweir DECL_FORMAT( _24BIT_TC_BGR )
120cdf0e10cSrcweir DECL_FORMAT( _24BIT_TC_RGB )
121cdf0e10cSrcweir DECL_FORMAT( _24BIT_TC_MASK )
122cdf0e10cSrcweir DECL_FORMAT( _32BIT_TC_ABGR )
123cdf0e10cSrcweir DECL_FORMAT( _32BIT_TC_ARGB )
124cdf0e10cSrcweir DECL_FORMAT( _32BIT_TC_BGRA )
125cdf0e10cSrcweir DECL_FORMAT( _32BIT_TC_RGBA )
126cdf0e10cSrcweir DECL_FORMAT( _32BIT_TC_MASK )
127cdf0e10cSrcweir //#endif // __PRIVATE
128cdf0e10cSrcweir
129cdf0e10cSrcweir protected:
130cdf0e10cSrcweir BitmapReadAccess( Bitmap& rBitmap, sal_Bool bModify );
131cdf0e10cSrcweir
132cdf0e10cSrcweir void Flush();
133cdf0e10cSrcweir void ReAccess( sal_Bool bModify );
134cdf0e10cSrcweir
135cdf0e10cSrcweir public:
136cdf0e10cSrcweir BitmapReadAccess( Bitmap& rBitmap );
137cdf0e10cSrcweir virtual ~BitmapReadAccess();
138cdf0e10cSrcweir
139cdf0e10cSrcweir inline sal_Bool operator!() const;
140cdf0e10cSrcweir
141cdf0e10cSrcweir inline long Width() const;
142cdf0e10cSrcweir inline long Height() const;
143cdf0e10cSrcweir inline Point TopLeft() const;
144cdf0e10cSrcweir inline Point BottomRight() const;
145cdf0e10cSrcweir
146cdf0e10cSrcweir inline sal_Bool IsTopDown() const;
147cdf0e10cSrcweir inline sal_Bool IsBottomUp() const;
148cdf0e10cSrcweir
149cdf0e10cSrcweir inline sal_uLong GetScanlineFormat() const;
150cdf0e10cSrcweir inline sal_uLong GetScanlineSize() const;
151cdf0e10cSrcweir
152cdf0e10cSrcweir inline sal_uInt16 GetBitCount() const;
153cdf0e10cSrcweir inline BitmapColor GetBestMatchingColor( const BitmapColor& rBitmapColor );
154cdf0e10cSrcweir
155cdf0e10cSrcweir inline Scanline GetBuffer() const;
156cdf0e10cSrcweir inline Scanline GetScanline( long nY ) const;
157cdf0e10cSrcweir
158cdf0e10cSrcweir inline sal_Bool HasPalette() const;
159cdf0e10cSrcweir inline const BitmapPalette& GetPalette() const;
160cdf0e10cSrcweir inline sal_uInt16 GetPaletteEntryCount() const;
161cdf0e10cSrcweir inline const BitmapColor& GetPaletteColor( sal_uInt16 nColor ) const;
162cdf0e10cSrcweir inline const BitmapColor& GetBestPaletteColor( const BitmapColor& rBitmapColor ) const;
163cdf0e10cSrcweir sal_uInt16 GetBestPaletteIndex( const BitmapColor& rBitmapColor ) const;
164cdf0e10cSrcweir
165cdf0e10cSrcweir inline sal_Bool HasColorMask() const;
166cdf0e10cSrcweir inline ColorMask& GetColorMask() const;
167cdf0e10cSrcweir
168cdf0e10cSrcweir inline BitmapColor GetPixelFromData( const sal_uInt8* pData, long nX ) const;
169cdf0e10cSrcweir inline void SetPixelOnData( sal_uInt8* pData, long nX, const BitmapColor& rBitmapColor );
170cdf0e10cSrcweir inline BitmapColor GetPixel( long nY, long nX ) const;
17187bc88d3SHerbert Dürr inline BitmapColor GetColor( long nY, long nX ) const;
17287bc88d3SHerbert Dürr inline sal_uInt8 GetPixelIndex( long nY, long nX ) const;
17387bc88d3SHerbert Dürr inline sal_uInt8 GetLuminance( long nY, long nX ) const;
174*f8c0d554SArmin Le Grand
175*f8c0d554SArmin Le Grand /** Get the interpolated color at coordinates fY, fX; if outside, return rFallback */
176*f8c0d554SArmin Le Grand BitmapColor GetInterpolatedColorWithFallback( double fY, double fX, const BitmapColor& rFallback ) const;
177*f8c0d554SArmin Le Grand
178*f8c0d554SArmin Le Grand /** Get the color at coordinates fY, fX; if outside, return rFallback. Automatically does the correct
179*f8c0d554SArmin Le Grand inside/outside checks, e.g. static_cast< sal_uInt32 >(-0.25) *is* 0, not -1 and has to be outside */
180*f8c0d554SArmin Le Grand BitmapColor GetColorWithFallback( double fY, double fX, const BitmapColor& rFallback ) const;
181*f8c0d554SArmin Le Grand
182*f8c0d554SArmin Le Grand /** Get the color at coordinates nY, nX; if outside, return rFallback */
183*f8c0d554SArmin Le Grand BitmapColor GetColorWithFallback( long nY, long nX, const BitmapColor& rFallback ) const;
184cdf0e10cSrcweir };
185cdf0e10cSrcweir
186cdf0e10cSrcweir // ---------------------
187cdf0e10cSrcweir // - BitmapWriteAccess -
188cdf0e10cSrcweir // ---------------------
189cdf0e10cSrcweir
190cdf0e10cSrcweir class VCL_DLLPUBLIC BitmapWriteAccess : public BitmapReadAccess
191cdf0e10cSrcweir {
192cdf0e10cSrcweir public:
193cdf0e10cSrcweir
194cdf0e10cSrcweir BitmapWriteAccess( Bitmap& rBitmap );
195cdf0e10cSrcweir virtual ~BitmapWriteAccess();
196cdf0e10cSrcweir
197cdf0e10cSrcweir void CopyScanline( long nY, const BitmapReadAccess& rReadAcc );
198cdf0e10cSrcweir void CopyScanline( long nY, ConstScanline aSrcScanline,
199cdf0e10cSrcweir sal_uLong nSrcScanlineFormat, sal_uLong nSrcScanlineSize );
200cdf0e10cSrcweir
201cdf0e10cSrcweir void CopyBuffer( const BitmapReadAccess& rReadAcc );
202cdf0e10cSrcweir
203cdf0e10cSrcweir inline void SetPalette( const BitmapPalette& rPalette );
204cdf0e10cSrcweir inline void SetPaletteEntryCount( sal_uInt16 nCount );
205cdf0e10cSrcweir inline void SetPaletteColor( sal_uInt16 nColor, const BitmapColor& rBitmapColor );
206cdf0e10cSrcweir
207cdf0e10cSrcweir inline void SetPixel( long nY, long nX, const BitmapColor& rBitmapColor );
20887bc88d3SHerbert Dürr inline void SetPixelIndex( long nY, long nX, sal_uInt8 cIndex );
209cdf0e10cSrcweir
210cdf0e10cSrcweir void SetLineColor();
211cdf0e10cSrcweir void SetLineColor( const Color& rColor );
212cdf0e10cSrcweir Color GetLineColor() const;
213cdf0e10cSrcweir
214cdf0e10cSrcweir void SetFillColor();
215cdf0e10cSrcweir void SetFillColor( const Color& rColor );
216cdf0e10cSrcweir Color GetFillColor() const;
217cdf0e10cSrcweir
218cdf0e10cSrcweir void Erase( const Color& rColor );
219cdf0e10cSrcweir
220cdf0e10cSrcweir void DrawLine( const Point& rStart, const Point& rEnd );
221cdf0e10cSrcweir
222cdf0e10cSrcweir void FillRect( const Rectangle& rRect );
223cdf0e10cSrcweir void DrawRect( const Rectangle& rRect );
224cdf0e10cSrcweir
225cdf0e10cSrcweir void FillPolygon( const Polygon& rPoly );
226cdf0e10cSrcweir void DrawPolygon( const Polygon& rPoly );
227cdf0e10cSrcweir
228cdf0e10cSrcweir void FillPolyPolygon( const PolyPolygon& rPoly );
229cdf0e10cSrcweir void DrawPolyPolygon( const PolyPolygon& rPolyPoly );
230cdf0e10cSrcweir
231cdf0e10cSrcweir private:
232cdf0e10cSrcweir
233cdf0e10cSrcweir BitmapColor* mpLineColor;
234cdf0e10cSrcweir BitmapColor* mpFillColor;
235cdf0e10cSrcweir
BitmapWriteAccess()236cdf0e10cSrcweir BitmapWriteAccess() {}
BitmapWriteAccess(const BitmapWriteAccess &)237cdf0e10cSrcweir BitmapWriteAccess( const BitmapWriteAccess& ) : BitmapReadAccess() {}
operator =(const BitmapWriteAccess &)238cdf0e10cSrcweir BitmapWriteAccess& operator=( const BitmapWriteAccess& ) { return *this; }
239cdf0e10cSrcweir };
240cdf0e10cSrcweir
241cdf0e10cSrcweir // -------------------
242cdf0e10cSrcweir // - Accessor Helper -
243cdf0e10cSrcweir // -------------------
244cdf0e10cSrcweir
245cdf0e10cSrcweir /** This template handles BitmapAccess the RAII way.
246cdf0e10cSrcweir
247cdf0e10cSrcweir Please don't use directly, but the ready-made typedefs for
248cdf0e10cSrcweir BitmapReadAccess and BitmapWriteAccess below.
249cdf0e10cSrcweir */
250cdf0e10cSrcweir template < class Access > class ScopedBitmapAccess
251cdf0e10cSrcweir {
252cdf0e10cSrcweir public:
ScopedBitmapAccess(Access * pAccess,Bitmap & rBitmap)253cdf0e10cSrcweir ScopedBitmapAccess( Access* pAccess,
254cdf0e10cSrcweir Bitmap& rBitmap ) :
255cdf0e10cSrcweir mpAccess( pAccess ),
256cdf0e10cSrcweir mrBitmap( rBitmap )
257cdf0e10cSrcweir {
258cdf0e10cSrcweir }
259cdf0e10cSrcweir
~ScopedBitmapAccess()260cdf0e10cSrcweir ~ScopedBitmapAccess()
261cdf0e10cSrcweir {
262cdf0e10cSrcweir mrBitmap.ReleaseAccess( mpAccess );
263cdf0e10cSrcweir }
264cdf0e10cSrcweir
get()265cdf0e10cSrcweir Access* get() { return mpAccess; }
get() const266cdf0e10cSrcweir const Access* get() const { return mpAccess; }
267cdf0e10cSrcweir
operator ->()268cdf0e10cSrcweir Access* operator->() { return mpAccess; }
operator ->() const269cdf0e10cSrcweir const Access* operator->() const { return mpAccess; }
270cdf0e10cSrcweir
operator *()271cdf0e10cSrcweir Access& operator*() { return *mpAccess; }
operator *() const272cdf0e10cSrcweir const Access& operator*() const { return *mpAccess; }
273cdf0e10cSrcweir
274cdf0e10cSrcweir private:
275cdf0e10cSrcweir Access* mpAccess;
276cdf0e10cSrcweir Bitmap& mrBitmap;
277cdf0e10cSrcweir };
278cdf0e10cSrcweir
279cdf0e10cSrcweir /** This wrapper handles BitmapReadAccess the RAII way.
280cdf0e10cSrcweir
281cdf0e10cSrcweir Use as follows:
282cdf0e10cSrcweir Bitmap aBitmap
283cdf0e10cSrcweir ScopedBitmapReadAccess pReadAccess( aBitmap.AcquireReadAccess(), aBitmap );
284cdf0e10cSrcweir pReadAccess->SetPixel()...
285cdf0e10cSrcweir
286cdf0e10cSrcweir @attention for practical reasons, ScopedBitmapReadAccess stores a
287cdf0e10cSrcweir reference to the provided bitmap, thus, make sure that the bitmap
288cdf0e10cSrcweir specified at construction time lives at least as long as the
289cdf0e10cSrcweir ScopedBitmapReadAccess.
290cdf0e10cSrcweir */
291cdf0e10cSrcweir typedef ScopedBitmapAccess< BitmapReadAccess > ScopedBitmapReadAccess;
292cdf0e10cSrcweir
293cdf0e10cSrcweir /** This wrapper handles BitmapWriteAccess the RAII way.
294cdf0e10cSrcweir
295cdf0e10cSrcweir Use as follows:
296cdf0e10cSrcweir Bitmap aBitmap
297cdf0e10cSrcweir ScopedBitmapWriteAccess pWriteAccess( aBitmap.AcquireWriteAccess(), aBitmap );
298cdf0e10cSrcweir pWriteAccess->SetPixel()...
299cdf0e10cSrcweir
300cdf0e10cSrcweir @attention for practical reasons, ScopedBitmapWriteAccess stores a
301cdf0e10cSrcweir reference to the provided bitmap, thus, make sure that the bitmap
302cdf0e10cSrcweir specified at construction time lives at least as long as the
303cdf0e10cSrcweir ScopedBitmapWriteAccess.
304cdf0e10cSrcweir */
305cdf0e10cSrcweir typedef ScopedBitmapAccess< BitmapWriteAccess > ScopedBitmapWriteAccess;
306cdf0e10cSrcweir
307cdf0e10cSrcweir // -----------
308cdf0e10cSrcweir // - Inlines -
309cdf0e10cSrcweir // -----------
310cdf0e10cSrcweir
operator !() const311cdf0e10cSrcweir inline sal_Bool BitmapReadAccess::operator!() const
312cdf0e10cSrcweir {
313cdf0e10cSrcweir return( mpBuffer == NULL );
314cdf0e10cSrcweir }
315cdf0e10cSrcweir
316cdf0e10cSrcweir // ------------------------------------------------------------------
317cdf0e10cSrcweir
Width() const318cdf0e10cSrcweir inline long BitmapReadAccess::Width() const
319cdf0e10cSrcweir {
320cdf0e10cSrcweir return( mpBuffer ? mpBuffer->mnWidth : 0L );
321cdf0e10cSrcweir }
322cdf0e10cSrcweir
323cdf0e10cSrcweir // ------------------------------------------------------------------
324cdf0e10cSrcweir
Height() const325cdf0e10cSrcweir inline long BitmapReadAccess::Height() const
326cdf0e10cSrcweir {
327cdf0e10cSrcweir return( mpBuffer ? mpBuffer->mnHeight : 0L );
328cdf0e10cSrcweir }
329cdf0e10cSrcweir
330cdf0e10cSrcweir // ------------------------------------------------------------------
331cdf0e10cSrcweir
TopLeft() const332cdf0e10cSrcweir inline Point BitmapReadAccess::TopLeft() const
333cdf0e10cSrcweir {
334cdf0e10cSrcweir return Point();
335cdf0e10cSrcweir }
336cdf0e10cSrcweir
337cdf0e10cSrcweir // ------------------------------------------------------------------
338cdf0e10cSrcweir
BottomRight() const339cdf0e10cSrcweir inline Point BitmapReadAccess::BottomRight() const
340cdf0e10cSrcweir {
341cdf0e10cSrcweir return Point( Width() - 1L, Height() - 1L );
342cdf0e10cSrcweir }
343cdf0e10cSrcweir
344cdf0e10cSrcweir // ------------------------------------------------------------------
345cdf0e10cSrcweir
IsTopDown() const346cdf0e10cSrcweir inline sal_Bool BitmapReadAccess::IsTopDown() const
347cdf0e10cSrcweir {
348cdf0e10cSrcweir DBG_ASSERT( mpBuffer, "Access is not valid!" );
349cdf0e10cSrcweir return( mpBuffer ? sal::static_int_cast<sal_Bool>( BMP_SCANLINE_ADJUSTMENT( mpBuffer->mnFormat ) == BMP_FORMAT_TOP_DOWN ) : sal_False );
350cdf0e10cSrcweir }
351cdf0e10cSrcweir
352cdf0e10cSrcweir // ------------------------------------------------------------------
353cdf0e10cSrcweir
IsBottomUp() const354cdf0e10cSrcweir inline sal_Bool BitmapReadAccess::IsBottomUp() const
355cdf0e10cSrcweir {
356cdf0e10cSrcweir return !IsTopDown();
357cdf0e10cSrcweir }
358cdf0e10cSrcweir
359cdf0e10cSrcweir // ------------------------------------------------------------------
360cdf0e10cSrcweir
GetScanlineFormat() const361cdf0e10cSrcweir inline sal_uLong BitmapReadAccess::GetScanlineFormat() const
362cdf0e10cSrcweir {
363cdf0e10cSrcweir DBG_ASSERT( mpBuffer, "Access is not valid!" );
364cdf0e10cSrcweir return( mpBuffer ? BMP_SCANLINE_FORMAT( mpBuffer->mnFormat ) : 0UL );
365cdf0e10cSrcweir }
366cdf0e10cSrcweir
367cdf0e10cSrcweir // ------------------------------------------------------------------
368cdf0e10cSrcweir
GetScanlineSize() const369cdf0e10cSrcweir inline sal_uLong BitmapReadAccess::GetScanlineSize() const
370cdf0e10cSrcweir {
371cdf0e10cSrcweir DBG_ASSERT( mpBuffer, "Access is not valid!" );
372cdf0e10cSrcweir return( mpBuffer ? mpBuffer->mnScanlineSize : 0UL );
373cdf0e10cSrcweir }
374cdf0e10cSrcweir
375cdf0e10cSrcweir // ------------------------------------------------------------------
376cdf0e10cSrcweir
GetBitCount() const377cdf0e10cSrcweir inline sal_uInt16 BitmapReadAccess::GetBitCount() const
378cdf0e10cSrcweir {
379cdf0e10cSrcweir DBG_ASSERT( mpBuffer, "Access is not valid!" );
380cdf0e10cSrcweir return( mpBuffer ? mpBuffer->mnBitCount : 0 );
381cdf0e10cSrcweir }
382cdf0e10cSrcweir
383cdf0e10cSrcweir // ------------------------------------------------------------------
384cdf0e10cSrcweir
GetBestMatchingColor(const BitmapColor & rBitmapColor)385cdf0e10cSrcweir inline BitmapColor BitmapReadAccess::GetBestMatchingColor( const BitmapColor& rBitmapColor )
386cdf0e10cSrcweir {
387cdf0e10cSrcweir if( HasPalette() )
388cdf0e10cSrcweir return BitmapColor( (sal_uInt8) GetBestPaletteIndex( rBitmapColor ) );
389cdf0e10cSrcweir else
390cdf0e10cSrcweir return rBitmapColor;
391cdf0e10cSrcweir }
392cdf0e10cSrcweir
393cdf0e10cSrcweir // ------------------------------------------------------------------
394cdf0e10cSrcweir
GetBuffer() const395cdf0e10cSrcweir inline Scanline BitmapReadAccess::GetBuffer() const
396cdf0e10cSrcweir {
397cdf0e10cSrcweir DBG_ASSERT( mpBuffer, "Access is not valid!" );
398cdf0e10cSrcweir return( mpBuffer ? mpBuffer->mpBits : NULL );
399cdf0e10cSrcweir }
400cdf0e10cSrcweir
401cdf0e10cSrcweir // ------------------------------------------------------------------
402cdf0e10cSrcweir
GetScanline(long nY) const403cdf0e10cSrcweir inline Scanline BitmapReadAccess::GetScanline( long nY ) const
404cdf0e10cSrcweir {
405cdf0e10cSrcweir DBG_ASSERT( mpBuffer, "Access is not valid!" );
406cdf0e10cSrcweir DBG_ASSERT( nY < mpBuffer->mnHeight, "y-coordinate out of range!" );
407cdf0e10cSrcweir return( mpBuffer ? mpScanBuf[ nY ] : NULL );
408cdf0e10cSrcweir }
409cdf0e10cSrcweir
410cdf0e10cSrcweir // ------------------------------------------------------------------
411cdf0e10cSrcweir
HasPalette() const412cdf0e10cSrcweir inline sal_Bool BitmapReadAccess::HasPalette() const
413cdf0e10cSrcweir {
414cdf0e10cSrcweir DBG_ASSERT( mpBuffer, "Access is not valid!" );
415cdf0e10cSrcweir return( mpBuffer && !!mpBuffer->maPalette );
416cdf0e10cSrcweir }
417cdf0e10cSrcweir
418cdf0e10cSrcweir // ------------------------------------------------------------------
419cdf0e10cSrcweir
GetPalette() const420cdf0e10cSrcweir inline const BitmapPalette& BitmapReadAccess::GetPalette() const
421cdf0e10cSrcweir {
422cdf0e10cSrcweir DBG_ASSERT( mpBuffer, "Access is not valid!" );
423cdf0e10cSrcweir return mpBuffer->maPalette;
424cdf0e10cSrcweir }
425cdf0e10cSrcweir
426cdf0e10cSrcweir // ------------------------------------------------------------------
427cdf0e10cSrcweir
GetPaletteEntryCount() const428cdf0e10cSrcweir inline sal_uInt16 BitmapReadAccess::GetPaletteEntryCount() const
429cdf0e10cSrcweir {
430cdf0e10cSrcweir DBG_ASSERT( HasPalette(), "Bitmap has no palette!" );
431cdf0e10cSrcweir return( HasPalette() ? mpBuffer->maPalette.GetEntryCount() : 0 );
432cdf0e10cSrcweir }
433cdf0e10cSrcweir
434cdf0e10cSrcweir // ------------------------------------------------------------------
435cdf0e10cSrcweir
GetPaletteColor(sal_uInt16 nColor) const436cdf0e10cSrcweir inline const BitmapColor& BitmapReadAccess::GetPaletteColor( sal_uInt16 nColor ) const
437cdf0e10cSrcweir {
438cdf0e10cSrcweir DBG_ASSERT( mpBuffer, "Access is not valid!" );
439cdf0e10cSrcweir DBG_ASSERT( HasPalette(), "Bitmap has no palette!" );
440cdf0e10cSrcweir return mpBuffer->maPalette[ nColor ];
441cdf0e10cSrcweir }
442cdf0e10cSrcweir
443cdf0e10cSrcweir // ------------------------------------------------------------------
444cdf0e10cSrcweir
GetBestPaletteColor(const BitmapColor & rBitmapColor) const445cdf0e10cSrcweir inline const BitmapColor& BitmapReadAccess::GetBestPaletteColor( const BitmapColor& rBitmapColor ) const
446cdf0e10cSrcweir {
447cdf0e10cSrcweir return GetPaletteColor( GetBestPaletteIndex( rBitmapColor ) );
448cdf0e10cSrcweir }
449cdf0e10cSrcweir
450cdf0e10cSrcweir // ------------------------------------------------------------------
451cdf0e10cSrcweir
HasColorMask() const452cdf0e10cSrcweir inline sal_Bool BitmapReadAccess::HasColorMask() const
453cdf0e10cSrcweir {
454cdf0e10cSrcweir DBG_ASSERT( mpBuffer, "Access is not valid!" );
455cdf0e10cSrcweir const sal_uLong nFormat = BMP_SCANLINE_FORMAT( mpBuffer->mnFormat );
456cdf0e10cSrcweir
457cdf0e10cSrcweir return( nFormat == BMP_FORMAT_8BIT_TC_MASK ||
458cdf0e10cSrcweir nFormat == BMP_FORMAT_16BIT_TC_MSB_MASK ||
459cdf0e10cSrcweir nFormat == BMP_FORMAT_16BIT_TC_LSB_MASK ||
460cdf0e10cSrcweir nFormat == BMP_FORMAT_24BIT_TC_MASK ||
461cdf0e10cSrcweir nFormat == BMP_FORMAT_32BIT_TC_MASK );
462cdf0e10cSrcweir }
463cdf0e10cSrcweir
464cdf0e10cSrcweir // ------------------------------------------------------------------
465cdf0e10cSrcweir
GetColorMask() const466cdf0e10cSrcweir inline ColorMask& BitmapReadAccess::GetColorMask() const
467cdf0e10cSrcweir {
468cdf0e10cSrcweir DBG_ASSERT( mpBuffer, "Access is not valid!" );
469cdf0e10cSrcweir return mpBuffer->maColorMask;
470cdf0e10cSrcweir }
471cdf0e10cSrcweir
472cdf0e10cSrcweir // ------------------------------------------------------------------
473cdf0e10cSrcweir
GetPixel(long nY,long nX) const474cdf0e10cSrcweir inline BitmapColor BitmapReadAccess::GetPixel( long nY, long nX ) const
475cdf0e10cSrcweir {
476cdf0e10cSrcweir DBG_ASSERT( mpBuffer, "Access is not valid!" );
477cdf0e10cSrcweir DBG_ASSERT( nX < mpBuffer->mnWidth, "x-coordinate out of range!" );
478cdf0e10cSrcweir DBG_ASSERT( nY < mpBuffer->mnHeight, "y-coordinate out of range!" );
479cdf0e10cSrcweir return mFncGetPixel( mpScanBuf[ nY ], nX, maColorMask );
480cdf0e10cSrcweir }
481cdf0e10cSrcweir
GetPixelIndex(long nY,long nX) const48287bc88d3SHerbert Dürr inline sal_uInt8 BitmapReadAccess::GetPixelIndex( long nY, long nX ) const
48387bc88d3SHerbert Dürr {
48487bc88d3SHerbert Dürr return GetPixel( nY, nX ).GetBlueOrIndex();
48587bc88d3SHerbert Dürr }
48687bc88d3SHerbert Dürr
487cdf0e10cSrcweir // ------------------------------------------------------------------
488cdf0e10cSrcweir
GetPixelFromData(const sal_uInt8 * pData,long nX) const489cdf0e10cSrcweir inline BitmapColor BitmapReadAccess::GetPixelFromData( const sal_uInt8* pData, long nX ) const
490cdf0e10cSrcweir {
491cdf0e10cSrcweir DBG_ASSERT( pData, "Access is not valid!" );
492cdf0e10cSrcweir return mFncGetPixel( pData, nX, maColorMask );
493cdf0e10cSrcweir }
494cdf0e10cSrcweir
495cdf0e10cSrcweir // ------------------------------------------------------------------
496cdf0e10cSrcweir
SetPixelOnData(sal_uInt8 * pData,long nX,const BitmapColor & rBitmapColor)497cdf0e10cSrcweir inline void BitmapReadAccess::SetPixelOnData( sal_uInt8* pData, long nX, const BitmapColor& rBitmapColor )
498cdf0e10cSrcweir {
499cdf0e10cSrcweir DBG_ASSERT( pData, "Access is not valid!" );
500cdf0e10cSrcweir mFncSetPixel( pData, nX, rBitmapColor, maColorMask );
501cdf0e10cSrcweir }
502cdf0e10cSrcweir
503cdf0e10cSrcweir // ------------------------------------------------------------------
504cdf0e10cSrcweir
GetColor(long nY,long nX) const505cdf0e10cSrcweir inline BitmapColor BitmapReadAccess::GetColor( long nY, long nX ) const
506cdf0e10cSrcweir {
50787bc88d3SHerbert Dürr if( HasPalette() )
50887bc88d3SHerbert Dürr return mpBuffer->maPalette[ GetPixelIndex( nY, nX ) ];
509cdf0e10cSrcweir else
510cdf0e10cSrcweir return GetPixel( nY, nX );
511cdf0e10cSrcweir }
512cdf0e10cSrcweir
513cdf0e10cSrcweir // ------------------------------------------------------------------
514cdf0e10cSrcweir
GetLuminance(long nY,long nX) const515cdf0e10cSrcweir inline sal_uInt8 BitmapReadAccess::GetLuminance( long nY, long nX ) const
516cdf0e10cSrcweir {
517cdf0e10cSrcweir return GetColor( nY, nX ).GetLuminance();
518cdf0e10cSrcweir }
519cdf0e10cSrcweir
520cdf0e10cSrcweir // ------------------------------------------------------------------
521cdf0e10cSrcweir
SetPalette(const BitmapPalette & rPalette)522cdf0e10cSrcweir inline void BitmapWriteAccess::SetPalette( const BitmapPalette& rPalette )
523cdf0e10cSrcweir {
524cdf0e10cSrcweir DBG_ASSERT( mpBuffer, "Access is not valid!" );
525cdf0e10cSrcweir mpBuffer->maPalette = rPalette;
526cdf0e10cSrcweir }
527cdf0e10cSrcweir
528cdf0e10cSrcweir // ------------------------------------------------------------------
529cdf0e10cSrcweir
SetPaletteEntryCount(sal_uInt16 nCount)530cdf0e10cSrcweir inline void BitmapWriteAccess::SetPaletteEntryCount( sal_uInt16 nCount )
531cdf0e10cSrcweir {
532cdf0e10cSrcweir DBG_ASSERT( mpBuffer, "Access is not valid!" );
533cdf0e10cSrcweir mpBuffer->maPalette.SetEntryCount( nCount );
534cdf0e10cSrcweir }
535cdf0e10cSrcweir
536cdf0e10cSrcweir // ------------------------------------------------------------------
537cdf0e10cSrcweir
SetPaletteColor(sal_uInt16 nColor,const BitmapColor & rBitmapColor)538cdf0e10cSrcweir inline void BitmapWriteAccess::SetPaletteColor( sal_uInt16 nColor, const BitmapColor& rBitmapColor )
539cdf0e10cSrcweir {
540cdf0e10cSrcweir DBG_ASSERT( mpBuffer, "Access is not valid!" );
541cdf0e10cSrcweir DBG_ASSERT( HasPalette(), "Bitmap has no palette!" );
542cdf0e10cSrcweir mpBuffer->maPalette[ nColor ] = rBitmapColor;
543cdf0e10cSrcweir }
544cdf0e10cSrcweir
545cdf0e10cSrcweir // ------------------------------------------------------------------
546cdf0e10cSrcweir
SetPixel(long nY,long nX,const BitmapColor & rBitmapColor)547cdf0e10cSrcweir inline void BitmapWriteAccess::SetPixel( long nY, long nX, const BitmapColor& rBitmapColor )
548cdf0e10cSrcweir {
549cdf0e10cSrcweir DBG_ASSERT( mpBuffer, "Access is not valid!" );
550cdf0e10cSrcweir DBG_ASSERT( nX < mpBuffer->mnWidth, "x-coordinate out of range!" );
551cdf0e10cSrcweir DBG_ASSERT( nY < mpBuffer->mnHeight, "y-coordinate out of range!" );
552cdf0e10cSrcweir mFncSetPixel( mpScanBuf[ nY ], nX, rBitmapColor, maColorMask );
553cdf0e10cSrcweir }
554cdf0e10cSrcweir
SetPixelIndex(long nY,long nX,sal_uInt8 cIndex)55587bc88d3SHerbert Dürr inline void BitmapWriteAccess::SetPixelIndex( long nY, long nX, sal_uInt8 cIndex )
55687bc88d3SHerbert Dürr {
55787bc88d3SHerbert Dürr SetPixel( nY, nX, BitmapColor( cIndex ));
55887bc88d3SHerbert Dürr }
55987bc88d3SHerbert Dürr
56087bc88d3SHerbert Dürr // ------------------------------------------------------------------
56187bc88d3SHerbert Dürr
562cdf0e10cSrcweir #endif // _SV_BMPACC_HXX
563