RetroZilla/modules/plugin/samples/SanePlugin/test/scanner.html
2015-10-20 23:03:22 -04:00

302 lines
7.3 KiB
HTML

<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>