Image-Sane
view release on metacpan or search on metacpan
examples/scanimage-perl view on Meta::CPAN
return @vector;
}
sub fetch_options {
$device = shift;
my $opt = $device->get_option_descriptor(0);
if ( not defined $opt ) {
die "Could not get option descriptor for option 0\n";
}
try {
$num_dev_options = $device->get_option(0);
}
catch {
die 'Could not get value for option 0:', $_->error, "\n";
};
# build the full table of long options
for my $i ( 1 .. $num_dev_options - 1 ) {
$opt = $device->get_option_descriptor($i);
if ( not defined $opt ) {
die "Could not get option descriptor for option $i\n";
}
next if ( not( $opt->{cap} & SANE_CAP_SOFT_SELECT ) );
$option_number{ $opt->{name} } = $i;
update_geometry( $opt, $i );
if ( $opt->{type} == SANE_TYPE_BOOL ) {
push @args, "$opt->{name}:s";
}
elsif ( $opt->{type} == SANE_TYPE_BUTTON ) {
push @args, $opt->{name};
}
else {
push @args, "$opt->{name}=s";
}
}
# Initialize width & height options based on backend default
# values for top-left x/y and bottom-right x/y:
for my $i ( 0 .. 1 ) {
if ( $window[$i] and not $window_val_user[$i] ) {
$window_val[$i] = $device->get_option( $window[$i] );
if ( $window[ $i + 2 ] ) {
my $pos = $device->get_option( $window[ $i + 2 ] );
$window_val[$i] -= $pos;
}
}
}
return;
}
# Keep track of top-left corner options (if they exist at
# all) and replace the bottom-right corner options by a
# width/height option (if they exist at all).
sub update_geometry {
my ( $opt, $i ) = @_;
if ( ( $opt->{type} == SANE_TYPE_FIXED or $opt->{type} == SANE_TYPE_INT )
and ( $opt->{unit} == SANE_UNIT_MM or $opt->{unit} == SANE_UNIT_PIXEL )
)
{
given ( $opt->{name} ) {
when (SANE_NAME_SCAN_BR_X) {
$window[0] = $i;
$opt->{name} = 'x';
$window_option[0] = $opt;
$window_option[0]->{title} = 'Scan width';
$window_option[0]->{desc} = 'Width of scan-area.';
$window_option[0]->{name} = 'x';
}
when (SANE_NAME_SCAN_BR_Y) {
$window[1] = $i;
$opt->{name} = 'y';
$window_option[1] = $opt;
$window_option[1]->{title} = 'Scan height';
$window_option[1]->{desc} = 'Height of scan-area.';
$window_option[1]->{name} = 'y';
}
when (SANE_NAME_SCAN_TL_X) {
$window[2] = $i;
$window_option[2] = $opt;
$window_option[2]->{name} = 'l';
}
when (SANE_NAME_SCAN_TL_Y) {
$window[$I_TL_Y] = $i;
$window_option[$I_TL_Y] = $opt;
$window_option[$I_TL_Y]->{name} = 't';
}
}
}
return;
}
sub set_option {
( $device, my $optnum, my $value ) = @_;
my $opt = $device->get_option_descriptor($optnum);
if ( $opt and ( $opt->{cap} & SANE_CAP_INACTIVE ) ) {
if ( $verbose > 0 ) {
printstderr(
"$prog_name: ignored request to set inactive option $opt->{name}\n"
);
}
return;
}
my $info;
try {
$info = $device->set_option( $optnum, $value );
}
catch {
die "$prog_name: setting of option --$opt->{name} failed ("
. $_->error . "\n";
};
if ( ( $info & SANE_INFO_INEXACT ) and $opt->{max_values} == 1 ) {
( run in 1.718 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )