[sane-devel] Re: [patch] xscanimage: resolution of the resulting GIMP image

Aurelien Jarno lists@aurel32.net
Sun, 12 Jan 2003 23:17:37 +0100


--BwCQnh7xodEAoBMC
Content-Type: multipart/mixed; boundary="LQksG6bCIzRHxTLp"
Content-Disposition: inline


--LQksG6bCIzRHxTLp
Content-Type: text/plain; charset=iso-8859-15
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sun, Jan 12, 2003 at 10:59:24PM +0100, Henning Meier-Geinitz wrote:
> Hi,
>=20
> On Sun, Jan 12, 2003 at 09:17:45PM +0100, Aurelien Jarno wrote:
>=20
> A bit too late for 1.0.10 but after that we can include the patch.
>=20
> > --- 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 */
> > =20
> > +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);
>=20
> Better check the return code. If this fails for some reason,
> num_options may be unitialized (or set it to 1).
>=20
> > +  for(i =3D 1 ; i < num_options ; i++)
> > +  {
> > +    option_desc =3D sane_get_option_descriptor(dev, i);
> > +    if (option_desc)
> > +      if (option_desc->name)	   =20
> > +        if (strncmp(option_desc->name,
> > +                    SANE_NAME_SCAN_RESOLUTION,=20
> > +    		    sizeof(SANE_NAME_SCAN_RESOLUTION)) =3D=3D 0)
> > +        {
> > +          sane_control_option (dev, i, SANE_ACTION_GET_VALUE, &resolut=
ion, 0);
>=20
> Same here.
>=20
> > +	  resolution =3D get_resolution(dev);
> > +         if (resolution !=3D 0) gimp_image_set_resolution(scan_win.ima=
ge_ID,=20
> > +			                                 resolution,=20
> > +						         resolution);
> > +
>=20
> 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

--LQksG6bCIzRHxTLp
Content-Type: text/plain; charset=iso-8859-15
Content-Disposition: attachment; filename="xscanimage.resolution.2.patch"
Content-Transfer-Encoding: quoted-printable

--- 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 */
=20
+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 =3D sane_control_option(dev, 0, SANE_ACTION_GET_VALUE, &num_optio=
ns, 0);
+  if (status !=3D SANE_STATUS_GOOD) return 0;
+ =20
+  for(i =3D 1 ; i < num_options ; i++)
+  {
+    option_desc =3D sane_get_option_descriptor(dev, i);
+    if (option_desc)
+      if (option_desc->name)	   =20
+        if (strncmp(option_desc->name,
+                    SANE_NAME_SCAN_RESOLUTION,=20
+                    sizeof(SANE_NAME_SCAN_RESOLUTION)) =3D=3D 0)
+        {
+          sane_control_option(dev, i, SANE_ACTION_GET_VALUE, &resolution, =
0);
+    	  if (status =3D=3D SANE_STATUS_GOOD)=20
+            return resolution;
+	  else
+            return 0;		 =20
+        }
+  }     =20
+  return 0;=20
+}
+
 static void
 update_preview (GSGDialog *dialog, void *arg)
@@ -864,4 +893,9 @@
   SANE_Status status;
   SANE_Handle dev =3D gsg_dialog_get_device (dialog);
+
+#ifdef HAVE_LIBGIMP_GIMP_H =20
+  SANE_Word resolution;
+#endif /* HAVE_LIBGIMP_GIMP_H */
+ =20
   const char *frame_type =3D 0;
   char buf[256];
@@ -1015,4 +1049,13 @@
 	  scan_win.image_ID =3D 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	 =20
+         resolution =3D get_resolution(dev);
+         if (resolution > 0) gimp_image_set_resolution(scan_win.image_ID,=
=20
+			                                resolution,=20
+						        resolution);
+#endif	 =20
+
 	  layer_ID =3D gimp_layer_new (scan_win.image_ID, "Background",
 				     scan_win.param.pixels_per_line,

--LQksG6bCIzRHxTLp--

--BwCQnh7xodEAoBMC
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.0 (GNU/Linux)

iD8DBQE+IemBw3ao2vG823MRAjqVAJ9uYyALM7UJGmgbkv72wAZ9Bh7WLwCgiJK6
x4ho+3VNYmBKUxwaRaeWFWk=
=z41i
-----END PGP SIGNATURE-----

--BwCQnh7xodEAoBMC--