[OK, this time with the patch!]
On Sat, Jul 26, 2003 at 03:42:59PM -0700, Ross Boylan wrote:
> I have attached a patch so that iscan, scanning software for Epson
> scanners from Epson Kowa, will record the scanning resolution when
> saving .png files.  Without this, some programs (e.g., hylafax) have
> to assume a resolution, and can be terribly wrong.  (I was inspired to
> do this because only the lower left corner of my 400 dpi scans was
> going out, since they were assumed to be postscript standard 72dpi).
> 
> I'm not sure if all versions of libpng support pHYS; if not, it might
> be good to protect the code with some appropriate ifdef's.  I had
> libpng10-dev (aka libpng2) as my development library when I compiled
> with gcc 3.3.
> 
> Despite the name, I have used and applied the patch to iscan 1.5.2,
> gcc 3.2 version.  I originally developed it against 1.5.1.
> 
> I (c) in my name and release it under GNU Public License v2 or later;
> I believe this is the same license as the software it is  patching,
> which is available at
> http://www.epkowa.co.jp/english/linux_e/lsd_e.html.
> 
> Ross Boylan
> 
> 
> P.S. There are some other changes I'd like to make, like having iscan
> remember whether you selected png or pnm, and having it remember what
> directory you are in.  I think that requires learning about gtk
> preferences, though.
> 
diff -ru iscan-1.5.1/frontend/pisa_change_unit.cc 
iscan-1.5.1-old/frontend/pisa_change_unit.cc
--- iscan-1.5.1/frontend/pisa_change_unit.cc    2003-02-05 01:58:04.000000000 -0800
+++ iscan-1.5.1-old/frontend/pisa_change_unit.cc        2003-06-19 22:10:37.000000000 
-0700
@@ -54,7 +54,6 @@
   return ret;
 }
 
-
 /*------------------------------------------------------------*/
 double inch2centi ( double inch, long zoom )
 {
@@ -66,3 +65,13 @@
 }
 
 
+/*------------------------------------------------------------*/
+unsigned long centi2pixel ( double centi, long resolution, long zoom )
+{
+  unsigned long        ret;
+
+  ret = ( long ) ( ( centi * resolution * zoom + 50 ) / (100* INCH2PIXEL));
+
+  return ret;
+}
+
diff -ru iscan-1.5.1/frontend/pisa_change_unit.h 
iscan-1.5.1-old/frontend/pisa_change_unit.h
--- iscan-1.5.1/frontend/pisa_change_unit.h     2003-02-05 01:58:04.000000000 -0800
+++ iscan-1.5.1-old/frontend/pisa_change_unit.h 2003-06-19 22:11:06.000000000 -0700
@@ -34,5 +34,6 @@
 double inches_reflect_zoom ( double inch, long zoom );
 long   inch2pixel ( double inch, long resolution, long zoom = 100 );
 double inch2centi ( double inch, long zoom = 100 );
+unsigned long centi2pixel ( double centi, long resolution, long zoom = 100);
 
 #endif // ___PISA_CHANGE_UNIT_H
diff -ru iscan-1.5.1/frontend/pisa_save_file.cc 
iscan-1.5.1-old/frontend/pisa_save_file.cc
--- iscan-1.5.1/frontend/pisa_save_file.cc      2003-03-15 01:11:15.000000000 -0800
+++ iscan-1.5.1-old/frontend/pisa_save_file.cc  2003-06-20 21:12:27.000000000 -0700
@@ -31,6 +31,7 @@
 
 #include "pisa_save_file.h"
 
+#include "pisa_change_unit.h"
 #include "pisa_error.h"
 #include <dlfcn.h>
 
@@ -58,11 +59,12 @@
 }
 
 void
-base_save_file::set_img_info( char pixel, int width, int height )
+base_save_file::set_img_info( char pixel, int width, int height, long resolution )
 {
   m_pixel  = static_cast< pisa_pixel_type >( pixel );
   m_width  = width;
   m_height = height;
+  m_resolution = resolution;
 }
 
 
@@ -150,6 +152,7 @@
       plib_png_destroy_write_struct    = ( lib_png_destroy_write_struct * ) dlsym ( 
m_handle_libpng, "png_destroy_write_struct" );
       plib_png_init_io                 = ( lib_png_init_io * )              dlsym ( 
m_handle_libpng, "png_init_io" );
       plib_png_set_IHDR                        = ( lib_png_set_IHDR * )             
dlsym ( m_handle_libpng, "png_set_IHDR" );
+      plib_png_set_pHYs                        = ( lib_png_set_pHYs * )             
dlsym ( m_handle_libpng, "png_set_pHYs" );
       plib_png_write_info              = ( lib_png_write_info * )           dlsym ( 
m_handle_libpng, "png_write_info" );
       plib_png_write_row               = ( lib_png_write_row * )            dlsym ( 
m_handle_libpng, "png_write_row" );
       plib_png_write_end               = ( lib_png_write_end * )            dlsym ( 
m_handle_libpng, "png_write_end" );
@@ -160,6 +163,7 @@
           ! plib_png_destroy_write_struct ||
           ! plib_png_init_io ||
           ! plib_png_set_IHDR ||
+          ! plib_png_set_pHYs ||
           ! plib_png_write_info ||
           ! plib_png_write_row ||
           ! plib_png_write_end )
@@ -287,7 +291,16 @@
                     PNG_INTERLACE_NONE,
                     PNG_COMPRESSION_TYPE_BASE, 
                     PNG_FILTER_TYPE_BASE );
-                                       
+
+  // should I care about Zoom?
+  png_uint_32 resolution = centi2pixel( 100.0, m_resolution);
+                               
+  plib_png_set_pHYs( m_png_ptr,
+                    m_info_ptr,
+                    resolution,
+                    resolution,
+                    PNG_RESOLUTION_METER);
+
   /*write the info*/
   plib_png_write_info(m_png_ptr, m_info_ptr);
 }
diff -ru iscan-1.5.1/frontend/pisa_save_file.h 
iscan-1.5.1-old/frontend/pisa_save_file.h
--- iscan-1.5.1/frontend/pisa_save_file.h       2003-03-15 01:11:15.000000000 -0800
+++ iscan-1.5.1-old/frontend/pisa_save_file.h   2003-06-19 22:41:02.000000000 -0700
@@ -42,7 +42,7 @@
   virtual ~base_save_file();
            base_save_file( const char *const filename );
 
-  void set_img_info( char pixel, int width, int height );
+  void set_img_info( char pixel, int width, int height, long resolution );
 
   virtual void write_header() = 0;
   virtual void write_row( unsigned char *img, int size ) = 0;
@@ -56,6 +56,7 @@
   
   int   m_width;
   int   m_height;
+  long  m_resolution;
 };
 
 class save_file_pnm : public base_save_file
@@ -114,6 +115,11 @@
                                      int interlace_type,
                                      int compression_type,
                                      int filter_type );
+  typedef void ( lib_png_set_pHYs ) ( png_structp png_ptr,
+                                     png_infop info_ptr,
+                                     png_uint_32 x,
+                                     png_uint_32 y,
+                                     int unit_type );
   typedef void ( lib_png_write_info ) ( png_structp png_ptr,
                                        png_infop info_ptr );
   typedef void ( lib_png_write_row ) ( png_structp png_ptr,
@@ -127,6 +133,7 @@
   lib_png_destroy_write_struct * plib_png_destroy_write_struct;
   lib_png_init_io              * plib_png_init_io;
   lib_png_set_IHDR             * plib_png_set_IHDR;
+  lib_png_set_pHYs              * plib_png_set_pHYs;
   lib_png_write_info           * plib_png_write_info;
   lib_png_write_row            * plib_png_write_row;
   lib_png_write_end            * plib_png_write_end;
diff -ru iscan-1.5.1/frontend/pisa_view_manager.cc 
iscan-1.5.1-old/frontend/pisa_view_manager.cc
--- iscan-1.5.1/frontend/pisa_view_manager.cc   2003-04-15 18:25:30.000000000 -0700
+++ iscan-1.5.1-old/frontend/pisa_view_manager.cc       2003-06-19 22:32:02.000000000 
-0700
@@ -1152,7 +1152,9 @@
          throw pisa_error( PISA_ERR_FILEOPEN );
        }
 
-      save_cls->set_img_info( m_set.imgtype.pixeltype, width, height );
+      // Perhaps get resolution from param?  But it has two!  Ross Boylan
+      save_cls->set_img_info( m_set.imgtype.pixeltype, width, height,
+                             ::g_view_manager->m_set.resolution);
       try
        {
          save_cls->write_header();

Reply via email to