diff --git a/src/plots/gl3d/scene.js b/src/plots/gl3d/scene.js index e26157ace03..9255329b49e 100644 --- a/src/plots/gl3d/scene.js +++ b/src/plots/gl3d/scene.js @@ -989,6 +989,37 @@ proto.updateFx = function(dragmode, hovermode) { scene.fullSceneLayout.hovermode = hovermode; }; +function flipPixels(pixels, w, h) { + for(var i = 0, q = h - 1; i < q; ++i, --q) { + for(var j = 0; j < w; ++j) { + for(var k = 0; k < 4; ++k) { + var a = 4 * (w * i + j) + k; + var b = 4 * (w * q + j) + k; + var tmp = pixels[a]; + pixels[a] = pixels[b]; + pixels[b] = tmp; + } + } + } +} + +function correctRGB(pixels, w, h) { + for(var i = 0; i < h; ++i) { + for(var j = 0; j < w; ++j) { + var k = 4 * (w * i + j); + + var a = pixels[k + 3]; // alpha + if(a > 0) { + var q = 255 / a; + + for(var l = 0; l < 3; ++l) { // RGB + pixels[k + l] = Math.min(q * pixels[k + l], 255); + } + } + } + } +} + proto.toImage = function(format) { var scene = this; @@ -1007,17 +1038,8 @@ proto.toImage = function(format) { var pixels = new Uint8Array(w * h * 4); gl.readPixels(0, 0, w, h, gl.RGBA, gl.UNSIGNED_BYTE, pixels); - - // Flip pixels - for(var j = 0, k = h - 1; j < k; ++j, --k) { - for(var i = 0; i < w; ++i) { - for(var l = 0; l < 4; ++l) { - var tmp = pixels[4 * (w * j + i) + l]; - pixels[4 * (w * j + i) + l] = pixels[4 * (w * k + i) + l]; - pixels[4 * (w * k + i) + l] = tmp; - } - } - } + flipPixels(pixels, w, h); + correctRGB(pixels, w, h); var canvas = document.createElement('canvas'); canvas.width = w; diff --git a/test/image/baselines/gl3d_bunny-hull.png b/test/image/baselines/gl3d_bunny-hull.png index 46c5ff94067..de4104538a5 100644 Binary files a/test/image/baselines/gl3d_bunny-hull.png and b/test/image/baselines/gl3d_bunny-hull.png differ diff --git a/test/image/baselines/gl3d_bunny.png b/test/image/baselines/gl3d_bunny.png index 3913dfbc47d..dce936dc338 100644 Binary files a/test/image/baselines/gl3d_bunny.png and b/test/image/baselines/gl3d_bunny.png differ diff --git a/test/image/baselines/gl3d_coloraxes.png b/test/image/baselines/gl3d_coloraxes.png index d642a30cdeb..0fd3f7530e5 100644 Binary files a/test/image/baselines/gl3d_coloraxes.png and b/test/image/baselines/gl3d_coloraxes.png differ diff --git a/test/image/baselines/gl3d_cone-lighting.png b/test/image/baselines/gl3d_cone-lighting.png index 0458516b58c..28a6d3dd0f4 100644 Binary files a/test/image/baselines/gl3d_cone-lighting.png and b/test/image/baselines/gl3d_cone-lighting.png differ diff --git a/test/image/baselines/gl3d_convex-hull.png b/test/image/baselines/gl3d_convex-hull.png index 3913dfbc47d..dce936dc338 100644 Binary files a/test/image/baselines/gl3d_convex-hull.png and b/test/image/baselines/gl3d_convex-hull.png differ diff --git a/test/image/baselines/gl3d_cube.png b/test/image/baselines/gl3d_cube.png index 40eaa6b5ad0..48c111576fa 100644 Binary files a/test/image/baselines/gl3d_cube.png and b/test/image/baselines/gl3d_cube.png differ diff --git a/test/image/baselines/gl3d_directions-streamtube1.png b/test/image/baselines/gl3d_directions-streamtube1.png index 3deec1d575a..fd774f0e5bd 100644 Binary files a/test/image/baselines/gl3d_directions-streamtube1.png and b/test/image/baselines/gl3d_directions-streamtube1.png differ diff --git a/test/image/baselines/gl3d_directions-streamtube2.png b/test/image/baselines/gl3d_directions-streamtube2.png index 5246b1f8028..9839a7de988 100644 Binary files a/test/image/baselines/gl3d_directions-streamtube2.png and b/test/image/baselines/gl3d_directions-streamtube2.png differ diff --git a/test/image/baselines/gl3d_directions-volume1.png b/test/image/baselines/gl3d_directions-volume1.png index d0c0e0f445b..b17b3055364 100644 Binary files a/test/image/baselines/gl3d_directions-volume1.png and b/test/image/baselines/gl3d_directions-volume1.png differ diff --git a/test/image/baselines/gl3d_indicator_scatter3d.png b/test/image/baselines/gl3d_indicator_scatter3d.png index c6a662fe5a6..f1f4d7582d5 100644 Binary files a/test/image/baselines/gl3d_indicator_scatter3d.png and b/test/image/baselines/gl3d_indicator_scatter3d.png differ diff --git a/test/image/baselines/gl3d_isosurface_thin_slices_transparent.png b/test/image/baselines/gl3d_isosurface_thin_slices_transparent.png index ee3a6e58c17..007cef9eea7 100644 Binary files a/test/image/baselines/gl3d_isosurface_thin_slices_transparent.png and b/test/image/baselines/gl3d_isosurface_thin_slices_transparent.png differ diff --git a/test/image/baselines/gl3d_isosurface_transparent.png b/test/image/baselines/gl3d_isosurface_transparent.png index 0ea4acbbf0d..bfeec812783 100644 Binary files a/test/image/baselines/gl3d_isosurface_transparent.png and b/test/image/baselines/gl3d_isosurface_transparent.png differ diff --git a/test/image/baselines/gl3d_marker-arrays.png b/test/image/baselines/gl3d_marker-arrays.png index 5b903b88912..c1a73af4158 100644 Binary files a/test/image/baselines/gl3d_marker-arrays.png and b/test/image/baselines/gl3d_marker-arrays.png differ diff --git a/test/image/baselines/gl3d_marker-color.png b/test/image/baselines/gl3d_marker-color.png index f0b7ca3766b..873ea813a5b 100644 Binary files a/test/image/baselines/gl3d_marker-color.png and b/test/image/baselines/gl3d_marker-color.png differ diff --git a/test/image/baselines/gl3d_mesh3d_enable-alpha-with-rgba-color.png b/test/image/baselines/gl3d_mesh3d_enable-alpha-with-rgba-color.png index c8b87c6a882..7c9f9ce8985 100644 Binary files a/test/image/baselines/gl3d_mesh3d_enable-alpha-with-rgba-color.png and b/test/image/baselines/gl3d_mesh3d_enable-alpha-with-rgba-color.png differ diff --git a/test/image/baselines/gl3d_opacity-scaling-spikes.png b/test/image/baselines/gl3d_opacity-scaling-spikes.png index f530c13aa85..4f3b24b0639 100644 Binary files a/test/image/baselines/gl3d_opacity-scaling-spikes.png and b/test/image/baselines/gl3d_opacity-scaling-spikes.png differ diff --git a/test/image/baselines/gl3d_rgb_dont_accept_alpha_scatter3d.png b/test/image/baselines/gl3d_rgb_dont_accept_alpha_scatter3d.png index 21896f14a40..b856cd72efd 100644 Binary files a/test/image/baselines/gl3d_rgb_dont_accept_alpha_scatter3d.png and b/test/image/baselines/gl3d_rgb_dont_accept_alpha_scatter3d.png differ diff --git a/test/image/baselines/gl3d_scatter3d-colorscale.png b/test/image/baselines/gl3d_scatter3d-colorscale.png index ab50286aabf..de456f47ec1 100644 Binary files a/test/image/baselines/gl3d_scatter3d-colorscale.png and b/test/image/baselines/gl3d_scatter3d-colorscale.png differ diff --git a/test/image/baselines/gl3d_scatter3d_line3d_error3d_enable-alpha-with-rgba-color.png b/test/image/baselines/gl3d_scatter3d_line3d_error3d_enable-alpha-with-rgba-color.png index e77b8c13e02..affdae1ede8 100644 Binary files a/test/image/baselines/gl3d_scatter3d_line3d_error3d_enable-alpha-with-rgba-color.png and b/test/image/baselines/gl3d_scatter3d_line3d_error3d_enable-alpha-with-rgba-color.png differ diff --git a/test/image/baselines/gl3d_scatter3d_line3d_error3d_transparent-with-zero-alpha.png b/test/image/baselines/gl3d_scatter3d_line3d_error3d_transparent-with-zero-alpha.png index 367d5e552b8..a37d21d16ce 100644 Binary files a/test/image/baselines/gl3d_scatter3d_line3d_error3d_transparent-with-zero-alpha.png and b/test/image/baselines/gl3d_scatter3d_line3d_error3d_transparent-with-zero-alpha.png differ diff --git a/test/image/baselines/gl3d_surface-lighting.png b/test/image/baselines/gl3d_surface-lighting.png index bcab31c6b3d..e96ceb15983 100644 Binary files a/test/image/baselines/gl3d_surface-lighting.png and b/test/image/baselines/gl3d_surface-lighting.png differ diff --git a/test/image/baselines/gl3d_traces-with-legend.png b/test/image/baselines/gl3d_traces-with-legend.png index 3df06dc64bb..ae50a3b186f 100644 Binary files a/test/image/baselines/gl3d_traces-with-legend.png and b/test/image/baselines/gl3d_traces-with-legend.png differ diff --git a/test/image/baselines/gl3d_traces-with-opacity.png b/test/image/baselines/gl3d_traces-with-opacity.png index 2d46bb03096..7c0deb95ffe 100644 Binary files a/test/image/baselines/gl3d_traces-with-opacity.png and b/test/image/baselines/gl3d_traces-with-opacity.png differ diff --git a/test/image/baselines/gl3d_transparent_same-depth.png b/test/image/baselines/gl3d_transparent_same-depth.png index b0757516867..510488931ac 100644 Binary files a/test/image/baselines/gl3d_transparent_same-depth.png and b/test/image/baselines/gl3d_transparent_same-depth.png differ diff --git a/test/image/baselines/gl3d_volume_airflow.png b/test/image/baselines/gl3d_volume_airflow.png index 91f683f4b72..ec3ec907f42 100644 Binary files a/test/image/baselines/gl3d_volume_airflow.png and b/test/image/baselines/gl3d_volume_airflow.png differ diff --git a/test/image/baselines/gl3d_volume_multiple-traces.png b/test/image/baselines/gl3d_volume_multiple-traces.png index cf55edcc916..94fee82f444 100644 Binary files a/test/image/baselines/gl3d_volume_multiple-traces.png and b/test/image/baselines/gl3d_volume_multiple-traces.png differ diff --git a/test/image/baselines/gl3d_volume_multiple-traces_one-cube.png b/test/image/baselines/gl3d_volume_multiple-traces_one-cube.png index b0139c04a50..f97aaf4c98b 100644 Binary files a/test/image/baselines/gl3d_volume_multiple-traces_one-cube.png and b/test/image/baselines/gl3d_volume_multiple-traces_one-cube.png differ diff --git a/test/image/baselines/gl3d_volume_opacityscale-iso.png b/test/image/baselines/gl3d_volume_opacityscale-iso.png index 6d9295e484b..ff654e2f4a8 100644 Binary files a/test/image/baselines/gl3d_volume_opacityscale-iso.png and b/test/image/baselines/gl3d_volume_opacityscale-iso.png differ