From 659d2b8277b083d8e6fcd269ba471d4eac2d0fcb Mon Sep 17 00:00:00 2001 From: Surma Date: Mon, 22 Feb 2021 17:58:15 +0000 Subject: [PATCH 1/2] Fix butteraugli for auto-optimizer --- codecs/visdif/visdif.cpp | 8 ++++---- codecs/visdif/visdif.wasm | Bin 58133 -> 58133 bytes 2 files changed, 4 insertions(+), 4 deletions(-) mode change 100644 => 100755 codecs/visdif/visdif.wasm diff --git a/codecs/visdif/visdif.cpp b/codecs/visdif/visdif.cpp index a13e5e31..2882ea0c 100644 --- a/codecs/visdif/visdif.cpp +++ b/codecs/visdif/visdif.cpp @@ -22,10 +22,10 @@ void planarize(std::vector& img, float* const row_b = img[2].Row(y); float* const row_a = img[3].Row(y); for (int x = 0; x < width; x++) { - row_r[x] = 255.0 * pow(rgba[y * width * 4 + x * 4 + 0] / 255.0, gamma); - row_g[x] = 255.0 * pow(rgba[y * width * 4 + x * 4 + 1] / 255.0, gamma); - row_b[x] = 255.0 * pow(rgba[y * width * 4 + x * 4 + 2] / 255.0, gamma); - row_a[x] = 255.0 * pow(rgba[y * width * 4 + x * 4 + 3] / 255.0, gamma); + row_r[x] = 255.0 * pow((uint8_t)rgba[(y * width + x) * 4 + 0] / 255.0, gamma); + row_g[x] = 255.0 * pow((uint8_t)rgba[(y * width + x) * 4 + 1] / 255.0, gamma); + row_b[x] = 255.0 * pow((uint8_t)rgba[(y * width + x) * 4 + 2] / 255.0, gamma); + row_a[x] = 255.0 * pow((uint8_t)rgba[(y * width + x) * 4 + 3] / 255.0, gamma); } } } diff --git a/codecs/visdif/visdif.wasm b/codecs/visdif/visdif.wasm old mode 100644 new mode 100755 index d236f0ce81b5a203e5ccc7e01862344ed5d24aee..76924847f88a846916486281f56d8f76dc98382b GIT binary patch delta 66 zcmbPwjCtxY<_$Bqvgk4}?3gUKO?vW Date: Mon, 22 Feb 2021 18:05:26 +0000 Subject: [PATCH 2/2] Review --- codecs/visdif/visdif.cpp | 14 +++++++------- codecs/visdif/visdif.js | 12 +++--------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/codecs/visdif/visdif.cpp b/codecs/visdif/visdif.cpp index 2882ea0c..0825cdea 100644 --- a/codecs/visdif/visdif.cpp +++ b/codecs/visdif/visdif.cpp @@ -7,7 +7,7 @@ using namespace butteraugli; // Turns an interleaved RGBA buffer into 4 planes for each color channel void planarize(std::vector& img, - const char* rgba, + const uint8_t* rgba, int width, int height, float gamma = 2.2) { @@ -22,10 +22,10 @@ void planarize(std::vector& img, float* const row_b = img[2].Row(y); float* const row_a = img[3].Row(y); for (int x = 0; x < width; x++) { - row_r[x] = 255.0 * pow((uint8_t)rgba[(y * width + x) * 4 + 0] / 255.0, gamma); - row_g[x] = 255.0 * pow((uint8_t)rgba[(y * width + x) * 4 + 1] / 255.0, gamma); - row_b[x] = 255.0 * pow((uint8_t)rgba[(y * width + x) * 4 + 2] / 255.0, gamma); - row_a[x] = 255.0 * pow((uint8_t)rgba[(y * width + x) * 4 + 3] / 255.0, gamma); + row_r[x] = 255.0 * pow(rgba[(y * width + x) * 4 + 0] / 255.0, gamma); + row_g[x] = 255.0 * pow(rgba[(y * width + x) * 4 + 1] / 255.0, gamma); + row_b[x] = 255.0 * pow(rgba[(y * width + x) * 4 + 2] / 255.0, gamma); + row_a[x] = 255.0 * pow(rgba[(y * width + x) * 4 + 3] / 255.0, gamma); } } } @@ -37,14 +37,14 @@ class VisDiff { public: VisDiff(std::string ref_img, int width, int height) { - planarize(this->ref_img, ref_img.c_str(), width, height); + planarize(this->ref_img, (uint8_t*)ref_img.c_str(), width, height); this->width = width; this->height = height; } double distance(std::string other_img) { std::vector img; - planarize(img, other_img.c_str(), width, height); + planarize(img, (uint8_t*)other_img.c_str(), width, height); ImageF diffmap; double diffvalue; diff --git a/codecs/visdif/visdif.js b/codecs/visdif/visdif.js index 38277fd0..8ccf662b 100644 --- a/codecs/visdif/visdif.js +++ b/codecs/visdif/visdif.js @@ -1,7 +1,7 @@ var visdif = (function() { - var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined; - if (typeof __filename !== 'undefined') _scriptDir = _scriptDir || __filename; + var _scriptDir = import.meta.url; + return ( function(visdif) { visdif = visdif || {}; @@ -71,10 +71,4 @@ f.run=Wb;if(f.preInit)for("function"==typeof f.preInit&&(f.preInit=[f.preInit]); } ); })(); -if (typeof exports === 'object' && typeof module === 'object') - module.exports = visdif; - else if (typeof define === 'function' && define['amd']) - define([], function() { return visdif; }); - else if (typeof exports === 'object') - exports["visdif"] = visdif; - \ No newline at end of file +export default visdif; \ No newline at end of file