|
Post by vovchik on Nov 5, 2018 19:25:00 GMT 1
Dear Peter and Joe, Thanks for all the advice and testing to figure out what might be wrong. The problem was with my Xresources and XDefaults. I had specified certain fonts there for xterm (using xft so that everything looked better) - and the ttf font specification for xterm interfered with the display on all platforms. As you can see, this is what I now get. With kind regards, vovchik Attachments:
|
|
|
Post by Pjot on Nov 5, 2018 20:07:47 GMT 1
Dear vovchik, Great! The picture is correct. I tried the program in OpenBSD as well and it works there too.
Hopefully your other programs still work properly with the correct fonts... BR Peter
|
|
|
Post by Pjot on Nov 6, 2018 12:07:55 GMT 1
All, The below code renders an image into the XTerm canvas, using the STB libraries. BR Peter EDIT: updated the program with performance improvement (25% faster). ' ' Load a JPG/PNG picture into the XTerm canvas using STB. (c) PvE - MIT license ' PRAGMA INCLUDE stb-master/stb_image.h PRAGMA OPTIONS -DSTB_IMAGE_IMPLEMENTATION -DSTBI_FAILURE_USERMSG
INCLUDE canvas-xterm
DECLARE w, h, channels TYPE unsigned int DECLARE r, g, b, a TYPE unsigned char DECLARE data TYPE unsigned char*
IF AMOUNT(ARGUMENT$) < 2 THEN EPRINT "Usage: picture <img> [type 0=mono 1=color (default)]" END 1 ENDIF
file$ = DIRNAME$(ME$) & "/" & TOKEN$(ARGUMENT$, 2)
IF NOT(FILEEXISTS(file$)) THEN EPRINT "File '" & file$ & "' not found!" END 1 ENDIF
' By default use 4 components (RGBA) comp = 4
' Verify argument IF AMOUNT(ARGUMENT$) = 3 THEN IF VAL(TOKEN$(ARGUMENT$, 3)) = 0 THEN comp = 1 ENDIF ENDIF
' Load the picture data = stbi_load(file$, &w, &h, &channels, comp)
IF data = NULL THEN PRINT stbi_failure_reason() FORMAT "ERROR: %s.\n" END 1 ENDIF
' Setup the XTerm canvas WINDOW(BASENAME$(file$), w, h)
' Render loop FOR y = 0 TO h-1 FOR x = 0 TO w-1 r = data[(x+y*w)*comp+0] g = data[(x+y*w)*comp+1] b = data[(x+y*w)*comp+2] a = data[(x+y*w)*comp+3] INK(r, g, b, a) PIXEL(x+1, y+1) NEXT NEXT
WAITKEY
Attachments:
|
|
|
Post by vovchik on Nov 6, 2018 12:50:10 GMT 1
Dear Peter, I am amazed at what the xterm canvas can do. Very nice and thanks. I would change the file code to this, however: file$ = REALPATH$(TOKEN$(ARGUMENT$, 2)) 'file$ = DIRNAME$(ME$) & "/" & TOKEN$(ARGUMENT$, 2) since, if the binary is not on your path, it otherwise prepends "./" to the image filespec. With kind regards, vovchik Attachments:
|
|
|
Post by Pjot on Nov 6, 2018 21:07:03 GMT 1
Thanks vovchik, Good to see it works for you too! Regarding your code suggestion, it makes sense when executing the program from the command line. However, from the GUI it will cause a runtime error ("no such file or directory") because it will look into the current working directory, which, in case of a GUI started from the desktop menu, is the home dir. So to make it work for the GUI, I had to add one more line: CHANGEDIR DIRNAME$(ME$) file$ = REALPATH$(TOKEN$(ARGUMENT$, 2))
I looked into an SVG version but it is more of the same. Rendering can be done from the block of data generated by NanoSVG for colorized pictures. The pixel generation is slow compared to OpenGL (XTerm has no hardware rendering), but for wire drawings I have used integer arithmetic to speed up the drawing primitives (LINE, CIRCLE, CBEZIER). Therefore, a wired SVG draws reasonably fast, and a wired animation can be done pretty realistically. BR Peter PRAGMA INCLUDE nanosvg-master/src/nanosvg.h
PRAGMA OPTIONS -DNANOSVG_IMPLEMENTATION
INCLUDE canvas-xterm
LOCAL image TYPE NSVGimage* LOCAL shape TYPE NSVGshape* LOCAL path TYPE NSVGpath* LOCAL w, h, i TYPE int LOCAL p TYPE float*
file$ = DIRNAME$(ME$) & "/broom.svg"
image = nsvgParseFromFile(file$, "px", 96.0f)
w = image->width h = image->height
WINDOW(file$, w, h)
shape = image->shapes
WHILE shape <> NULL path = shape->paths WHILE path <> NULL FOR i = 0 TO (path->npts-1)-1 STEP 3 p = &path->pts[i*2] CBEZIER(p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]) NEXT i path = path->next WEND shape = shape->next WEND
WAITKEY
Attachments:
|
|
|
Post by vovchik on Nov 6, 2018 22:51:15 GMT 1
Dear Peter, works nicely. And we can get GL gradients to work, too, I think. If I'm not mistaken, I do that with SVGs in my my gui enhancement for canvas. I will have a look at that code, and at some code I used with FLTK. With kind regards, vovchik Attachments:
|
|
|
Post by Pjot on Nov 14, 2018 21:31:48 GMT 1
XTerm has no double buffering, so I took the effort to implement this myself. This should speed up the (ASCII) rendering somewhat and also should improve the performance of animations. The idea is threefold: - all drawing actions take place in a 2-dimensional array in memory
- the array has a shadow array to which the rendering is being compared, so only the differences need to be drawn
- the actual coordinates are stored in an index so the untouched pixels can be skipped in the main rendering loop.
Also, I discovered that the libc 'fputs' function is faster than 'fprintf', so I have changed this too (also in the implementation of BaCon itself). This has resulted in an updated XTERM canvas. The previous programs now draw a lot faster! Also, the program below should animate reasonably well on most modern hardware Enjoy, Peter INCLUDE canvas-xterm
WINDOW("Vaccuum", 600, 400)
DECLARE x1=200, yy=200, a=200
SUB redraw INK(200,200,200,255) CLS FOR i = 4 TO 255 x2 = x1 + COS(i + a) * i * 6 y2 = yy + SIN(i + a) * i * 6 INK(100, 100, 150, 255) CIRCLE(80 + x2, y2, i, i, FALSE) NEXT INCR a IF a > 360 THEN a = -a INK(0,0,0,255) PRINT HOUR(NOW), MINUTE(NOW), SECOND(NOW) FORMAT "%02ld:%02ld:%02ld" TO t$ TEXT(t$, 10, 20) TEXT("Particles Cleaner", 60, 375) ENDSUB
CALLBACK(20, redraw) WAITKEY
|
|
|
Post by vovchik on Nov 14, 2018 22:13:15 GMT 1
Dear Peter,
Thanks for the new version. It is MUCH faster than the old one, but, at run time, I get this:
ERROR: signal for SEGMENTATION FAULT received - memory invalid or array out of bounds? Try to compile the program with TRAP LOCAL to find the cause.
and the window disappears. Any idea why?
With kind regards, vovchik
|
|
|
Post by rikky on Nov 15, 2018 6:42:18 GMT 1
I'm sorry for not always responding, but I have also real work, for getting some money, and then for the computer, I have also other projects. So if something doesn't work, I am sometimes reluctant of reporting this, for I might not be able (or willing) to follow up. Which is the least you have to do then. But, since I like this stuff with xterm, and I am not able to replicate this, I give it a try. I get : bacon -v BaCon version 3.8 on Linux armv7l - (c) Peter van Eerten - MIT License.
bacon /blabla/vacuum.bac Converting '/home/pi/bin/BaCon/playroom/canvas_xterm/vacuum.bac'... done, 1140 lines were processed in 1.071 seconds. Compiling '/home/pi/bin/BaCon/playroom/canvas_xterm/vacuum.bac'... cc -D_XOPEN_SOURCE=600 -D_POSIX_SOURCE -D_DEFAULT_SOURCE -D_ATFILE_SOURCE -c vacuum.bac.c Makefile.bacon:6: recipe for target 'vacuum.bac.o' failed Compiler error:
Description: file 'canvas-xterm.bac' line 403: POKE XTERM.buffer, Int_Col(255, 255, 255, 0) SIZE XTERM.bufsize Cause: macro "Int_Col" requires 4 arguments, but only 2 given
To be honest, I think I have some wrong type of x-term. Rik.
|
|
|
Post by Pjot on Nov 15, 2018 7:36:39 GMT 1
Hi guys,
@ vovchik: with which program do you see this error happening?
@ rikky: you're using the 3.8 version of BaCon, please upgrade to 3.8.1.
Best regards, Peter
|
|
|
Post by vovchik on Nov 15, 2018 9:43:10 GMT 1
Dear Peter,
The abrupt exit occurs will all the test progs (tree, img, vacuum), except for the svg cbezier test, which fails to compile and gives me:
In file included from xterm-svg.bac.c:2:0: xterm-svg.bac.c: In function ‘main’: xterm-svg.bac.h:504:15: error: expected identifier before ‘(’ token #define WIDTH (COLUMNS) ^ xterm-svg.bac.h:414:15: note: in expansion of macro ‘WIDTH’ #define width WIDTH ^ xterm-svg.bac.c:545:16: note: in expansion of macro ‘width’ w=(int)(image->width); ^ xterm-svg.bac.h:507:16: error: expected identifier before ‘(’ token #define HEIGHT (ROWS) ^ xterm-svg.bac.h:417:16: note: in expansion of macro ‘HEIGHT’ #define height HEIGHT ^ xterm-svg.bac.c:548:16: note: in expansion of macro ‘height’ h=(int)(image->height); ^ make: *** [xterm-svg.bac.o] Error 1
I assume it is something in canvas-xterm.bac that is causing the problem. I am using the latest beta (11.11.18).
With kind regards, vovchik
|
|
|
Post by rikky on Nov 15, 2018 15:20:21 GMT 1
Ok updated to Ba con 3.8.1. Now I get the same as Vovchik.
Rik.
|
|
|
Post by Pjot on Nov 15, 2018 21:08:06 GMT 1
Thanks guys, This is yet another 32bit/64bit issue ...please obtain the latest canvas-xterm and it should work on your 32bit platforms as well. Best regards,
Peter
PS on my 32bit VM there seems to be a rounding error, but I could not find the reason. Please let me know if you see weird drawing behavior.
|
|
|
Post by vovchik on Nov 15, 2018 21:56:16 GMT 1
Dear Peter,
Thanks for the fix. Everything works and the drawings all look normal. The speed increase is great. I hope this fix also works for Rik.
With kind regards, vovchik
|
|
|
Post by rikky on Nov 16, 2018 6:45:54 GMT 1
Yes. Now they work. Thanks. Rik.
|
|