Re: [Gqview-devel] Diplay pixel coordinates, and rgb-data / pixel coordinates for editor
Laurent MONIN <[email protected]> Sun, 1 Mar 2009 11:38:36 +0100
| Newsgroups | gmane.comp.gnome.apps.geeqie.devel,gmane.comp.gnome.apps.gqview.devel |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format. --Multipart=_Sun__1_Mar_2009_11_38_36_+0100_=LO0Y1eBK_mApb3w Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Sun, 01 Mar 2009 00:38:28 +0100 Ruben Stein <[email protected]> wrote: > I missed a feature in gqview, so I implemented it today. It is an > optional status-bar add-on showing the pixel-coordinates of the mouse > and the rgb-values of this pixel. I also added %x and %y as > editor-macros working together with %p to use the pixel values for a > call to a script. Furthermore I added a checkbox in the view-menu to > turn off the feature as it may be disturbing to see the permanently > changing values if you do not need them. > > Referring to former feature requests I think maybe someone might want > to use it: > https://sourceforge.net/tracker/index.php?func=detail&aid=1145036&group_id=4050&atid=354050 > https://sourceforge.net/mailarchive/message.php?msg_name=40F9E2BE.9080606%40techspecs.com > > It was my first try adding _senseful_ ;) features to an open source > project, so any advices are appreciated. Unfortunately I did not > recogise that gqview is outdated, so I learned my first lesson. Anyway > ... the attached patch applies to GQView 2.1.5 src-dir, diffed against > the svn-tag in the geeqie-repository of that version. > > Greetings, Ruben > > Hi Ruben, this is an interesting patch but i fear it may never be committed to gqview devel tree since there were no activity since a long time there. It's why the Geeqie project was started. I adapted your patch to match current Geeqie devel tree (but the editors part which has changed a lot). This will permit to all to test it and comment. Regards, -- Laurent MONIN aka Zas --Multipart=_Sun__1_Mar_2009_11_38_36_+0100_=LO0Y1eBK_mApb3w Content-Type: text/x-patch; name="info_pixel_geeqie_rev1447.patch" Content-Disposition: attachment; filename="info_pixel_geeqie_rev1447.patch" Content-Transfer-Encoding: quoted-printable Index: layout.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- layout.c (r=E9vision 1447) +++ layout.c (copie de travail) @@ -51,6 +51,7 @@ #define TOOLWINDOW_DEF_HEIGHT 450 =20 #define PROGRESS_WIDTH 150 +#define PIXEL_LABEL_WIDTH 130 #define ZOOM_LABEL_WIDTH 64 =20 #define PANE_DIVIDER_SIZE 10 @@ -720,12 +721,38 @@ } } =20 +void layout_status_update_pixel(LayoutWindow *lw) +{ + gchar *text; +=09 + if (!layout_valid(&lw) || !lw->image) return; + + if (!lw->image->unknown) + { + gint x_pixel, y_pixel, r_mouse, g_mouse, b_mouse; + pixbuf_renderer_get_mouse_position(PIXBUF_RENDERER(lw->image->pr), &x_pi= xel, &y_pixel); + pixbuf_renderer_get_mouse_colors(PIXBUF_RENDERER(lw->image->pr), &r_mous= e, &g_mouse, &b_mouse); + if(x_pixel > 0 && y_pixel > 0) + { + text =3D g_strdup_printf(_("pos (%d,%d) rgb (%d,%d,%d)"),=20 + x_pixel, y_pixel, r_mouse, g_mouse, b_mouse); + } + else + { + text =3D g_strdup(""); + } + gtk_label_set_text(GTK_LABEL(lw->info_pixel), text); + g_free(text); + } +} + void layout_status_update_all(LayoutWindow *lw) { layout_status_update_progress(lw, 0.0, NULL); layout_status_update_info(lw, NULL); layout_status_update_image(lw); layout_status_update_write(lw); + layout_status_update_pixel(lw); } =20 static GtkWidget *layout_status_label(gchar *text, GtkWidget *box, gint st= art, gint size, gint expand) @@ -813,6 +840,8 @@ lw->info_details =3D layout_status_label(NULL, hbox, TRUE, 0, TRUE); if (!small_format) gtk_box_pack_start(GTK_BOX(hbox), lw->info_color, FALS= E, FALSE, 0); if (!small_format) gtk_box_pack_start(GTK_BOX(hbox), lw->info_write, FALS= E, FALSE, 0); + lw->info_pixel =3D layout_status_label(NULL, hbox, FALSE, PIXEL_LABEL_WID= TH, TRUE); + if (lw->options.info_pixel_hidden) gtk_widget_hide(gtk_widget_get_parent(= lw->info_pixel)); lw->info_zoom =3D layout_status_label(NULL, hbox, FALSE, ZOOM_LABEL_WIDTH= , FALSE); } =20 @@ -833,6 +862,7 @@ LayoutWindow *lw =3D data; =20 layout_status_update_info(lw, NULL); + layout_status_update_pixel(lw); } =20 static void layout_list_thumb_cb(ViewFile *vf, gdouble val, const gchar *t= ext, gpointer data) @@ -1747,6 +1777,7 @@ lw->info_color =3D NULL; lw->info_status =3D NULL; lw->info_details =3D NULL; + lw->info_pixel =3D NULL; lw->info_zoom =3D NULL; =20 if (lw->ui_manager) g_object_unref(lw->ui_manager); @@ -1905,6 +1936,31 @@ return lw->options.toolbar_hidden; } =20 +void layout_info_pixel_toggle(LayoutWindow *lw) +{ + if (!layout_valid(&lw)) return; + if (!lw->info_pixel) return; + + lw->options.info_pixel_hidden =3D !lw->options.info_pixel_hidden; + + GtkWidget *frame =3D gtk_widget_get_parent(lw->info_pixel); + if (lw->options.info_pixel_hidden) + { + if (GTK_WIDGET_VISIBLE(frame)) gtk_widget_hide(frame); + } + else + { + if (!GTK_WIDGET_VISIBLE(frame)) gtk_widget_show(frame); + } +} + +gint layout_info_pixel_hidden(LayoutWindow *lw) +{ + if (!layout_valid(&lw)) return TRUE; + + return lw->options.info_pixel_hidden; +} + /* *------------------------------------------------------------------------= ----- * base @@ -2175,7 +2231,8 @@ WRITE_SEPARATOR(); =20 WRITE_BOOL(*layout, toolbar_hidden); -=09 + WRITE_BOOL(*layout, info_pixel_hidden); + WRITE_UINT(*layout, image_overlay.state); WRITE_INT(*layout, image_overlay.histogram_channel); WRITE_INT(*layout, image_overlay.histogram_mode); @@ -2242,6 +2299,7 @@ if (READ_BOOL(*layout, tools_hidden)) continue; if (READ_BOOL(*layout, tools_restore_state)) continue; if (READ_BOOL(*layout, toolbar_hidden)) continue; + if (READ_BOOL(*layout, info_pixel_hidden)) continue; =20 if (READ_UINT(*layout, image_overlay.state)) continue; if (READ_INT(*layout, image_overlay.histogram_channel)) continue; Index: layout.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- layout.h (r=E9vision 1447) +++ layout.h (copie de travail) @@ -42,6 +42,7 @@ =20 void layout_status_update_progress(LayoutWindow *lw, gdouble val, const gc= har *text); void layout_status_update_info(LayoutWindow *lw, const gchar *text); +void layout_status_update_pixel(LayoutWindow *lw); void layout_status_update_image(LayoutWindow *lw); void layout_status_update_write(LayoutWindow *lw); void layout_status_update_all(LayoutWindow *lw); @@ -101,6 +102,8 @@ =20 void layout_toolbar_toggle(LayoutWindow *lw); gint layout_toolbar_hidden(LayoutWindow *lw); +void layout_info_pixel_toggle(LayoutWindow *lw); +gint layout_info_pixel_hidden(LayoutWindow *lw); =20 void layout_split_change(LayoutWindow *lw, ImageSplitMode mode); =20 Index: options.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- options.c (r=E9vision 1447) +++ options.c (copie de travail) @@ -105,6 +105,7 @@ options->layout.show_marks =3D FALSE; options->layout.show_thumbnails =3D FALSE; options->layout.style =3D 0; + options->layout.info_pixel_hidden =3D TRUE; options->layout.toolbar_hidden =3D FALSE; options->layout.tools_float =3D FALSE; options->layout.tools_hidden =3D FALSE; Index: pixbuf-renderer.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- pixbuf-renderer.c (r=E9vision 1447) +++ pixbuf-renderer.c (copie de travail) @@ -15,8 +15,11 @@ #include <string.h> #include <math.h> =20 +#include "main.h" #include "pixbuf-renderer.h" + #include "intl.h" +#include "layout.h" =20 #include <gtk/gtk.h> =20 @@ -506,6 +509,12 @@ =20 pr->scroller_id =3D -1; pr->scroller_overlay =3D -1; +=09 + pr->x_mouse =3D -1; + pr->y_mouse =3D -1; + pr->r_mouse =3D -1; + pr->g_mouse =3D -1; + pr->b_mouse =3D -1; =20 pr->source_tiles_enabled =3D FALSE; pr->source_tiles =3D NULL; @@ -3027,6 +3036,7 @@ h -=3D (ny - y); w =3D CLAMP(w, 0, pr->width - nx); h =3D CLAMP(h, 0, pr->height - ny); + =20 if (w < 1 || h < 1) return; =20 if (pr_queue_to_tiles(pr, nx, ny, w, h, clamp, render, new_data, only_exi= sting) && @@ -3092,8 +3102,79 @@ g_signal_emit(pr, signals[SIGNAL_DRAG], 0, bevent); } =20 + /* *------------------------------------------------------------------- + * pixel information at mouse position + *------------------------------------------------------------------- + */ + + /* put color information if mouse is on valid pixel */ +static void pr_pixel_color_update(PixbufRenderer *pr) +{ + GdkPixbuf *pb =3D pr->pixbuf; + gint p_alpha; + gint prs; + guchar *p_pix; + guchar *pp; + + if (!pb) return; + + if (pr->x_pixel < 0 || pr->x_pixel > pr->image_width) return; + if (pr->y_pixel < 0 || pr->y_pixel > pr->image_height) return; + + p_alpha =3D gdk_pixbuf_get_has_alpha(pb); + prs =3D gdk_pixbuf_get_rowstride(pb); + p_pix =3D gdk_pixbuf_get_pixels(pb); + + pp =3D p_pix + pr->y_pixel * prs + (pr->x_pixel * (p_alpha ? 4 : 3)); + pr->r_mouse =3D *pp; + pp++; + pr->g_mouse =3D *pp; + pp++; + pr->b_mouse =3D *pp; +} +=20 + +/* update pixel coordinates on layout bar if mouse is above pr*/ +static void pr_pixel_update(PixbufRenderer *pr) +{ + gboolean update =3D FALSE; + gboolean valid =3D FALSE; + gint x_pixel =3D (gint)((gdouble)(pr->x_mouse - pr->x_offset + pr->x_scro= ll) / pr->scale); + gint y_pixel =3D (gint)((gdouble)(pr->y_mouse - pr->y_offset + pr->y_scro= ll) / pr->scale); + gint x_pixel_clamped =3D CLAMP(x_pixel, 0, pr->image_width - 1); + gint y_pixel_clamped =3D CLAMP(y_pixel, 0, pr->image_height - 1); +=09 + if(x_pixel =3D=3D x_pixel_clamped && y_pixel =3D=3D y_pixel_clamped) + { + pr->x_pixel =3D x_pixel; + pr->y_pixel =3D y_pixel; + update =3D TRUE; + valid =3D TRUE; + } + else + { + if(pr->x_pixel !=3D -1 || pr->y_pixel !=3D -1) + { + pr->x_pixel =3D pr->y_pixel =3D -1; + update =3D TRUE; + } + } + + if(update =3D=3D TRUE) + { + if(valid =3D=3D TRUE) + { + pr_pixel_color_update(pr); + } + /* update status bar */ + layout_status_update_pixel((LayoutWindow *)pixbuf_renderer_get_parent(pr= )); + } +} + +/* + *------------------------------------------------------------------- * sync and clamp *------------------------------------------------------------------- */ @@ -3347,12 +3428,14 @@ /* center new image */ pr->x_scroll =3D ((gdouble)pr->image_width / 2.0 * pr->scale) - pr->vi= s_width / 2; pr->y_scroll =3D ((gdouble)pr->image_height / 2.0 * pr->scale) - pr->v= is_height / 2; + pr_pixel_update(pr); break; case PR_SCROLL_RESET_TOPLEFT: default: /* reset to upper left */ pr->x_scroll =3D 0; pr->y_scroll =3D 0; + pr_pixel_update(pr); break; } } @@ -3654,7 +3737,11 @@ pr->scroller_xpos =3D bevent->x; pr->scroller_ypos =3D bevent->y; } - +=09 + pr->x_mouse =3D bevent->x; + pr->y_mouse =3D bevent->y; + pr_pixel_update(pr); +=09 if (!pr->in_drag || !gdk_pointer_is_grabbed()) return FALSE; =20 if (pr->drag_moved < PR_DRAG_SCROLL_THRESHHOLD) @@ -3941,6 +4028,11 @@ =20 pr->x_scroll =3D source->x_scroll; pr->y_scroll =3D source->y_scroll; + pr->x_mouse =3D source->x_mouse; + pr->y_mouse =3D source->y_mouse; + pr->r_mouse =3D source->r_mouse; + pr->g_mouse =3D source->g_mouse; + pr->b_mouse =3D source->b_mouse; =20 scroll_reset =3D pr->scroll_reset; pr->scroll_reset =3D PR_SCROLL_RESET_NOCHANGE; @@ -4071,6 +4163,42 @@ } } =20 +gint pixbuf_renderer_get_mouse_colors(PixbufRenderer *pr, gint *r_mouse, g= int *g_mouse, gint *b_mouse) +{ + g_return_val_if_fail(IS_PIXBUF_RENDERER(pr), FALSE); + g_return_val_if_fail(r_mouse !=3D NULL && g_mouse !=3D NULL && b_mouse != =3D NULL, FALSE); + + if (!pr->pixbuf && !pr->source_tiles_enabled) + { + *r_mouse =3D -1; + *g_mouse =3D -1; + *b_mouse =3D -1; + return FALSE; + } + + *r_mouse =3D pr->r_mouse; + *g_mouse =3D pr->g_mouse; + *b_mouse =3D pr->b_mouse; + return TRUE; +} + +gint pixbuf_renderer_get_mouse_position(PixbufRenderer *pr, gint *x_pixel,= gint *y_pixel) +{ + g_return_val_if_fail(IS_PIXBUF_RENDERER(pr), FALSE); + g_return_val_if_fail(x_pixel !=3D NULL && y_pixel !=3D NULL, FALSE); + + if (!pr->pixbuf && !pr->source_tiles_enabled) + { + *x_pixel =3D -1; + *y_pixel =3D -1; + return FALSE; + } + + *x_pixel =3D pr->x_pixel; + *y_pixel =3D pr->y_pixel; + return TRUE; +} + gint pixbuf_renderer_get_image_size(PixbufRenderer *pr, gint *width, gint = *height) { g_return_val_if_fail(IS_PIXBUF_RENDERER(pr), FALSE); Index: pixbuf-renderer.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- pixbuf-renderer.h (r=E9vision 1447) +++ pixbuf-renderer.h (copie de travail) @@ -59,6 +59,16 @@ gint x_offset; /* offset of image start (non-zero when image < window) */ gint y_offset; =20 + gint x_mouse; /* last position of mouse on image */ + gint y_mouse; + + gint x_pixel; /* pixel coordinates of the mouse */ + gint y_pixel; + + gint r_mouse; /* color information at mouse position */ + gint g_mouse; + gint b_mouse; + gint vis_width; /* dimensions of visible part of image */ gint vis_height; =20 @@ -258,6 +268,8 @@ gint pixbuf_renderer_overlay_get(PixbufRenderer *pr, gint id, GdkPixbuf **= pixbuf, gint *x, gint *y); void pixbuf_renderer_overlay_remove(PixbufRenderer *pr, gint id); =20 +gint pixbuf_renderer_get_mouse_position(PixbufRenderer *pr, gint *x_pixel,= gint *y_pixel); +gint pixbuf_renderer_get_mouse_colors(PixbufRenderer *pr, gint *r_mouse, g= int *g_mouse, gint *b_mouse); =20 #endif /* vim: set shiftwidth=3D8 softtabstop=3D0 cindent cinoptions=3D{1s: */ Index: layout_util.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- layout_util.c (r=E9vision 1447) +++ layout_util.c (copie de travail) @@ -666,6 +666,16 @@ layout_toolbar_toggle(lw); } =20 +static void layout_menu_info_pixel_cb(GtkToggleAction *action, gpointer da= ta) +{ + LayoutWindow *lw =3D data; + + if (lw->options.info_pixel_hidden =3D=3D gtk_toggle_action_get_active(act= ion)) return; + + layout_exit_fullscreen(lw); + layout_info_pixel_toggle(lw); +} + /* NOTE: these callbacks are called also from layout_util_sync_views */ static void layout_menu_bar_cb(GtkToggleAction *action, gpointer data) { @@ -1260,6 +1270,7 @@ { "ShowMarks", NULL, N_("Show _Marks"), "M", NULL, CB(layout_me= nu_marks_cb), FALSE }, { "FloatTools", PIXBUF_INLINE_ICON_FLOAT, N_("_Float file list"), "L", = NULL, CB(layout_menu_float_cb), FALSE }, { "HideToolbar", NULL, N_("Hide tool_bar"), NULL, NULL, CB(layout_menu= _toolbar_cb), FALSE }, + { "HideInfoPixel", NULL, N_("Hide Pi_xel Info"), NULL, NULL, CB(layout= _menu_info_pixel_cb), FALSE }, { "SBar", NULL, N_("_Info"), "<control>K", NULL, CB(layout_menu_bar_c= b), FALSE }, { "ExifWin", NULL, N_("E_xif window"), "<control>E", NULL, CB(layout_m= enu_bar_exif_cb), FALSE }, { "SBarSort", NULL, N_("Sort _manager"), "<control>S", NULL, CB(layout= _menu_bar_sort_cb), FALSE }, @@ -1418,6 +1429,7 @@ " <menuitem action=3D'FloatTools'/>" " <menuitem action=3D'HideTools'/>" " <menuitem action=3D'HideToolbar'/>" +" <menuitem action=3D'HideInfoPixel'/>" " <placeholder name=3D'ToolsSection'/>" " <separator/>" " <menuitem action=3D'SBar'/>" @@ -1852,6 +1864,9 @@ =20 action =3D gtk_action_group_get_action(lw->action_group, "HideToolbar"); gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.toolb= ar_hidden); +=09 + action =3D gtk_action_group_get_action(lw->action_group, "HideInfoPixel"); + gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.info_= pixel_hidden); =20 action =3D gtk_action_group_get_action(lw->action_group, "ShowMarks"); gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.show_= marks); Index: typedefs.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- typedefs.h (r=E9vision 1447) +++ typedefs.h (copie de travail) @@ -532,7 +532,8 @@ gboolean tools_restore_state; =20 gboolean toolbar_hidden; -=09 + gboolean info_pixel_hidden; + gchar *home_path; }; =20 @@ -625,7 +626,8 @@ GtkWidget *info_details; GtkWidget *info_zoom; GtkWidget *info_write; - + GtkWidget *info_pixel; +=09 /* slide show */ =20 SlideShowData *slideshow; --Multipart=_Sun__1_Mar_2009_11_38_36_+0100_=LO0Y1eBK_mApb3w Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------------ Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise -Strategies to boost innovation and cut costs with open source participation -Receive a $600 discount off the registration fee with the source code: SFAD http://p.sf.net/sfu/XcvMzF8H --Multipart=_Sun__1_Mar_2009_11_38_36_+0100_=LO0Y1eBK_mApb3w Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Geeqie-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/geeqie-devel --Multipart=_Sun__1_Mar_2009_11_38_36_+0100_=LO0Y1eBK_mApb3w--