mirror of
https://github.com/maptiler/tileserver-gl.git
synced 2024-09-11 12:05:41 +03:00
chore: simplify alpha premultiplication, now supported by sharp (#1073)
Maplibre-native outputs premultiplied pixels values. The sharp library did not support it so we added code to cancel the alpha premultiplication. Note that this can only visible onr raster tiles (and probably static maps). The sharp library now supports premultiplied pixels with the right config. Let's use it: it should be faster and easie to maintain. Feature announced here: https://github.com/lovell/sharp/issues/1599#issuecomment-837004081 Feature developped here by @mnutt: https://github.com/lovell/sharp/pull/2685 Signed-off-by: Martin d'Allens <martin.dallens@liberty-rider.com>
This commit is contained in:
parent
526766c8f4
commit
b25a6420dd
@ -428,24 +428,9 @@ const respondImage = (
|
||||
return res.status(500).header('Content-Type', 'text/plain').send(err);
|
||||
}
|
||||
|
||||
// Fix semi-transparent outlines on raw, premultiplied input
|
||||
// https://github.com/maptiler/tileserver-gl/issues/350#issuecomment-477857040
|
||||
for (let i = 0; i < data.length; i += 4) {
|
||||
const alpha = data[i + 3];
|
||||
const norm = alpha / 255;
|
||||
if (alpha === 0) {
|
||||
data[i] = 0;
|
||||
data[i + 1] = 0;
|
||||
data[i + 2] = 0;
|
||||
} else {
|
||||
data[i] = data[i] / norm;
|
||||
data[i + 1] = data[i + 1] / norm;
|
||||
data[i + 2] = data[i + 2] / norm;
|
||||
}
|
||||
}
|
||||
|
||||
const image = sharp(data, {
|
||||
raw: {
|
||||
premultiplied: true,
|
||||
width: params.width * scale,
|
||||
height: params.height * scale,
|
||||
channels: 4,
|
||||
|
Loading…
Reference in New Issue
Block a user