Skip to content

Commit

Permalink
feat: Video input, injectNative, tests.
Browse files Browse the repository at this point in the history
v2.0.0 Cosmic Jellyfish
  • Loading branch information
robertleeplummerjr committed Sep 17, 2019
1 parent 56e673a commit 2bc76ad
Show file tree
Hide file tree
Showing 27 changed files with 677 additions and 252 deletions.
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,9 @@ Settings are an object used to create a `kernel` or `kernelMap`. Example: `gpu.
* `precision` or `kernel.setPrecision('unsigned' | 'single')` **New in V2!**: 'single' or 'unsigned' - if 'single' output texture uses float32 for each colour channel rather than 8
* `fixIntegerDivisionAccuracy` or `kernel.setFixIntegerDivisionAccuracy(boolean)` : boolean - some cards have accuracy issues dividing by factors of three and some other primes (most apple kit?). Default on for affected cards, disable if accuracy not required.
* `functions` or `kernel.setFunctions(object)`: array, array of functions to be used inside kernel. If undefined, inherits from `GPU` instance.
* `nativeFunctions` or `kernel.setNativeFunctions(object)`: object, defined as: `{ functionName: functionSource }`
* `nativeFunctions` or `kernel.setNativeFunctions(object)`: object, defined as: `{ name: string, source: string, settings: object }`. This is generally set via using GPU.addNativeFunction()
* VERY IMPORTANT! - Use this to add special native functions to your environment when you need specific functionality is needed.
* `injectedNative` or `kernel.setInjectedNative(string)` **New in V2!**: string, defined as: `{ functionName: functionSource }`. This is for injecting native code before translated kernel functions.
* `subKernels` or `kernel.setSubKernels(array)`: array, generally inherited from `GPU` instance.
* `immutable` or `kernel.setImmutable(boolean)`: boolean, default = `false`
* `strictIntegers` or `kernel.setStrictIntegers(boolean)`: boolean, default = `false` - allows undefined argumentTypes and function return values to use strict integer declarations.
Expand Down Expand Up @@ -376,6 +377,7 @@ Debugging can be done in a variety of ways, and there are different levels of de
```
* HTML Image
* Array of HTML Images
* Video Element **New in V2!**
To define an argument, simply add it to the kernel function like regular JavaScript.
### Input Examples
Expand Down Expand Up @@ -407,7 +409,7 @@ const kernel = gpu.createKernel(function(image) {
this.color(pixel[0], pixel[1], pixel[2], pixel[3]);
})
.setGraphical(true)
.setOutput([100]);
.setOutput([100, 100]);
const image = new document.createElement('img');
image.src = 'my/image/source.png';
Expand All @@ -425,7 +427,7 @@ const kernel = gpu.createKernel(function(image) {
this.color(pixel[0], pixel[1], pixel[2], pixel[3]);
})
.setGraphical(true)
.setOutput([100]);
.setOutput([100, 100]);
const image1 = new document.createElement('img');
image1.src = 'my/image/source1.png';
Expand All @@ -447,6 +449,22 @@ function onload() {
};
```
An HTML Video: **New in V2!**
```js
const kernel = gpu.createKernel(function(videoFrame) {
const pixel = videoFrame[this.thread.y][this.thread.x];
this.color(pixel[0], pixel[1], pixel[2], pixel[3]);
})
.setGraphical(true)
.setOutput([100, 100]);
const video = new document.createElement('video');
video.src = 'my/video/source.webm';
kernel(image); //note, try and use requestAnimationFrame, and the video should be ready or playing
// Result: video frame
```
## Graphical Output
Sometimes, you want to produce a `canvas` image instead of doing numeric computations. To achieve this, set the `graphical` flag to `true` and the output dimensions to `[width, height]`. The thread identifiers will now refer to the `x` and `y` coordinate of the pixel you are producing. Inside your kernel function, use `this.color(r,g,b)` or `this.color(r,g,b,a)` to specify the color of the pixel.
Expand Down Expand Up @@ -633,6 +651,7 @@ Types that can be used with GPU.js are as follows:
* 'Array3D(4)' **New in V2!**
* 'HTMLImage'
* 'HTMLImageArray'
* 'HTMLVideo' **New in V2!**
* 'Number'
* 'Float'
* 'Integer'
Expand Down
Loading

0 comments on commit 2bc76ad

Please sign in to comment.