/
danehansen-ImageDataReader.min.js
120 lines (113 loc) · 10.2 KB
/
danehansen-ImageDataReader.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
* This devtool is neither made for production nor for readable output files.
* It uses "eval()" calls to create a separate source file in the browser devtools.
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
* or disable the default devtool with "devtool: false".
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
*/
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("@danehansen/math"));
else if(typeof define === 'function' && define.amd)
define(["@danehansen/math"], factory);
else if(typeof exports === 'object')
exports["danehansen"] = factory(require("@danehansen/math"));
else
root["danehansen"] = root["danehansen"] || {}, root["danehansen"]["ImageDataReader"] = factory(root["danehansen"]["math"]);
})(self, function(__WEBPACK_EXTERNAL_MODULE__danehansen_math__) {
return /******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ({
/***/ "./src/ImageDataReader.js":
/*!********************************!*\
!*** ./src/ImageDataReader.js ***!
\********************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"WHITE_BRIGHTNESS\": () => (/* binding */ WHITE_BRIGHTNESS),\n/* harmony export */ \"red\": () => (/* binding */ _red),\n/* harmony export */ \"green\": () => (/* binding */ _green),\n/* harmony export */ \"blue\": () => (/* binding */ _blue),\n/* harmony export */ \"opacity\": () => (/* binding */ _opacity),\n/* harmony export */ \"brightness\": () => (/* binding */ _brightness),\n/* harmony export */ \"default\": () => (/* binding */ ImageDataReader)\n/* harmony export */ });\n/* harmony import */ var _danehansen_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @danehansen/math */ \"@danehansen/math\");\n/* harmony import */ var _danehansen_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_danehansen_math__WEBPACK_IMPORTED_MODULE_0__);\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _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); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\n\nvar WHITE_BRIGHTNESS = 255 * 3;\n\nfunction _red(data, width, x, y) {\n return data[(y * width + x) * 4];\n}\n\n\n\nfunction _green(data, width, x, y) {\n return data[(y * width + x) * 4 + 1];\n}\n\n\n\nfunction _blue(data, width, x, y) {\n return data[(y * width + x) * 4 + 2];\n}\n\n\n\nfunction _opacity(data, width, x, y) {\n return data[(y * width + x) * 4 + 3];\n}\n\n\n\nfunction _brightness(data, width, x, y) {\n return _red(data, width, x, y) + _blue(data, width, x, y) + _green(data, width, x, y);\n}\n\n\n\nvar ImageDataReader = /*#__PURE__*/function () {\n function ImageDataReader(src, srcCrop, destWidth, destHeight) {\n _classCallCheck(this, ImageDataReader);\n\n this._src = src;\n this._srcCrop = srcCrop || {\n x: 0,\n y: 0,\n width: src.videoWidth || src.width,\n height: src.videoHeight || src.height\n };\n this._destWidth = destWidth || this._srcCrop.width;\n this._destHeight = destHeight || this._srcCrop.height;\n this._canvas = document.createElement(\"canvas\");\n this._context = this._canvas.getContext(\"2d\");\n this._canvas.width = this._destWidth;\n this._canvas.height = this._destHeight;\n this.update();\n }\n\n _createClass(ImageDataReader, [{\n key: \"update\",\n value: function update() {\n this._context.drawImage(this._src, this._srcCrop.x, this._srcCrop.y, this._srcCrop.width, this._srcCrop.height, 0, 0, this._destWidth, this._destHeight);\n\n this.data = this._context.getImageData(0, 0, this._destWidth, this._destHeight).data;\n }\n }, {\n key: \"red\",\n value: function red(x, y) {\n return _red(this.data, this._destWidth, x, y);\n }\n }, {\n key: \"green\",\n value: function green(x, y) {\n return _green(this.data, this._destWidth, x, y);\n }\n }, {\n key: \"blue\",\n value: function blue(x, y) {\n return _blue(this.data, this._destWidth, x, y);\n }\n }, {\n key: \"opacity\",\n value: function opacity(x, y) {\n return _opacity(this.data, this._destWidth, x, y);\n }\n }, {\n key: \"brightness\",\n value: function brightness(x, y) {\n var b = _brightness(this.data, this._destWidth, x, y); // if (this._shouldAdjust) {\n // if (b < this._avg) {\n // b = Math.round(\n // (normalize(this._low, this._avg, b) / 2) * WHITE_BRIGHTNESS\n // );\n // } else {\n // b = Math.round(\n // (normalize(this._avg, this._high, b) / 2) * WHITE_BRIGHTNESS +\n // Math.floor(WHITE_BRIGHTNESS / 2)\n // );\n // }\n // }\n\n\n if (this._shouldAdjust) {\n b = Math.round((0,_danehansen_math__WEBPACK_IMPORTED_MODULE_0__.normalize)(this._low, this._high, b) * WHITE_BRIGHTNESS);\n }\n\n return b;\n }\n }, {\n key: \"adjustContrast\",\n value: function adjustContrast(reset) {\n if (reset) {\n this._shouldAdjust = false;\n } else {\n this._low = WHITE_BRIGHTNESS;\n this._high = 0; // this._avg = 0;\n\n for (var i = 0, length = this.data.length; i < length; i += 4) {\n var b = this.data[i] + this.data[i + 1] + this.data[i + 2]; // this._avg += b;\n\n this._high = Math.max(this._high, b);\n this._low = Math.min(this._low, b);\n } // this._avg = Math.round(this._avg / (this._destWidth * this._destHeight));\n\n\n this._shouldAdjust = this._low !== 0 || this._high !== WHITE_BRIGHTNESS; /// ||\n // this._avg !== Math.floor(WHITE_BRIGHTNESS / 2);\n\n this._shouldAdjust = true;\n }\n }\n }]);\n\n return ImageDataReader;\n}();\n\n\n\n//# sourceURL=webpack://danehansen.ImageDataReader/./src/ImageDataReader.js?");
/***/ }),
/***/ "@danehansen/math":
/*!*************************************************************************************************************************************!*\
!*** external {"amd":"@danehansen/math","commonjs":"@danehansen/math","commonjs2":"@danehansen/math","root":["danehansen","math"]} ***!
\*************************************************************************************************************************************/
/***/ ((module) => {
module.exports = __WEBPACK_EXTERNAL_MODULE__danehansen_math__;
/***/ })
/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
/******/ /* webpack/runtime/compat get default export */
/******/ (() => {
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = (module) => {
/******/ var getter = module && module.__esModule ?
/******/ () => (module['default']) :
/******/ () => (module);
/******/ __webpack_require__.d(getter, { a: getter });
/******/ return getter;
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/define property getters */
/******/ (() => {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = (exports, definition) => {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ (() => {
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ })();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ (() => {
/******/ // define __esModule on exports
/******/ __webpack_require__.r = (exports) => {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ })();
/******/
/************************************************************************/
/******/
/******/ // startup
/******/ // Load entry module and return exports
/******/ // This entry module can't be inlined because the eval devtool is used.
/******/ var __webpack_exports__ = __webpack_require__("./src/ImageDataReader.js");
/******/
/******/ return __webpack_exports__;
/******/ })()
;
});