Image-Sane

 view release on metacpan or  search on metacpan

examples/scanadf-perl  view on Meta::CPAN


        $prev_index = $index;
        $prev_value = $value;
        $separator  = substr $str, 0, 1;
    }

    if ( $verbose > 2 ) {
        printstderr("$prog_name: value for --$opt->{name} is: ");
        for (@vector) {
            printstderr("$_ ");
        }
        printstderr("\n");
    }

    return @vector;
}

sub fetch_options {
    $device = shift;

    # We got a device, find out how many options it has:
    $num_dev_options = $device->get_option(0);
    if ( $Sane::STATUS != SANE_STATUS_GOOD ) {
        die "$prog_name: unable to determine option count\n";
    }

    for my $i ( 0 .. $num_dev_options - 1 ) {
        my $opt = $device->get_option_descriptor($i);

        next if ( !( $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 $window[ $i + 2 ] and not $window_val_user[$i] ) {
            my $pos = $device->get_option( $window[ $i + 2 ] );
            if ( defined $pos ) { $window_val[$i] = $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 || $opt->{type} == SANE_TYPE_INT )
        and ( $opt->{unit} == SANE_UNIT_MM || $opt->{unit} == SANE_UNIT_PIXEL )
      )
    {
        given ( $opt->{name} ) {
            when (SANE_NAME_SCAN_TL_X) {
                $window[2] = $i;
                $opt->{name} = 'l';
            }
            when (SANE_NAME_SCAN_TL_Y) {
                $window[3] = $i;      ## no critic (ProhibitMagicNumbers)
                $opt->{name} = 't';
            }
            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 scanning area.';
                if ( !$window_val_user[0] ) {
                    $window_val[0] = $device->get_option($i);
                }
            }
            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 scanning area.';
                if ( !$window_val_user[1] ) {
                    $window_val[1] = $device->get_option($i);
                }
            }
        }
    }
    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 ) {
            warn
"$prog_name: ignored request to set inactive option $opt->{name}\n";
        }
        return;
    }

    my $info = $device->set_option( $optnum, $value );
    if ( $Sane::STATUS != SANE_STATUS_GOOD ) {
        die
"$prog_name: setting of option --$opt->{name} failed ($Sane::STATUS)\n";
    }

    if ( ( $info & SANE_INFO_INEXACT ) and $opt->{max_values} == 1 ) {
        my $orig = $value;
        $value = $device->get_option($optnum);



( run in 1.935 second using v1.01-cache-2.11-cpan-2398b32b56e )