LibreOffice Module vcl (master)  1
bitmapaccess.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #ifndef INCLUDED_VCL_BMPACC_HXX
21 #define INCLUDED_VCL_BMPACC_HXX
22 
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 
30 typedef BitmapColor (*FncGetPixel)(ConstScanline pScanline, long nX, const ColorMask& rMask);
31 typedef void (*FncSetPixel)(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask);
32 
34 {
35  friend class BitmapReadAccess;
36 
37 public:
39  virtual ~BitmapInfoAccess();
40 
41  bool operator!() const
42  {
43  return mpBuffer == nullptr;
44  }
45 
46  long Width() const
47  {
48  return mpBuffer ? mpBuffer->mnWidth : 0L;
49  }
50 
51  long Height() const
52  {
53  return mpBuffer ? mpBuffer->mnHeight : 0L;
54  }
55 
56  bool IsTopDown() const
57  {
58  assert(mpBuffer && "Access is not valid!");
59 
61  }
62 
63  bool IsBottomUp() const
64  {
65  return !IsTopDown();
66  }
67 
69  {
70  assert(mpBuffer && "Access is not valid!");
71 
73  }
74 
75  sal_uInt32 GetScanlineSize() const
76  {
77  assert(mpBuffer && "Access is not valid!");
78 
79  return mpBuffer ? mpBuffer->mnScanlineSize : 0;
80  }
81 
82  sal_uInt16 GetBitCount() const
83  {
84  assert(mpBuffer && "Access is not valid!");
85 
86  return mpBuffer ? mpBuffer->mnBitCount : 0;
87  }
88 
90  {
91  if (HasPalette())
92  return BitmapColor(static_cast<sal_uInt8>(GetBestPaletteIndex(rBitmapColor)));
93  else
94  return rBitmapColor;
95  }
96 
97  bool HasPalette() const
98  {
99  assert(mpBuffer && "Access is not valid!");
100 
101  return mpBuffer && !!mpBuffer->maPalette;
102  }
103 
104  const BitmapPalette& GetPalette() const
105  {
106  assert(mpBuffer && "Access is not valid!");
107 
108  return mpBuffer->maPalette;
109  }
110 
111  sal_uInt16 GetPaletteEntryCount() const
112  {
113  assert(HasPalette() && "Bitmap has no palette!");
114 
115  return HasPalette() ? mpBuffer->maPalette.GetEntryCount() : 0;
116  }
117 
118  const BitmapColor& GetPaletteColor( sal_uInt16 nColor ) const
119  {
120  assert(mpBuffer && "Access is not valid!");
121  assert(HasPalette() && "Bitmap has no palette!");
122 
123  return mpBuffer->maPalette[nColor];
124  }
125 
126  const BitmapColor& GetBestPaletteColor(const BitmapColor& rBitmapColor) const
127  {
128  return GetPaletteColor(GetBestPaletteIndex(rBitmapColor));
129  }
130 
131  sal_uInt16 GetBestPaletteIndex(const BitmapColor& rBitmapColor) const;
132 
134  {
135  assert(mpBuffer && "Access is not valid!");
136 
137  return mpBuffer->maColorMask;
138  }
139 
140 private:
141  BitmapInfoAccess(const BitmapInfoAccess&) = delete;
142  BitmapInfoAccess& operator=(const BitmapInfoAccess&) = delete;
143 
144 protected:
149 };
150 
151 
153 {
154  friend class BitmapWriteAccess;
155 
156 public:
158  virtual ~BitmapReadAccess() override;
159 
161  {
162  assert(mpBuffer && "Access is not valid!");
163 
164  return mpBuffer ? mpBuffer->mpBits : nullptr;
165  }
166 
167  Scanline GetScanline(long nY) const
168  {
169  assert(mpBuffer && "Access is not valid!");
170  assert(nY < mpBuffer->mnHeight && "y-coordinate out of range!");
171 
173  {
174  return mpBuffer->mpBits + (nY * mpBuffer->mnScanlineSize);
175  }
176  return mpBuffer->mpBits + ((mpBuffer->mnHeight - 1 - nY) * mpBuffer->mnScanlineSize);
177  }
178 
179  BitmapColor GetPixelFromData(const sal_uInt8* pData, long nX) const
180  {
181  assert(pData && "Access is not valid!");
182 
183  return mFncGetPixel( pData, nX, maColorMask );
184  }
185 
186  sal_uInt8 GetIndexFromData(const sal_uInt8* pData, long nX) const
187  {
188  return GetPixelFromData( pData, nX ).GetIndex();
189  }
190 
191  void SetPixelOnData(sal_uInt8* pData, long nX, const BitmapColor& rBitmapColor)
192  {
193  assert(pData && "Access is not valid!");
194 
195  mFncSetPixel(pData, nX, rBitmapColor, maColorMask);
196  }
197 
198  BitmapColor GetPixel(long nY, long nX) const
199  {
200  assert(mpBuffer && "Access is not valid!");
201  assert(nX < mpBuffer->mnWidth && "x-coordinate out of range!");
202  assert(nY < mpBuffer->mnHeight && "y-coordinate out of range!");
203 
204  return mFncGetPixel(GetScanline(nY), nX, maColorMask );
205  }
206 
207  BitmapColor GetColor(long nY, long nX) const
208  {
209  if (HasPalette())
210  return mpBuffer->maPalette[GetPixelIndex(nY, nX)];
211  else
212  return GetPixel(nY, nX);
213  }
214 
215  sal_uInt8 GetPixelIndex(long nY, long nX) const
216  {
217  return GetPixel(nY, nX).GetIndex();
218  }
219 
221  BitmapColor GetInterpolatedColorWithFallback( double fY, double fX, const BitmapColor& rFallback ) const;
222 
225  BitmapColor GetColorWithFallback( double fY, double fX, const BitmapColor& rFallback ) const;
226 
227 private:
228  BitmapReadAccess(const BitmapReadAccess&) = delete;
229  BitmapReadAccess& operator=(const BitmapReadAccess&) = delete;
230 
231 protected:
234 
235  SAL_DLLPRIVATE bool ImplSetAccessPointers( ScanlineFormat nFormat );
236 
237 public:
238 
239  SAL_DLLPRIVATE BitmapBuffer* ImplGetBitmapBuffer() const
240  {
241  return mpBuffer;
242  }
243 
244  static BitmapColor GetPixelForN1BitMsbPal(ConstScanline pScanline, long nX, const ColorMask& rMask);
245  static BitmapColor GetPixelForN1BitLsbPal(ConstScanline pScanline, long nX, const ColorMask& rMask);
246  static BitmapColor GetPixelForN4BitMsnPal(ConstScanline pScanline, long nX, const ColorMask& rMask);
247  static BitmapColor GetPixelForN4BitLsnPal(ConstScanline pScanline, long nX, const ColorMask& rMask);
248  static BitmapColor GetPixelForN8BitPal(ConstScanline pScanline, long nX, const ColorMask& rMask);
249  static BitmapColor GetPixelForN8BitTcMask(ConstScanline pScanline, long nX, const ColorMask& rMask);
250  static BitmapColor GetPixelForN24BitTcBgr(ConstScanline pScanline, long nX, const ColorMask& rMask);
251  static BitmapColor GetPixelForN24BitTcRgb(ConstScanline pScanline, long nX, const ColorMask& rMask);
252  static BitmapColor GetPixelForN32BitTcAbgr(ConstScanline pScanline, long nX, const ColorMask& rMask);
253  static BitmapColor GetPixelForN32BitTcXbgr(ConstScanline pScanline, long nX, const ColorMask& rMask);
254  static BitmapColor GetPixelForN32BitTcArgb(ConstScanline pScanline, long nX, const ColorMask& rMask);
255  static BitmapColor GetPixelForN32BitTcXrgb(ConstScanline pScanline, long nX, const ColorMask& rMask);
256  static BitmapColor GetPixelForN32BitTcBgra(ConstScanline pScanline, long nX, const ColorMask& rMask);
257  static BitmapColor GetPixelForN32BitTcBgrx(ConstScanline pScanline, long nX, const ColorMask& rMask);
258  static BitmapColor GetPixelForN32BitTcRgba(ConstScanline pScanline, long nX, const ColorMask& rMask);
259  static BitmapColor GetPixelForN32BitTcRgbx(ConstScanline pScanline, long nX, const ColorMask& rMask);
260  static BitmapColor GetPixelForN32BitTcMask(ConstScanline pScanline, long nX, const ColorMask& rMask);
261 
262  static void SetPixelForN1BitMsbPal(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask);
263  static void SetPixelForN1BitLsbPal(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask);
264  static void SetPixelForN4BitMsnPal(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask);
265  static void SetPixelForN4BitLsnPal(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask);
266  static void SetPixelForN8BitPal(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask);
267  static void SetPixelForN8BitTcMask(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask);
268  static void SetPixelForN24BitTcBgr(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask);
269  static void SetPixelForN24BitTcRgb(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask);
270  static void SetPixelForN32BitTcAbgr(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask);
271  static void SetPixelForN32BitTcXbgr(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask);
272  static void SetPixelForN32BitTcArgb(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask);
273  static void SetPixelForN32BitTcXrgb(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask);
274  static void SetPixelForN32BitTcBgra(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask);
275  static void SetPixelForN32BitTcBgrx(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask);
276  static void SetPixelForN32BitTcRgba(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask);
277  static void SetPixelForN32BitTcRgbx(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask);
278  static void SetPixelForN32BitTcMask(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask);
279 
280 };
281 
282 
283 #endif // INCLUDED_VCL_BMPACC_HXX
284 
285 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
double mnHeight
static BitmapColor GetPixelForN4BitLsnPal(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:74
Scanline GetBuffer() const
static BitmapColor GetPixelForN8BitTcMask(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:105
sal_uInt8 GetIndex() const
Definition: BitmapColor.hxx:61
void(* FncSetPixel)(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
ColorMask maColorMask
static void SetPixelForN32BitTcRgba(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:330
Scanline GetScanline(long nY) const
const BitmapColor & GetBestPaletteColor(const BitmapColor &rBitmapColor) const
BitmapColor GetColorWithFallback(double fY, double fX, const BitmapColor &rFallback) const
Get the color at coordinates fY, fX; if outside, return rFallback.
Definition: bmpacc.cxx:336
virtual ~BitmapReadAccess() override
Definition: bmpacc.cxx:109
virtual ~BitmapInfoAccess()
Definition: bmpacc.cxx:71
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
static BitmapColor GetPixelForN32BitTcArgb(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:206
static void SetPixelForN32BitTcBgrx(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:293
sal_uInt16 GetBitCount() const
SAL_DLLPRIVATE bool ImplSetAccessPointers(ScanlineFormat nFormat)
Definition: bmpacc.cxx:122
static BitmapColor GetPixelForN32BitTcBgrx(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:270
sal_uInt16 GetBestPaletteIndex(const BitmapColor &rBitmapColor) const
Definition: bmpacc.cxx:81
long Width() const
sal_uInt8 GetPixelIndex(long nY, long nX) const
static void SetPixelForN32BitTcXrgb(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:245
static void SetPixelForN24BitTcBgr(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:130
static BitmapColor GetPixelForN32BitTcRgba(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:302
static void SetPixelForN32BitTcMask(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:357
sal_uInt16 mnBitCount
static void SetPixelForN4BitMsnPal(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:58
ScanlineFormat
Definition: Scanline.hxx:28
static BitmapColor GetPixelForN4BitMsnPal(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:53
static BitmapColor GetPixelForN32BitTcMask(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:350
static BitmapColor GetPixelForN8BitPal(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:95
BitmapColor GetInterpolatedColorWithFallback(double fY, double fX, const BitmapColor &rFallback) const
Get the interpolated color at coordinates fY, fX; if outside, return rFallback.
Definition: bmpacc.cxx:247
void SetPixelOnData(sal_uInt8 *pData, long nX, const BitmapColor &rBitmapColor)
static BitmapColor GetPixelForN32BitTcBgra(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:254
BitmapBuffer * mpBuffer
static BitmapColor GetPixelForN1BitMsbPal(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:23
static BitmapColor GetPixelForN32BitTcXbgr(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:174
SAL_DLLPRIVATE BitmapBuffer * ImplGetBitmapBuffer() const
ScanlineFormat mnFormat
FncGetPixel mFncGetPixel
sal_uInt16 GetEntryCount() const
sal_uInt8 * Scanline
Definition: Scanline.hxx:25
static void SetPixelForN32BitTcXbgr(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:197
bool IsTopDown() const
sal_uInt32 GetScanlineSize() const
bool HasPalette() const
ScanlineFormat GetScanlineFormat() const
static BitmapColor GetPixelForN24BitTcBgr(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:118
BitmapAccessMode
sal_uInt8 * mpBits
static BitmapColor GetPixelForN32BitTcXrgb(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:222
static BitmapColor GetPixelForN32BitTcAbgr(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:158
friend class BitmapReadAccess
bool operator!() const
BitmapColor GetPixel(long nY, long nX) const
sal_uInt16 GetPaletteEntryCount() const
ColorMask & GetColorMask() const
FncSetPixel mFncSetPixel
const sal_uInt8 * ConstScanline
Definition: Scanline.hxx:26
BitmapInfoAccess(Bitmap &rBitmap, BitmapAccessMode nMode=BitmapAccessMode::Info)
Definition: bmpacc.cxx:32
static BitmapColor GetPixelForN32BitTcRgbx(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:318
long Height() const
unsigned char sal_uInt8
static void SetPixelForN8BitPal(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:100
BitmapColor GetColor(long nY, long nX) const
const BitmapPalette & GetPalette() const
double mnWidth
static void SetPixelForN1BitLsbPal(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:43
static void SetPixelForN32BitTcBgra(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:282
bool IsBottomUp() const
ColorMask maColorMask
BitmapColor GetPixelFromData(const sal_uInt8 *pData, long nX) const
ScanlineFormat RemoveScanline(ScanlineFormat nFormat)
Definition: Scanline.hxx:57
BitmapPalette maPalette
static void SetPixelForN4BitLsnPal(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:79
static void SetPixelForN32BitTcRgbx(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:341
BitmapAccessMode const mnAccessMode
const BitmapColor & GetPaletteColor(sal_uInt16 nColor) const
static BitmapColor GetPixelForN1BitLsbPal(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:38
static BitmapColor GetPixelForN24BitTcRgb(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:138
BitmapColor(* FncGetPixel)(ConstScanline pScanline, long nX, const ColorMask &rMask)
static void SetPixelForN8BitTcMask(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:112
static void SetPixelForN1BitMsbPal(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:28
BitmapInfoAccess & operator=(const BitmapInfoAccess &)=delete
BitmapColor GetBestMatchingColor(const BitmapColor &rBitmapColor)
static void SetPixelForN32BitTcArgb(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:234
static void SetPixelForN32BitTcAbgr(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:186
BitmapReadAccess & operator=(const BitmapReadAccess &)=delete
static void SetPixelForN24BitTcRgb(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:150
sal_uInt8 GetIndexFromData(const sal_uInt8 *pData, long nX) const
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo