LibreOffice Module vcl (master)  1
BitmapReadAccess.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_BITMAPREADACCESS_HXX
21 #define INCLUDED_VCL_BITMAPREADACCESS_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 #include <vcl/BitmapInfoAccess.hxx>
30 
32 {
33  friend class BitmapWriteAccess;
34 
35 public:
37  virtual ~BitmapReadAccess() override;
38 
40  {
41  assert(mpBuffer && "Access is not valid!");
42 
43  return mpBuffer ? mpBuffer->mpBits : nullptr;
44  }
45 
47  {
48  assert(mpBuffer && "Access is not valid!");
49  assert(nY < mpBuffer->mnHeight && "y-coordinate out of range!");
50 
52  {
53  return mpBuffer->mpBits + (nY * mpBuffer->mnScanlineSize);
54  }
55  return mpBuffer->mpBits + ((mpBuffer->mnHeight - 1 - nY) * mpBuffer->mnScanlineSize);
56  }
57 
59  {
60  assert(pData && "Access is not valid!");
61 
62  return mFncGetPixel(pData, nX, maColorMask);
63  }
64 
66  {
67  return GetPixelFromData(pData, nX).GetIndex();
68  }
69 
70  void SetPixelOnData(sal_uInt8* pData, tools::Long nX, const BitmapColor& rBitmapColor)
71  {
72  assert(pData && "Access is not valid!");
73 
74  mFncSetPixel(pData, nX, rBitmapColor, maColorMask);
75  }
76 
78  {
79  assert(mpBuffer && "Access is not valid!");
80  assert(nX < mpBuffer->mnWidth && "x-coordinate out of range!");
81  assert(nY < mpBuffer->mnHeight && "y-coordinate out of range!");
82 
83  return mFncGetPixel(GetScanline(nY), nX, maColorMask);
84  }
85 
86  BitmapColor GetPixel(const Point& point) const { return GetPixel(point.Y(), point.X()); }
87 
89  {
90  if (HasPalette())
91  {
92  const BitmapBuffer* pBuffer = mpBuffer;
93  return pBuffer->maPalette[GetPixelIndex(nY, nX)];
94  }
95  else
96  return GetPixel(nY, nX);
97  }
98 
99  BitmapColor GetColor(const Point& point) const { return GetColor(point.Y(), point.X()); }
100 
102  {
103  return GetPixel(nY, nX).GetIndex();
104  }
105 
106  sal_uInt8 GetPixelIndex(const Point& point) const
107  {
108  return GetPixelIndex(point.Y(), point.X());
109  }
110 
112  BitmapColor GetInterpolatedColorWithFallback(double fY, double fX,
113  const BitmapColor& rFallback) const;
114 
117  BitmapColor GetColorWithFallback(double fY, double fX, const BitmapColor& rFallback) const;
118 
119 private:
120  BitmapReadAccess(const BitmapReadAccess&) = delete;
121  BitmapReadAccess& operator=(const BitmapReadAccess&) = delete;
122 
123 protected:
126 
127 public:
128  SAL_DLLPRIVATE BitmapBuffer* ImplGetBitmapBuffer() const { return mpBuffer; }
129 
131  const ColorMask& rMask);
133  const ColorMask& rMask);
135  const ColorMask& rMask);
137  const ColorMask& rMask);
139  const ColorMask& rMask);
141  const ColorMask& rMask);
143  const ColorMask& rMask);
145  const ColorMask& rMask);
147  const ColorMask& rMask);
149  const ColorMask& rMask);
151  const ColorMask& rMask);
153  const ColorMask& rMask);
155  const ColorMask& rMask);
157  const ColorMask& rMask);
158 
159  static void SetPixelForN1BitMsbPal(Scanline pScanline, tools::Long nX,
160  const BitmapColor& rBitmapColor, const ColorMask& rMask);
161  static void SetPixelForN1BitLsbPal(Scanline pScanline, tools::Long nX,
162  const BitmapColor& rBitmapColor, const ColorMask& rMask);
163  static void SetPixelForN8BitPal(Scanline pScanline, tools::Long nX,
164  const BitmapColor& rBitmapColor, const ColorMask& rMask);
165  static void SetPixelForN24BitTcBgr(Scanline pScanline, tools::Long nX,
166  const BitmapColor& rBitmapColor, const ColorMask& rMask);
167  static void SetPixelForN24BitTcRgb(Scanline pScanline, tools::Long nX,
168  const BitmapColor& rBitmapColor, const ColorMask& rMask);
169  static void SetPixelForN32BitTcAbgr(Scanline pScanline, tools::Long nX,
170  const BitmapColor& rBitmapColor, const ColorMask& rMask);
171  static void SetPixelForN32BitTcXbgr(Scanline pScanline, tools::Long nX,
172  const BitmapColor& rBitmapColor, const ColorMask& rMask);
173  static void SetPixelForN32BitTcArgb(Scanline pScanline, tools::Long nX,
174  const BitmapColor& rBitmapColor, const ColorMask& rMask);
175  static void SetPixelForN32BitTcXrgb(Scanline pScanline, tools::Long nX,
176  const BitmapColor& rBitmapColor, const ColorMask& rMask);
177  static void SetPixelForN32BitTcBgra(Scanline pScanline, tools::Long nX,
178  const BitmapColor& rBitmapColor, const ColorMask& rMask);
179  static void SetPixelForN32BitTcBgrx(Scanline pScanline, tools::Long nX,
180  const BitmapColor& rBitmapColor, const ColorMask& rMask);
181  static void SetPixelForN32BitTcRgba(Scanline pScanline, tools::Long nX,
182  const BitmapColor& rBitmapColor, const ColorMask& rMask);
183  static void SetPixelForN32BitTcRgbx(Scanline pScanline, tools::Long nX,
184  const BitmapColor& rBitmapColor, const ColorMask& rMask);
185  static void SetPixelForN32BitTcMask(Scanline pScanline, tools::Long nX,
186  const BitmapColor& rBitmapColor, const ColorMask& rMask);
187 
190 };
191 
192 #endif // INCLUDED_VCL_BITMAPREADACCESS_HXX
193 
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
double mnHeight
static BitmapColor GetPixelForN1BitMsbPal(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
sal_uInt8 GetIndexFromData(const sal_uInt8 *pData, tools::Long nX) const
Scanline GetBuffer() const
static void SetPixelForN32BitTcBgra(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
sal_uInt8 GetIndex() const
Definition: BitmapColor.hxx:70
sal_uInt8 GetPixelIndex(tools::Long nY, tools::Long nX) const
static BitmapColor GetPixelForN32BitTcRgbx(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
static BitmapColor GetPixelForN32BitTcXbgr(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
static void SetPixelForN32BitTcArgb(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
static FncSetPixel SetPixelFunction(ScanlineFormat nFormat)
BitmapColor GetColorWithFallback(double fY, double fX, const BitmapColor &rFallback) const
Get the color at coordinates fY, fX; if outside, return rFallback.
virtual ~BitmapReadAccess() override
static void SetPixelForN32BitTcXbgr(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
tools::Long mnHeight
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
sal_uInt8 GetPixelIndex(const Point &point) const
long Long
static BitmapColor GetPixelForN32BitTcXrgb(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
void SetPixelOnData(sal_uInt8 *pData, tools::Long nX, const BitmapColor &rBitmapColor)
ScanlineFormat
Definition: Scanline.hxx:29
Scanline GetScanline(tools::Long nY) const
static void SetPixelForN1BitMsbPal(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
BitmapColor GetInterpolatedColorWithFallback(double fY, double fX, const BitmapColor &rFallback) const
Get the interpolated color at coordinates fY, fX; if outside, return rFallback.
void(* FncSetPixel)(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
BitmapBuffer * mpBuffer
static void SetPixelForN32BitTcBgrx(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
static void SetPixelForN32BitTcMask(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
SAL_DLLPRIVATE BitmapBuffer * ImplGetBitmapBuffer() const
ScanlineFormat mnFormat
FncGetPixel mFncGetPixel
sal_uInt8 * Scanline
Definition: Scanline.hxx:26
BitmapColor GetPixel(const Point &point) const
bool HasPalette() const
static BitmapColor GetPixelForN24BitTcBgr(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
static void SetPixelForN1BitLsbPal(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
static BitmapColor GetPixelForN32BitTcBgrx(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
BitmapColor GetColor(tools::Long nY, tools::Long nX) const
static BitmapColor GetPixelForN32BitTcMask(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
static BitmapColor GetPixelForN32BitTcRgba(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
BitmapAccessMode
static void SetPixelForN32BitTcRgbx(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
sal_uInt8 * mpBits
static BitmapColor GetPixelForN1BitLsbPal(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
friend class BitmapReadAccess
static BitmapColor GetPixelForN32BitTcAbgr(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
FncSetPixel mFncSetPixel
const sal_uInt8 * ConstScanline
Definition: Scanline.hxx:27
static BitmapColor GetPixelForN8BitPal(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
static FncGetPixel GetPixelFunction(ScanlineFormat nFormat)
static BitmapColor GetPixelForN32BitTcBgra(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
tools::Long mnScanlineSize
unsigned char sal_uInt8
BitmapColor GetColor(const Point &point) const
static void SetPixelForN32BitTcXrgb(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
static BitmapColor GetPixelForN24BitTcRgb(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
double mnWidth
BitmapColor GetPixelFromData(const sal_uInt8 *pData, tools::Long nX) const
BitmapPalette maPalette
BitmapColor(* FncGetPixel)(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
static void SetPixelForN8BitPal(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
static void SetPixelForN24BitTcRgb(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
static void SetPixelForN24BitTcBgr(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
BitmapColor GetPixel(tools::Long nY, tools::Long nX) const
BitmapInfoAccess & operator=(const BitmapInfoAccess &)=delete
static BitmapColor GetPixelForN32BitTcArgb(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
static void SetPixelForN32BitTcAbgr(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
static void SetPixelForN32BitTcRgba(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)