File: scanner.html

package info (click to toggle)
iceweasel 2.0.0.19-0etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 298,784 kB
  • ctags: 317,912
  • sloc: cpp: 1,796,902; ansic: 987,677; xml: 109,036; makefile: 47,777; asm: 35,201; perl: 26,983; sh: 20,879; cs: 6,232; java: 5,513; python: 3,249; pascal: 459; lex: 306; php: 244; csh: 132; objc: 97; yacc: 79; ada: 49; awk: 14; sql: 4; sed: 4
file content (301 lines) | stat: -rw-r--r-- 7,498 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
<HTML>
  <HEAD>
    <TITLE>Image Scanner Application</TITLE>
  </HEAD>
  <BODY>
    <P>
    This is a simple test page for the HP 6300C USB scanner. 
    </P>
    <TABLE>
      <TR>
        <TD>
          <CENTER>
            <EMBED type="application/X-sane-plugin"
	           name="scanner"
		   onScanComplete="ScanCompleteCallback()"
		   onInitComplete="InitCompleteCallback()" 
                   device="hp:/dev/usbscanner" 
		   width="300" height="413"
                   line_width="4" line_style="solid">
          </CENTER>
        </TD>
        <TD>
          <CENTER>

	    <!-- Pan zoom box -->
            <INPUT type="button" onclick="panRegionVert(-10)" 
                   value="Pan Up" ><BR>
            <INPUT type="button" onclick="panRegionHor(-10)"
	           value="Pan Left" >
            <INPUT type="button" onclick="panRegionHor(10)" 
                   value="Pan Right" ><BR>
            <INPUT type="button" onclick="panRegionVert(10)" 
                   value="Pan Down" ><BR><BR>

            <!-- Zoom in/out -->
            <INPUT type="button" onclick="adjustRegion(-10)" 
                   value="Zoom In" >
            <INPUT type="button" onclick="adjustRegion(10)"
	           value="Zoom Out" ><BR><BR>

            <!-- Scanner controls -->
            <INPUT type="button" onclick="ScanHi()" 
                   value="Scan Selected Region">
            <INPUT type="button" onclick="GetPreview()"
	           value="Preview"><BR>
            <INPUT type="button" onclick="Save()" 
                   value="Save Current Image"><br><br>

	    <!-- SANE test -->
	    <INPUT type="button" onclick="doDump()"
	           value="Dump">

          </CENTER>
        </TD>
      </TR>
    </TABLE>

    <TEXTAREA id="status" rows="20" cols="80"></TEXTAREA>


<SCRIPT>

// globals
var inscan = true;
var br_x = 0, br_y = 0, tl_x = 0, tl_y = 0;
var max_br_x = 0, max_br_y = 0;
var last_br_x, last_br_y, last_tl_x, last_tl_y;

function sdump(str)
{
    var status = document.getElementById('status');
    
    status.value = str;
    dump(str + "\n");
}

function doDump()
{
    try {
	var aScanner = document.scanner.nsISanePluginInstance;
  	sdump("ActiveDevice = " + aScanner.ActiveDevice + "\n" +
	      "State = " + aScanner.State + "\n" + 
	      "Quality = " + aScanner.Quality + "\n" + 
	      "Method = " + aScanner.Method + "\n" + 
	      "DeviceOptions = " + aScanner.DeviceOptions + "\n" + 
	      "ImageParameters = " + aScanner.ImageParameters + "\n" + 
	      "AvailableDevices = " + aScanner.AvailableDevices + "\n");  
    } catch (ex) {
	sdump("Error trying to dump: \n" + ex + "\n");
    }
}

function adjustRegion(factor) {
    try {
	var aScanner = document.scanner.nsISanePluginInstance;
	var x, y, height, width;
	x = aScanner.ZoomX;
	y = aScanner.ZoomY;


	width = aScanner.ZoomWidth 
	    + factor;
	height = Math.floor(width * 413/300);

	aScanner.Crop(x, y, width, height);
    } catch (ex) {
	dump("Unable to zoom by " + factor + "\n" + ex + "\n");
    }
}

function panRegionHor(factor) {
  try {
      var x, y, height, width;
      var aScanner = document.scanner.nsISanePluginInstance;

      if (aScanner.ZoomX + factor < 0) 
	  x = aScanner.ZoomX;
      else
	  x = aScanner.ZoomX + factor;


      y = aScanner.ZoomY;
      width = aScanner.ZoomWidth;
      height = aScanner.ZoomHeight;

      aScanner.Crop(x, y, width, height);
  } catch (ex) {
      dump("Unable to pan to requested location!\n");
  }
}

function panRegionVert(factor) {
  try {
      var x, y, height, width;
      var aScanner = document.scanner.nsISanePluginInstance;

      if (aScanner.ZoomY + factor < 0) 
	  y = aScanner.ZoomY;
      else
	  y = aScanner.ZoomY + factor;
      
      x = aScanner.ZoomX;
      width = aScanner.ZoomWidth;
      height = aScanner.ZoomHeight;

      aScanner.Crop(x, y, width, height);
  } catch (ex) {
      dump("Unable to pan to requested location!\n");
  }
}

function Save() {
    try {
      var aScanner = document.scanner.nsISanePluginInstance;

      aScanner.SaveImage();
    } catch (ex) {
	dump("Error trying to save current image!\n");
    }
}

function GetPreview()
{
  if (inscan)
    return;

  try {
      var aScanner = document.scanner.nsISanePluginInstance;

      // Reset scan area for entire bed
      tl_x = tl_y = 0;
      br_x = max_br_x;
      br_y = max_br_y;
      aScanner.SetOption("tl-x", tl_x.toString(10));
      aScanner.SetOption("tl-y", tl_y.toString(10));
      aScanner.SetOption("br-x", br_x.toString(10));
      aScanner.SetOption("br-y", br_y.toString(10));

      // Set the lowest resolution the HP ScanJet 6300C supports
      aScanner.SetOption("mode", "Color");
      aScanner.SetOption("resolution", "12");
      
      inscan = true;
      aScanner.ScanImage();

      // Scanning is a threaded function, so getting here 
      // only means that a scan operation was successfully started.
  } catch (ex) {
    dump("Error trying to get preview image!");
  }
}

function ScanHi()
{
    if (inscan)
	return;

    try {
	var aScanner = document.scanner.nsISanePluginInstance;

	// store last scan area coordinates
	// so that Restore() knows what scan
	// area coordinates to restore to.
	last_br_x = br_x;
	last_br_y = br_y;
	last_tl_x = tl_x;
	last_tl_y = tl_y;

	// factors used in converting from zoom box
	// to scanner coordinates
	var xfactor = last_br_x/300;
	var yfactor = last_br_y/413;

	// zoom box coordinates
	var z_br_x = aScanner.ZoomWidth + aScanner.ZoomX;
	var z_br_y = aScanner.ZoomHeight + aScanner.ZoomY;
	var z_tl_x = aScanner.ZoomX;
	var z_tl_y = aScanner.ZoomY;

	br_x = Math.floor(z_br_x * xfactor);
	br_y = Math.floor(z_br_y * yfactor);
	tl_x = Math.floor((z_tl_x * xfactor) + last_tl_x);
	tl_y = Math.floor((z_tl_y * yfactor) + last_tl_y);

	last_br_x = br_x;
	last_br_y = br_y;
	last_tl_x = tl_x;
	last_tl_y = tl_y;

	// set the scan area for zoom box
	aScanner.SetOption("tl-x", tl_x);
	aScanner.SetOption("tl-y", tl_y);
	aScanner.SetOption("br-x", br_x);
	aScanner.SetOption("br-y", br_y);

	// For speed of testing, high resolution is set to 
	// just 150dpi
	aScanner.SetOption("resolution", "150");

	inscan = true;
	aScanner.ScanImage();

	// Scanning is a threaded operation so getting here
	// only means that we have successfully started a scan.
    } catch (ex) {
	dump("Error trying to scan at 150!\n"+ ex + "\n");
    }
}

function ScanCompleteCallback()
{
    inscan = false;
    dump("Completed Scan!\n");
}

function InitCompleteCallback()
{
    // Additional device specific initialization
    try {
	var aScanner = document.scanner.nsISanePluginInstance;

	// Reset scan area for entire bed
	tl_x = tl_y = 0;
	br_x = max_br_x;
	br_y = max_br_y;
	aScanner.SetOption("tl-x", tl_x.toString(10));
	aScanner.SetOption("tl-y", tl_y.toString(10));
	aScanner.SetOption("br-x", br_x.toString(10));
	aScanner.SetOption("br-y", br_y.toString(10));
	
	// this particular scan seems to scan in a
	// a little dark by default
	aScanner.SetOption("brightness", "30");
	aScanner.SetOption("contrast", "10");
	aScanner.Quality = 80;
	aScanner.Method = "FAST";
	aScanner.SetOption("mode", "Color");

	// Set the maximum bottom x and bottom y
	// for the HP ScanJet 6300C
	last_br_x = br_x = max_br_x = 14141852;
	last_br_y = br_y = max_br_y = 19456836;
	last_tl_x = tl_x;
	last_tl_y = tl_y;

	inscan = false;
    } catch (ex) {
	dump("Error trying to set device specific initialization!\n");
    }
}

    </SCRIPT>
  </BODY>
</HTML>