🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

webgltexture-loader-ndarray

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webgltexture-loader-ndarray - npm Package Compare versions

Comparing version

to
0.12.0-minor.adc60f91

63

lib/drawNDArrayTexture.js

@@ -1,31 +0,11 @@

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
import ndarray from "ndarray";
var _ndarray = require("ndarray");
import ops from "ndarray-ops";
import pool from "typedarray-pool";
var _ndarray2 = _interopRequireDefault(_ndarray);
var _ndarrayOps = require("ndarray-ops");
var _ndarrayOps2 = _interopRequireDefault(_ndarrayOps);
var _typedarrayPool = require("typedarray-pool");
var _typedarrayPool2 = _interopRequireDefault(_typedarrayPool);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
if (typeof Buffer === "undefined") {
var _class, _temp;
global.Buffer = (_temp = _class = function Buffer() {
_classCallCheck(this, Buffer);
}, _class.isBuffer = function (b) {
return b instanceof Buffer;
}, _temp);
global.Buffer = (_temp = _class = class Buffer {}, _class.isBuffer = b => b instanceof Buffer, _temp);
}

@@ -43,14 +23,14 @@

function convertFloatToUint8(out, inp) {
_ndarrayOps2.default.muls(out, inp, 255.0);
ops.muls(out, inp, 255.0);
}
exports.default = function (gl, texture, array, floatSupported) {
var dtype = array.dtype;
var shape = array.shape.slice();
var maxSize = gl.getParameter(gl.MAX_TEXTURE_SIZE);
export default ((gl, texture, array, floatSupported) => {
let dtype = array.dtype;
let shape = array.shape.slice();
let maxSize = gl.getParameter(gl.MAX_TEXTURE_SIZE);
if (shape[0] < 0 || shape[0] > maxSize || shape[1] < 0 || shape[1] > maxSize) {
throw new Error("gl-react: Invalid texture size");
}
var packed = isPacked(shape, array.stride.slice());
var type = 0;
let packed = isPacked(shape, array.stride.slice());
let type = 0;
if (dtype === "float32") {

@@ -69,7 +49,7 @@ type = gl.FLOAT;

}
var format = 0;
let format = 0;
if (shape.length === 2) {
format = gl.LUMINANCE;
shape = [shape[0], shape[1], 1];
array = (0, _ndarray2.default)(array.data, shape, [array.stride[0], array.stride[1], 1], array.offset);
array = ndarray(array.data, shape, [array.stride[0], array.stride[1], 1], array.offset);
} else if (shape.length === 3) {

@@ -94,13 +74,12 @@ if (shape[2] === 1) {

}
var buffer = void 0,
buf_store = void 0;
var size = array.size;
let buffer, buf_store;
let size = array.size;
if (!packed) {
var stride = [shape[2], shape[2] * shape[0], 1];
buf_store = _typedarrayPool2.default.malloc(size, dtype);
var buf_array = (0, _ndarray2.default)(buf_store, shape, stride, 0);
let stride = [shape[2], shape[2] * shape[0], 1];
buf_store = pool.malloc(size, dtype);
let buf_array = ndarray(buf_store, shape, stride, 0);
if ((dtype === "float32" || dtype === "float64") && type === gl.UNSIGNED_BYTE) {
convertFloatToUint8(buf_array, array);
} else {
_ndarrayOps2.default.assign(buf_array, array);
ops.assign(buf_array, array);
}

@@ -115,5 +94,5 @@ buffer = buf_store.subarray(0, size);

if (buf_store) {
_typedarrayPool2.default.free(buf_store);
pool.free(buf_store);
}
};
});
//# sourceMappingURL=drawNDArrayTexture.js.map

@@ -1,82 +0,40 @@

"use strict";
import { WebGLTextureLoaderSyncHashCache, globalRegistry } from "webgltexture-loader";
Object.defineProperty(exports, "__esModule", {
value: true
});
import drawNDArrayTexture from "./drawNDArrayTexture";
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
class NDArrayTextureLoader extends WebGLTextureLoaderSyncHashCache {
constructor(gl) {
super(gl);
this.floatSupported = gl.getExtension("OES_texture_float") && gl.getExtension("OES_texture_float_linear");
}
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
canLoad(obj) {
return obj.shape && obj.data && obj.stride;
}
var _webgltextureLoader = require("webgltexture-loader");
inputHash(input) {
return input;
}
var _drawNDArrayTexture = require("./drawNDArrayTexture");
getNoCache(input) {
const { gl } = this;
const texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
const [width, height] = input.shape;
drawNDArrayTexture(gl, texture, input, this.floatSupported);
return { texture, width, height };
}
var _drawNDArrayTexture2 = _interopRequireDefault(_drawNDArrayTexture);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var NDArrayTextureLoader = function (_WebGLTextureLoaderSy) {
_inherits(NDArrayTextureLoader, _WebGLTextureLoaderSy);
function NDArrayTextureLoader(gl) {
_classCallCheck(this, NDArrayTextureLoader);
var _this = _possibleConstructorReturn(this, (NDArrayTextureLoader.__proto__ || Object.getPrototypeOf(NDArrayTextureLoader)).call(this, gl));
_this.floatSupported = gl.getExtension("OES_texture_float") && gl.getExtension("OES_texture_float_linear");
return _this;
update(input) {
// For now we assume the NDArray always change & need a redraw but we might try to only update if changes later
const { gl } = this;
const { texture } = this.get(input);
gl.bindTexture(gl.TEXTURE_2D, texture);
drawNDArrayTexture(gl, texture, input, this.floatSupported);
}
}
_createClass(NDArrayTextureLoader, [{
key: "canLoad",
value: function canLoad(obj) {
return obj.shape && obj.data && obj.stride;
}
}, {
key: "inputHash",
value: function inputHash(input) {
return input;
}
}, {
key: "getNoCache",
value: function getNoCache(input) {
var gl = this.gl;
globalRegistry.add(NDArrayTextureLoader);
var texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
var _input$shape = _slicedToArray(input.shape, 2),
width = _input$shape[0],
height = _input$shape[1];
(0, _drawNDArrayTexture2.default)(gl, texture, input, this.floatSupported);
return { texture: texture, width: width, height: height };
}
}, {
key: "update",
value: function update(input) {
// For now we assume the NDArray always change & need a redraw but we might try to only update if changes later
var gl = this.gl;
var _get = this.get(input),
texture = _get.texture;
gl.bindTexture(gl.TEXTURE_2D, texture);
(0, _drawNDArrayTexture2.default)(gl, texture, input, this.floatSupported);
}
}]);
return NDArrayTextureLoader;
}(_webgltextureLoader.WebGLTextureLoaderSyncHashCache);
_webgltextureLoader.globalRegistry.add(NDArrayTextureLoader);
exports.default = NDArrayTextureLoader;
export default NDArrayTextureLoader;
//# sourceMappingURL=NDArrayTextureLoader.js.map
{
"name": "webgltexture-loader-ndarray",
"version": "0.10.0",
"version": "0.12.0-minor.adc60f91",
"description": "ndarray loader for webgltexture-loader",

@@ -17,4 +17,4 @@ "main": "lib/NDArrayTextureLoader.js",

"typedarray-pool": "^1.1.0",
"webgltexture-loader": "^0.6.0"
"webgltexture-loader": "^0.12.0-minor.adc60f91"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet