-
-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
deno-canvas canvas & 2D context & image objects do not match the browser #34
Comments
Image object in here is quite different from Web Image object in browsers, here it is an object that wraps SkImage. It will be difficult to change its API now. As a workaround, we can make a new web-compatible Image object that is accepted along with Skia Image object. Other issues that were mentioned seem like a regression when the underlying library was updated. They’ll be an easy fix. Btw, have you considered using skia_canvas (https://deno.land/x/skia_canvas)? Which is much more accurate and faster. It is based on Skia too and is web compatible. |
Hi, and thanks for the quick and informative response! Let me briefly sketch out my work and how the compatibility between Deno and the browser and workers matter. My Agent Based Modeling system uses a very strict Model/View split. Models deal with data and their transforms while the view provides visual and interactive (MVC) views of the model. Here are three examples: The Models can run almost everywhere: browser, workers, Deno; in 2D, 3D and on Maps. Deno comes in in two ways: yet another place to run Models storing their data and images in files .. but also being our main test system now. It's FAST, reducing our earlier testing from well over a minute to 6 seconds! Models do not create images, that's for Views. BUT Models use images as Data! GIS tiles, elevation data and so on. And indeed we're interested in Deno as an off-line data transformer, getting OpenStreetMap (OSM) data and crunching it. The data can be images. So managing all this would be easier if deno-canvas were compatible. It seems that I can work around most problems. Image, I think, is the biggie. We currently have to manage the Dom Image & canvas vs the Worker imageBitmap and Offscreen canvas which is fairly simple. But deno-canvas Images having functions for width/height is pretty messy. So any help would be great! |
OK, I've now got some slightly ugly workarounds that let me run all 24 of my demo AgentScript Models (not Views .. yet!). OTOH, yes it would be nice to have a truly compatible deno image, canvas, and 2d context. For me Image having functions for width/height and canvas context not having the ctx.canvas work properly are the main issues in terms of getting stuff to run. I haven't tested deeply .. for example does the same (data) image produce the same results in the browser and deno. One thing I'm starting to use in the browser is the ImageBitmap and the OffscreenCanvas, both required for browser workers. Kinda nice! Thanks again for the help and insights. |
We have web-compatible Canvas, Context2D and Image objects in the Skia Canvas project. The API is nearly same, and it only has more capabilities than deno-canvas rather than being less. Can I provide any help in getting Skia Canvas work according to your needs instead? If not, I can proceed with improving web compatibility of this module so that it can fit your use case. Some more info: While deno-canvas is a port of canvaskit-wasm, that is Wasm compiled Skia-based implementation of HTML Canvas, originally made for Node.js and the browser, it has many inconsistencies with the web API which are harder to overcome. On the other hand, Skia Canvas was made from scratch using Skia native library and close attention was paid to web compatibility. |
OK, let me use Skia Canvas a bit to see if it resolves the problems I had with deno-canvas. Thanks again! |
Oops, I may be doing this wrong. First I ran deno upgrade .. I was already current: Then I tried importing all of skiaCanvas, or just Canvas & Image. I.e either of: Both failed. I tried both with just -A and with -A --unstable flags:
And here's the other import:
Running without --unstable gives this:
I bet I'm missing something! :) Any advice? I like skia's api etc, looks promising, but gotta get over this hump. Thanks for your patience! |
- src/domUtils.js - integrate deno-canvas so that all Models can run in deno. working with deno developer to use Skia instead of deno-canvas to remove some major oddities! DjDeveloperr/deno-canvas#34 This requires use ImageBitmap and OffscreenCanvas, now on all browsers - imagePromise: now runs in deno, workers, browser - flag: preferDOM default to false - adds use of ImageBitmap as default image type - add imageSize method returning [width, height] - required because deno-canvas's image has width & height as functions! - createCanvas: like imagePromise, now runs in deno, workers, browser - upgraded to use the above: imageToCtx, cloneCanvas, createCtx - resizeCanvas: removed until deno-canvas issues resolved. currently unused anyway - src/jsUtils.js - fetchImageBitmap: might not need with new ImagePromise. not currently used - test/ - test/denomodels.js: now can run all tests in deno worker - test/denoworker.js: import deno-canvas, and store in globalThis
I noticed that the deno build was for mac os x 12.6 which I don't have due to having an older iMac (late 2014). That could be the problem. |
Yup, when I imported the skia_canvas modules with my newly installed Ventura macOS on my M1 macbook, the imports worked. But my dev iMac is too old for an upgrade higher than it's current BigSur, sigh. Do you know if there are versions of skia_canvas that would work on BigSur? |
I'm afraid there is no simple way to get a JS canvas and Image with either deno_canvas or with skiaCanvas. Skia seems the most likely to succeed but it doesn't import correctly in workers! I'll see if skia avoids the list of problems up top. If so, my choices are:
I'll try skia for a couple of days and hope we can resolve the worker import failures. Let me know what you think. |
This is from a deno issue, denoland/deno#18919
The response was:
Here's the issue & thanks for the great project!
A few experiments show that the deno-canvas's canvas, context, and image objects do not match the browsers. This makes it difficult to impossible to have interoperability between deno and browsers, a goal of many of us.
Some examples:
I believe the man problem is Image using functions for width/height, we might be able to work around the rest. Or do you have an insight how we might work around that issue too?
Thanks!
The text was updated successfully, but these errors were encountered: