Blender V2.61 - r43446
|
00001 /* 00002 * Copyright 2011, Blender Foundation. 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 */ 00018 00019 #ifndef __UTIL_COLOR_H__ 00020 #define __UTIL_COLOR_H__ 00021 00022 #include "util_math.h" 00023 #include "util_types.h" 00024 00025 CCL_NAMESPACE_BEGIN 00026 00027 __device float color_srgb_to_scene_linear(float c) 00028 { 00029 if(c < 0.04045f) 00030 return (c < 0.0f)? 0.0f: c * (1.0f/12.92f); 00031 else 00032 return pow((c + 0.055f)*(1.0f/1.055f), 2.4f); 00033 } 00034 00035 __device float color_scene_linear_to_srgb(float c) 00036 { 00037 if(c < 0.0031308f) 00038 return (c < 0.0f)? 0.0f: c * 12.92f; 00039 else 00040 return 1.055f * pow(c, 1.0f/2.4f) - 0.055f; 00041 } 00042 00043 #ifndef __KERNEL_OPENCL__ 00044 00045 __device float3 color_srgb_to_scene_linear(float3 c) 00046 { 00047 return make_float3( 00048 color_srgb_to_scene_linear(c.x), 00049 color_srgb_to_scene_linear(c.y), 00050 color_srgb_to_scene_linear(c.z)); 00051 } 00052 00053 __device float3 color_scene_linear_to_srgb(float3 c) 00054 { 00055 return make_float3( 00056 color_scene_linear_to_srgb(c.x), 00057 color_scene_linear_to_srgb(c.y), 00058 color_scene_linear_to_srgb(c.z)); 00059 } 00060 00061 #endif 00062 00063 __device float linear_rgb_to_gray(float3 c) 00064 { 00065 return c.x*0.2126f + c.y*0.7152f + c.z*0.0722f; 00066 } 00067 00068 CCL_NAMESPACE_END 00069 00070 #endif /* __UTIL_COLOR_H__ */ 00071