Skip to content

Commit 41c7783

Browse files
committed
move flip pixel logic into a function
1 parent 0e5c9c5 commit 41c7783

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/plots/gl3d/scene.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,20 @@ proto.updateFx = function(dragmode, hovermode) {
989989
scene.fullSceneLayout.hovermode = hovermode;
990990
};
991991

992+
function flipPixels(pixels, w, h) {
993+
for(var j = 0, k = h - 1; j < k; ++j, --k) {
994+
for(var i = 0; i < w; ++i) {
995+
for(var l = 0; l < 4; ++l) {
996+
var a = 4 * (w * j + i) + l;
997+
var b = 4 * (w * k + i) + l;
998+
var tmp = pixels[a];
999+
pixels[a] = pixels[b];
1000+
pixels[b] = tmp;
1001+
}
1002+
}
1003+
}
1004+
}
1005+
9921006
proto.toImage = function(format) {
9931007
var scene = this;
9941008

@@ -1007,19 +1021,7 @@ proto.toImage = function(format) {
10071021

10081022
var pixels = new Uint8Array(w * h * 4);
10091023
gl.readPixels(0, 0, w, h, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
1010-
1011-
// Flip pixels
1012-
for(var j = 0, k = h - 1; j < k; ++j, --k) {
1013-
for(var i = 0; i < w; ++i) {
1014-
for(var l = 0; l < 4; ++l) {
1015-
var a = 4 * (w * j + i) + l;
1016-
var b = 4 * (w * k + i) + l;
1017-
var tmp = pixels[a];
1018-
pixels[a] = pixels[b];
1019-
pixels[b] = tmp;
1020-
}
1021-
}
1022-
}
1024+
flipPixels(pixels, w, h);
10231025

10241026
var canvas = document.createElement('canvas');
10251027
canvas.width = w;

0 commit comments

Comments
 (0)