gnome-scan r804 - in branches/GNOME_SCAN_0_6: . src
- From: bersace svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-scan r804 - in branches/GNOME_SCAN_0_6: . src
- Date: Sat, 31 Jan 2009 14:54:09 +0000 (UTC)
Author: bersace
Date: Sat Jan 31 14:54:09 2009
New Revision: 804
URL: http://svn.gnome.org/viewvc/gnome-scan?rev=804&view=rev
Log:
Fix grey scanning in Gimp plugin
Modified:
branches/GNOME_SCAN_0_6/ChangeLog
branches/GNOME_SCAN_0_6/src/Makefile.am
branches/GNOME_SCAN_0_6/src/flegita-gimp-sink.c
branches/GNOME_SCAN_0_6/src/flegita-gimp.c
Modified: branches/GNOME_SCAN_0_6/src/Makefile.am
==============================================================================
--- branches/GNOME_SCAN_0_6/src/Makefile.am (original)
+++ branches/GNOME_SCAN_0_6/src/Makefile.am Sat Jan 31 14:54:09 2009
@@ -72,6 +72,7 @@
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/
Modified: branches/GNOME_SCAN_0_6/src/flegita-gimp-sink.c
==============================================================================
--- branches/GNOME_SCAN_0_6/src/flegita-gimp-sink.c (original)
+++ branches/GNOME_SCAN_0_6/src/flegita-gimp-sink.c Sat Jan 31 14:54:09 2009
@@ -45,7 +45,9 @@
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 @@
/* 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 @@
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 @@
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 @@
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 @@
-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);
Modified: branches/GNOME_SCAN_0_6/src/flegita-gimp.c
==============================================================================
--- branches/GNOME_SCAN_0_6/src/flegita-gimp.c (original)
+++ branches/GNOME_SCAN_0_6/src/flegita-gimp.c Sat Jan 31 14:54:09 2009
@@ -112,7 +112,7 @@
"Ã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 @@
/* 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 @@
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 @@
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]