Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 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 * Contributors: Amorilia (amorilia@users.sourceforge.net) 00019 * 00020 * ***** END GPL LICENSE BLOCK ***** 00021 */ 00022 00028 /* 00029 * This file is based on a similar file from the NVIDIA texture tools 00030 * (http://nvidia-texture-tools.googlecode.com/) 00031 * 00032 * Original license from NVIDIA follows. 00033 */ 00034 00035 // Copyright NVIDIA Corporation 2007 -- Ignacio Castano <icastano@nvidia.com> 00036 // 00037 // Permission is hereby granted, free of charge, to any person 00038 // obtaining a copy of this software and associated documentation 00039 // files (the "Software"), to deal in the Software without 00040 // restriction, including without limitation the rights to use, 00041 // copy, modify, merge, publish, distribute, sublicense, and/or sell 00042 // copies of the Software, and to permit persons to whom the 00043 // Software is furnished to do so, subject to the following 00044 // conditions: 00045 // 00046 // The above copyright notice and this permission notice shall be 00047 // included in all copies or substantial portions of the Software. 00048 // 00049 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00050 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 00051 // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00052 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 00053 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 00054 // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 00055 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00056 // OTHER DEALINGS IN THE SOFTWARE. 00057 00058 #ifndef _DDS_PIXELFORMAT_H 00059 #define _DDS_PIXELFORMAT_H 00060 00061 #include <Common.h> 00062 00063 namespace PixelFormat 00064 { 00065 00066 // Convert component @a c having @a inbits to the returned value having @a outbits. 00067 inline uint convert(uint c, uint inbits, uint outbits) 00068 { 00069 if (inbits == 0) 00070 { 00071 return 0; 00072 } 00073 else if (inbits >= outbits) 00074 { 00075 // truncate 00076 return c >> (inbits - outbits); 00077 } 00078 else 00079 { 00080 // bitexpand 00081 return (c << (outbits - inbits)) | convert(c, inbits, outbits - inbits); 00082 } 00083 } 00084 00085 // Get pixel component shift and size given its mask. 00086 inline void maskShiftAndSize(uint mask, uint * shift, uint * size) 00087 { 00088 if (!mask) 00089 { 00090 *shift = 0; 00091 *size = 0; 00092 return; 00093 } 00094 00095 *shift = 0; 00096 while((mask & 1) == 0) { 00097 ++(*shift); 00098 mask >>= 1; 00099 } 00100 00101 *size = 0; 00102 while((mask & 1) == 1) { 00103 ++(*size); 00104 mask >>= 1; 00105 } 00106 } 00107 00108 inline float quantizeCeil(float f, int inbits, int outbits) 00109 { 00110 //uint i = f * (float(1 << inbits) - 1); 00111 //i = convert(i, inbits, outbits); 00112 //float result = float(i) / (float(1 << outbits) - 1); 00113 //nvCheck(result >= f); 00114 float result; 00115 int offset = 0; 00116 do { 00117 uint i = offset + uint(f * (float(1 << inbits) - 1)); 00118 i = convert(i, inbits, outbits); 00119 result = float(i) / (float(1 << outbits) - 1); 00120 offset++; 00121 } while (result < f); 00122 00123 return result; 00124 } 00125 00126 /* 00127 inline float quantizeRound(float f, int bits) 00128 { 00129 float scale = float(1 << bits); 00130 return fround(f * scale) / scale; 00131 } 00132 00133 inline float quantizeFloor(float f, int bits) 00134 { 00135 float scale = float(1 << bits); 00136 return floor(f * scale) / scale; 00137 } 00138 */ 00139 00140 } // PixelFormat namespace 00141 00142 #endif // _DDS_IMAGE_PIXELFORMAT_H