Home | History | Annotate | Download | only in Common
      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 namespace sw
     18 {
     19 	inline uint64_t FNV_1a(uint64_t hash, unsigned char data)
     20 	{
     21 		return (hash ^ data) * 1099511628211;
     22 	}
     23 
     24 	uint64_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 
     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 	}
     49 }
     50