diff options
author | Moonchild <moonchild@palemoon.org> | 2022-11-30 11:32:44 +0000 |
---|---|---|
committer | Moonchild <moonchild@palemoon.org> | 2022-11-30 14:28:09 +0000 |
commit | 2e888727e0e08c2f34544da3e410bc03e58fb312 (patch) | |
tree | 535c7c83875802f95b9b0518a264a570f6fdc164 /image | |
parent | bc165aebf8f5e9396a9ebbe9fe5b2b6b7a56f612 (diff) | |
download | uxp-2e888727e0e08c2f34544da3e410bc03e58fb312.tar.gz |
Issue #2040 - Pre-multiply the alpha values in our JXL decode buffer.
Using selective calculation (only if not opaque) and fast integer
math here should optimize well in compilers.
Diffstat (limited to 'image')
-rw-r--r-- | image/decoders/nsJXLDecoder.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/image/decoders/nsJXLDecoder.cpp b/image/decoders/nsJXLDecoder.cpp index fa4f6e77de..64a192877d 100644 --- a/image/decoders/nsJXLDecoder.cpp +++ b/image/decoders/nsJXLDecoder.cpp @@ -145,6 +145,12 @@ nsJXLDecoder::ReadJXLData(const char* aData, size_t aLength) // We currently have a channel ordering mis-match here. for (uint8_t* pixPtr = rowPtr; pixPtr < rowPtr + mInfo.xsize * 4; pixPtr+=4){ std::swap(pixPtr[0], pixPtr[2]); + // Pre-multiply, too + if (pixPtr[3] < 255) { + pixPtr[0]=((uint16_t)pixPtr[0]*(uint16_t)pixPtr[3]) >> 8; + pixPtr[1]=((uint16_t)pixPtr[1]*(uint16_t)pixPtr[3]) >> 8; + pixPtr[2]=((uint16_t)pixPtr[2]*(uint16_t)pixPtr[3]) >> 8; + } } pipe->WriteBuffer(reinterpret_cast<uint32_t*>(rowPtr)); } |