[gnome-scan/gnome-scan-0-6: 16/23] Fix grey scanning in Gimp plugin
- From: Philipp Sadleder <phsadleder src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-scan/gnome-scan-0-6: 16/23] Fix grey scanning in Gimp plugin
- Date: Wed, 22 Apr 2009 04:46:30 -0400 (EDT)
commit 8f352098def681edc9bef58de941e5eec5e5caa6
Author: Ã?tienne Bersac <bersace src gnome org>
Date: Sat Jan 31 14:54:09 2009 +0000
Fix grey scanning in Gimp plugin
svn path=/branches/GNOME_SCAN_0_6/; revision=804
---
ChangeLog | 22 +++++++++-
src/Makefile.am | 1 +
src/flegita-gimp-sink.c | 116 ++++++++++++++++++++++++++++++++---------------
src/flegita-gimp.c | 15 ++++---
4 files changed, 111 insertions(+), 43 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 1c24beb..0bf7cb0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2009-01-31 Ã?tienne BERSAC <bersace03 laposte net>
+
+ * src/Makefile.am:
+
+ Link gimp plugin before installing it.
+
+ * src/flegita-gimp-sink.c:
+
+ Proprerly create Image for the type of the incomming GEGL
+ buffer. And create layer for the image base type instead of
+ incomming GEGL buffer.
+
+ This allow to scan new Grey image, scan grey data in RGB data,
+ etc. Thanks GEGL and Babl for the job :)
+
+ * src/flegita-gimp.c:
+
+ Allow to run Save as layer on GRAY image as well. Only indexed
+ images are not supported (that's a GEGL â??limitationâ??).
+
2009-01-19 Philipp Sadleder <philipp sadleder de>
* modules/gsane-meta-param.c (meta_param_paper_size_add_param):
@@ -25,7 +45,7 @@
2009-01-09 Philipp Sadleder <philipp sadleder de>
- * Backport fix for crash on module unload from gnome-scan trunk.
+ * Backport fix for crash on module unload from gnome-scan trunk.
2008-08-09 Ã?tienne Bersac <bersace03 gmail com>
diff --git a/src/Makefile.am b/src/Makefile.am
index ce55c73..a3cb854 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -72,6 +72,7 @@ flegita_gimp_LDFLAGS = \
GIMPVERSION=2.6
quick: $(libgimp_PROGRAMS)
+ ./$(libgimp_PROGRAMS); true
mkdir -p ~/.gimp-$(GIMPVERSION)/plug-ins/.libs/
cp -r $(libgimp_PROGRAMS) ~/.gimp-$(GIMPVERSION)/plug-ins/
cp -r .libs/* ~/.gimp-$(GIMPVERSION)/plug-ins/.libs/
diff --git a/src/flegita-gimp-sink.c b/src/flegita-gimp-sink.c
index f3ca5ef..6aa28ca 100644
--- a/src/flegita-gimp-sink.c
+++ b/src/flegita-gimp-sink.c
@@ -45,7 +45,9 @@ struct _FlegitaGimpSinkPrivate
GimpDrawable *drawable;
const GeglRectangle *extent;
GeglRectangle actual_extent;
+ gdouble res;
BablFormat *format;
+ guint image_type;
GimpPixelRgn rgn;
gpointer iter;
GeglBuffer *buffer;
@@ -127,6 +129,77 @@ flegita_gimp_sink_new (gint32 image_ID,
/* INTERNALS */
+
+/* Create a new image with type computed from incomming gegl buffer
+ type. */
+static gint32
+fgs_create_image(FlegitaGimpSink *sink)
+{
+ FlegitaGimpSinkPrivate *priv = GET_PRIVATE (sink);
+ BablFormat *format = NULL;
+ guint image_type = 0;
+ guint image_base_type = 0;
+
+ g_object_get (priv->buffer, "format", &format, NULL);
+
+ switch (format->components) {
+ case 1:
+ image_type = GIMP_GRAY_IMAGE;
+ image_base_type = GIMP_GRAY;
+ break;
+ case 3:
+ default:
+ image_type = GIMP_RGB_IMAGE;
+ image_base_type = GIMP_RGB;
+ break;
+ }
+
+ sink->image_ID = gimp_image_new (1, 1, image_base_type);
+ g_debug("Image ID is %d", sink->image_ID);
+
+ gimp_image_set_resolution (sink->image_ID, priv->res, priv->res);
+ priv->image_type = image_type;
+ return sink->image_ID;
+}
+
+/* Compute babl format and update layer type according to image type
+ (not incomming gegl buffer type) */
+static BablFormat*
+fgs_compute_babl_format(FlegitaGimpSink *sink)
+{
+ FlegitaGimpSinkPrivate *priv = GET_PRIVATE (sink);
+ BablFormat *format = NULL;
+ gchar*format_name = NULL;
+ gint i;
+ gint bps;
+
+ g_object_get (priv->buffer, "format", &format, NULL);
+ bps = format->type[0]->bits;
+
+ switch (gimp_image_base_type(sink->image_ID)) {
+ case GIMP_GRAY:
+ format_name = "Y";
+ priv->image_type = GIMP_GRAY_IMAGE;
+ break;
+ default:
+ format_name = "RGB";
+ priv->image_type = GIMP_RGB_IMAGE;
+ break;
+ }
+
+ for (i = 0; i < format->components; i++) {
+ g_debug (G_STRLOC ": component %i:%s use %i bits",i,
+ format->type[i]->instance.name,
+ format->type[i]->bits);
+ }
+ format_name = g_strdup_printf ("%s u%i", format_name, bps > 8 ? 16 : bps);
+
+ g_debug("Format is %s", format_name);
+
+ return (BablFormat*) babl_format (format_name);
+}
+
+
static void
fgs_configure (GnomeScanPlugin *plugin, GnomeScanSettings *settings)
{
@@ -135,11 +208,7 @@ fgs_configure (GnomeScanPlugin *plugin, GnomeScanSettings *settings)
priv->layer_name = gnome_scan_settings_get_string (settings,
PARAM_LAYER_NAME);
- if (sink->is_new) {
- gdouble res = gnome_scan_settings_get_double (settings, "resolution");
- gimp_image_set_resolution (sink->image_ID,
- res, res);
- }
+ priv->res = gnome_scan_settings_get_double (settings, "resolution");
}
static GList*
@@ -162,9 +231,8 @@ fgs_start_frame (GnomeScanPlugin *plugin)
FlegitaGimpSink *sink = FLEGITA_GIMP_SINK (plugin);
FlegitaGimpSinkPrivate *priv = GET_PRIVATE (sink);
GimpPixelRgn rgn;
- BablFormat *format = NULL;
- gchar*format_name = NULL;
gint i;
+ gdouble opacity = 100.;
if (!gegl_buffer_get_pixel_count (priv->buffer)) {
g_warning (G_STRLOC ": No image to process !");
@@ -175,39 +243,15 @@ fgs_start_frame (GnomeScanPlugin *plugin)
priv->actual_extent.width = priv->extent->width - priv->extent->x;
priv->actual_extent.height = priv->extent->height - priv->extent->y;
- g_debug (G_STRLOC ": rect is %ix%i+%i+%i",
- priv->extent->width, priv->extent->height,
- priv->extent->x, priv->extent->y);
- g_object_get (priv->buffer, "format", &format, NULL);
+ if (!sink->image_ID)
+ fgs_create_image(sink);
- guint image_type = 0;
- switch (format->components) {
- case 1:
- image_type = GIMP_GRAY_IMAGE;
- format_name = "Y";
- break;
- case 3:
- default:
- image_type = GIMP_RGB_IMAGE;
- format_name = "RGB";
- break;
- }
-
- gint bps = format->type[0]->bits;
- for (i = 0; i < format->components; i++) {
- g_debug (G_STRLOC ": component %i:%s use %i bits",i,
- format->type[i]->instance.name,
- format->type[i]->bits);
- }
- format_name = g_strdup_printf ("%s u%i", format_name, bps > 8 ? 16 : bps);
-
- priv->format = (BablFormat*) babl_format (format_name);
- gdouble opacity = 100.;
+ priv->format = fgs_compute_babl_format(sink);
priv->layer = gimp_layer_new (sink->image_ID,
priv->layer_name,
priv->actual_extent.width, priv->actual_extent.height,
- image_type,
+ priv->image_type,
opacity,
GIMP_NORMAL_MODE);
@@ -269,7 +313,7 @@ fgs_end_frame (GnomeScanPlugin *plugin)
-1);
gimp_image_undo_freeze (image);
- /* center */
+ /* by default, center new layer */
gimp_layer_translate (priv->layer,
(gimp_image_width (image) - priv->actual_extent.width) / 2,
(gimp_image_height (image) - priv->actual_extent.height) / 2);
diff --git a/src/flegita-gimp.c b/src/flegita-gimp.c
index a5ff709..d13439b 100644
--- a/src/flegita-gimp.c
+++ b/src/flegita-gimp.c
@@ -112,7 +112,7 @@ query (void)
"Ã?tienne Bersac <bersace03 laposte net>",
"2006-2007",
_("Scan as Layer..."),
- "RGB*",
+ "RGB*,GRAY*",
GIMP_PLUGIN,
G_N_ELEMENTS (scan_as_layer_args), G_N_ELEMENTS (scan_return),
scan_as_layer_args, scan_return);
@@ -144,8 +144,8 @@ run (const gchar *name,
/* if we are scanning, create a new image */
g_debug (G_STRLOC " " PROCEDURE_SCAN);
if (g_str_equal (name, PROCEDURE_SCAN)) {
- image_ID = gimp_image_new (1, 1, GIMP_RGB);
- is_new = TRUE;
+ image_ID = 0;
+ is_new = TRUE;
}
/* else use the existing one. */
else {
@@ -156,6 +156,7 @@ run (const gchar *name,
GnomeScanSettings* settings = gnome_scan_settings_new();
GnomeScanSink *sink = flegita_gimp_sink_new(image_ID, is_new);
+ FlegitaGimpSink *fgs = FLEGITA_GIMP_SINK(sink);
GnomeScanJob *job = gnome_scan_job_new(settings, sink);
/* set default scan resolution from existing image */
@@ -170,11 +171,13 @@ run (const gchar *name,
gnome_scan_job_set_settings(job, settings);
GtkWidget*dialog = gnome_scan_dialog_new (NULL, job);
gnome_scan_dialog_run (GNOME_SCAN_DIALOG (dialog));
+ g_object_unref(settings);
- gimp_image_get_layers (image_ID,
- &n_layers);
+ if (is_new && fgs->image_ID) {
+ image_ID = fgs->image_ID;
+ gimp_image_get_layers (image_ID,
+ &n_layers);
- if (is_new) {
/* if we have a layer, then display */
if (n_layers == 1) {
gimp_display_new (image_ID);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]