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(sal_uInt16 nCount)
61  : maBitmapColor(nCount)
62  {
63  }
64 
65  bool operator==( const BitmapPalette& rBitmapPalette ) const
66  {
67  return maBitmapColor == rBitmapPalette.maBitmapColor;
68  }
69 
70  bool operator!=(const BitmapPalette& rBitmapPalette) const
71  {
72  return !( *this == rBitmapPalette );
73  }
74 
75  bool operator!() const
76  {
77  return maBitmapColor.empty();
78  }
79 
80  sal_uInt16 GetEntryCount() const
81  {
82  return maBitmapColor.size();
83  }
84 
85  void SetEntryCount(sal_uInt16 nCount)
86  {
87  maBitmapColor.resize(nCount);
88  }
89 
90  const BitmapColor& operator[](sal_uInt16 nIndex) const
91  {
92  assert(nIndex < maBitmapColor.size() && "Palette index is out of range");
93  return maBitmapColor[nIndex];
94  }
95 
96  BitmapColor& operator[](sal_uInt16 nIndex)
97  {
98  assert(nIndex < maBitmapColor.size() && "Palette index is out of range");
99  return maBitmapColor[nIndex];
100  }
101 
102  sal_uInt16 GetBestIndex(const BitmapColor& rCol) const
103  {
104  sal_uInt16 nRetIndex = 0;
105 
106  if (!maBitmapColor.empty())
107  {
108  for (size_t j = 0; j < maBitmapColor.size(); ++j)
109  {
110  if (rCol == maBitmapColor[j])
111  {
112  return j;
113  }
114  }
115 
116  sal_uInt16 nLastErr = SAL_MAX_UINT16;
117  for (size_t i = 0; i < maBitmapColor.size(); ++i)
118  {
119  const sal_uInt16 nActErr = rCol.GetColorError(maBitmapColor[i]);
120  if ( nActErr < nLastErr )
121  {
122  nLastErr = nActErr;
123  nRetIndex = i;
124  }
125  }
126  }
127 
128  return nRetIndex;
129  }
130 
131  bool IsGreyPalette() const;
132 };
133 
134 #endif // INCLUDED_VCL_BITMAPPALETTE_HXX
135 
136 /* 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
sal_uInt16 GetColorError(const Color &rCompareColor) const
sal_uInt16 GetEntryCount() const
SAL_DLLPRIVATE BitmapColor * ImplGetColorBuffer()
int i
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