blob: 36d1df2dad19453ac52a08234800eae53c0f3a00 [file] [log] [blame]
Nicolas Capens68a82382018-10-02 13:16:55 -04001// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#include "Math.hpp"
16
Nicolas Capens157ba262019-12-10 17:49:14 -050017namespace sw {
18
19inline uint64_t FNV_1a(uint64_t hash, unsigned char data)
Nicolas Capens68a82382018-10-02 13:16:55 -040020{
Nicolas Capens157ba262019-12-10 17:49:14 -050021 return (hash ^ data) * 1099511628211;
Nicolas Capens68a82382018-10-02 13:16:55 -040022}
Nicolas Capens157ba262019-12-10 17:49:14 -050023
24uint64_t FNV_1a(const unsigned char *data, int size)
25{
26 int64_t hash = 0xCBF29CE484222325;
27
28 for(int i = 0; i < size; i++)
29 {
30 hash = FNV_1a(hash, data[i]);
31 }
32
33 return hash;
34}
35
36unsigned char sRGB8toLinear8(unsigned char value)
37{
38 static unsigned char sRGBtoLinearTable[256] = { 255 };
39 if(sRGBtoLinearTable[0] == 255)
40 {
41 for(int i = 0; i < 256; i++)
42 {
43 sRGBtoLinearTable[i] = static_cast<unsigned char>(sw::sRGBtoLinear(static_cast<float>(i) / 255.0f) * 255.0f + 0.5f);
44 }
45 }
46
47 return sRGBtoLinearTable[value];
48}
49
50} // namespace sw