Skip to content

Commit

Permalink
Merge pull request #309 from gpujs/308-y-cpu-flip
Browse files Browse the repository at this point in the history
#308 process images in reverse y on cpu
  • Loading branch information
robertleeplummerjr authored Jun 8, 2018
2 parents d5a1734 + 480976d commit 3dad60d
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 61 deletions.
4 changes: 2 additions & 2 deletions bin/gpu-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* GPU Accelerated JavaScript
*
* @version 1.4.0
* @date Tue Jun 05 2018 20:28:34 GMT-0400 (EDT)
* @version 1.4.1
* @date Fri Jun 08 2018 16:46:30 GMT-0400 (EDT)
*
* @license MIT
* The MIT License
Expand Down
4 changes: 2 additions & 2 deletions bin/gpu-core.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 28 additions & 19 deletions bin/gpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* GPU Accelerated JavaScript
*
* @version 1.4.0
* @date Tue Jun 05 2018 20:28:35 GMT-0400 (EDT)
* @version 1.4.1
* @date Fri Jun 08 2018 16:46:31 GMT-0400 (EDT)
*
* @license MIT
* The MIT License
Expand Down Expand Up @@ -1033,7 +1033,7 @@ module.exports = function (_KernelBase) {
var pixelsData = this._canvasCtx.getImageData(0, 0, image.width, image.height).data;
var imageArray = new Array(image.height);
var index = 0;
for (var y = 0; y < image.height; y++) {
for (var y = image.height - 1; y >= 0; y--) {
imageArray[y] = new Array(image.width);
for (var x = 0; x < image.width; x++) {
imageArray[y][x] = [pixelsData[index++] / 255, pixelsData[index++] / 255, pixelsData[index++] / 255, pixelsData[index++] / 255];
Expand Down Expand Up @@ -3492,7 +3492,8 @@ module.exports = function (_KernelBase) {
this.setUniform1i('user_' + name, this.argumentsLength);
break;
}
case 'Number':
case 'Integer':
case 'Float':
{
this.setUniform1f('user_' + name, value);
break;
Expand Down Expand Up @@ -3687,15 +3688,15 @@ module.exports = function (_KernelBase) {
}, paramDim);

result.push('uniform highp sampler2D user_' + paramName, 'highp vec2 user_' + paramName + 'Size = vec2(' + paramSize[0] + '.0, ' + paramSize[1] + '.0)', 'highp vec3 user_' + paramName + 'Dim = vec3(' + paramDim[0] + '.0, ' + paramDim[1] + '.0, ' + paramDim[2] + '.0)');
} else if (paramType === 'Number' && Number.isInteger(param)) {
} else if (paramType === 'Integer') {
result.push('highp float user_' + paramName + ' = ' + param + '.0');
} else if (paramType === 'Number') {
} else if (paramType === 'Float') {
result.push('highp float user_' + paramName + ' = ' + param);
}
} else {
if (paramType === 'Array' || paramType === 'Texture' || paramType === 'Input' || paramType === 'HTMLImage') {
result.push('uniform highp sampler2D user_' + paramName, 'uniform highp vec2 user_' + paramName + 'Size', 'uniform highp vec3 user_' + paramName + 'Dim');
} else if (paramType === 'Number') {
} else if (paramType === 'Integer' || paramType === 'Float') {
result.push('uniform highp float user_' + paramName);
} else {
throw new Error('Param type ' + paramType + ' not supported in WebGL, only WebGL2');
Expand All @@ -3713,12 +3714,17 @@ module.exports = function (_KernelBase) {
if (this.constants) {
for (var name in this.constants) {
if (!this.constants.hasOwnProperty(name)) continue;
var value = parseFloat(this.constants[name]);

if (Number.isInteger(value)) {
result.push('const float constants_' + name + ' = ' + parseInt(value) + '.0');
} else {
result.push('const float constants_' + name + ' = ' + parseFloat(value));
var value = this.constants[name];
var type = utils.getArgumentType(value);
switch (type) {
case 'Integer':
result.push('const float constants_' + name + ' = ' + parseInt(value) + '.0');
break;
case 'Float':
result.push('const float constants_' + name + ' = ' + parseFloat(value));
break;
default:
throw new Error('Unsupported constant ' + name + ' type ' + type);
}
}
}
Expand All @@ -3736,7 +3742,6 @@ module.exports = function (_KernelBase) {
for (var i = 0; i < names.length; i++) {
result.push('highp float ' + names[i] + ' = 0.0');
}

} else {
result.push('highp float kernelResult = 0.0');
}
Expand Down Expand Up @@ -5119,7 +5124,8 @@ module.exports = function (_WebGLKernel) {
this.setUniform1i('user_' + name, this.argumentsLength);
break;
}
case 'Number':
case 'Integer':
case 'Float':
{
this.setUniform1f('user_' + name, value);
break;
Expand Down Expand Up @@ -5276,17 +5282,17 @@ module.exports = function (_WebGLKernel) {
}, paramDim);

result.push('uniform highp sampler2D user_' + paramName, 'highp vec2 user_' + paramName + 'Size = vec2(' + paramSize[0] + '.0, ' + paramSize[1] + '.0)', 'highp vec3 user_' + paramName + 'Dim = vec3(' + paramDim[0] + '.0, ' + paramDim[1] + '.0, ' + paramDim[2] + '.0)');
} else if (paramType === 'Number' && Number.isInteger(param)) {
} else if (paramType === 'Integer') {
result.push('highp float user_' + paramName + ' = ' + param + '.0');
} else if (paramType === 'Number') {
} else if (paramType === 'Float') {
result.push('highp float user_' + paramName + ' = ' + param);
}
} else {
if (paramType === 'Array' || paramType === 'Texture' || paramType === 'Input' || paramType === 'HTMLImage') {
result.push('uniform highp sampler2D user_' + paramName, 'uniform highp vec2 user_' + paramName + 'Size', 'uniform highp vec3 user_' + paramName + 'Dim');
} else if (paramType === 'HTMLImageArray') {
result.push('uniform highp sampler2DArray user_' + paramName, 'uniform highp vec2 user_' + paramName + 'Size', 'uniform highp vec3 user_' + paramName + 'Dim');
} else if (paramType === 'Number') {
} else if (paramType === 'Integer' || paramType === 'Float') {
result.push('uniform highp float user_' + paramName);
}
}
Expand Down Expand Up @@ -6201,7 +6207,10 @@ var Utils = function (_UtilsCore) {
}
return 'Array';
} else if (typeof arg === 'number') {
return 'Number';
if (Number.isInteger(arg)) {
return 'Integer';
}
return 'Float';
} else if (arg instanceof Texture) {
return 'Texture';
} else if (arg instanceof Input) {
Expand Down
18 changes: 9 additions & 9 deletions bin/gpu.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/backend/cpu/kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ module.exports = function (_KernelBase) {
var pixelsData = this._canvasCtx.getImageData(0, 0, image.width, image.height).data;
var imageArray = new Array(image.height);
var index = 0;
for (var y = 0; y < image.height; y++) {
for (var y = image.height - 1; y >= 0; y--) {
imageArray[y] = new Array(image.width);
for (var x = 0; x < image.width; x++) {
imageArray[y][x] = [pixelsData[index++] / 255, pixelsData[index++] / 255, pixelsData[index++] / 255, pixelsData[index++] / 255];
Expand Down
36 changes: 16 additions & 20 deletions dist/backend/web-gl/kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,8 @@ module.exports = function (_KernelBase) {
this.setUniform1i('user_' + name, this.argumentsLength);
break;
}
case 'Number':
case 'Integer':
case 'Float':
{
this.setUniform1f('user_' + name, value);
break;
Expand Down Expand Up @@ -1031,15 +1032,15 @@ module.exports = function (_KernelBase) {
}, paramDim);

result.push('uniform highp sampler2D user_' + paramName, 'highp vec2 user_' + paramName + 'Size = vec2(' + paramSize[0] + '.0, ' + paramSize[1] + '.0)', 'highp vec3 user_' + paramName + 'Dim = vec3(' + paramDim[0] + '.0, ' + paramDim[1] + '.0, ' + paramDim[2] + '.0)');
} else if (paramType === 'Number' && Number.isInteger(param)) {
} else if (paramType === 'Integer') {
result.push('highp float user_' + paramName + ' = ' + param + '.0');
} else if (paramType === 'Number') {
} else if (paramType === 'Float') {
result.push('highp float user_' + paramName + ' = ' + param);
}
} else {
if (paramType === 'Array' || paramType === 'Texture' || paramType === 'Input' || paramType === 'HTMLImage') {
result.push('uniform highp sampler2D user_' + paramName, 'uniform highp vec2 user_' + paramName + 'Size', 'uniform highp vec3 user_' + paramName + 'Dim');
} else if (paramType === 'Number') {
} else if (paramType === 'Integer' || paramType === 'Float') {
result.push('uniform highp float user_' + paramName);
} else {
throw new Error('Param type ' + paramType + ' not supported in WebGL, only WebGL2');
Expand All @@ -1063,12 +1064,17 @@ module.exports = function (_KernelBase) {
if (this.constants) {
for (var name in this.constants) {
if (!this.constants.hasOwnProperty(name)) continue;
var value = parseFloat(this.constants[name]);

if (Number.isInteger(value)) {
result.push('const float constants_' + name + ' = ' + parseInt(value) + '.0');
} else {
result.push('const float constants_' + name + ' = ' + parseFloat(value));
var value = this.constants[name];
var type = utils.getArgumentType(value);
switch (type) {
case 'Integer':
result.push('const float constants_' + name + ' = ' + parseInt(value) + '.0');
break;
case 'Float':
result.push('const float constants_' + name + ' = ' + parseFloat(value));
break;
default:
throw new Error('Unsupported constant ' + name + ' type ' + type);
}
}
}
Expand Down Expand Up @@ -1096,16 +1102,6 @@ module.exports = function (_KernelBase) {
for (var i = 0; i < names.length; i++) {
result.push('highp float ' + names[i] + ' = 0.0');
}

/* this is v2 prep
result.push('highp float kernelResult = 0.0');
result.push('layout(location = 0) out highp float fradData0 = 0.0');
for (let i = 0; i < names.length; i++) {
result.push(
`highp float ${ names[i] } = 0.0`,
`layout(location = ${ i + 1 }) out highp float fragData${ i + 1 } = 0.0`
);
}*/
} else {
result.push('highp float kernelResult = 0.0');
}
Expand Down
9 changes: 5 additions & 4 deletions dist/backend/web-gl2/kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ module.exports = function (_WebGLKernel) {
this.setUniform1i('user_' + name, this.argumentsLength);
break;
}
case 'Number':
case 'Integer':
case 'Float':
{
this.setUniform1f('user_' + name, value);
break;
Expand Down Expand Up @@ -510,17 +511,17 @@ module.exports = function (_WebGLKernel) {
}, paramDim);

result.push('uniform highp sampler2D user_' + paramName, 'highp vec2 user_' + paramName + 'Size = vec2(' + paramSize[0] + '.0, ' + paramSize[1] + '.0)', 'highp vec3 user_' + paramName + 'Dim = vec3(' + paramDim[0] + '.0, ' + paramDim[1] + '.0, ' + paramDim[2] + '.0)');
} else if (paramType === 'Number' && Number.isInteger(param)) {
} else if (paramType === 'Integer') {
result.push('highp float user_' + paramName + ' = ' + param + '.0');
} else if (paramType === 'Number') {
} else if (paramType === 'Float') {
result.push('highp float user_' + paramName + ' = ' + param);
}
} else {
if (paramType === 'Array' || paramType === 'Texture' || paramType === 'Input' || paramType === 'HTMLImage') {
result.push('uniform highp sampler2D user_' + paramName, 'uniform highp vec2 user_' + paramName + 'Size', 'uniform highp vec3 user_' + paramName + 'Dim');
} else if (paramType === 'HTMLImageArray') {
result.push('uniform highp sampler2DArray user_' + paramName, 'uniform highp vec2 user_' + paramName + 'Size', 'uniform highp vec3 user_' + paramName + 'Dim');
} else if (paramType === 'Number') {
} else if (paramType === 'Integer' || paramType === 'Float') {
result.push('uniform highp float user_' + paramName);
}
}
Expand Down
7 changes: 5 additions & 2 deletions dist/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ var Utils = function (_UtilsCore) {
*
* @param {Object} arg - The argument object to evaluate type
*
* @returns {String} Argument type Array/Number/Texture/Unknown
* @returns {String} Argument type Array/Number/Float/Texture/Unknown
*
*/

Expand All @@ -327,7 +327,10 @@ var Utils = function (_UtilsCore) {
}
return 'Array';
} else if (typeof arg === 'number') {
return 'Number';
if (Number.isInteger(arg)) {
return 'Integer';
}
return 'Float';
} else if (arg instanceof Texture) {
return 'Texture';
} else if (arg instanceof Input) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gpu.js",
"version": "1.4.0",
"version": "1.4.1",
"description": "GPU Accelerated JavaScript",
"main": "./dist/index.js",
"directories": {
Expand Down
2 changes: 1 addition & 1 deletion src/backend/cpu/kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ ${ this.subKernelOutputVariableNames === null
const pixelsData = this._canvasCtx.getImageData(0, 0, image.width, image.height).data;
const imageArray = new Array(image.height);
let index = 0;
for (let y = 0; y < image.height; y++) {
for (let y = image.height - 1; y >= 0; y--) {
imageArray[y] = new Array(image.width);
for (let x = 0; x < image.width; x++) {
imageArray[y][x] = [pixelsData[index++] / 255, pixelsData[index++] / 255, pixelsData[index++] / 255, pixelsData[index++] / 255];
Expand Down

0 comments on commit 3dad60d

Please sign in to comment.