John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1 | // SwiftShader Software Renderer |
| 2 | // |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3 | // Copyright(c) 2005-2012 TransGaming Inc. |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4 | // |
| 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 | |
| 16 | namespace sw |
| 17 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 18 | inline uint64_t FNV_1a(uint64_t hash, unsigned char data) |
| 19 | { |
| 20 | return (hash ^ data) * 1099511628211; |
| 21 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 22 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 23 | uint64_t FNV_1a(const unsigned char *data, int size) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 24 | { |
| 25 | int64_t hash = 0xCBF29CE484222325; |
| 26 | |
| 27 | for(int i = 0; i < size; i++) |
| 28 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 29 | hash = FNV_1a(hash, data[i]); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | return hash; |
| 33 | } |
Alexis Hetu | feccd1d | 2015-09-18 11:38:31 -0400 | [diff] [blame] | 34 | |
| 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 Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 48 | } |