[sane-devel] Re: [patch] xscanimage: resolution of the resulting GIMP image
Aurelien Jarno
lists at aurel32.net
Sun Jan 12 22:17:37 GMT 2003
On Sun, Jan 12, 2003 at 10:59:24PM +0100, Henning Meier-Geinitz wrote:
> Hi,
>
> On Sun, Jan 12, 2003 at 09:17:45PM +0100, Aurelien Jarno wrote:
>
> A bit too late for 1.0.10 but after that we can include the patch.
>
> > --- xscanimage.c 2003-01-12 20:45:27.000000000 +0100
> > +++ /home/aurel32/xscanimage.c 2003-01-12 20:45:09.000000000 +0100
> > @@ -380,4 +380,29 @@
> > #endif /* HAVE_LIBGIMP_GIMP_H */
> >
> > +static SANE_Word get_resolution(SANE_Handle dev)
> > +{
> > + int i;
> > + SANE_Word resolution;
> > + SANE_Int num_options;
> > + const SANE_Option_Descriptor *option_desc;
> > +
> > + sane_control_option (dev, 0, SANE_ACTION_GET_VALUE, &num_options, 0);
>
> Better check the return code. If this fails for some reason,
> num_options may be unitialized (or set it to 1).
>
> > + for(i = 1 ; i < num_options ; i++)
> > + {
> > + option_desc = sane_get_option_descriptor(dev, i);
> > + if (option_desc)
> > + if (option_desc->name)
> > + if (strncmp(option_desc->name,
> > + SANE_NAME_SCAN_RESOLUTION,
> > + sizeof(SANE_NAME_SCAN_RESOLUTION)) == 0)
> > + {
> > + sane_control_option (dev, i, SANE_ACTION_GET_VALUE, &resolution, 0);
>
> Same here.
>
> > + resolution = get_resolution(dev);
> > + if (resolution != 0) gimp_image_set_resolution(scan_win.image_ID,
> > + resolution,
> > + resolution);
> > +
>
> Is this function part of gimp 1.0? Just to make sure that xscanimage
> still compiles on older installations.
This function appears in gimp 1.1.0.
I modified my patch using your advices, it should be better.
Regards,
Aurelien
-------------- next part --------------
--- xscanimage.c.orig 2003-01-12 23:12:03.000000000 +0100
+++ xscanimage.c 2003-01-12 23:12:23.000000000 +0100
@@ -380,4 +380,33 @@
#endif /* HAVE_LIBGIMP_GIMP_H */
+static SANE_Word get_resolution(SANE_Handle dev)
+{
+ SANE_Status status;
+ SANE_Word resolution;
+ SANE_Int num_options, i;
+ const SANE_Option_Descriptor *option_desc;
+
+ status = sane_control_option(dev, 0, SANE_ACTION_GET_VALUE, &num_options, 0);
+ if (status != SANE_STATUS_GOOD) return 0;
+
+ for(i = 1 ; i < num_options ; i++)
+ {
+ option_desc = sane_get_option_descriptor(dev, i);
+ if (option_desc)
+ if (option_desc->name)
+ if (strncmp(option_desc->name,
+ SANE_NAME_SCAN_RESOLUTION,
+ sizeof(SANE_NAME_SCAN_RESOLUTION)) == 0)
+ {
+ sane_control_option(dev, i, SANE_ACTION_GET_VALUE, &resolution, 0);
+ if (status == SANE_STATUS_GOOD)
+ return resolution;
+ else
+ return 0;
+ }
+ }
+ return 0;
+}
+
static void
update_preview (GSGDialog *dialog, void *arg)
@@ -864,4 +893,9 @@
SANE_Status status;
SANE_Handle dev = gsg_dialog_get_device (dialog);
+
+#ifdef HAVE_LIBGIMP_GIMP_H
+ SANE_Word resolution;
+#endif /* HAVE_LIBGIMP_GIMP_H */
+
const char *frame_type = 0;
char buf[256];
@@ -1015,4 +1049,13 @@
scan_win.image_ID = gimp_image_new (scan_win.param.pixels_per_line,
scan_win.param.lines, image_type);
+
+/* the following is supported since gimp-1.1.0 */
+#ifdef GIMP_HAVE_RESOLUTION_INFO
+ resolution = get_resolution(dev);
+ if (resolution > 0) gimp_image_set_resolution(scan_win.image_ID,
+ resolution,
+ resolution);
+#endif
+
layer_ID = gimp_layer_new (scan_win.image_ID, "Background",
scan_win.param.pixels_per_line,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://alioth-lists.debian.net/pipermail/sane-devel/attachments/20030112/ff8fa13b/attachment.sig>
More information about the sane-devel
mailing list