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_BITMAPREADACCESS_HXX
21 #define INCLUDED_VCL_BITMAPREADACCESS_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>
29 #include <vcl/BitmapInfoAccess.hxx>
31 class SAL_DLLPUBLIC_RTTI BitmapReadAccess
: public BitmapInfoAccess
33 friend class BitmapWriteAccess
;
36 VCL_DLLPUBLIC
BitmapReadAccess(Bitmap
& rBitmap
,
37 BitmapAccessMode nMode
= BitmapAccessMode::Read
);
38 VCL_DLLPUBLIC
virtual ~BitmapReadAccess() override
;
40 Scanline
GetBuffer() const
42 assert(mpBuffer
&& "Access is not valid!");
44 return mpBuffer
? mpBuffer
->mpBits
: nullptr;
47 Scanline
GetScanline(tools::Long nY
) const
49 assert(mpBuffer
&& "Access is not valid!");
50 assert(nY
< mpBuffer
->mnHeight
&& "y-coordinate out of range!");
52 if (mpBuffer
->mnFormat
& ScanlineFormat::TopDown
)
54 return mpBuffer
->mpBits
+ (nY
* mpBuffer
->mnScanlineSize
);
56 return mpBuffer
->mpBits
+ ((mpBuffer
->mnHeight
- 1 - nY
) * mpBuffer
->mnScanlineSize
);
59 BitmapColor
GetPixelFromData(const sal_uInt8
* pData
, tools::Long nX
) const
61 assert(pData
&& "Access is not valid!");
63 return mFncGetPixel(pData
, nX
, maColorMask
);
66 sal_uInt8
GetIndexFromData(const sal_uInt8
* pData
, tools::Long nX
) const
68 return GetPixelFromData(pData
, nX
).GetIndex();
71 void SetPixelOnData(sal_uInt8
* pData
, tools::Long nX
, const BitmapColor
& rBitmapColor
)
73 assert(pData
&& "Access is not valid!");
75 mFncSetPixel(pData
, nX
, rBitmapColor
, maColorMask
);
78 BitmapColor
GetPixel(tools::Long nY
, tools::Long nX
) const
80 assert(mpBuffer
&& "Access is not valid!");
81 assert(nX
< mpBuffer
->mnWidth
&& "x-coordinate out of range!");
82 assert(nY
< mpBuffer
->mnHeight
&& "y-coordinate out of range!");
84 return mFncGetPixel(GetScanline(nY
), nX
, maColorMask
);
87 BitmapColor
GetPixel(const Point
& point
) const { return GetPixel(point
.Y(), point
.X()); }
89 BitmapColor
GetColor(tools::Long nY
, tools::Long nX
) const
93 const BitmapBuffer
* pBuffer
= mpBuffer
;
94 return pBuffer
->maPalette
[GetPixelIndex(nY
, nX
)];
97 return GetPixel(nY
, nX
);
100 BitmapColor
GetColor(const Point
& point
) const { return GetColor(point
.Y(), point
.X()); }
102 sal_uInt8
GetPixelIndex(tools::Long nY
, tools::Long nX
) const
104 return GetPixel(nY
, nX
).GetIndex();
107 sal_uInt8
GetPixelIndex(const Point
& point
) const
109 return GetPixelIndex(point
.Y(), point
.X());
112 /** Get the interpolated color at coordinates fY, fX; if outside, return rFallback */
113 BitmapColor
GetInterpolatedColorWithFallback(double fY
, double fX
,
114 const BitmapColor
& rFallback
) const;
116 /** Get the color at coordinates fY, fX; if outside, return rFallback. Automatically does the correct
117 inside/outside checks, e.g. static_cast< sal_uInt32 >(-0.25) *is* 0, not -1 and has to be outside */
118 BitmapColor
GetColorWithFallback(double fY
, double fX
, const BitmapColor
& rFallback
) const;
121 BitmapReadAccess(const BitmapReadAccess
&) = delete;
122 BitmapReadAccess
& operator=(const BitmapReadAccess
&) = delete;
125 FncGetPixel mFncGetPixel
;
126 FncSetPixel mFncSetPixel
;
129 BitmapBuffer
* ImplGetBitmapBuffer() const { return mpBuffer
; }
131 static BitmapColor
GetPixelForN1BitMsbPal(ConstScanline pScanline
, tools::Long nX
,
132 const ColorMask
& rMask
);
133 static BitmapColor
GetPixelForN1BitLsbPal(ConstScanline pScanline
, tools::Long nX
,
134 const ColorMask
& rMask
);
135 static BitmapColor
GetPixelForN8BitPal(ConstScanline pScanline
, tools::Long nX
,
136 const ColorMask
& rMask
);
137 static BitmapColor
GetPixelForN24BitTcBgr(ConstScanline pScanline
, tools::Long nX
,
138 const ColorMask
& rMask
);
139 static BitmapColor
GetPixelForN24BitTcRgb(ConstScanline pScanline
, tools::Long nX
,
140 const ColorMask
& rMask
);
141 static BitmapColor
GetPixelForN32BitTcAbgr(ConstScanline pScanline
, tools::Long nX
,
142 const ColorMask
& rMask
);
143 static BitmapColor
GetPixelForN32BitTcXbgr(ConstScanline pScanline
, tools::Long nX
,
144 const ColorMask
& rMask
);
145 static BitmapColor
GetPixelForN32BitTcArgb(ConstScanline pScanline
, tools::Long nX
,
146 const ColorMask
& rMask
);
147 static BitmapColor
GetPixelForN32BitTcXrgb(ConstScanline pScanline
, tools::Long nX
,
148 const ColorMask
& rMask
);
149 static BitmapColor
GetPixelForN32BitTcBgra(ConstScanline pScanline
, tools::Long nX
,
150 const ColorMask
& rMask
);
151 static BitmapColor
GetPixelForN32BitTcBgrx(ConstScanline pScanline
, tools::Long nX
,
152 const ColorMask
& rMask
);
153 static BitmapColor
GetPixelForN32BitTcRgba(ConstScanline pScanline
, tools::Long nX
,
154 const ColorMask
& rMask
);
155 static BitmapColor
GetPixelForN32BitTcRgbx(ConstScanline pScanline
, tools::Long nX
,
156 const ColorMask
& rMask
);
157 static BitmapColor
GetPixelForN32BitTcMask(ConstScanline pScanline
, tools::Long nX
,
158 const ColorMask
& rMask
);
160 static void SetPixelForN1BitMsbPal(Scanline pScanline
, tools::Long nX
,
161 const BitmapColor
& rBitmapColor
, const ColorMask
& rMask
);
162 static void SetPixelForN1BitLsbPal(Scanline pScanline
, tools::Long nX
,
163 const BitmapColor
& rBitmapColor
, const ColorMask
& rMask
);
164 static void SetPixelForN8BitPal(Scanline pScanline
, tools::Long nX
,
165 const BitmapColor
& rBitmapColor
, const ColorMask
& rMask
);
166 static void SetPixelForN24BitTcBgr(Scanline pScanline
, tools::Long nX
,
167 const BitmapColor
& rBitmapColor
, const ColorMask
& rMask
);
168 static void SetPixelForN24BitTcRgb(Scanline pScanline
, tools::Long nX
,
169 const BitmapColor
& rBitmapColor
, const ColorMask
& rMask
);
170 static void SetPixelForN32BitTcAbgr(Scanline pScanline
, tools::Long nX
,
171 const BitmapColor
& rBitmapColor
, const ColorMask
& rMask
);
172 static void SetPixelForN32BitTcXbgr(Scanline pScanline
, tools::Long nX
,
173 const BitmapColor
& rBitmapColor
, const ColorMask
& rMask
);
174 static void SetPixelForN32BitTcArgb(Scanline pScanline
, tools::Long nX
,
175 const BitmapColor
& rBitmapColor
, const ColorMask
& rMask
);
176 static void SetPixelForN32BitTcXrgb(Scanline pScanline
, tools::Long nX
,
177 const BitmapColor
& rBitmapColor
, const ColorMask
& rMask
);
178 static void SetPixelForN32BitTcBgra(Scanline pScanline
, tools::Long nX
,
179 const BitmapColor
& rBitmapColor
, const ColorMask
& rMask
);
180 static void SetPixelForN32BitTcBgrx(Scanline pScanline
, tools::Long nX
,
181 const BitmapColor
& rBitmapColor
, const ColorMask
& rMask
);
182 static void SetPixelForN32BitTcRgba(Scanline pScanline
, tools::Long nX
,
183 const BitmapColor
& rBitmapColor
, const ColorMask
& rMask
);
184 static void SetPixelForN32BitTcRgbx(Scanline pScanline
, tools::Long nX
,
185 const BitmapColor
& rBitmapColor
, const ColorMask
& rMask
);
186 static void SetPixelForN32BitTcMask(Scanline pScanline
, tools::Long nX
,
187 const BitmapColor
& rBitmapColor
, const ColorMask
& rMask
);
189 static FncGetPixel
GetPixelFunction(ScanlineFormat nFormat
);
190 static FncSetPixel
SetPixelFunction(ScanlineFormat nFormat
);
193 #endif // INCLUDED_VCL_BITMAPREADACCESS_HXX
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */