Apply second half of [#21590] .dds textures: fix for DXT1n format + sync with upstrea...
[blender.git] / source / blender / imbuf / intern / dds / PixelFormat.h
index 2602681d979c83fe954ac7d41f1431a6e746e981..35c6eacb9722709948024d260aef60275bc6a89d 100644 (file)
                        }
                }
 
+        inline float quantizeCeil(float f, int inbits, int outbits)
+        {
+            //uint i = f * (float(1 << inbits) - 1);
+            //i = convert(i, inbits, outbits);
+            //float result = float(i) / (float(1 << outbits) - 1);
+            //nvCheck(result >= f);
+            float result;
+            int offset = 0;
+            do {
+                uint i = offset + uint(f * (float(1 << inbits) - 1));
+                i = convert(i, inbits, outbits);
+                result = float(i) / (float(1 << outbits) - 1);
+                offset++;
+            } while (result < f);
+
+            return result;
+        }
+
+        /*
+        inline float quantizeRound(float f, int bits)
+        {
+            float scale = float(1 << bits);
+            return fround(f * scale) / scale;
+        }
+
+        inline float quantizeFloor(float f, int bits)
+        {
+            float scale = float(1 << bits);
+            return floor(f * scale) / scale;
+        }
+        */
+
        } // PixelFormat namespace
 
 #endif // _DDS_IMAGE_PIXELFORMAT_H