@@ -5,12 +5,35 @@ window.Module = {
55 }
66}
77
8- const onProcessImage = ( ) => {
8+ const processImageBtn = document . getElementById ( 'process-image-btn' )
9+ const img = document . getElementById ( 'input-image' )
10+
11+ const getImageData = ( ) => {
12+ const canvas = document . createElement ( 'canvas' )
13+ canvas . width = img . width
14+ canvas . height = img . height
15+ ctx = canvas . getContext ( '2d' )
16+ ctx . drawImage ( img , 0 , 0 , img . width , img . height )
17+ const imageData = ctx . getImageData ( 0 , 0 , canvas . width , canvas . height )
18+ return imageData
19+ }
20+
21+ const onProcessImage = processImage => ( ) => {
922 console . log ( '[onProcessImage]' )
10- Module . ccall ( 'fred' , null , [ 'number' , 'string' ] , [ 42 , 'Hello' ] )
23+ const { data, width, height } = getImageData ( )
24+ processImage ( data , width , height )
25+ }
26+
27+ const wrapProcessImage = module => {
28+ const ident = 'processImage'
29+ const returnType = null
30+ const argTypes = [ 'array' , 'number' , 'number' ]
31+ const processImage = module . cwrap ( ident , returnType , argTypes )
32+ return processImage
1133}
1234
13- const init = Module => {
35+ const init = module => {
1436 console . log ( '[init]' )
15- document . getElementById ( 'process-image-btn' ) . addEventListener ( 'click' , onProcessImage )
37+ const processImage = wrapProcessImage ( module )
38+ processImageBtn . addEventListener ( 'click' , onProcessImage ( processImage ) )
1639}
0 commit comments