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 
31 class SAL_DLLPUBLIC_RTTI BitmapReadAccess : public BitmapInfoAccess
32 {
33  friend class BitmapWriteAccess;
34 
35 public:
38  VCL_DLLPUBLIC virtual ~BitmapReadAccess() override;
39 
41  {
42  assert(mpBuffer && "Access is not valid!");
43 
44  return mpBuffer ? mpBuffer->mpBits : nullptr;
45  }
46 
48  {
49  assert(mpBuffer && "Access is not valid!");
50  assert(nY < mpBuffer->mnHeight && "y-coordinate out of range!");
51 
53  {
54  return mpBuffer->mpBits + (nY * mpBuffer->mnScanlineSize);
55  }
56  return mpBuffer->mpBits + ((mpBuffer->mnHeight - 1 - nY) * mpBuffer->mnScanlineSize);
57  }
58 
60  {
61  assert(pData && "Access is not valid!");
62 
63  return mFncGetPixel(pData, nX, maColorMask);
64  }
65 
67  {
68  return GetPixelFromData(pData, nX).GetIndex();
69  }
70 
71  void SetPixelOnData(sal_uInt8* pData, tools::Long nX, const BitmapColor& rBitmapColor)
72  {
73  assert(pData && "Access is not valid!");
74 
75  mFncSetPixel(pData, nX, rBitmapColor, maColorMask);
76  }
77 
79  {
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!");
83 
84  return mFncGetPixel(GetScanline(nY), nX, maColorMask);
85  }
86 
87  BitmapColor GetPixel(const Point& point) const { return GetPixel(point.Y(), point.X()); }
88 
90  {
91  if (HasPalette())
92  {
93  const BitmapBuffer* pBuffer = mpBuffer;
94  return pBuffer->maPalette[GetPixelIndex(nY, nX)];
95  }
96  else
97  return GetPixel(nY, nX);
98  }
99 
100  BitmapColor GetColor(const Point& point) const { return GetColor(point.Y(), point.X()); }
101 
103  {
104  return GetPixel(nY, nX).GetIndex();
105  }
106 
107  sal_uInt8 GetPixelIndex(const Point& point) const
108  {
109  return GetPixelIndex(point.Y(), point.X());
110  }
111 
113  BitmapColor GetInterpolatedColorWithFallback(double fY, double fX,
114  const BitmapColor& rFallback) const;
115 
118  BitmapColor GetColorWithFallback(double fY, double fX, const BitmapColor& rFallback) const;
119 
120 private:
121  BitmapReadAccess(const BitmapReadAccess&) = delete;
122  BitmapReadAccess& operator=(const BitmapReadAccess&) = delete;
123 
124 protected:
127 
128 public:
130 
132  const ColorMask& rMask);
134  const ColorMask& rMask);
136  const ColorMask& rMask);
138  const ColorMask& rMask);
140  const ColorMask& rMask);
142  const ColorMask& rMask);
144  const ColorMask& rMask);
146  const ColorMask& rMask);
148  const ColorMask& rMask);
150  const ColorMask& rMask);
152  const ColorMask& rMask);
154  const ColorMask& rMask);
156  const ColorMask& rMask);
158  const ColorMask& rMask);
159 
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);
188 
191 };
192 
193 #endif // INCLUDED_VCL_BITMAPREADACCESS_HXX
194 
195 /* 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 VCL_DLLPUBLIC ~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)
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)
BitmapBuffer * ImplGetBitmapBuffer() const
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)