فهرست منبع

Update bcdec to latest version

BlueCube3310 10 ماه پیش
والد
کامیت
529897cb0c
2فایلهای تغییر یافته به همراه38 افزوده شده و 22 حذف شده
  1. 1 1
      thirdparty/README.md
  2. 37 21
      thirdparty/misc/bcdec.h

+ 1 - 1
thirdparty/README.md

@@ -652,7 +652,7 @@ Collection of single-file libraries used in Godot components.
 
 
 - `bcdec.h`
 - `bcdec.h`
   * Upstream: https://github.com/iOrange/bcdec
   * Upstream: https://github.com/iOrange/bcdec
-  * Version: git (026acf98ea271045cb10713daa96ba98528badb7, 2022)
+  * Version: git (3b29f8f44466c7d59852670f82f53905cf627d48, 2024)
   * License: MIT
   * License: MIT
 - `clipper.{cpp,hpp}`
 - `clipper.{cpp,hpp}`
   * Upstream: https://sourceforge.net/projects/polyclipping
   * Upstream: https://sourceforge.net/projects/polyclipping

+ 37 - 21
thirdparty/misc/bcdec.h

@@ -1,4 +1,4 @@
-/* bcdec.h - v0.96
+/* bcdec.h - v0.97
    provides functions to decompress blocks of BC compressed images
    provides functions to decompress blocks of BC compressed images
    written by Sergii "iOrange" Kudlai in 2022
    written by Sergii "iOrange" Kudlai in 2022
 
 
@@ -30,6 +30,11 @@
                                         - Split BC6H decompression function into 'half' and
                                         - Split BC6H decompression function into 'half' and
                                           'float' variants
                                           'float' variants
 
 
+      Michael Schmidt (@RunDevelopment) - Found better "magic" coefficients for integer interpolation
+                                          of reference colors in BC1 color block, that match with
+                                          the floating point interpolation. This also made it faster
+                                          than integer division by 3!
+
    bugfixes:
    bugfixes:
       @linkmauve
       @linkmauve
 
 
@@ -39,6 +44,9 @@
 #ifndef BCDEC_HEADER_INCLUDED
 #ifndef BCDEC_HEADER_INCLUDED
 #define BCDEC_HEADER_INCLUDED
 #define BCDEC_HEADER_INCLUDED
 
 
+#define BCDEC_VERSION_MAJOR 0
+#define BCDEC_VERSION_MINOR 97
+
 /* if BCDEC_STATIC causes problems, try defining BCDECDEF to 'inline' or 'static inline' */
 /* if BCDEC_STATIC causes problems, try defining BCDECDEF to 'inline' or 'static inline' */
 #ifndef BCDECDEF
 #ifndef BCDECDEF
 #ifdef BCDEC_STATIC
 #ifdef BCDEC_STATIC
@@ -96,6 +104,7 @@ BCDECDEF void bcdec_bc6h_float(const void* compressedBlock, void* decompressedBl
 BCDECDEF void bcdec_bc6h_half(const void* compressedBlock, void* decompressedBlock, int destinationPitch, int isSigned);
 BCDECDEF void bcdec_bc6h_half(const void* compressedBlock, void* decompressedBlock, int destinationPitch, int isSigned);
 BCDECDEF void bcdec_bc7(const void* compressedBlock, void* decompressedBlock, int destinationPitch);
 BCDECDEF void bcdec_bc7(const void* compressedBlock, void* decompressedBlock, int destinationPitch);
 
 
+#endif /* BCDEC_HEADER_INCLUDED */
 
 
 #ifdef BCDEC_IMPLEMENTATION
 #ifdef BCDEC_IMPLEMENTATION
 
 
@@ -110,35 +119,44 @@ static void bcdec__color_block(const void* compressedBlock, void* decompressedBl
     c0 = ((unsigned short*)compressedBlock)[0];
     c0 = ((unsigned short*)compressedBlock)[0];
     c1 = ((unsigned short*)compressedBlock)[1];
     c1 = ((unsigned short*)compressedBlock)[1];
 
 
+    /* Unpack 565 ref colors */
+    r0 = (c0 >> 11) & 0x1F;
+    g0 = (c0 >> 5)  & 0x3F;
+    b0 =  c0        & 0x1F;
+
+    r1 = (c1 >> 11) & 0x1F;
+    g1 = (c1 >> 5)  & 0x3F;
+    b1 =  c1        & 0x1F;
+
     /* Expand 565 ref colors to 888 */
     /* Expand 565 ref colors to 888 */
-    r0 = (((c0 >> 11) & 0x1F) * 527 + 23) >> 6;
-    g0 = (((c0 >> 5)  & 0x3F) * 259 + 33) >> 6;
-    b0 =  ((c0        & 0x1F) * 527 + 23) >> 6;
-    refColors[0] = 0xFF000000 | (b0 << 16) | (g0 << 8) | r0;
+    r = (r0 * 527 + 23) >> 6;
+    g = (g0 * 259 + 33) >> 6;
+    b = (b0 * 527 + 23) >> 6;
+    refColors[0] = 0xFF000000 | (b << 16) | (g << 8) | r;
 
 
-    r1 = (((c1 >> 11) & 0x1F) * 527 + 23) >> 6;
-    g1 = (((c1 >> 5)  & 0x3F) * 259 + 33) >> 6;
-    b1 =  ((c1        & 0x1F) * 527 + 23) >> 6;
-    refColors[1] = 0xFF000000 | (b1 << 16) | (g1 << 8) | r1;
+    r = (r1 * 527 + 23) >> 6;
+    g = (g1 * 259 + 33) >> 6;
+    b = (b1 * 527 + 23) >> 6;
+    refColors[1] = 0xFF000000 | (b << 16) | (g << 8) | r;
 
 
     if (c0 > c1 || onlyOpaqueMode) {    /* Standard BC1 mode (also BC3 color block uses ONLY this mode) */
     if (c0 > c1 || onlyOpaqueMode) {    /* Standard BC1 mode (also BC3 color block uses ONLY this mode) */
         /* color_2 = 2/3*color_0 + 1/3*color_1
         /* color_2 = 2/3*color_0 + 1/3*color_1
            color_3 = 1/3*color_0 + 2/3*color_1 */
            color_3 = 1/3*color_0 + 2/3*color_1 */
-        r = (2 * r0 + r1 + 1) / 3;
-        g = (2 * g0 + g1 + 1) / 3;
-        b = (2 * b0 + b1 + 1) / 3;
+        r = ((2 * r0 + r1) *  351 +   61) >>  7;
+        g = ((2 * g0 + g1) * 2763 + 1039) >> 11;
+        b = ((2 * b0 + b1) *  351 +   61) >>  7;
         refColors[2] = 0xFF000000 | (b << 16) | (g << 8) | r;
         refColors[2] = 0xFF000000 | (b << 16) | (g << 8) | r;
 
 
-        r = (r0 + 2 * r1 + 1) / 3;
-        g = (g0 + 2 * g1 + 1) / 3;
-        b = (b0 + 2 * b1 + 1) / 3;
+        r = ((r0 + r1 * 2) *  351 +   61) >>  7;
+        g = ((g0 + g1 * 2) * 2763 + 1039) >> 11;
+        b = ((b0 + b1 * 2) *  351 +   61) >>  7;
         refColors[3] = 0xFF000000 | (b << 16) | (g << 8) | r;
         refColors[3] = 0xFF000000 | (b << 16) | (g << 8) | r;
     } else {                            /* Quite rare BC1A mode */
     } else {                            /* Quite rare BC1A mode */
         /* color_2 = 1/2*color_0 + 1/2*color_1;
         /* color_2 = 1/2*color_0 + 1/2*color_1;
            color_3 = 0;                         */
            color_3 = 0;                         */
-        r = (r0 + r1 + 1) >> 1;
-        g = (g0 + g1 + 1) >> 1;
-        b = (b0 + b1 + 1) >> 1;
+        r = ((r0 + r1) * 1053 +  125) >>  8;
+        g = ((g0 + g1) * 4145 + 1019) >> 11;
+        b = ((b0 + b1) * 1053 +  125) >>  8;
         refColors[2] = 0xFF000000 | (b << 16) | (g << 8) | r;
         refColors[2] = 0xFF000000 | (b << 16) | (g << 8) | r;
 
 
         refColors[3] = 0x00000000;
         refColors[3] = 0x00000000;
@@ -1269,8 +1287,6 @@ BCDECDEF void bcdec_bc7(const void* compressedBlock, void* decompressedBlock, in
 
 
 #endif /* BCDEC_IMPLEMENTATION */
 #endif /* BCDEC_IMPLEMENTATION */
 
 
-#endif /* BCDEC_HEADER_INCLUDED */
-
 /* LICENSE:
 /* LICENSE:
 
 
 This software is available under 2 licenses -- choose whichever you prefer.
 This software is available under 2 licenses -- choose whichever you prefer.
@@ -1326,4 +1342,4 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 
 For more information, please refer to <https://unlicense.org>
 For more information, please refer to <https://unlicense.org>
 
 
-*/
+*/