-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.mjs
77 lines (49 loc) · 1.4 KB
/
index.mjs
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
//import * as io from './src/io/index.mjs';
import Matrix from './src/core/Matrix.mjs';
import ImageBinary from './src/ImageBinary.mjs';
import ImageGray from './src/ImageGray.mjs';
import ImageRGB from './src/ImageRGB.mjs';
//import ImageObjects from './src/ImageObjects/ImageObjects.mjs';
/** load
*
* @param {String} path
* @param {Function} handlerCallback
*/
function load( path, handlerCallback ) {
var source = new Image();
source.onload = function() {
const context = createContext( source );
const imagedata = context.getImageData(0,0,source.width, source.height);
handlerCallback( context, imagedata );
};
source.src = path;
}
/** createContext
*
* @param {Image|HTMLCanvasElement|ImageData} source
* @param {HTMLElement} parentNode
* @return {CanvasRenderingContext2D}
*/
function createContext( source ) {
var canvas = document.createElement("canvas"),
context = canvas.getContext("2d");
if( source ) {
canvas.width = source.width;
canvas.height = source.height;
if( source instanceof Image || source instanceof HTMLCanvasElement) {
context.drawImage( source, 0, 0, source.width, source.height );
} else if( source instanceof ImageData ) {
context.putImageData( source, 0, 0 );
}
}
///
return context;
}
///
export default {
// io,
Matrix,
ImageBinary, ImageGray, ImageRGB,
// ImageObjects,
load, createContext,
};