-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from gaiborjosue/main
feat(frameworks): Added xtk and papaya frameworks
- Loading branch information
Showing
12 changed files
with
401 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Framework } from "../framework.js"; | ||
|
||
import { Util } from "../util.js"; | ||
|
||
export class Papaya extends Framework { | ||
constructor(instance) { | ||
super(instance); | ||
this.name = "papaya"; | ||
} | ||
|
||
get_image(from_canvas) { | ||
let canvas = this.instance[0].viewer.canvas; | ||
let ctx = canvas.getContext("2d"); | ||
|
||
let image = ctx.getImageData(0, 0, canvas.width, canvas.height); | ||
let rgba_image = Util.rgba_to_grayscale(image.data) | ||
|
||
return { data: rgba_image, width: image.width, height: image.height }; | ||
// return {'data':pixels, 'width':image.width, 'height':image.height}; | ||
} | ||
|
||
set_image(new_pixels) { | ||
let originalcanvas = this.instance[0].viewer.canvas; | ||
|
||
let newcanvas = window.document.createElement("canvas"); | ||
newcanvas.width = originalcanvas.width; | ||
newcanvas.height = originalcanvas.height; | ||
|
||
let ctx = newcanvas.getContext("2d"); | ||
|
||
let newPixelsRgba = Util.grayscale_to_rgba(new_pixels); | ||
|
||
let newPixelsClamped = new Uint8ClampedArray(newPixelsRgba); | ||
|
||
let newImageData = new ImageData( | ||
newPixelsClamped, | ||
newcanvas.width, | ||
newcanvas.height | ||
); | ||
|
||
// Draw the new image data onto the canvas | ||
ctx.putImageData(newImageData, 0, 0); | ||
|
||
newcanvas.onclick = function () { | ||
// on click, we will restore the nv canvas | ||
newcanvas.parentNode.replaceChild(originalcanvas, newcanvas); | ||
}; | ||
|
||
// replace nv canvas with new one | ||
originalcanvas.parentNode.replaceChild(newcanvas, originalcanvas); | ||
} | ||
} |
Oops, something went wrong.