Skip to content

Commit 6878635

Browse files
committed
correct RGB - no need to multiply alpha
1 parent a259945 commit 6878635

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/plots/gl3d/scene.js

+18
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,23 @@ function flipPixels(pixels, w, h) {
10031003
}
10041004
}
10051005

1006+
function correctRGB(pixels, w, h) {
1007+
for(var i = 0; i < h; ++i) {
1008+
for(var j = 0; j < w; ++j) {
1009+
var k = 4 * (w * i + j);
1010+
1011+
var a = pixels[k + 3]; // alpha
1012+
if(a > 0) {
1013+
var q = 255 / a;
1014+
1015+
for(var l = 0; l < 3; ++l) { // RGB
1016+
pixels[k + l] = Math.min(q * pixels[k + l], 255);
1017+
}
1018+
}
1019+
}
1020+
}
1021+
}
1022+
10061023
proto.toImage = function(format) {
10071024
var scene = this;
10081025

@@ -1022,6 +1039,7 @@ proto.toImage = function(format) {
10221039
var pixels = new Uint8Array(w * h * 4);
10231040
gl.readPixels(0, 0, w, h, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
10241041
flipPixels(pixels, w, h);
1042+
correctRGB(pixels, w, h);
10251043

10261044
var canvas = document.createElement('canvas');
10271045
canvas.width = w;

0 commit comments

Comments
 (0)