|
5 | 5 | * GPU Accelerated JavaScript |
6 | 6 | * |
7 | 7 | * @version 2.0.0-rc.14 |
8 | | - * @date Fri May 17 2019 18:42:19 GMT-0400 (Eastern Daylight Time) |
| 8 | + * @date Sat May 18 2019 17:22:48 GMT-0400 (Eastern Daylight Time) |
9 | 9 | * |
10 | 10 | * @license MIT |
11 | 11 | * The MIT License |
|
18 | 18 | * GPU Accelerated JavaScript |
19 | 19 | * |
20 | 20 | * @version 2.0.0-rc.14 |
21 | | - * @date Fri May 17 2019 18:42:16 GMT-0400 (Eastern Daylight Time) |
| 21 | + * @date Sat May 18 2019 17:22:46 GMT-0400 (Eastern Daylight Time) |
22 | 22 | * |
23 | 23 | * @license MIT |
24 | 24 | * The MIT License |
@@ -1310,23 +1310,9 @@ class CPUKernel extends Kernel { |
1310 | 1310 | return imageArray; |
1311 | 1311 | } |
1312 | 1312 |
|
1313 | | - getPixels() { |
| 1313 | + getPixels(flip) { |
1314 | 1314 | const [width, height] = this.output; |
1315 | | - const halfHeight = height / 2 | 0; |
1316 | | - const bytesPerRow = width * 4; |
1317 | | - const temp = new Uint8Array(width * 4); |
1318 | | - const pixels = this._imageData.data.slice(0); |
1319 | | - for (let y = 0; y < halfHeight; ++y) { |
1320 | | - var topOffset = y * bytesPerRow; |
1321 | | - var bottomOffset = (height - y - 1) * bytesPerRow; |
1322 | | - |
1323 | | - temp.set(pixels.subarray(topOffset, topOffset + bytesPerRow)); |
1324 | | - |
1325 | | - pixels.copyWithin(topOffset, bottomOffset, bottomOffset + bytesPerRow); |
1326 | | - |
1327 | | - pixels.set(temp, bottomOffset); |
1328 | | - } |
1329 | | - return pixels; |
| 1315 | + return flip ? utils.flipPixels(this._imageData.data, width, height) : this._imageData.data.slice(0); |
1330 | 1316 | } |
1331 | 1317 |
|
1332 | 1318 | _imageTo3DArray(images) { |
@@ -4048,15 +4034,16 @@ class GLKernel extends Kernel { |
4048 | 4034 | } |
4049 | 4035 | return zResults; |
4050 | 4036 | } |
4051 | | - getPixels() { |
| 4037 | + |
| 4038 | + getPixels(flip) { |
4052 | 4039 | const { |
4053 | 4040 | context: gl, |
4054 | 4041 | output |
4055 | 4042 | } = this; |
4056 | 4043 | const [width, height] = output; |
4057 | 4044 | const pixels = new Uint8Array(width * height * 4); |
4058 | 4045 | gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels); |
4059 | | - return pixels; |
| 4046 | + return flip ? pixels : utils.flipPixels(pixels, width, height); |
4060 | 4047 | } |
4061 | 4048 |
|
4062 | 4049 | renderKernelsToArrays() { |
@@ -4135,7 +4122,6 @@ module.exports = { |
4135 | 4122 | GLKernel, |
4136 | 4123 | renderStrategy |
4137 | 4124 | }; |
4138 | | - |
4139 | 4125 | },{"../../texture":68,"../../utils":69,"../kernel":14}],12:[function(require,module,exports){ |
4140 | 4126 | const getContext = require('gl'); |
4141 | 4127 | const { WebGLKernel } = require('../web-gl/kernel'); |
@@ -10377,6 +10363,23 @@ const utils = { |
10377 | 10363 | argumentTypes, |
10378 | 10364 | returnType: settings.returnType || null, |
10379 | 10365 | }; |
| 10366 | + }, |
| 10367 | + flipPixels: (pixels, width, height) => { |
| 10368 | + const halfHeight = height / 2 | 0; |
| 10369 | + const bytesPerRow = width * 4; |
| 10370 | + const temp = new Uint8Array(width * 4); |
| 10371 | + const result = pixels.slice(0); |
| 10372 | + for (let y = 0; y < halfHeight; ++y) { |
| 10373 | + const topOffset = y * bytesPerRow; |
| 10374 | + const bottomOffset = (height - y - 1) * bytesPerRow; |
| 10375 | + |
| 10376 | + temp.set(result.subarray(topOffset, topOffset + bytesPerRow)); |
| 10377 | + |
| 10378 | + result.copyWithin(topOffset, bottomOffset, bottomOffset + bytesPerRow); |
| 10379 | + |
| 10380 | + result.set(temp, bottomOffset); |
| 10381 | + } |
| 10382 | + return result; |
10380 | 10383 | } |
10381 | 10384 | }; |
10382 | 10385 |
|
|
0 commit comments