line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Win32::Scanner::EZTWAIN;
|
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
5908
|
use warnings;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
27
|
|
5
|
1
|
|
|
1
|
|
5
|
use Carp;
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
87
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require 5;
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
require Exporter;
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
5
|
use vars qw( @ISA $VERSION );
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
95
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @ISA = qw(Exporter);
|
14
|
|
|
|
|
|
|
our @EXPORT = qw(TWAIN_BW TWAIN_GRAY TWAIN_RGB TWAIN_PALETTE TWAIN_ANYTYPE TWAIN_ACQUIRE_SUCCESS TWAIN_ACQUIRE_FAILED TWAIN_ACQUIRE_ERROPENFILE TWAIN_ACQUIRE_WEIRD TWAIN_ACQUIRE_ERRWRITEFILE);
|
15
|
|
|
|
|
|
|
our $VERSION = "0.01";
|
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
1387
|
use Win32::API;
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
###########################################################################
|
20
|
|
|
|
|
|
|
###
|
21
|
|
|
|
|
|
|
### Define variables for this module
|
22
|
|
|
|
|
|
|
###
|
23
|
|
|
|
|
|
|
###########################################################################
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $twain_select_image_source;
|
26
|
|
|
|
|
|
|
my $twain_acquire_to_file;
|
27
|
|
|
|
|
|
|
my $twain_acquire_to_clipboard;
|
28
|
|
|
|
|
|
|
my $twain_is_available;
|
29
|
|
|
|
|
|
|
my $twain_easy_version;
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
###########################################################################
|
33
|
|
|
|
|
|
|
###
|
34
|
|
|
|
|
|
|
### Define constants for this module, functions are exported.
|
35
|
|
|
|
|
|
|
###
|
36
|
|
|
|
|
|
|
###########################################################################
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub TWAIN_BW { 1; }
|
39
|
|
|
|
|
|
|
sub TWAIN_GRAY { 2; }
|
40
|
|
|
|
|
|
|
sub TWAIN_RGB { 4; }
|
41
|
|
|
|
|
|
|
sub TWAIN_PALETTE { 8; }
|
42
|
|
|
|
|
|
|
sub TWAIN_ANYTYPE { 0; }
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Pixel types, from the well documented C header file eztwain.h
|
45
|
|
|
|
|
|
|
#
|
46
|
|
|
|
|
|
|
# 1 1-bit per pixel, B&W.
|
47
|
|
|
|
|
|
|
# 2 1,4, or 8-bit grayscale.
|
48
|
|
|
|
|
|
|
# 4 24-bit RGB color.
|
49
|
|
|
|
|
|
|
# 8 1,4, or 8-bit palette.
|
50
|
|
|
|
|
|
|
# 0 Any of the above (recommend).
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub TWAIN_ACQUIRE_SUCCESS { 0; }
|
53
|
|
|
|
|
|
|
sub TWAIN_ACQUIRE_FAILED { -1; }
|
54
|
|
|
|
|
|
|
sub TWAIN_ACQUIRE_ERROPENFILE { -2; }
|
55
|
|
|
|
|
|
|
sub TWAIN_ACQUIRE_WEIRD { -3; }
|
56
|
|
|
|
|
|
|
sub TWAIN_ACQUIRE_ERRWRITEFILE { -4; }
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# Return values, from the well documented C header file eztwain.h
|
59
|
|
|
|
|
|
|
#
|
60
|
|
|
|
|
|
|
# 0 Success.
|
61
|
|
|
|
|
|
|
# -1 Acquire failed OR user cancelled File Save dialog.
|
62
|
|
|
|
|
|
|
# -2 File open error (invalid path or name, or access denied).
|
63
|
|
|
|
|
|
|
# -3 (weird) Unable to lock DIB - probably an invalid handle.
|
64
|
|
|
|
|
|
|
# -4 Writing BMP data failed, possibly output device is full.
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
###########################################################################
|
68
|
|
|
|
|
|
|
###
|
69
|
|
|
|
|
|
|
### Construct our object, and import API calls.
|
70
|
|
|
|
|
|
|
###
|
71
|
|
|
|
|
|
|
###########################################################################
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub new {
|
74
|
|
|
|
|
|
|
my $class = shift;
|
75
|
|
|
|
|
|
|
my %parms = @_;
|
76
|
|
|
|
|
|
|
my $self;
|
77
|
|
|
|
|
|
|
my $path_to_dll = "";
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
if(defined $parms{-dll}) { $path_to_dll = $parms{-dll}; }
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
$twain_select_image_source = new Win32::API("${path_to_dll}eztw32.dll", "TWAIN_SelectImageSource", ['N'], 'N') || croak "Importing API call TWAIN_SelectImageSource failed";
|
82
|
|
|
|
|
|
|
$twain_acquire_to_file = new Win32::API("${path_to_dll}eztw32.dll", "TWAIN_AcquireToFilename", ['N', 'P'], 'N') || croak "Importing API call TWAIN_AcquireToFilename failed";
|
83
|
|
|
|
|
|
|
$twain_acquire_to_clipboard = new Win32::API("${path_to_dll}eztw32.dll", "TWAIN_AcquireToClipboard", ['N', 'I'], 'N') || croak "Importing API call TWAIN_AcquireToClipboard failed";
|
84
|
|
|
|
|
|
|
$twain_is_available = new Win32::API("${path_to_dll}eztw32.dll", "TWAIN_IsAvailable", undef, 'N') || croak "Importing API call TWAIN_IsAvailable failed";
|
85
|
|
|
|
|
|
|
$twain_easy_version = new Win32::API("${path_to_dll}eztw32.dll", "TWAIN_EasyVersion", undef, 'N') || croak "Importing API call TWAIN_EasyVersion failed";
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
%{$self} = %parms;
|
88
|
|
|
|
|
|
|
bless $self, $class;
|
89
|
|
|
|
|
|
|
return $self;
|
90
|
|
|
|
|
|
|
}
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
###########################################################################
|
94
|
|
|
|
|
|
|
###
|
95
|
|
|
|
|
|
|
### Methods.
|
96
|
|
|
|
|
|
|
###
|
97
|
|
|
|
|
|
|
###########################################################################
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# select_image_source, acquire_to_file and acquire_to_clipboard don't need
|
100
|
|
|
|
|
|
|
# a windows handle. TWAIN wants to defocus and disable the application
|
101
|
|
|
|
|
|
|
# window that called him. According to the documented source file of
|
102
|
|
|
|
|
|
|
# eztw32.dll you may omit the handle. If you omit the handle, eztw32.dll
|
103
|
|
|
|
|
|
|
# will create an invisible proxy window. But what ever you do, don't pass
|
104
|
|
|
|
|
|
|
# the handle of your console window, if you do this anyway, it can really
|
105
|
|
|
|
|
|
|
# screw things up.
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub select_image_source
|
108
|
|
|
|
|
|
|
{
|
109
|
|
|
|
|
|
|
my $self = shift; my $hwnd = 0;
|
110
|
|
|
|
|
|
|
if(defined $self->{-hwnd}) { $hwnd = $self->{-hwnd}; }
|
111
|
|
|
|
|
|
|
return $twain_select_image_source->Call($hwnd);
|
112
|
|
|
|
|
|
|
}
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub acquire_to_file
|
115
|
|
|
|
|
|
|
{
|
116
|
|
|
|
|
|
|
my ($self, $file) = @_; my $hwnd = 0;
|
117
|
|
|
|
|
|
|
if(defined $self->{-hwnd}) { $hwnd = $self->{-hwnd}; }
|
118
|
|
|
|
|
|
|
if(!defined $file) { $file = ""; }
|
119
|
|
|
|
|
|
|
return $twain_acquire_to_file->Call($hwnd, $file);
|
120
|
|
|
|
|
|
|
}
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub acquire_to_clipboard
|
123
|
|
|
|
|
|
|
{
|
124
|
|
|
|
|
|
|
my($self, $pixtype) = @_; my $hwnd = 0;
|
125
|
|
|
|
|
|
|
if(defined $self->{-hwnd}) { $hwnd = $self->{-hwnd}; }
|
126
|
|
|
|
|
|
|
if(!defined $pixtype) { $pixtype = TWAIN_ANYTYPE; }
|
127
|
|
|
|
|
|
|
return $twain_acquire_to_clipboard->Call($hwnd, $pixtype);
|
128
|
|
|
|
|
|
|
}
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub is_available { return $twain_is_available->Call(); }
|
131
|
|
|
|
|
|
|
sub easy_version { return sprintf("%.2f", ($twain_easy_version->Call() / 100)); }
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
1;
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
__END__
|