1 // 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 
17 #include "CPUID.hpp"
18 
19 namespace sw
20 {
FNV_1a(uint64_t hash,unsigned char data)21 	inline uint64_t FNV_1a(uint64_t hash, unsigned char data)
22 	{
23 		return (hash ^ data) * 1099511628211;
24 	}
25 
FNV_1a(const unsigned char * data,int size)26 	uint64_t FNV_1a(const unsigned char *data, int size)
27 	{
28 		int64_t hash = 0xCBF29CE484222325;
29 
30 		for(int i = 0; i < size; i++)
31 		{
32 			hash = FNV_1a(hash, data[i]);
33 		}
34 
35 		return hash;
36 	}
37 
sRGB8toLinear8(unsigned char value)38 	unsigned char sRGB8toLinear8(unsigned char value)
39 	{
40 		static unsigned char sRGBtoLinearTable[256] = { 255 };
41 		if(sRGBtoLinearTable[0] == 255)
42 		{
43 			for(int i = 0; i < 256; i++)
44 			{
45 				sRGBtoLinearTable[i] = static_cast<unsigned char>(sw::sRGBtoLinear(static_cast<float>(i) / 255.0f) * 255.0f + 0.5f);
46 			}
47 		}
48 
49 		return sRGBtoLinearTable[value];
50 	}
51 }
52