1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_VCL_BITMAPINFOACCESS_HXX
21 #define INCLUDED_VCL_BITMAPINFOACCESS_HXX
23 #include <vcl/dllapi.h>
24 #include <vcl/bitmap.hxx>
25 #include <vcl/Scanline.hxx>
26 #include <vcl/BitmapBuffer.hxx>
27 #include <vcl/BitmapColor.hxx>
28 #include <vcl/BitmapAccessMode.hxx>
30 bool Bitmap32IsPreMultipled();
32 typedef BitmapColor (*FncGetPixel
)(ConstScanline pScanline
, tools::Long nX
, const ColorMask
& rMask
);
33 typedef void (*FncSetPixel
)(Scanline pScanline
, tools::Long nX
, const BitmapColor
& rBitmapColor
,
34 const ColorMask
& rMask
);
36 class VCL_DLLPUBLIC BitmapInfoAccess
38 friend class BitmapReadAccess
;
41 BitmapInfoAccess(Bitmap
& rBitmap
, BitmapAccessMode nMode
= BitmapAccessMode::Info
);
42 virtual ~BitmapInfoAccess();
44 bool operator!() const { return mpBuffer
== nullptr; }
46 tools::Long
Width() const { return mpBuffer
? mpBuffer
->mnWidth
: 0L; }
48 tools::Long
Height() const { return mpBuffer
? mpBuffer
->mnHeight
: 0L; }
50 bool IsTopDown() const
52 assert(mpBuffer
&& "Access is not valid!");
54 return mpBuffer
&& (mpBuffer
->mnFormat
& ScanlineFormat::TopDown
);
57 bool IsBottomUp() const { return !IsTopDown(); }
59 ScanlineFormat
GetScanlineFormat() const
61 assert(mpBuffer
&& "Access is not valid!");
63 return mpBuffer
? RemoveScanline(mpBuffer
->mnFormat
) : ScanlineFormat::NONE
;
66 sal_uInt32
GetScanlineSize() const
68 assert(mpBuffer
&& "Access is not valid!");
70 return mpBuffer
? mpBuffer
->mnScanlineSize
: 0;
73 sal_uInt16
GetBitCount() const
75 assert(mpBuffer
&& "Access is not valid!");
77 return mpBuffer
? mpBuffer
->mnBitCount
: 0;
80 BitmapColor
GetBestMatchingColor(const BitmapColor
& rBitmapColor
) const
83 return BitmapColor(static_cast<sal_uInt8
>(GetBestPaletteIndex(rBitmapColor
)));
88 bool HasPalette() const
90 const BitmapBuffer
* pBuffer
= mpBuffer
;
92 assert(pBuffer
&& "Access is not valid!");
94 return pBuffer
&& !!pBuffer
->maPalette
;
97 const BitmapPalette
& GetPalette() const
99 const BitmapBuffer
* pBuffer
= mpBuffer
;
101 assert(pBuffer
&& "Access is not valid!");
103 return pBuffer
->maPalette
;
106 sal_uInt16
GetPaletteEntryCount() const
108 const BitmapBuffer
* pBuffer
= mpBuffer
;
110 assert(HasPalette() && "Bitmap has no palette!");
112 return HasPalette() ? pBuffer
->maPalette
.GetEntryCount() : 0;
115 const BitmapColor
& GetPaletteColor(sal_uInt16 nColor
) const
117 const BitmapBuffer
* pBuffer
= mpBuffer
;
118 assert(pBuffer
&& "Access is not valid!");
119 assert(HasPalette() && "Bitmap has no palette!");
121 return pBuffer
->maPalette
[nColor
];
124 sal_uInt16
GetBestPaletteIndex(const BitmapColor
& rBitmapColor
) const;
126 const ColorMask
& GetColorMask() const
128 const BitmapBuffer
* pBuffer
= mpBuffer
;
130 assert(pBuffer
&& "Access is not valid!");
132 return pBuffer
->maColorMask
;
136 BitmapInfoAccess(const BitmapInfoAccess
&) = delete;
137 BitmapInfoAccess
& operator=(const BitmapInfoAccess
&) = delete;
141 BitmapBuffer
* mpBuffer
;
142 ColorMask maColorMask
;
143 BitmapAccessMode mnAccessMode
;
146 #endif // INCLUDED_VCL_BITMAPINFOACCESS_HXX
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */