|
Post by alexfish on Jul 28, 2022 7:23:09 GMT 1
Hi All with reference to Navigation 2 thread I needed to create an app that would overlay one image with another So taking a leaf out of Vovchik's picscale and extend it a bit using HUG + gdk_pixbuf_composite and other bits pixbuf UPDATE:: NewLib: example in folder Updated as marked : fixbug in geo cache New thread will be started in Tutorials, soon Update: added GuiDesigner: Update: added GuiDesigner2: can read back a desinger.bac file: ie a bacon file without SUBS OR REM's Without KeyWords in do that when your happy with the DESIGN + many improvements , of note ICON name find , see demo in the archive enter widget name in entry box press return Since No docs: click on a widget@ ADDED. also need updated imager5.2 LATEST imager5.2 Jan 9 2023 BR Alex Attachments:imager5.2.tar.gz (43.27 KB)
|
|
|
Post by vovchik on Jul 28, 2022 13:48:17 GMT 1
Dear Alex,
Thanks. It works as advertised. With a bit of input tweaking (file selection and possible scaling) it could be used for all sorts of image compositing.
With kind regards, vovchik
|
|
|
Post by alexfish on Jul 29, 2022 0:04:19 GMT 1
Hi vovchik suppose a lot of things are possible from the initial imager , maps ,games ,retro games blagh blagh to a must have tool also something rick would like to achieve ' gps navigation ' , so idea would be to make an include.bac here threw cairo into the mix + weather & tides , One needs xtide install . as can see we would need to scale or resize th likes of the weatherimage the bits , as in mix it , the initial harbour image will change to tides for whitby like the picky , play with the bits put in the original directory INCLUDE hug.bac
HUGOPTIONS ("NOSCALING") ' no hug bits IMPORT "cairo_surface_write_to_png(int,char*)" FROM "libcairo.so.2" TYPE int IMPORT "cairo_image_surface_create_from_png(char *)" FROM "libcairo.so.2" TYPE int IMPORT "gdk_pixbuf_get_width(int)" FROM "libgdk_pixbuf-2.0.so.0" TYPE int IMPORT "gdk_pixbuf_get_height(int)" FROM "libgdk_pixbuf-2.0.so.0" TYPE int IMPORT "gdk_pixbuf_save(long,char*,char*,void*,...)" FROM "libgdk_pixbuf-2.0.so.0" TYPE int IMPORT "gdk_pixbuf_composite(long,long,int,int,int,int,double,double,double,double, int,int)" FROM "libgdk_pixbuf-2.0.so.0" TYPE int
FUNCTION UpdateTide() PRINT "UPDATE" IF FILEEXISTS(MYDIR$ & "whitby.png") THEN DELETE FILE MYDIR$ & "whitby.png" END IF
tide$ = EXEC$("tide -pi 8 -lb y -f p -gs l -tl y -m g -gw 884 -el y -o " & MYDIR$ & "whitby.png -l whitby")
TEXT(tide,MYDIR$ & "whitby.png") SYNC RETURN TRUE END FUNCTION HOME$ = GETENVIRON$("HOME") MYDIR$ = HOME$ & "/imagerdemo/" PRINT
IF FILEEXISTS(MYDIR$ & "whitby.png") THEN DELETE FILE MYDIR$ & "whitby.png" END IF
IF FILEEXISTS(MYDIR$ &"weather.png") THEN DELETE FILE MYDIR$ & "weather.png" END IF
weather$= EXEC$("curl wttr.in/whitby.png --output " & MYDIR$ &"weather.png") PRINT weather$ tide$ = EXEC$("tide -pi 8 -lb y -f p -gs l -tl y -m g -gw 884 -el y -o " & MYDIR$ & "whitby.png -l whitby") PRINT tide$ caro = cairo_image_surface_create_from_png(MYDIR$ &"20888.png") cairo_surface_write_to_png (caro,MYDIR$ & "my.png") carotest = gdk_pixbuf_new_from_file(MYDIR$ & "my.png" , NULL)
wth = gdk_pixbuf_new_from_file(MYDIR$ &"weather.png" , NULL) im = gdk_pixbuf_new_from_file(MYDIR$ &"/whitby.png" , NULL) width2 = gdk_pixbuf_get_width(wth) height2 = gdk_pixbuf_get_height(wth) width = gdk_pixbuf_get_width(im) height = gdk_pixbuf_get_height(im) g_object_unref(im) g_object_unref(wth)
win = WINDOW("Weather& Tides",width2+10,height + height2+20)
tide = IMAGE(MYDIR$ & "my.png",width2,height) ATTACH(win,tide,5,5)
source2 = IMAGE(MYDIR$ & "weather.png",width2,height2) ATTACH(win,source2,5,height+10)
'normal Update every 5 Minutes = 1000*60*5 TIMEOUT(1000*60,UpdateTide)
DISPLAY
HAVE FUN BR alex Attachments:
|
|
|
Post by rikky on Jul 29, 2022 17:23:01 GMT 1
With a little bit of changing to my needs (I do not like to have all this in my home directory) , I can confirm that it works. (and the former one also)
Thanks.
Rik.
|
|
|
Post by alexfish on Jul 30, 2022 1:30:09 GMT 1
Hi Rik over last 10 years of been here as a member, + breaks between have noted there are lots of methods to achieve a goal, possible goal is members have an impact in a positive way, all one needs to do is read as regards the methods it is no more than what we have on a linux system I suppose that Pjot knows how the libs work esp in terms of .so files here looking to combine the likes of pixbuf + other bits + cairo and more ,into one lib as in a libhug / image manipulation connection here been something like IMPORT "blagh(int)" FROM "libfoo.1.0.so.0" TYPE int in terms of r&d its only an idea, it might be a shit idea yet some succeed what one can do with the bits... Honestly, it's horses for courses. my favourite sane is , if it breaks you can keep both bits on the fun side of things FUN_WITH_LINUX BR Alex
|
|
|
Post by alexfish on Jul 30, 2022 21:15:41 GMT 1
Hi All
same theme but here creating an empty pixbuf & save as png , got a weird result got a 40pix diff in the vertical, tried convert
convert -size 800x600 xc:transparent dum.png that works
here placing tiles module 256x256 in pixbuf 800x600
INCLUDE hug.bac
HUGOPTIONS ("NOSCALING") ' no hug "libcairo.so.2" TYPE int IMPORT "gdk_pixbuf_get_width(int)" FROM "libgdk_pixbuf-2.0.so.0" TYPE int IMPORT "gdk_pixbuf_get_height(int)" FROM "libgdk_pixbuf-2.0.so.0" TYPE int IMPORT "gdk_pixbuf_save(long,char*,char*,void*,...)" FROM "libgdk_pixbuf-2.0.so.0" TYPE int IMPORT "gdk_pixbuf_composite(long,long,int,int,int,int,double,double,double,double, int,int)" FROM "libgdk_pixbuf-2.0.so.0" TYPE int IMPORT "gdk_pixbuf_new(int,int,int,int,int)" FROM "libgdk_pixbuf-2.0.so.0" TYPE int
DECLARE destination$ DECLARE source$ DECLARE source_width DECLARE source_height DECLARE destination_width DECLARE destination_height
' Map2Seamap using equal tile size images =================================== FUNCTION Map2Seamap()
PRINT OSMDIR$ & source$ PRINT OSMDIR$ & destination$ RESULT$ = OSMDIR$ & "test.png" im1 = gdk_pixbuf_new_from_file(OSMDIR$ & destination$ , NULL) im2 = gdk_pixbuf_new_from_file(OSMDIR$ & source$, NULL)
w = gdk_pixbuf_get_width(im2) h = gdk_pixbuf_get_height(im2)
'gdk_pixbuf_composite (src, dest,dest_x,dest_y,dest_width, ' dest_height,offset_x, offset_y,dscale_x,dscale_y,interp_type,ioverall_alpha) gdk_pixbuf_composite(im2, im1, 256, 40, w, h, 256,40, 1,1, 0,255) gdk_pixbuf_composite(im2, im1, 256, 40+256, w, h, 256,40+256, 1,1, 0,255) gdk_pixbuf_composite(im2, im1, 0, 40+256, w, h, 0,40+256, 1,1, 0,255) gdk_pixbuf_save (im1, RESULT$, "png", 0, NULL, NULL, NULL) g_object_unref(im1) g_object_unref(im2) IF FILEEXISTS(RESULT$) THEN PRINT RESULT$ TEXT(destination,RESULT$) END IF
RETURN TRUE END FUNCTION
SUB GET_IMG_SIZE(Destination$ , Source$)
dest = gdk_pixbuf_new_from_file(OSMDIR$ & destination$ , NULL) src = gdk_pixbuf_new_from_file(OSMDIR$ & source$, NULL)
destination_width = gdk_pixbuf_get_width(dest) destination_height = gdk_pixbuf_get_height(dest)
source_width = gdk_pixbuf_get_width(src) source_height = gdk_pixbuf_get_height(src) g_object_unref(dest) g_object_unref(src)
END SUB '============================================================ HOME$ = GETENVIRON$("HOME") OSMDIR$ = HOME$ & "/imagerdemo/" 'make blank buffer.png dum = gdk_pixbuf_new(0,1,8,800,600) gdk_pixbuf_save (dum, OSMDIR$ & "dum.png", "png", 0, NULL, NULL, NULL) g_object_unref(dum) destination$ = "dum.png" source$ = "20888.png"
GET_IMG_SIZE(OSMDIR$ & destination$,OSMDIR$ & source$) win = WINDOW("HUG imager",800,800)
' destination (base) image ===================================== destination = IMAGE(OSMDIR$ & destination$,800,520) ATTACH(win,destination,0,0)
' image overlay =============================================== source = IMAGE(OSMDIR$ & source$,source_width,source_height) ATTACH(win,source,256*2,0)
'================================================================= ent = ENTRY("20888.png",300,30) ATTACH(win,ent,5,5)
' click to composit the two images composite = BUTTON("composite",-1,25) ATTACH(win,composite,800-150,650)
CALLBACK( composite,Map2Seamap)
DISPLAY
Have Fun + BR Alex
|
|
|
Post by alexfish on Jul 30, 2022 22:38:42 GMT 1
How does one make a slippy layer in hug ,Cheat here adding another layer at the widow declaration do this win = WINDOW("HUG imager",800,800) layer = hug_widget_attach(STR$(win)) layern = gtk_fixed_new() hug_widget_attach(STR$(win))= layern gtk_fixed_put(layer,layern,0,0) ' try moving the layer gtk_fixed_move(layer,layern, 20, 20) gtk_widget_set_size_request(layern,800,600) gtk_widget_show(layern)
try + and also negative like -100. can make the layer than the window ie 2000x2000 one can do a lot with this try adding another layer , what for , more bits to animate and so on and on how can one make the bits move TIMEOUT SYNC etc space invaders ooh Have Fun Alex
|
|
|
Post by alexfish on Aug 7, 2022 19:58:19 GMT 1
Hi All with reference to several thread posts re image problems ... in short an image may not be an image or badly formed generally size -1 will sow a possible problem cut shorter , a simple image check ' image file check & delete
OPTION PARSE FALSE 'pkg-config --libs gdk-pixbuf-2.0 '===================================================== PRAGMA LDFLAGS `pkg-config --libs gdk-pixbuf-2.0` PRAGMA OPTIONS `pkg-config --cflags gdk-pixbuf-2.0` '= INCLUDES c. Header ================================== PRAGMA INCLUDE <gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf.h>
'=======================================================
SUB check_image(myfile$,delete) PRINT myfile$ IF delete THEN PRINT " AUTO DELETE" ELSE PRINT "NO DELETE " END IF LOCAL im2 TYPE GdkPixbuf*
im2 = gdk_pixbuf_new_from_file(myfile$, NULL) g_object_ref(im2) w = gdk_pixbuf_get_width(im2) h = gdk_pixbuf_get_height(im2) PRINT "W " , w ," H ",h ' -w -h generally dirty/empty IF w = -1 THEN
PRINT "Width " , w , "height " , h
IF delete THEN
DELETE FILE myfile$
END IF
ELSE
END IF
g_object_unref(im2)
END SUB '=========================================
'Example usage check_image ("home/pi/pin.png", FALSE) ' if bad as in -w -h then option , look at image in the file browser ' if new image close browser the open browser again BR Alex although a different file here is what to spot '16388.sea.png that one shows size w-1 h-1 can also note from images that openstreetmap bits are now been converted as in composed into seamaps . wonder why , looks like the download section of openseamap is dude , well its is from here. Attachments:
|
|
|
Post by alexfish on Aug 30, 2022 20:54:45 GMT 1
Hi All So as from Navigation bits Hug open Seamap Prototype set up, allgos's for getting gps postions are posted on 'navigation gps' & 'navigation 2' + how to set the Directories Basic Map ,shown openseamaps INCLUDE "hug.bac" HUGOPTIONS("NOSCALING") SUB SetImages() ' IN USE : User Set the directory ' /home/pi/bacon-osm-maps/10/503 ' /home/pi/bacon-osm-maps/10/504
LOCAL PTRX , PTRY LOCAL YDIR = 317 LOCAL XDIR = 503
FOR xx = 0 TO 1 FOR yy= 0 TO 1 img=IMAGE("/home/pi/bacon-osm-maps/10/" & STR$(XDIR) & "/" & STR$(YDIR) & ".png",256,256) PRINT "/home/pi/bacon-osm-maps/10/" & STR$(XDIR) & "/" & STR$(YDIR) ATTACH(win,img,PTRX,PTRY) PRINT PTRX , ":", PTRY INCR YDIR INCR PTRY ,256 NEXT PTRY = 0 YDIR = 317 INCR PTRX , 256 INCR XDIR NEXT END SUB
win = WINDOW("HugMaps",256*2,256*2) SetImages() DISPLAY
BR Alex Attachments:
|
|
|
Post by alexfish on Nov 14, 2022 0:51:26 GMT 1
LIB UPDATED FIRST POST
BR Alex
|
|
|
Post by alexfish on Nov 15, 2022 2:03:31 GMT 1
Well thoughts at end of day tints and hints and alpha If can take a pixbuf and just render it using the updated lib I added this a rectangle with alpha + draw a line using the compositor need this import IMPORT "gdk_pixbuf_fill(long,unsigned int32)" FROM GDK$ TYPE void SUB TEST_ALPHA()
LOCAL pix, ebox, context,dest,scr pix = hug_gui_properties.canvas ebox = hug_widget_ebox(STR$(pix)) context = hug_widget_context(STR$(pix)) dest = gdk_pixbuf_new (0,TRUE,8,400,100) gdk_pixbuf_fill(dest,0xff00ff99) 'solid line 2pix scr = gdk_pixbuf_new (0,TRUE,8,400,2) gdk_pixbuf_fill(scr,0xff0000ff) gdk_pixbuf_composite(scr,dest, 0, 20, 400, 1, 0,0, 1,1, 0,255)
gdk_draw_pixbuf(pix, context, dest, 0, 0,20,120, 400,100, 0, 0, 0) gtk_widget_queue_draw(hug_widget_image(STR$(ebox)) ) g_object_unref(dest) g_object_unref(scr) END SUB a lot can be done with just 2 bits , can make a pixel and draw it where you like on the destination buffer 2&2make4 4&4 & so on Viola see Picky, its the pinky alpha rect + solid line BR Alex Attachments:
|
|
|
Post by alexfish on Nov 15, 2022 10:42:28 GMT 1
Hi All
Draw Circle using pixbuf's
TEST
SUB TEST_ALPHACIRCLE() /* gdk_pixbuf_composite ( const GdkPixbuf* src, GdkPixbuf* dest, int dest_x, int dest_y, int dest_width, int dest_height, double offset_x, double offset_y, double scale_x, double scale_y, GdkInterpType interp_type, int overall_alpha */ LOCAL pix, ebox, context,dest,scr pix = hug_gui_properties.canvas ebox = hug_widget_ebox(STR$(pix)) context = hug_widget_context(STR$(pix)) dest = gdk_pixbuf_new (0,TRUE,8,400,300)
gdk_pixbuf_fill(dest,0xff00ff99) 'Pixel scr = gdk_pixbuf_new (0,TRUE,8,1,1) gdk_pixbuf_fill(scr,0xff0000ff) 'circle LOCAL a,x=320,y=240,r=50,c,lx,ly TYPE float
FOR a=0 TO 360 STEP 0.5 lx = SIN(RAD(a+c))*r ly = COS(RAD(a+c))*r PRINT "Plot :" , 120 + lx, ":",120 + ly gdk_pixbuf_composite(scr,dest, 120 + lx, 120 + ly, 1, 1, 0,0, 1,1, 0,255) NEXT
gdk_draw_pixbuf(pix, context, dest, 0, 0,20,120, 400,300, 0, 0, 0) gtk_widget_queue_draw(hug_widget_image(STR$(ebox)) ) g_object_unref(dest) g_object_unref(scr)
END SUB
code not refined: hot off the press and have to go out
Suppose one could do some adjustments and save as png
Have Fun + BR Alex
|
|
|
Post by alexfish on Nov 17, 2022 1:41:56 GMT 1
Hi All Found the pointer without cast problem in gdk_pixbuf_new_from_data it bug the heck out of me since that indicates the data function as in type, well docs.gtk.org/gdk-pixbuf/ctor.Pixbuf.new_from_data.htmldocs indicated a NULL NULL on unused , I think says he so in the CAIRO_RENDER have 0, 0 in last 2 args SUB CAIRO_RENDER(long csr, int hug_xpos, int hug_ypos)
LOCAL data TYPE unsigned char * data = cairo_image_surface_get_data (csr)
LOCAL pix, ebox, context,w,h LOCAL buf TYPE long REM Get the associated canvas pix = hug_gui_properties.canvas ebox = hug_widget_ebox(STR$(pix)) context = hug_widget_context(STR$(pix)) '====================================================== buf = gdk_pixbuf_new_from_data(data, 0,TRUE,8,cairo_image_surface_get_width(csr),cairo_image_surface_get_height(csr),cairo_image_surface_get_stride (csr),0,0) w = gdk_pixbuf_get_width(buf) h = gdk_pixbuf_get_height(buf) gdk_draw_pixbuf(pix, context, buf, 0, 0, hug_xpos, hug_ypos, w,h, 0, 0, 0) g_object_unref(buf)
END SUB
Have entered the SUB , Since partway through finalising some of the bit Will update Lib when done Also note That gdk_pixbuf_new_from_data() only accepts data with no alpha: If the in memory cairo surface has alpha data then image will not show: get out = save as png then load the file SVG via pixloader should be fine BR Alex
|
|
|
Post by alexfish on Nov 18, 2022 2:25:40 GMT 1
Hi All I was scanning through the thread to find vovchik's HEX2RGB possible try to add pure hex as unsigned int32 for pixbuf found example on X11 thread along with ufo in cairo did an example of pure pixbuf, had to reduce by factor of 2 CONST GDK_INTERP_HYPER = 3 GDK$ = "libgdk_pixbuf-2.0.so.0" IMPORT "gdk_pixbuf_new (int,int,int ,int ,int)" FROM GDK$ TYPE long IMPORT "gdk_pixbuf_get_width(int)" FROM GDK$ TYPE int IMPORT "gdk_pixbuf_get_height(int)" FROM GDK$ TYPE int IMPORT "gdk_pixbuf_save(long,char*,char*,void*,...)" FROM GDK$ TYPE long IMPORT "gdk_pixbuf_composite(long,long,int,int,int,int,double,double,double,double, int,int)" FROM GDK$ TYPE long IMPORT "gdk_pixbuf_new_from_data (unsigned char * ,int ,int,int ,int,int ,int ,long,long)" FROM GDK$ TYPE long IMPORT "gdk_pixbuf_scale_simple(long,int,int,int)" FROM GDK$ TYPE long IMPORT "gdk_pixbuf_loader_new()" FROM GDK$ TYPE long IMPORT "gdk_pixbuf_loader_write(long,unsigned char*, long int, int)" FROM GDK$ TYPE int IMPORT "gdk_pixbuf_loader_close(long,int)" FROM GDK$ TYPE int IMPORT "gdk_pixbuf_loader_get_pixbuf(long)" FROM GDK$ TYPE long IMPORT "gdk_pixbuf_get_byte_length(long)" FROM GDK$ TYPE unsigned long IMPORT "gdk_pixbuf_fill(long,unsigned int32)" FROM GDK$ TYPE void IMPORT "g_object_unref(long)" FROM "libgobject-2.0.so.0" TYPE void
DECLARE dest,scr DECLARE xs = 1 TYPE int DECLARE ys = 1 TYPE int DECLARE a = 700 TYPE int b = a * a DECLARE c = 600 TYPE int DECLARE q, r, y TYPE float DECLARE i, m, n, p, x, st TYPE int DECLARE ia TYPE double
dest = gdk_pixbuf_new (0,TRUE,8,850,750) gdk_pixbuf_fill(dest,0x000000ff) scr = gdk_pixbuf_new (0,TRUE,8,1,1) gdk_pixbuf_fill(scr,0xff0000ff)
FOR x = 0 TO a STEP xs s = x * x p = SQR(b - s) st = 6 * ys FOR i = -p TO p STEP st r = SQR(s + i * i) / a q = (r - 1.0) * SIN(24 * r) y = FLOOR(i / 3 + q * c) IF i= -p THEN m = y n = y END IF IF y > m THEN m = y IF y < n THEN n = y IF m = y OR n = y THEN gdk_pixbuf_composite(scr,dest, (-x + 800)/2, (y+700)/2, 1, 1, 0,0, 1,1, GDK_INTERP_HYPER,100) gdk_pixbuf_composite(scr,dest, (x + 800)/2, (y+700)/2, 1, 1, 0,0, 1,1, GDK_INTERP_HYPER,100) END IF NEXT i NEXT x
gdk_pixbuf_save(dest,"ufo.png","png",0,NULL)
g_object_unref(dest) g_object_unref(scr)
PRINT "Done"
on pi this takes about 6.5 sec although the original ufo demo is on X11 window , it takes about 16 seconds on rpi4 compiler directives/flags have changed since those posts on X11 change header to ' cairo double buffering X11 test card = set window resize false. ' this will prevent the no name double buffer bug on resizable window ' vov = added ButtonPress in SELECT/CASE to exit and rbga
' *********************** ' COMPILER DIRECTIVES ' ***********************
PRAGMA LDFLAGS `pkg-config --cflags --libs x11 --libs xext --libs cairo` PRAGMA INCLUDE </usr/include/X11/Xlib.h> PRAGMA INCLUDE </usr/include/X11/Xutil.h> PRAGMA INCLUDE </usr/include/X11/Xos.h> PRAGMA INCLUDE </usr/include/X11/keysym.h> PRAGMA INCLUDE </usr/include/X11/extensions/Xdbe.h> ' PRAGMA INCLUDE cairo.h ' PRAGMA INCLUDE cairo-xlib.h ' for new compile scheme PRAGMA INCLUDE <cairo/cairo.h> PRAGMA INCLUDE <cairo/cairo-xlib.h> BR Alex Picky Attachments:
|
|
|
Post by Pjot on Nov 18, 2022 9:30:29 GMT 1
Hi Alex,
Thanks for all your demos. By the way, I never looked very detailed into the GDK Pixbuf stuff, but as it turns out, it is very powerful.
Regards Peter
|
|