Fix HDR image support in AVIF decoder
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
# WebP decoder
|
||||
# AVIF decoder
|
||||
|
||||
- Source: <https://github.com/webmproject/libwebp>
|
||||
- Version: v1.0.2
|
||||
- Source: <https://github.com/AOMediaCodec/libavif>
|
||||
- Version: v0.5.4
|
||||
|
||||
## Example
|
||||
|
||||
@ -9,13 +9,9 @@ See `example.html`
|
||||
|
||||
## API
|
||||
|
||||
### `int version()`
|
||||
|
||||
Returns the version of libwebp as a number. va.b.c is encoded as 0x0a0b0c
|
||||
|
||||
### `RawImage decode(std::string buffer)`
|
||||
|
||||
Decodes the given webp buffer into raw RGBA. `RawImage` is a class with 3 fields: `buffer`, `width`, and `height`.
|
||||
Decodes the given avif buffer into raw RGBA. `RawImage` is a class with 3 fields: `buffer`, `width`, and `height`.
|
||||
|
||||
### `void free_result()`
|
||||
|
||||
|
@ -56,16 +56,40 @@ RawImage decode(std::string avifimage) {
|
||||
// ... image->rgbPlanes;
|
||||
// ... image->rgbRowBytes;
|
||||
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
int pixelOffset = y * image->width + x;
|
||||
result[pixelOffset * 4 + 0] = image->rgbPlanes[0][pixelOffset];
|
||||
result[pixelOffset * 4 + 1] = image->rgbPlanes[1][pixelOffset];
|
||||
result[pixelOffset * 4 + 2] = image->rgbPlanes[2][pixelOffset];
|
||||
if (image->alphaPlane) {
|
||||
result[pixelOffset * 4 + 3] = image->alphaPlane[pixelOffset];
|
||||
} else {
|
||||
result[pixelOffset * 4 + 3] = 255;
|
||||
if (image->depth > 8) {
|
||||
uint16_t depthDivistor = 1 << (image->depth - 8);
|
||||
// Plane ptrs are uint16_t*
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
int pixelOffset = y * image->width + x;
|
||||
result[pixelOffset * 4 + 0] = (uint8_t)(
|
||||
((uint16_t *)(image->rgbPlanes[0]))[pixelOffset] / depthDivistor);
|
||||
result[pixelOffset * 4 + 1] = (uint8_t)(
|
||||
((uint16_t *)(image->rgbPlanes[1]))[pixelOffset] / depthDivistor);
|
||||
result[pixelOffset * 4 + 2] = (uint8_t)(
|
||||
((uint16_t *)(image->rgbPlanes[2]))[pixelOffset] / depthDivistor);
|
||||
if (image->alphaPlane) {
|
||||
result[pixelOffset * 4 + 3] = (uint8_t)(
|
||||
((uint16_t *)(image->alphaPlane))[pixelOffset] / depthDivistor);
|
||||
} else {
|
||||
result[pixelOffset * 4 + 3] = 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// Plane ptrs are uint8_t*
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
int pixelOffset = y * image->width + x;
|
||||
result[pixelOffset * 4 + 0] = image->rgbPlanes[0][pixelOffset];
|
||||
result[pixelOffset * 4 + 1] = image->rgbPlanes[1][pixelOffset];
|
||||
result[pixelOffset * 4 + 2] = image->rgbPlanes[2][pixelOffset];
|
||||
if (image->alphaPlane) {
|
||||
result[pixelOffset * 4 + 3] = image->alphaPlane[pixelOffset];
|
||||
} else {
|
||||
result[pixelOffset * 4 + 3] = 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
@ -10,7 +10,7 @@ export CPPFLAGS="${OPTIMIZE}"
|
||||
echo "============================================="
|
||||
echo "Compiling libaom"
|
||||
echo "============================================="
|
||||
(
|
||||
test -n "$SKIP_LIBAOM" || (
|
||||
cd node_modules/libavif/ext
|
||||
test -d aom || git clone -b v1.0.0-errata1-avif --depth 1 https://aomedia.googlesource.com/aom aom
|
||||
|
||||
@ -40,7 +40,7 @@ echo "============================================="
|
||||
echo "============================================="
|
||||
echo "Compiling libavif"
|
||||
echo "============================================="
|
||||
(
|
||||
test -n "$SKIP_LIBAVIF" || (
|
||||
cd node_modules/libavif
|
||||
mkdir -p build
|
||||
cd build
|
||||
|
Reference in New Issue
Block a user