-
Notifications
You must be signed in to change notification settings - Fork 15
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
draw image from stream #14
Comments
You wouldn't need my lib for this. I think node-canvas can write directly
to the framebuffer (/dev/fb1)
ons. 30. mai 2018 kl. 00:34 skrev Bubblerobot <notifications@github.com>:
… Hi (me again), I got it to work and its really cool, this opens a few very
cool possibilities.
I am using the npm library canvas to draw offscreen images and animations,
now to put them on the pitft i need to write a .png file before i can pass
them over to the pitft, this is fairly slow and somewhat ugly and
unnecessary (see following code) ... would it be possible to pass a stream
directly to fb.image(...) ?
var Buffer = {
update: function (canvas) {
var out = fs.createWriteStream(image_path);
var stream = canvas.pngStream();
stream.pipe(out);
out.on('finish', function () {
fb.image(0, 0, image_path);
});
}
};
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#14>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAZ4E-vt2EQoRbNU6E3fUq_6Jme3fmRUks5t3czcgaJpZM4USUws>
.
|
thanks for the tip, but i have not been able figured that out yet, i went throught doc and examples. there is some Buffer stuff, but i found nothing on how to use the framebuffer ... |
This discussion looks promising: Automattic/node-canvas#1172 My guess is that external framebuffer support for node-canvas is just around the corner. |
The branch in Automattic/node-canvas#1094 is a better bet for raw FB access; I don't think that will end up in the main node-canvas branch anytime soon. v2.x of canvas has RGB16_565 support already, and you can get the raw Buffer with (Edit: sounds like not quite that simple, maybe. https://unix.stackexchange.com/questions/20458/how-to-use-dev-fb0-as-a-console-from-userspace-or-output-text-to-it) |
What you suggested about writing directly to the framme buffer device never
crossed my mind. As long as the pixel format is correct it should work. Let
me know if it works.
ons. 30. mai 2018 kl. 18:32 skrev Zach Bjornson <notifications@github.com>:
The branch in Automattic/node-canvas#1094
<Automattic/node-canvas#1094> is a better bet for
raw FB access; I don't think that will end up in the main node-canvas
branch anytime soon. v2.x of canvas has RGB16_565 support already, and you
can get the raw Buffer with canvas.toBuffer("raw") -- never used a FB ,
but maybe it's as simple as writing that RGB16_565 buffer to /dev/fb1?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#14 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAZ4E0ymDUiLCRdXCQ7xTLTooNEzsCnnks5t3smcgaJpZM4USUws>
.
--
Werner Kvalem Vesterås <wvesteraas@gmail.com>
Bråtenalléen 21A
0487 OSLO
Tel +47 932 72 429
|
yes! i search through their repository and came across recent 'Added framebuffer device support' as well it seems there is some work going on, very exciting PS: i will stick to your library, its less weight and its fast :-) e.v. will adapt my code to this. |
hmm, just read the feedback from zbjornson , i really can't see how the code would look like ... |
me again :-) i was to quick, the install procedure works but ... when executing pitft it fails at this command var fb = pitft("/dev/fb1"); with FATAL ERROR: v8::ToLocalChecked Empty MaybeLocal. cheers |
I've tested my updated library on node versions 8.x, 9.x and 10.x, and it works. Could you give me more details about your setup? |
@brainlessboy I don't know much about FBs nor do I have a device or X server to test with right now, so this may be completely wrong, but here's a shot: // Using canvas 2.x
const {createCanvas} = require("canvas");
const canvas = createCanvas(200, 200, {pixelFormat: "RGB16_565"});
// draw stuff on the canvas...
const buff = canvas.toBuffer("raw"); // buff is a Buffer containing RGB15_565 data Then I think you can just write that to the device, like this: const fs = require("fs");
const fb = fs.openSync("/dev/fb1", "w");
fs.writeSync(fb, buff, 0, buff.byteLength, 0); This skips over using If that works, that's not as ugly as I thought it might be. I do want to find and document a nice way to work with FBs because it's a recurring issue in node-canvas. Options include adding it to node-canvas itself, writing a C++ plugin for node-canvas or writing a JS wrapper that does something like the above. Please let us know if that works! |
Hi,
It works! I just tested it on my PiTFT 3.5" (480x320), with the following
code:
const Canvas = require("canvas");
const canvas = new Canvas(480, 320, {pixelFormat: "RGB15_565"});
const ctx = canvas.getContext('2d');
ctx.font = '30px Impact';
ctx.rotate(.1);
ctx.fillText("Awesome!", 50, 100);
var te = ctx.measureText('Awesome!');
ctx.strokeStyle = 'rgba(0,0,0,0.5)';
ctx.beginPath();
ctx.lineTo(50, 102);
ctx.lineTo(50 + te.width, 102);
ctx.stroke();
const fs = require("fs");
const fb = fs.openSync("/dev/fb1", "w");
const buff = canvas.toBuffer("raw"); // buff is a Buffer containing RGB15_565 data
fs.writeSync(fb, buff, 0, buff.byteLength, 0);
However, the program exits with the following error:
fs.js:753
return binding.writeBuffer(fd, buffer, offset, length, position);
^
Error: EFBIG: file too large, write
at Object.fs.writeSync (fs.js:753:20)
at Object.<anonymous> (/home/pi/node/test/index.js:21:4)
at Module._compile (module.js:641:30)
at Object.Module._extensions..js (module.js:652:10)
at Module.load (module.js:560:32)
at tryModuleLoad (module.js:503:12)
at Function.Module._load (module.js:495:3)
at Function.Module.runMain (module.js:682:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:613:3
|
i am working with a raspberrypi 3 with raspbian light so not entierly sure what would help, e.v. the log from the node-gyp rebuild? pi@raspberrypi:~/spghty/node_modules/pitft $ sudo node-gyp rebuild |
I've only tested it on an ordinary Raspbian Stretch installation. After a
fresh install, I installed Node, and then followed these instructions to
install drivers for my PITFT:
https://forums.adafruit.com/viewtopic.php?f=47&t=134568
2018-05-30 21:24 GMT+02:00 Bubblerobot <notifications@github.com>:
… i am working with a raspberrypi 3 with raspbian light so not entierly sure
what would help, e.v. the log from the node-gyp rebuild?
***@***.***:~/spghty/node_modules/pitft $ sudo node-gyp rebuild
gyp info it worked if it ends with ok
gyp info using ***@***.***
gyp info using ***@***.*** | linux | arm
gyp info spawn /usr/bin/python2
gyp info spawn args [ '/usr/lib/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args 'binding.gyp',
gyp info spawn args '-f',
gyp info spawn args 'make',
gyp info spawn args '-I',
gyp info spawn args '/home/pi/spghty/node_modules/
pitft/build/config.gypi',
gyp info spawn args '-I',
gyp info spawn args '/usr/lib/node_modules/node-gyp/addon.gypi',
gyp info spawn args '-I',
gyp info spawn args '/root/.node-gyp/10.3.0/include/node/common.gypi',
gyp info spawn args '-Dlibrary=shared_library',
gyp info spawn args '-Dvisibility=default',
gyp info spawn args '-Dnode_root_dir=/root/.node-gyp/10.3.0',
gyp info spawn args '-Dnode_gyp_dir=/usr/lib/node_modules/node-gyp',
gyp info spawn args '-Dnode_lib_file=/root/.node-
gyp/10.3.0/<(target_arch)/node.lib',
gyp info spawn args '-Dmodule_root_dir=/home/pi/
spghty/node_modules/pitft',
gyp info spawn args '-Dnode_engine=v8',
gyp info spawn args '--depth=.',
gyp info spawn args '--no-parallel',
gyp info spawn args '--generator-output',
gyp info spawn args 'build',
gyp info spawn args '-Goutput_dir=.' ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
make: Entering directory '/home/pi/spghty/node_modules/pitft/build'
CXX(target) Release/obj.target/pitft/src/pitft.o
CXX(target) Release/obj.target/pitft/src/framebuffer.o
SOLINK_MODULE(target) Release/obj.target/pitft.node
COPY Release/pitft.node
make: Leaving directory '/home/pi/spghty/node_modules/pitft/build'
gyp info ok
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#14 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAZ4E-QjOVKyO5EcO1PoeGtWotBFuEiNks5t3vIEgaJpZM4USUws>
.
--
Werner Kvalem Vesterås <wvesteraas@gmail.com>
Bråtenalléen 21A
0487 OSLO
Tel +47 932 72 429
|
@vesteraas neat! The image shows up, but then node crashes with |
@ vesteraas you are right, a little tinkering, i exchanged the pitft with a Pomironi Hyper Screen ... then i had to sudo apt-get install fbi (this adds quiet an amount of libs that deal with framebuffer, specially cairo) after that fbi install and sending an image to the screen works (the pitft heart ;-), but using pitft gets me now a different error -> 'Segmentation fault' |
The buffer.byteLength has a value of 614400. Printing out canvas.width and canvas.height reports 480 and 320, but a ctx.fillRect(0,0,240,160) produces a rectangle that fills the entire screen, when it should only fill a quarter of the screen. Not sure about the ioctl stuff. |
Thanks @vesteraas -- looks like a bug in node-canvas, the buffer shouldn't be that big. Will look into it. |
Ah actually -- I had a typo in my example. It should be |
@zbjornson @vesteraas IT WORKS!! and it runs very smooth at 800x480!
with your help i was able to actually stream a 3d javascript canvas based animated visualisation to a screen without X or a Browser! this also works with standard hdmi if no screen hat is available and only raspbian stretch. this opens up quiet a few possibilities ... |
@zbjornson changing the pixel format to RGB16_565 did not help. |
@brainlessboy the hyperpixel looks like a neat display! I will order one myself! |
@zbjornson I was on version 1.6.x... Everything works, after |
\o/ fantastic, thanks 😀 |
so after successful tinkering with the HyperPixel and your advise :-) i started with a slightly different setup, exact same software but a different PITFT (PiTFT 2.2 display with 320x240 16-bit color pixels) EFBIG: file too large, write i am not sure where to tweak ... either on the canvas side? const canvas = createCanvas(320, 240,{pixelFormat: "RGB16_565"}); or on the buffer write side ... const buff = canvas.toBuffer("raw"); e.v. you have tip :-) |
@brainlessboy are you definitely using canvas v2.x? ( I put a full example here: |
@zbjornson exacctly |
any idea what i could try? or any recommendation on what direction i could tinker? like playing with the stream, alter it or what ever? |
Hi (me again), I got it to work and its really cool, this opens a few very cool possibilities.
I am using the npm library canvas to draw offscreen images and animations, now to put them on the pitft i need to write a .png file before i can pass them over to the pitft, this is fairly slow and somewhat ugly and unnecessary (see following code) ... would it be possible to pass a stream directly to fb.image(...) ?
var Buffer = {
update: function (canvas) {
var out = fs.createWriteStream(image_path);
var stream = canvas.pngStream();
stream.pipe(out);
out.on('finish', function () {
fb.image(0, 0, image_path);
});
}
};
The text was updated successfully, but these errors were encountered: