pike.git / src / modules / SANE / sane.c

version» Context lines:

pike.git/src/modules/SANE/sane.c:22:   #include "error.h"   #include "mapping.h"   #include "multiset.h"   #include "backend.h"   #include "operators.h"   #include "module_support.h"   #include "builtin_functions.h"      #include "../Image/image.h"    + RCSID("$Id: sane.c,v 1.4 2000/03/02 19:22:23 per Exp $"); +  + /* + **! module SANE + **! + **! This module enables access to the SANE (Scanner Access Now Easy) + **! library from pike + **! + **! note + **! $Id: sane.c,v 1.4 2000/03/02 19:22:23 per Exp $ + */ +    static int sane_is_inited;      struct scanner   {    SANE_Handle h;   };      static void init_sane()   {    if( sane_init( NULL, NULL ) )
pike.git/src/modules/SANE/sane.c:46:   static void push_device( SANE_Device *d )   {    push_text( "name" ); push_text( d->name );    push_text( "vendor" ); push_text( d->vendor );    push_text( "model" ); push_text( d->model );    push_text( "type" ); push_text( d->type );    f_aggregate_mapping( 8 );   }       + /* + **! method array(mapping) list-scanners() + **! + **! Returns an array with all available scanners. + **! + **! Example: + **! <pre> + **! Pike v0.7 release 120 running Hilfe v2.0 (Incremental Pike Frontend) + **! > SANE.list_scanners(); + **! Result: ({ + **! ([ + **! "model":"Astra 1220S ", + **! "name":"umax:/dev/scg1f", + **! "type":"flatbed scanner", + **! "vendor":"UMAX " + **! ]), + **! ([ + **! "model":"Astra 1220S ", + **! "name":"net:lain.idonex.se:umax:/dev/scg1f", + **! "type":"flatbed scanner", + **! "vendor":"UMAX " + **! ]) + **! }) + **! + **! </pre> + */   static void f_list_scanners( INT32 args )   {    SANE_Device **devices;    int i = 0;       if( !sane_is_inited ) init_sane();    switch( sane_get_devices( (void *)&devices, 0 ) )    {    case 0:    while( devices[i] ) push_device( devices[i++] );
pike.git/src/modules/SANE/sane.c:158:    push_text( "list" );    for( i = 0; o->constraint.string_list[i]; i++ )    push_text( o->constraint.string_list[i] );    f_aggregate( i );    f_aggregate_mapping( 4 );    break;    }    f_aggregate_mapping( sp - osp );   }    + /* + **! class Scanner + **! Scanner s = Scanner( scanner name ) + */   static void f_scanner_create( INT32 args )   {    char *name;    if(!sane_is_inited) init_sane();    get_all_args( "create", args, "%s", &name );       if( sane_open( name, &THIS->h ) )    error("Failed to open scanner \"%s\"\n", name );   }    -  + /* + **! function array(mapping) list_options( ) + */   static void f_scanner_list_options( INT32 args )   {    int i, n;    const SANE_Option_Descriptor *d;    pop_n_elems( args );       for( i = 1; (d = sane_get_option_descriptor( THIS->h, i) ); i++ )    push_option_descriptor( d );    f_aggregate( i-1 );   }
pike.git/src/modules/SANE/sane.c:192:    const SANE_Option_Descriptor *d;    for( i = 1; (d = sane_get_option_descriptor( THIS->h, i ) ); i++ )    if(d->name && !strcmp( d->name, name ) )    {    *p = d;    return i;    }    error("No such option: %s\n", name );   }    +  + /* + **! function void set_option( string name, mixed new_value ) + **! function void set_option( string name ) + **! If no value is specified, the option is set to it's default value + */   static void f_scanner_set_option( INT32 args )   {    char *name;    int no;    SANE_Int int_value;    float float_value;    SANE_Int tmp;    const SANE_Option_Descriptor *d;    get_all_args( "set_option", args, "%s", &name );   
pike.git/src/modules/SANE/sane.c:235:    break;    }    } else {    int_value = 1;    sane_control_option( THIS->h, no, SANE_ACTION_SET_AUTO, &int_value, &tmp );    }    pop_n_elems( args );    push_int( 0 );   }    +  + /* + **! function mixed get_option( string name ) + */   static void f_scanner_get_option( INT32 args )   {    char *name;    int no;    SANE_Int int_value;    float f;    SANE_Int tmp;    const SANE_Option_Descriptor *d;    get_all_args( "get_option", args, "%s", &name );   
pike.git/src/modules/SANE/sane.c:273:    case SANE_TYPE_STRING:    sane_control_option( THIS->h, no, SANE_ACTION_GET_VALUE,    &name, &tmp );    pop_n_elems( args );    push_text( name );    case SANE_TYPE_GROUP:    break;    }   }    + /* + **! function mapping(string:int) get_parameters( ) + */   static void f_scanner_get_parameters( INT32 args )   {    SANE_Parameters p;    pop_n_elems( args );    sane_get_parameters( THIS->h, &p );    push_text( "format" ); push_int( p.format );    push_text( "last_frame" ); push_int( p.last_frame );    push_text( "lines" ); push_int( p.lines );    push_text( "depth" ); push_int( p.depth );    push_text( "pixels_per_line" ); push_int( p.pixels_per_line );
pike.git/src/modules/SANE/sane.c:352:    {    push_text( "Image.Image" );    APPLY_MASTER( "resolv", 1 );    image_program = program_from_svalue( sp - 1 );    sp--;/* Do not free image program.. */    }    if( !image_program )    error("No Image.Image?!\n");   }    + /* + **! function Image.Image simple_scan( ) + */   static void f_scanner_simple_scan( INT32 args )   {    SANE_Parameters p;    SANE_Handle h = THIS->h;    struct object *o;    rgb_group *r;          assert_image_program();   
pike.git/src/modules/SANE/sane.c:404:    get_comp_frame( h, &p, ((char *)r)+2 );    break;    }    }    while( !p.last_frame );       THREADS_DISALLOW();    push_object( o );   }    + /* + **! function void row_scan(function(Image.Image,int,Scanner:void) callback) + */   static void f_scanner_row_scan( INT32 args )   {    SANE_Parameters p;    SANE_Handle h = THIS->h;    struct svalue *s;    struct object *o;    rgb_group *r, or;    int i, nr;       if( sane_start( THIS->h ) ) error("Start failed\n");
pike.git/src/modules/SANE/sane.c:546:    {    set_read_callback( fd, 0, 0 );    free_object( c->o );    free_object( c->t );    free_svalue( &c->callback );    free( c->buffer );    free( c );    }   }    + /* + **! function void nonblocking_row_scan(function(Image.Image,int,Scanner,int:void) callback) + */   static void f_scanner_nonblocking_row_scan( INT32 args )   {    SANE_Parameters p;    SANE_Handle h = THIS->h;    struct svalue *s;    int fd;    struct row_scan_struct *rsp;       if( sane_start( THIS->h ) ) error("Start failed\n");    if( sane_get_parameters( THIS->h, &p ) ) error("Get parameters failed\n");