summaryrefslogtreecommitdiff
path: root/thirdparty/etcpak/Error.cpp
diff options
context:
space:
mode:
authorK. S. Ernest (iFire) Lee <ernest.lee@chibifire.com>2021-04-06 22:05:56 -0700
committerRémi Verschelde <rverschelde@gmail.com>2021-04-13 00:12:12 +0200
commitd840165a324b5c218ca3a4882f030986855c8383 (patch)
tree7c5f4b091ecc647f2b6ed48135945f84c6dc2de9 /thirdparty/etcpak/Error.cpp
parentb895071895cffcbcda7f4156d7175ba5b8068852 (diff)
Add `etcpak` library for faster ETC/ETC2/S3TC imports.
- `etc` module was renamed to `etcpak` and modified to use the new library. - PKM importer is removed in the process, it's obsolete. - Old library `etc2comp` is removed. - S3TC compression no longer done via `squish` (but decompression still is). - Slight modifications to etcpak sources for MinGW compatibility, to fix LLVM `-Wc++11-narrowing` errors, and to allow using vendored or system libpng. Co-authored-by: Rémi Verschelde <rverschelde@gmail.com>
Diffstat (limited to 'thirdparty/etcpak/Error.cpp')
-rw-r--r--thirdparty/etcpak/Error.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/thirdparty/etcpak/Error.cpp b/thirdparty/etcpak/Error.cpp
new file mode 100644
index 0000000000..014ecdab66
--- /dev/null
+++ b/thirdparty/etcpak/Error.cpp
@@ -0,0 +1,48 @@
+#include <stdint.h>
+
+#include "Error.hpp"
+#include "Math.hpp"
+
+float CalcMSE3( const Bitmap& bmp, const Bitmap& out )
+{
+ float err = 0;
+
+ const uint32_t* p1 = bmp.Data();
+ const uint32_t* p2 = out.Data();
+ size_t cnt = bmp.Size().x * bmp.Size().y;
+
+ for( size_t i=0; i<cnt; i++ )
+ {
+ uint32_t c1 = *p1++;
+ uint32_t c2 = *p2++;
+
+ err += sq( ( c1 & 0x000000FF ) - ( c2 & 0x000000FF ) );
+ err += sq( ( ( c1 & 0x0000FF00 ) >> 8 ) - ( ( c2 & 0x0000FF00 ) >> 8 ) );
+ err += sq( ( ( c1 & 0x00FF0000 ) >> 16 ) - ( ( c2 & 0x00FF0000 ) >> 16 ) );
+ }
+
+ err /= cnt * 3;
+
+ return err;
+}
+
+float CalcMSE1( const Bitmap& bmp, const Bitmap& out )
+{
+ float err = 0;
+
+ const uint32_t* p1 = bmp.Data();
+ const uint32_t* p2 = out.Data();
+ size_t cnt = bmp.Size().x * bmp.Size().y;
+
+ for( size_t i=0; i<cnt; i++ )
+ {
+ uint32_t c1 = *p1++;
+ uint32_t c2 = *p2++;
+
+ err += sq( ( c1 >> 24 ) - ( c2 & 0xFF ) );
+ }
+
+ err /= cnt;
+
+ return err;
+}