Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[node] semitransparent white areas gets grey on transparent background #9124

Closed
prozessor13 opened this issue May 29, 2017 · 1 comment
Closed
Labels
Core The cross-platform C++ core, aka mbgl Node.js node-mapbox-gl-native

Comments

@prozessor13
Copy link

Platform:
Node
Mapbox SDK version:
mapbox-gl-native@3.5.2

when rendering pixels with opacity (like backgrounds, fill-areas, halos, ..) as the first layer, the color-values are multiplied by the opacity factor. e.g.

rgba(255,255,255,0.5) gets to rgba(128,128,128,0.5)
rgba(255,0,0,0.8) gets to rgba(204,0,0,0.8)

Steps to trigger behavior

run the attached test-script: opacitytest.zip

  1. node test.js style.json
  2. convert image.png -define histogram:unique-colors=true -format %c histogram:info:-

Expected behavior

an image with color: rgba(255,0,0,0.8)

Actual behavior

an image with color: rgba(204,0,0,0.8)

thanks for help!
regards. max.

@kkaefer
Copy link
Contributor

kkaefer commented May 29, 2017

Thanks for reporting this issue.

In OpenGL, we use premultiplied colors because it simplifies color blending a lot. Once we have finished rendering the image, we retrieve it from the GPU. In the case of the command line utilities, we're using encodePNG, which gets the image data, and then "unpremultiplies" it, since PNG only supports non-premultiplied colors.

The Node binding however, returns the premultiplied image buffer as is, and expects the encoder to unpremultiply in case they need to convert it to a PNG. We do it this way, because some users of the library require premultiplied colors as input (e.g. when blending it with further images before encoding as PNG).

I suggest you check the library you use whether it supports premultiplied input, or request that feature from its author.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Core The cross-platform C++ core, aka mbgl Node.js node-mapbox-gl-native
Projects
None yet
Development

No branches or pull requests

2 participants