blob: 290d4ab83cf3495a98a5e13510cb9578f986c22a [file] [log] [blame]
Nicolas Capens0bac2852016-05-07 06:09:58 -04001// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
John Bauman89401822014-05-06 15:04:28 -04002//
Nicolas Capens0bac2852016-05-07 06:09:58 -04003// 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
John Bauman89401822014-05-06 15:04:28 -04006//
Nicolas Capens0bac2852016-05-07 06:09:58 -04007// http://www.apache.org/licenses/LICENSE-2.0
John Bauman89401822014-05-06 15:04:28 -04008//
Nicolas Capens0bac2852016-05-07 06:09:58 -04009// 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.
John Bauman89401822014-05-06 15:04:28 -040014
15#include "Math.hpp"
16
John Bauman89401822014-05-06 15:04:28 -040017namespace sw
18{
John Bauman66b8ab22014-05-06 15:57:45 -040019 inline uint64_t FNV_1a(uint64_t hash, unsigned char data)
20 {
21 return (hash ^ data) * 1099511628211;
22 }
John Bauman89401822014-05-06 15:04:28 -040023
John Bauman66b8ab22014-05-06 15:57:45 -040024 uint64_t FNV_1a(const unsigned char *data, int size)
John Bauman89401822014-05-06 15:04:28 -040025 {
26 int64_t hash = 0xCBF29CE484222325;
Nicolas Capensccd5ecb2017-01-14 12:52:55 -050027
John Bauman89401822014-05-06 15:04:28 -040028 for(int i = 0; i < size; i++)
29 {
John Bauman66b8ab22014-05-06 15:57:45 -040030 hash = FNV_1a(hash, data[i]);
John Bauman89401822014-05-06 15:04:28 -040031 }
32
33 return hash;
34 }
Alexis Hetufeccd1d2015-09-18 11:38:31 -040035
36 unsigned 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 }
John Bauman89401822014-05-06 15:04:28 -040049}