blob: e8ae3d2f00a3b330638e1621d65f5a16a1cd586e [file] [log] [blame]
John Bauman89401822014-05-06 15:04:28 -04001// SwiftShader Software Renderer
2//
John Bauman66b8ab22014-05-06 15:57:45 -04003// Copyright(c) 2005-2012 TransGaming Inc.
John Bauman89401822014-05-06 15:04:28 -04004//
5// All rights reserved. No part of this software may be copied, distributed, transmitted,
6// transcribed, stored in a retrieval system, translated into any human or computer
7// language by any means, or disclosed to third parties without the explicit written
8// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
9// or implied, including but not limited to any patent rights, are granted to you.
10//
11
12#include "Math.hpp"
13
14#include "CPUID.hpp"
15
16namespace sw
17{
John Bauman66b8ab22014-05-06 15:57:45 -040018 inline uint64_t FNV_1a(uint64_t hash, unsigned char data)
19 {
20 return (hash ^ data) * 1099511628211;
21 }
John Bauman89401822014-05-06 15:04:28 -040022
John Bauman66b8ab22014-05-06 15:57:45 -040023 uint64_t FNV_1a(const unsigned char *data, int size)
John Bauman89401822014-05-06 15:04:28 -040024 {
25 int64_t hash = 0xCBF29CE484222325;
26
27 for(int i = 0; i < size; i++)
28 {
John Bauman66b8ab22014-05-06 15:57:45 -040029 hash = FNV_1a(hash, data[i]);
John Bauman89401822014-05-06 15:04:28 -040030 }
31
32 return hash;
33 }
Alexis Hetufeccd1d2015-09-18 11:38:31 -040034
35 unsigned char sRGB8toLinear8(unsigned char value)
36 {
37 static unsigned char sRGBtoLinearTable[256] = { 255 };
38 if(sRGBtoLinearTable[0] == 255)
39 {
40 for(int i = 0; i < 256; i++)
41 {
42 sRGBtoLinearTable[i] = static_cast<unsigned char>(sw::sRGBtoLinear(static_cast<float>(i) / 255.0f) * 255.0f + 0.5f);
43 }
44 }
45
46 return sRGBtoLinearTable[value];
47 }
John Bauman89401822014-05-06 15:04:28 -040048}