LibreOffice Module vcl (master)  1
BitmapPalette.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_BITMAPPALETTE_HXX
21 #define INCLUDED_VCL_BITMAPPALETTE_HXX
22 
23 #include <vcl/dllapi.h>
24 #include <vcl/BitmapColor.hxx>
25 #include <vcl/checksum.hxx>
26 #include <vector>
27 
29 {
30  friend class SalBitmap;
31  friend class BitmapAccess;
32 
33 private:
34 
35  std::vector<BitmapColor> maBitmapColor;
36 
37 public:
38 
39  SAL_DLLPRIVATE const BitmapColor* ImplGetColorBuffer() const
40  {
41  return maBitmapColor.data();
42  }
43 
44  SAL_DLLPRIVATE BitmapColor* ImplGetColorBuffer()
45  {
46  return maBitmapColor.data();
47  }
48 
50  {
51  return vcl_get_checksum(0, maBitmapColor.data(), maBitmapColor.size() * sizeof(BitmapColor));
52  }
53 
54 public:
55 
57  {
58  }
59 
60  BitmapPalette(std::initializer_list<BitmapColor> aBitmapColor) : maBitmapColor(aBitmapColor)
61  {
62  }
63 
64  BitmapPalette(sal_uInt16 nCount)
65  : maBitmapColor(nCount)
66  {
67  }
68 
69  bool operator==( const BitmapPalette& rBitmapPalette ) const
70  {
71  return maBitmapColor == rBitmapPalette.maBitmapColor;
72  }
73 
74  bool operator!=(const BitmapPalette& rBitmapPalette) const
75  {
76  return !( *this == rBitmapPalette );
77  }
78 
79  bool operator!() const
80  {
81  return maBitmapColor.empty();
82  }
83 
84  sal_uInt16 GetEntryCount() const
85  {
86  return maBitmapColor.size();
87  }
88 
89  void SetEntryCount(sal_uInt16 nCount)
90  {
91  maBitmapColor.resize(nCount);
92  }
93 
94  const BitmapColor& operator[](sal_uInt16 nIndex) const
95  {
96  assert(nIndex < maBitmapColor.size() && "Palette index is out of range");
97  return maBitmapColor[nIndex];
98  }
99 
100  BitmapColor& operator[](sal_uInt16 nIndex)
101  {
102  assert(nIndex < maBitmapColor.size() && "Palette index is out of range");
103  return maBitmapColor[nIndex];
104  }
105 
106  sal_uInt16 GetBestIndex(const BitmapColor& rCol) const
107  {
108  sal_uInt16 nRetIndex = 0;
109 
110  if (!maBitmapColor.empty())
111  {
112  for (size_t j = 0; j < maBitmapColor.size(); ++j)
113  {
114  if (rCol == maBitmapColor[j])
115  {
116  return j;
117  }
118  }
119 
120  sal_uInt16 nLastErr = SAL_MAX_UINT16;
121  for (size_t i = 0; i < maBitmapColor.size(); ++i)
122  {
123  const sal_uInt16 nActErr = rCol.GetColorError(maBitmapColor[i]);
124  if ( nActErr < nLastErr )
125  {
126  nLastErr = nActErr;
127  nRetIndex = i;
128  }
129  }
130  }
131 
132  return nRetIndex;
133  }
134 
136  bool IsGreyPalette8Bit() const;
138  bool IsGreyPaletteAny() const;
139 };
140 
141 #endif // INCLUDED_VCL_BITMAPPALETTE_HXX
142 
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const BitmapColor & operator[](sal_uInt16 nIndex) const
sal_uInt64 BitmapChecksum
Definition: checksum.hxx:30
BitmapChecksum GetChecksum() const
BitmapPalette(sal_uInt16 nCount)
void SetEntryCount(sal_uInt16 nCount)
bool operator!() const
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
BitmapChecksum vcl_get_checksum(BitmapChecksum Checksum, const void *Data, sal_uInt32 DatLen)
Definition: checksum.hxx:72
SAL_DLLPRIVATE const BitmapColor * ImplGetColorBuffer() const
#define SAL_MAX_UINT16
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
sal_uInt16 GetColorError(const Color &rCompareColor) const
sal_uInt16 GetEntryCount() const
int i
SAL_DLLPRIVATE BitmapColor * ImplGetColorBuffer()
sal_uInt16 GetBestIndex(const BitmapColor &rCol) const
BitmapColor & operator[](sal_uInt16 nIndex)
std::vector< BitmapColor > maBitmapColor
bool operator!=(const BitmapPalette &rBitmapPalette) const
bool operator==(const BitmapPalette &rBitmapPalette) const
BitmapPalette(std::initializer_list< BitmapColor > aBitmapColor)