LibreOffice Module vcl (master)  1
BitmapInfoAccess.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_BITMAPINFOACCESS_HXX
21 #define INCLUDED_VCL_BITMAPINFOACCESS_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 
31 
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);
35 
37 {
38  friend class BitmapReadAccess;
39 
40 public:
42  virtual ~BitmapInfoAccess();
43 
44  bool operator!() const { return mpBuffer == nullptr; }
45 
46  tools::Long Width() const { return mpBuffer ? mpBuffer->mnWidth : 0L; }
47 
48  tools::Long Height() const { return mpBuffer ? mpBuffer->mnHeight : 0L; }
49 
50  bool IsTopDown() const
51  {
52  assert(mpBuffer && "Access is not valid!");
53 
55  }
56 
57  bool IsBottomUp() const { return !IsTopDown(); }
58 
60  {
61  assert(mpBuffer && "Access is not valid!");
62 
64  }
65 
66  sal_uInt32 GetScanlineSize() const
67  {
68  assert(mpBuffer && "Access is not valid!");
69 
70  return mpBuffer ? mpBuffer->mnScanlineSize : 0;
71  }
72 
73  sal_uInt16 GetBitCount() const
74  {
75  assert(mpBuffer && "Access is not valid!");
76 
77  return mpBuffer ? mpBuffer->mnBitCount : 0;
78  }
79 
81  {
82  if (HasPalette())
83  return BitmapColor(static_cast<sal_uInt8>(GetBestPaletteIndex(rBitmapColor)));
84  else
85  return rBitmapColor;
86  }
87 
88  bool HasPalette() const
89  {
90  assert(mpBuffer && "Access is not valid!");
91 
92  return mpBuffer && !!mpBuffer->maPalette;
93  }
94 
95  const BitmapPalette& GetPalette() const
96  {
97  assert(mpBuffer && "Access is not valid!");
98 
99  return mpBuffer->maPalette;
100  }
101 
102  sal_uInt16 GetPaletteEntryCount() const
103  {
104  assert(HasPalette() && "Bitmap has no palette!");
105 
106  return HasPalette() ? mpBuffer->maPalette.GetEntryCount() : 0;
107  }
108 
109  const BitmapColor& GetPaletteColor(sal_uInt16 nColor) const
110  {
111  assert(mpBuffer && "Access is not valid!");
112  assert(HasPalette() && "Bitmap has no palette!");
113 
114  return mpBuffer->maPalette[nColor];
115  }
116 
117  const BitmapColor& GetBestPaletteColor(const BitmapColor& rBitmapColor) const
118  {
119  return GetPaletteColor(GetBestPaletteIndex(rBitmapColor));
120  }
121 
122  sal_uInt16 GetBestPaletteIndex(const BitmapColor& rBitmapColor) const;
123 
125  {
126  assert(mpBuffer && "Access is not valid!");
127 
128  return mpBuffer->maColorMask;
129  }
130 
131 private:
132  BitmapInfoAccess(const BitmapInfoAccess&) = delete;
133  BitmapInfoAccess& operator=(const BitmapInfoAccess&) = delete;
134 
135 protected:
140 };
141 
142 #endif // INCLUDED_VCL_BITMAPINFOACCESS_HXX
143 
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
tools::Long Height() const
ColorMask maColorMask
BitmapAccessMode mnAccessMode
const BitmapColor & GetBestPaletteColor(const BitmapColor &rBitmapColor) const
tools::Long mnHeight
virtual ~BitmapInfoAccess()
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
long Long
sal_uInt16 GetBitCount() const
sal_uInt16 GetBestPaletteIndex(const BitmapColor &rBitmapColor) const
bool Bitmap32IsPreMultipled()
sal_uInt16 mnBitCount
ScanlineFormat
Definition: Scanline.hxx:28
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
void(* FncSetPixel)(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
BitmapBuffer * mpBuffer
ScanlineFormat mnFormat
sal_uInt16 GetEntryCount() const
sal_uInt8 * Scanline
Definition: Scanline.hxx:25
bool IsTopDown() const
sal_uInt32 GetScanlineSize() const
bool HasPalette() const
ScanlineFormat GetScanlineFormat() const
BitmapAccessMode
tools::Long Width() const
bool operator!() const
sal_uInt16 GetPaletteEntryCount() const
ColorMask & GetColorMask() const
const sal_uInt8 * ConstScanline
Definition: Scanline.hxx:26
BitmapInfoAccess(Bitmap &rBitmap, BitmapAccessMode nMode=BitmapAccessMode::Info)
tools::Long mnScanlineSize
const BitmapPalette & GetPalette() const
bool IsBottomUp() const
ScanlineFormat RemoveScanline(ScanlineFormat nFormat)
Definition: Scanline.hxx:56
BitmapPalette maPalette
const BitmapColor & GetPaletteColor(sal_uInt16 nColor) const
BitmapColor(* FncGetPixel)(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
tools::Long mnWidth
BitmapColor GetBestMatchingColor(const BitmapColor &rBitmapColor)
BitmapReadAccess & operator=(const BitmapReadAccess &)=delete
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo