mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-11 16:26:20 +00:00
Merge pull request #1100 from MaxGraey/opt-visdif-codec
This commit is contained in:
14
codecs/visdif/BUILD.md
Normal file
14
codecs/visdif/BUILD.md
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
This codec currently needs monkey-patching of Emscripten
|
||||||
|
|
||||||
|
```
|
||||||
|
$ docker run --rm -it -v $(PWD):/src squoosh-cpp "/bin/bash"
|
||||||
|
# cat << EOF | patch /emsdk/upstream/emscripten/system/lib/dlmalloc.c
|
||||||
|
659c659
|
||||||
|
< #define MALLOC_ALIGNMENT ((size_t)(2 * sizeof(void *)))
|
||||||
|
---
|
||||||
|
> #define MALLOC_ALIGNMENT ((size_t)(16U))
|
||||||
|
EOF
|
||||||
|
# emcc --clear-cache
|
||||||
|
# /emsdk/upstream/emscripten/embuilder build libdlmalloc --force
|
||||||
|
# emmake make
|
||||||
|
```
|
||||||
@@ -5,12 +5,19 @@
|
|||||||
using namespace emscripten;
|
using namespace emscripten;
|
||||||
using namespace butteraugli;
|
using namespace butteraugli;
|
||||||
|
|
||||||
|
#define GAMMA 2.2
|
||||||
|
|
||||||
|
static float SrgbToLinear[256];
|
||||||
|
|
||||||
|
inline void gammaLookupTable() {
|
||||||
|
SrgbToLinear[0] = 0;
|
||||||
|
for (int i = 1; i < 256; ++i) {
|
||||||
|
SrgbToLinear[i] = static_cast<float>(255.0 * pow(i / 255.0, GAMMA));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Turns an interleaved RGBA buffer into 4 planes for each color channel
|
// Turns an interleaved RGBA buffer into 4 planes for each color channel
|
||||||
void planarize(std::vector<ImageF>& img,
|
void planarize(std::vector<ImageF>& img, const uint8_t* rgba, int width, int height) {
|
||||||
const uint8_t* rgba,
|
|
||||||
int width,
|
|
||||||
int height,
|
|
||||||
float gamma = 2.2) {
|
|
||||||
assert(img.size() == 0);
|
assert(img.size() == 0);
|
||||||
img.push_back(ImageF(width, height));
|
img.push_back(ImageF(width, height));
|
||||||
img.push_back(ImageF(width, height));
|
img.push_back(ImageF(width, height));
|
||||||
@@ -22,10 +29,10 @@ void planarize(std::vector<ImageF>& img,
|
|||||||
float* const row_b = img[2].Row(y);
|
float* const row_b = img[2].Row(y);
|
||||||
float* const row_a = img[3].Row(y);
|
float* const row_a = img[3].Row(y);
|
||||||
for (int x = 0; x < width; x++) {
|
for (int x = 0; x < width; x++) {
|
||||||
row_r[x] = 255.0 * pow(rgba[(y * width + x) * 4 + 0] / 255.0, gamma);
|
row_r[x] = SrgbToLinear[rgba[(y * width + x) * 4 + 0]];
|
||||||
row_g[x] = 255.0 * pow(rgba[(y * width + x) * 4 + 1] / 255.0, gamma);
|
row_g[x] = SrgbToLinear[rgba[(y * width + x) * 4 + 1]];
|
||||||
row_b[x] = 255.0 * pow(rgba[(y * width + x) * 4 + 2] / 255.0, gamma);
|
row_b[x] = SrgbToLinear[rgba[(y * width + x) * 4 + 2]];
|
||||||
row_a[x] = 255.0 * pow(rgba[(y * width + x) * 4 + 3] / 255.0, gamma);
|
row_a[x] = SrgbToLinear[rgba[(y * width + x) * 4 + 3]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -37,6 +44,7 @@ class VisDiff {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
VisDiff(std::string ref_img, int width, int height) {
|
VisDiff(std::string ref_img, int width, int height) {
|
||||||
|
gammaLookupTable();
|
||||||
planarize(this->ref_img, (uint8_t*)ref_img.c_str(), width, height);
|
planarize(this->ref_img, (uint8_t*)ref_img.c_str(), width, height);
|
||||||
this->width = width;
|
this->width = width;
|
||||||
this->height = height;
|
this->height = height;
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user