|
Post by vovchik on Apr 13, 2015 14:14:38 GMT 1
Dear all, If you ever wanted a "trailing" mouse cursor, this little demo takes that idea to the extreme. I used Peter's latest HUG (included). Have fun.... With kind regards, vovchik UPDATED: Added sparkling torus. It's quite nice, I think. UPDATED again: Added singularity simulation.
|
|
|
Post by vovchik on Apr 14, 2015 16:17:13 GMT 1
Dear all, Another (pastel) maze generator that is quite pretty. Have fun... With kind regards, vovchik Attachments:maze.bac.tar.gz (2.88 KB)
|
|
|
Post by Pjot on Apr 14, 2015 19:00:10 GMT 1
Hi vovchik, Pretty cool demo's, they work out of the box Thanks Peter
|
|
|
Post by vovchik on Apr 14, 2015 19:58:25 GMT 1
Dear Peter,
Thanks. I am glad that they worked fine on your machine without alteration/tweaking. I hope that is the case with others and that I can come up with a few more using pretty much unadulterated HUG.
With kind regards, vovchik
|
|
|
Post by vovchik on Apr 15, 2015 21:25:05 GMT 1
Dear all, I have just finished a little scattershot demo. Rather minimal coding for a nice effect. Move the mouse and left-click. Hope it works for you.... With kind regards, vovchik UPDATED: Added another mod using pastels, so fireworks will be easy. Attachments:scattershot.bac.tar.gz (2.13 KB)
|
|
|
Post by Pjot on Apr 18, 2015 13:59:14 GMT 1
Thanks vovchik! Very interesting demo BR Peter
|
|
|
Post by vovchik on Apr 18, 2015 21:35:42 GMT 1
Dear Peter,
Thanks. I am also surprised that we can get such effects on a HUG canvas without opacity and objects. I am now wondering how we could get a POINT (or TINT) function in HUG that would return the RGB of a pixel on the GTK canvas. In theory, the drawing area could be copied into a pixbuf and, after a typically 80 byte offset from the start of the pixbuf (which can be read in by a GDK function), and the pixels read individually. They are there (in row/stride format) as RGBs or RGBAs, meaning that we could do pixel fades, XORs, moves and a number of other useful things. Using pixbufs is better than using pixmaps, I gather, since pixmaps are more complicated, have gamma adjustments and do not have the simple pixel layout we need for queries and manipulation. It would also be possible to write directly into the pixbuf and then update the GDK Drawing Area. What do you think?
With kind regards, vovchik
|
|
|
Post by Pjot on Apr 19, 2015 10:31:15 GMT 1
Hi vovchik,
Your question has come up before elsewhere, and it would be nice functionality indeed. However, to the best of my knowledge, GTK2 does not an API to actually retrieve the RGB value of a pixel. (Correct me if I'm wrong, I haven't looked into it for the last year, maybe things have changed?)
It could be worked around (partially) by maintaining a parallel array with the same dimensions of the canvas, and at each time the PIXEL directive is invoked with a color, the color is stored in this array also. But it works only partially, because there would be a problem when using CIRCLE or SQUARE or OUT...
BR Peter
|
|
|
Post by vovchik on Apr 20, 2015 12:05:57 GMT 1
Dear Peter, It think it can be done, and I think I just might have done it here. Now we need to organize the RGB as an array of x:y RECORDs or an rgb 3-element ARRAY constructed from the pixel buffer and the TINT or POINT could be implemented pretty easily. Also, CIRCLEs, LINEs, PIXELs and OUTs could be written to persistent pixbufs first and kept track of as objects, I think. Some more thinking needed... With kind regards, vovchik ' *********************** ' INCLUDES ' ***********************
INCLUDE "hug.bac", ATTACH, CALLBACK, CANVAS, DISPLAY, DRAW, HUGLIB$, \ HUGOPTIONS, INIT, MOUSE, QUIT, SQUARE, SYNC, WINDOW
' *********************** ' END INCLUDES ' ***********************
' *********************** ' INITIALIZATION ' ***********************
SEED NOW gdk$ = HUGLIB$("gdk") INIT HUGOPTIONS("NOSCALING") HUGOPTIONS("CANVAS GTK") canvas_w = 400 canvas_h = 400
' *********************** ' END INITIALIZATION ' ***********************
' *********************** ' IMPORTS ' ***********************
' gdk IMPORT "gdk_pixbuf_scale_simple(long,int,int,int)" FROM gdk$ TYPE long IMPORT "gdk_pixbuf_get_width(long)" FROM gdk$ TYPE int IMPORT "gdk_pixbuf_get_height(long)" FROM gdk$ TYPE int IMPORT "gdk_pixbuf_get_byte_length(long)" FROM gdk$ TYPE unsigned long IMPORT "gdk_pixbuf_get_from_drawable(long,long,long,int,int,int,int,int,int)" FROM gdk$ TYPE long IMPORT "gdk_colormap_get_system" FROM gdk$ TYPE long IMPORT "gdk_pixbuf_get_pixels(long)" FROM gdk$ TYPE unsigned char*
' *********************** ' END IMPORTS ' ***********************
' *********************** ' SUBS & FUNCTIONS ' ***********************
' ------------------ SUB UPDATE_PIXBUF(long mybuf, int hug_xpos, int hug_ypos, int hug_xsize, int hug_ysize) ' ------------------ LOCAL pix, ebox, context, buf REM Get the associated canvas pix = hug_gui_properties.canvas ebox = hug_widget_ebox(STR$(pix)) IF HUG_CANVAS_TYPE = 0 THEN context = hug_widget_context(STR$(pix)) buf = gdk_pixbuf_scale_simple(mybuf, hug_xsize, hug_ysize, 3) gdk_draw_pixbuf(pix, context, buf, 0, 0, hug_xpos, hug_ypos, hug_xsize, hug_ysize, 0, 0, 0) gtk_widget_queue_draw(hug_widget_image(STR$(ebox)) ) g_object_unref(buf) ELIF HUG_CANVAS_TYPE = 2 THEN context = goo_canvas_get_root_item(pix) buf = gdk_pixbuf_scale_simple(mybuf, hug_xsize, hug_ysize, 3) WIDGET = goo_canvas_image_new(context, buf, hug_xpos, hug_ypos, NULL) g_object_set(WIDGET, "width", (double)hug_xsize, "height", (double)hug_ysize, NULL) g_object_unref(buf) END IF END SUB
' ------------------ SUB CHANGE_PIXBUF() ' ------------------ LOCAL ww, hh, i TYPE int LOCAL bytes TYPE unsigned long LOCAL pixx, c1 LOCAL pixbuf_pixels TYPE unsigned char* LOCAL j TYPE unsigned char c1 = hug_gui_properties.canvas pixx = gdk_pixbuf_get_from_drawable(pixx, c1, gdk_colormap_get_system(), \ 0, 0, 0, 0, canvas_w, canvas_h) ww = gdk_pixbuf_get_width(pixx) hh = gdk_pixbuf_get_height(pixx) bytes = gdk_pixbuf_get_byte_length(pixx) PRINT "Pixbuf pixel width: ", ww, " height: ", hh, " size: ", bytes pixbuf_pixels = gdk_pixbuf_get_pixels(pixx) FOR i = 0 TO bytes - 2 STEP 4 j = pixbuf_pixels[i] IF j > 1 AND i < bytes THEN pixbuf_pixels[i] = (unsigned char)(RANDOM(128) + 64) END IF NEXT UPDATE_PIXBUF(pixx, 0, 0, canvas_w, canvas_h) g_object_unref(pixx) END SUB
' ------------------ SUB MY_ACTION() ' ------------------ IF MOUSE(2) = 3 THEN QUIT ELIF MOUSE(2) = 1 THEN CHANGE_PIXBUF() END IF END SUB
' ------------------ SUB MK_GUI() ' ------------------ ' create main window win = WINDOW("Direct pixbuf (left-click or right-click to exit)", canvas_w + 20, canvas_h + 20) ' create canvas canvas = CANVAS(canvas_w, canvas_h) ATTACH(win, canvas, 10, 10) DRAW(canvas) SQUARE("black", 0, 0, canvas_w, canvas_h, 1) SQUARE("red", 50, 50, canvas_w - 100, canvas_h - 100, 1) ' play with pixbuf CALLBACK(canvas, MY_ACTION) SYNC END SUB
' *********************** ' END SUBS & FUNCTIONS ' ***********************
' *********************** ' MAIN ' ***********************
MK_GUI() DISPLAY
' *********************** ' END MAIN ' ***********************
|
|
|
Post by vovchik on Apr 20, 2015 14:31:45 GMT 1
Dear Peter, And, along the same lines, we can use SVGs for objects WITH ALPHA (!), including text, which would greatly enhance what can be done with CIRCLE, SQUARE, LINE, OUT etc., like in the following example (these entities can be easily stored as objects): With kind regards, vovchik PS. I added the two examples as an attachment. ' *********************** ' INCLUDES ' ***********************
INCLUDE "hug.bac", ATTACH, CALLBACK, CANVAS, DISPLAY, DRAW, HUGLIB$, \ HUGOPTIONS, INIT, MOUSE, QUIT, SQUARE, SYNC, WINDOW
' *********************** ' END INCLUDES ' ***********************
' *********************** ' INITIALIZATION ' ***********************
SEED NOW gtk$ = HUGLIB$("gtk") gdk$ = HUGLIB$("gdk") INIT HUGOPTIONS("NOSCALING") HUGOPTIONS("CANVAS GTK") DECLARE canvas_w, canvas_h TYPE int DECLARE ball$, svg_string$ TYPE STRING canvas_w = 400 canvas_h = 400 ball$ = CONCAT$("<svg width='64' height='64' opacity='0.85'>" \ " <radialGradient fx='5%' fy='5%' id='rg' r='65%'>" \ " <stop offset='0%' stop-color='white'/>" \ " <stop offset='100%' stop-color='magenta'/>" \ " </radialGradient>" \ " <circle cx='32' cy='32' r='30' stroke-width='2' " \ " stroke='#6a6a6a' fill='url(#rg)'/>" \ "</svg>") svg_string$ = CONCAT$("<svg width='400' height='55'> " \ "<defs> " \ "<filter id='f01'> " \ " <feColorMatrix type='saturate' values='1' in='SourceAlpha' /> " \ " <feGaussianBlur in='SourceAlpha' stdDeviation='3' result='result0' /> " \ " <feSpecularLighting lighting-color='lightyellow' specularConstant='1.05' " \ " surfaceScale='3' result='result1' specularExponent='35' in='result0'> " \ " <feDistantLight elevation='45' azimuth='225' /> " \ " </feSpecularLighting> " \ " <feComposite operator='in' in='result1' in2='SourceAlpha' result='result2' /> " \ " <feComposite k3='2' k2='0.5' k1='-0.5' result='result4' in='SourceGraphic' " \ " operator='arithmetic' /> " \ " <feBlend blend='normal' mode='darken' /> " \ "</filter> " \ "<linearGradient id='bg' gradientUnits='objectBoundingBox' " \ " x1='1' x2='1' y1='0' y2='1'> " \ " <stop stop-color='gray' offset='0'/> " \ " <stop stop-color='black' offset='0.34'/> " \ "</linearGradient> " \ "<linearGradient id='fg' gradientTransform='matrix(1,0,0,1,0,0)' y2='0' " \ " x2='6.12e-17' y1='1' x1='0'> " \ " <stop stop-color='red' offset='0%' /> " \ " <stop stop-color='black' offset='100%'></stop> " \ "</linearGradient> " \ "</defs> " \ "<rect rx='15' ry='15' width='100%' height='100%' fill='none' " \ " stroke='none' stroke-width='2' fill-opacity='0.6' stroke-opacity='0.8'/> " \ "<g font-family='sans-serif' word-spacing='0' line-height='100%' color='black' " \ " font-weight='bold' letter-spacing='0' font-size='58' text-anchor='middle' " \ " stroke='lawngreen' stroke-linecap='round' stroke-width='1.25' stroke-linejoin='round'> " \ " <text> " \ " <tspan x='50%' y='90%' fill-opacity='.98' filter='url(#f01)'>SVG TEXT</tspan> " \ " </text> " \ "</g> " \ "</svg>")
' *********************** ' END INITIALIZATION ' ***********************
' *********************** ' IMPORTS ' ***********************
' gtk IMPORT "gtk_widget_get_toplevel(long)" FROM gtk$ TYPE long IMPORT "gtk_window_set_icon(long,long)" FROM gtk$ TYPE void ' gdk misc IMPORT "gdk_pixbuf_scale_simple(long,int,int,int)" FROM gdk$ TYPE long IMPORT "gdk_pixbuf_get_width(long)" FROM gdk$ TYPE int IMPORT "gdk_pixbuf_get_height(long)" FROM gdk$ TYPE int IMPORT "gdk_pixbuf_get_byte_length(long)" FROM gdk$ TYPE unsigned long IMPORT "gdk_pixbuf_get_from_drawable(long,long,long,int,int,int,int,int,int)" FROM gdk$ TYPE long IMPORT "gdk_colormap_get_system" FROM gdk$ TYPE long IMPORT "gdk_pixbuf_get_pixels(long)" FROM gdk$ TYPE unsigned char* ' gdk pixbuf loader IMPORT "gdk_pixbuf_loader_new()" FROM gdk$ TYPE long IMPORT "gdk_pixbuf_loader_write(long,unsigned char*, long, 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_scale_simple(long,int,int,int)" FROM gdk$ TYPE long
' *********************** ' END IMPORTS ' ***********************
' *********************** ' SUBS & FUNCTIONS ' ***********************
' ------------------ FUNCTION SVG_BUFF(STRING svg$) ' ------------------ ' create pixbuf as svg LOCAL pixloader, pixbuf TYPE long LOCAL size TYPE NUMBER LOCAL res TYPE int LOCAL raw_array TYPE unsigned char* size = LEN(svg$) raw_array = (unsigned char*)svg$ pixloader = gdk_pixbuf_loader_new() res = gdk_pixbuf_loader_write(pixloader, raw_array, size, 0) res = gdk_pixbuf_loader_close(pixloader, 0) pixbuf = gdk_pixbuf_loader_get_pixbuf(pixloader) RETURN pixbuf END FUNCTION
' ------------------ SUB SET_WINICON(long widget, STRING svg$) ' ------------------ ' set tray icon for application using inline svg string LOCAL pix pix = SVG_BUFF(svg$) gtk_window_set_icon(gtk_widget_get_toplevel(widget), pix) g_object_unref(pix) END SUB
' ------------------ SUB PICTURE_SVG(STRING hug_file$, int hug_xpos, int hug_ypos, int hug_xsize, int hug_ysize) ' ------------------ LOCAL pix, ebox, context, buf REM Get the associated canvas pix = hug_gui_properties.canvas ebox = hug_widget_ebox(STR$(pix)) IF HUG_CANVAS_TYPE = 0 THEN context = hug_widget_context(STR$(pix)) buf = gdk_pixbuf_scale_simple(SVG_BUFF(hug_file$), hug_xsize, hug_ysize, 3) gdk_draw_pixbuf(pix, context, buf, 0, 0, hug_xpos, hug_ypos, hug_xsize, hug_ysize, 0, 0, 0) gtk_widget_queue_draw(hug_widget_image(STR$(ebox)) ) g_object_unref(buf) ELIF HUG_CANVAS_TYPE = 2 THEN context = goo_canvas_get_root_item(pix) buf = gdk_pixbuf_scale_simple(SVG_BUFF(hug_file$), hug_xsize, hug_ysize, 3) WIDGET = goo_canvas_image_new(context, buf, hug_xpos, hug_ypos, NULL) g_object_set(WIDGET, "width", (double)hug_xsize, "height", (double)hug_ysize, NULL) g_object_unref(buf) END IF END SUB
' ------------------ SUB UPDATE_PIXBUF(long mybuf, int hug_xpos, int hug_ypos, int hug_xsize, int hug_ysize) ' ------------------ LOCAL pix, ebox, context, buf REM Get the associated canvas pix = hug_gui_properties.canvas ebox = hug_widget_ebox(STR$(pix)) IF HUG_CANVAS_TYPE = 0 THEN context = hug_widget_context(STR$(pix)) buf = gdk_pixbuf_scale_simple(mybuf, hug_xsize, hug_ysize, 3) gdk_draw_pixbuf(pix, context, buf, 0, 0, hug_xpos, hug_ypos, hug_xsize, hug_ysize, 0, 0, 0) gtk_widget_queue_draw(hug_widget_image(STR$(ebox)) ) g_object_unref(buf) ELIF HUG_CANVAS_TYPE = 2 THEN context = goo_canvas_get_root_item(pix) buf = gdk_pixbuf_scale_simple(mybuf, hug_xsize, hug_ysize, 3) WIDGET = goo_canvas_image_new(context, buf, hug_xpos, hug_ypos, NULL) g_object_set(WIDGET, "width", (double)hug_xsize, "height", (double)hug_ysize, NULL) g_object_unref(buf) END IF END SUB
' ------------------ SUB CHANGE_PIXBUF() ' ------------------ LOCAL ww, hh, i TYPE int LOCAL bytes TYPE unsigned long LOCAL pixx, c1 LOCAL pixbuf_pixels TYPE unsigned char* LOCAL j TYPE unsigned char c1 = hug_gui_properties.canvas pixx = gdk_pixbuf_get_from_drawable(pixx, c1, gdk_colormap_get_system(), \ 0, 0, 0, 0, canvas_w, canvas_h) ww = gdk_pixbuf_get_width(pixx) hh = gdk_pixbuf_get_height(pixx) bytes = gdk_pixbuf_get_byte_length(pixx) PRINT "Pixbuf pixel width: ", ww, " height: ", hh, " size: ", bytes pixbuf_pixels = gdk_pixbuf_get_pixels(pixx) FOR i = 0 TO bytes - 2 STEP 4 j = pixbuf_pixels[i] IF j > 1 AND i < bytes THEN pixbuf_pixels[i] = (unsigned char)(RANDOM(128) + 64) END IF NEXT i UPDATE_PIXBUF(pixx, 0, 0, canvas_w, canvas_h) g_object_unref(pixx) END SUB
' ------------------ SUB MY_ACTION() ' ------------------ IF MOUSE(2) = 3 THEN QUIT ELIF MOUSE(2) = 1 THEN CHANGE_PIXBUF() END IF END SUB
' ------------------ SUB MK_GUI() ' ------------------ ' create main window win = WINDOW("Direct pixbuf (left-click or right-click to exit)", canvas_w + 20, canvas_h + 20) ' create canvas canvas = CANVAS(canvas_w, canvas_h) ATTACH(win, canvas, 10, 10) DRAW(canvas) SQUARE("black", 0, 0, canvas_w, canvas_h, 1) SQUARE("red", 50, 50, canvas_w - 100, canvas_h - 100, 1) PICTURE_SVG(ball$, 168, 168, 64, 64) PICTURE_SVG(ball$, 184, 184, 32, 32) PICTURE_SVG(svg_string$, 0, 320, 400, 75) ' play with pixbuf CALLBACK(canvas, MY_ACTION) SYNC END SUB
' *********************** ' END SUBS & FUNCTIONS ' ***********************
' *********************** ' MAIN ' ***********************
MK_GUI() DISPLAY
' *********************** ' END MAIN ' ***********************
Attachments:tint.bac.tar.gz (2.67 KB)
|
|
|
Post by Pjot on Apr 20, 2015 20:38:51 GMT 1
Hi vovchik,
Thanks for pointing to the right functions - I have hacked a small program below which is able to retrieve the actual color at coordinate (x, y).
Would this be the functionality you're looking for? If so, then we can add it as a function to HUG?
BR Peter
INCLUDE "hug.bac", ATTACH, CANVAS, DISPLAY, HUGLIB$, HUGOPTIONS, INIT, QUIT, SQUARE, WINDOW, OUT
INIT
gdk$ = HUGLIB$("gdk") HUGOPTIONS("NOSCALING") HUGOPTIONS("CANVAS GTK")
CONST canvas_w = 400 CONST canvas_h = 400
IMPORT "gdk_pixbuf_get_n_channels" FROM gdk$ TYPE int IMPORT "gdk_pixbuf_get_rowstride" FROM gdk$ TYPE int IMPORT "gdk_pixbuf_get_pixels(long)" FROM gdk$ TYPE unsigned char* IMPORT "gdk_pixbuf_get_from_drawable(void*,long,long,int,int,int,int,int,int)" FROM gdk$ TYPE long IMPORT "gdk_colormap_get_system" FROM gdk$ TYPE long
win = WINDOW("Get Color", canvas_w, canvas_h)
canv = CANVAS(canvas_w, canvas_h) ATTACH(win, canv, 0, 0) SQUARE("red", 50, 50, 100, 100, TRUE)
DECLARE p, pixels TYPE unsigned char* DECLARE pixbuf, c1 DECLARE col$
c1 = hug_gui_properties.canvas
pixbuf = gdk_pixbuf_get_from_drawable(NULL, c1, gdk_colormap_get_system(), 0, 0, 0, 0, canvas_w, canvas_h) pixels = gdk_pixbuf_get_pixels(pixbuf)
x = 10 y = 10 p = pixels + y * gdk_pixbuf_get_rowstride(pixbuf) + x * gdk_pixbuf_get_n_channels(pixbuf) PRINT "#", (unsigned char)p[0], (unsigned char)p[1], (unsigned char)p[2] FORMAT "%s%02X%02X%02X\n" TO col$ OUT("Color at (10, 10) is white. Got from canvas: " & col$, "#000000", "#FFFFFF", 10, 200)
x = 60 y = 60 p = pixels + y * gdk_pixbuf_get_rowstride(pixbuf) + x * gdk_pixbuf_get_n_channels(pixbuf) PRINT "#", (unsigned char)p[0], (unsigned char)p[1], (unsigned char)p[2] FORMAT "%s%02X%02X%02X\n" TO col$ OUT("Color at (60, 60) is red. Got from canvas: " & col$, "#000000", "#FFFFFF", 10, 250)
DISPLAY
|
|
|
Post by vovchik on Apr 20, 2015 22:23:52 GMT 1
Dear Peter, Thanks. That would be great. I am also thinking that it might be useful to have the pixbuf of the canvas easily accessible for manipulations and restoration of the original (i.e. GET_PIXBUF and PUT_PIXBUF). Just thinking at the moment.... The function to return the pixel color could be TINT or HUE, for example...or PIXCOL, and probably as an unsigned int (but anything reasonable will do, even a HEX string). Writing directly to the pixbuf is great fun. With kind regards, vovchik
|
|
|
Post by vovchik on Apr 21, 2015 18:17:21 GMT 1
Dear Peter,
What about something like this?
With kind regards, vovchik
INCLUDE "hug.bac", ATTACH, CANVAS, DISPLAY, HUGLIB$, HUGOPTIONS, INIT, QUIT, SQUARE, WINDOW, OUT
INIT gdk$ = HUGLIB$("gdk") HUGOPTIONS("NOSCALING") HUGOPTIONS("CANVAS GTK") CONST canvas_w = 400 CONST canvas_h = 400
IMPORT "gdk_pixbuf_get_n_channels" FROM gdk$ TYPE int IMPORT "gdk_pixbuf_get_rowstride" FROM gdk$ TYPE int IMPORT "gdk_pixbuf_get_pixels(long)" FROM gdk$ TYPE unsigned char* IMPORT "gdk_pixbuf_get_from_drawable(void*,long,long,int,int,int,int,int,int)" FROM gdk$ TYPE long IMPORT "gdk_colormap_get_system" FROM gdk$ TYPE long
' ------------------ FUNCTION PIXCOL(int xx, int yy, int mode) ' ------------------ LOCAL r1, b1, g1, rgb TYPE unsigned int LOCAL pixbuf, c1 LOCAL p, pixels TYPE unsigned char* c1 = hug_gui_properties.canvas pixbuf = gdk_pixbuf_get_from_drawable(NULL, c1, \ gdk_colormap_get_system(), 0, 0, 0, 0, canvas_w, canvas_h) pixels = gdk_pixbuf_get_pixels(pixbuf) p = pixels + yy * gdk_pixbuf_get_rowstride(pixbuf) + \ xx * gdk_pixbuf_get_n_channels(pixbuf) r1 = (unsigned char)p[0] g1 = (unsigned char)p[1] b1 = (unsigned char)p[2] rgb = (unsigned int )((r1 << 16) + (g1 << 8) + (b1)) g_object_unref(pixbuf) SELECT mode CASE 0 RETURN (unsigned int)rgb CASE 1 RETURN (unsigned int)r1 CASE 2 RETURN (unsigned int)g1 CASE 3 RETURN (unsigned int)b1 END SELECT END FUNCTION
win = WINDOW("Get Color", canvas_w, canvas_h) canv = CANVAS(canvas_w, canvas_h) ATTACH(win, canv, 0, 0) SQUARE("red", 50, 50, 100, 100, TRUE) x = 10 y = 10 OUT("Color at (10, 10) is white. Got from canvas: " & HEX$(PIXCOL(x, y, 0)), "#000000", "#FFFFFF", 10, 200) PRINT "HEX: ", HEX$(PIXCOL(x, y, 0)), \ " R: ",PIXCOL(x, y, 1), " G: ", PIXCOL(x, y, 2), " B: ", PIXCOL(x, y, 3) x = 60 y = 60 OUT("Color at (60, 60) is red. Got from canvas: " & HEX$(PIXCOL(x, y, 0)), "#000000", "#FFFFFF", 10, 250) PRINT "HEX: ", HEX$(PIXCOL(x, y, 0)), \ " R: ",PIXCOL(x, y, 1), " G: ", PIXCOL(x, y, 2), " B: ", PIXCOL(x, y, 3) DISPLAY
|
|
|
Post by alexfish on Apr 24, 2015 19:24:42 GMT 1
Hi Vovchik & at Peter looking further at gdk2 docs , it may be possible to work out the alpha if present. gdk2 pixbuffeither way , a nice enhancement to hug lib. BR Alex
|
|
|
Post by vovchik on Apr 24, 2015 19:36:00 GMT 1
Dear Alex (and Peter),
You are right about the alpha. I was able to read the alpha back from SVGs with opacity < 1.0, since the pixbuf created has an alpha channel (gdk_pixbuf_get_n_channels = 4 = RGBA) and 3 = RGB). Accordingly, each pixel is then 4 unsigned chars long. What happens, though, is that once the pixbuf is drawn on the GTK canvas (with alpha intact), it gets transformed into an RGB. What would be nice, in addition to getting the RGBA info, would be to set up a canvas with RGBA. I have to read up on that to see whether it is possible. Any ideas? It certainly is possible with GOO and Cairo, but I do not know about straight GTK and GDK.
With kind regards, vovchik
|
|