-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathui.html
More file actions
32 lines (28 loc) · 1.1 KB
/
Copy pathui.html
File metadata and controls
32 lines (28 loc) · 1.1 KB
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
<!-- <h2>Rectangle Creator</h2>
<p>Count: <input id="count" value="5"></p>
<button id="create">Create</button>
<button id="cancel">Cancel</button> -->
<script>
// Create an event handler to receive messages from the main
// thread.
window.onmessage = async (event) => {
// Just get the bytes directly from the pluginMessage since
// that's the only type of message we'll receive in this
// plugin. In more complex plugins, you'll want to check the
// type of the message.
const bytes = event.data.pluginMessage
const canvas = document.createElement('canvas')
const ctx = canvas.getContext('2d')
const imageData = await decode(canvas, ctx, bytes)
const pixels = imageData.data
// Do the actual work of inverting the colors.
for (let i = 0; i < pixels.length; i += 4) {
pixels[i + 0] = 255 - pixels[i + 0]
pixels[i + 1] = 255 - pixels[i + 1]
pixels[i + 2] = 255 - pixels[i + 2]
// Don't invert the alpha channel.
}
const newBytes = await encode(canvas, ctx, imageData)
window.parent.postMessage({pluginMessage: newBytes}, '*')
}
</script>