0029528: Visualization, TKOpenGl - allow defining sRGB textures
[occt.git] / src / Quantity / Quantity_ColorRGBAHasher.hxx
CommitLineData
a71a71de 1// Copyright (c) 2017 OPEN CASCADE SAS
2//
3// This file is part of Open CASCADE Technology software library.
4//
5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
10//
11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
13
14#ifndef _Quantity_ColorRGBAHasher_HeaderFile
15#define _Quantity_ColorRGBAHasher_HeaderFile
16
17#include <Quantity_ColorRGBA.hxx>
18#include <Quantity_ColorHasher.hxx>
19
20//! Hasher of Quantity_ColorRGBA.
21struct Quantity_ColorRGBAHasher
22{
23
2b2be3fb 24 //! Returns hash code for the given RGBA color, in the range [1, theUpperBound]
25 //! @param theColor the RGBA color object which hash code is to be computed
26 //! @param theUpperBound the upper bound of the range a computing hash code must be within
27 //! @return a computed hash code, in the range [1, theUpperBound]
a71a71de 28 static Standard_Integer HashCode (const Quantity_ColorRGBA& theColor,
2b2be3fb 29 const Standard_Integer theUpperBound)
a71a71de 30 {
31 const NCollection_Vec4<float>& aColor = theColor;
32 uint32_t aColor32 = (uint32_t(aColor.a() * 255.0f) << 24)
33 + (uint32_t(aColor.b() * 255.0f) << 16)
34 + (uint32_t(aColor.g() * 255.0f) << 8)
35 + uint32_t(aColor.r() * 255.0f);
2b2be3fb 36 return ::HashCode(aColor32, theUpperBound);
a71a71de 37 }
38
39 //! Returns true if two colors are equal.
40 static Standard_Boolean IsEqual (const Quantity_ColorRGBA& theColor1,
41 const Quantity_ColorRGBA& theColor2)
42 {
43 return theColor1 == theColor2;
44 }
45
46};
47
48#endif // _Quantity_ColorRGBAHasher_HeaderFile