1 /*
2    SANE EPSON backend
3    Copyright (C) 2001, 2005 SEIKO EPSON Corporation
4 
5    This file is part of the `iscan' program.
6 
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11 
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16 
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21    As a special exception, the copyright holders give permission
22    to link the code of this program with the esmod library and
23    distribute linked combinations including the two.  You must obey
24    the GNU General Public License in all respects for all of the
25    code used other then esmod.
26 */
27 
28 #include "pisa_change_unit.h"
29 
30 const double CM_PER_INCH = 2.54;	// exact, per definition
31 
32 
33 double
inches_reflect_zoom(double inch,long zoom)34 inches_reflect_zoom (double inch, long zoom)
35 {
36   return inch * zoom / 100;
37 }
38 
39 double
inch2centi(double inch,long zoom)40 inch2centi (double inch, long zoom)
41 {
42   return (inch * CM_PER_INCH * zoom) / 100;
43 }
44 
45 
46 long
inch2width(double inch,long resolution,long zoom,bool monochrome)47 inch2width (double inch, long resolution, long zoom, bool monochrome)
48 {
49   int boundary = (monochrome ? 32 : 8);
50 
51   return (inch2pixel (inch, resolution, zoom) / boundary) * boundary;
52 }
53 
54 long
inch2height(double inch,long resolution,long zoom)55 inch2height (double inch, long resolution, long zoom)
56 {
57   return inch2pixel (inch, resolution, zoom);
58 }
59 
60 long
inch2pixel(double inch,long resolution,long zoom)61 inch2pixel (double inch, long resolution, long zoom)
62 {
63   return (long) ((inch * resolution * zoom) / 100);
64 }
65 
66 long
inch2pixel(bool is_width,double inch,long resolution,long zoom)67 inch2pixel (bool is_width,
68 	    double inch, long resolution, long zoom)
69 {
70   return (is_width
71 	  ? inch2width  (inch, resolution, zoom)
72 	  : inch2height (inch, resolution, zoom));
73 }
74 
75 
76 long
centi2width(double centi,long resolution,long zoom)77 centi2width (double centi, long resolution, long zoom)
78 {
79   return (centi2pixel (centi, resolution, zoom) / 8) * 8;
80 }
81 
82 long
centi2height(double centi,long resolution,long zoom)83 centi2height (double centi, long resolution, long zoom)
84 {
85   return centi2pixel (centi, resolution, zoom);
86 }
87 
88 long
centi2pixel(double centi,long resolution,long zoom)89 centi2pixel (double centi, long resolution, long zoom)
90 {
91   return (long) ((centi * resolution * zoom) / (100 * CM_PER_INCH));
92 }
93 
94 long
centi2pixel(bool is_width,double centi,long resolution,long zoom)95 centi2pixel (bool is_width,
96 	     double centi, long resolution, long zoom)
97 {
98   return (is_width
99 	  ? centi2width  (centi, resolution, zoom)
100 	  : centi2height (centi, resolution, zoom));
101 }
102