1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_VCL_BITMAPPALETTE_HXX
21 #define INCLUDED_VCL_BITMAPPALETTE_HXX
23 #include <vcl/dllapi.h>
24 #include <vcl/BitmapColor.hxx>
25 #include <vcl/checksum.hxx>
28 class VCL_DLLPUBLIC BitmapPalette
30 friend class SalBitmap
;
31 friend class BitmapAccess
;
35 std::vector
<BitmapColor
> maBitmapColor
;
39 SAL_DLLPRIVATE
const BitmapColor
* ImplGetColorBuffer() const
41 return maBitmapColor
.data();
44 SAL_DLLPRIVATE BitmapColor
* ImplGetColorBuffer()
46 return maBitmapColor
.data();
49 BitmapChecksum
GetChecksum() const
51 return vcl_get_checksum(0, maBitmapColor
.data(), maBitmapColor
.size() * sizeof(BitmapColor
));
60 BitmapPalette(sal_uInt16 nCount
)
61 : maBitmapColor(nCount
)
65 bool operator==( const BitmapPalette
& rBitmapPalette
) const
67 return maBitmapColor
== rBitmapPalette
.maBitmapColor
;
70 bool operator!=(const BitmapPalette
& rBitmapPalette
) const
72 return !( *this == rBitmapPalette
);
75 bool operator!() const
77 return maBitmapColor
.empty();
80 sal_uInt16
GetEntryCount() const
82 return maBitmapColor
.size();
85 void SetEntryCount(sal_uInt16 nCount
)
87 maBitmapColor
.resize(nCount
);
90 const BitmapColor
& operator[](sal_uInt16 nIndex
) const
92 assert(nIndex
< maBitmapColor
.size() && "Palette index is out of range");
93 return maBitmapColor
[nIndex
];
96 BitmapColor
& operator[](sal_uInt16 nIndex
)
98 assert(nIndex
< maBitmapColor
.size() && "Palette index is out of range");
99 return maBitmapColor
[nIndex
];
102 sal_uInt16
GetBestIndex(const BitmapColor
& rCol
) const
104 sal_uInt16 nRetIndex
= 0;
106 if (!maBitmapColor
.empty())
108 for (size_t j
= 0; j
< maBitmapColor
.size(); ++j
)
110 if (rCol
== maBitmapColor
[j
])
116 sal_uInt16 nLastErr
= SAL_MAX_UINT16
;
117 for (size_t i
= 0; i
< maBitmapColor
.size(); ++i
)
119 const sal_uInt16 nActErr
= rCol
.GetColorError(maBitmapColor
[i
]);
120 if ( nActErr
< nLastErr
)
131 bool IsGreyPalette() const;
134 #endif // INCLUDED_VCL_BITMAPPALETTE_HXX
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */