piuspatch  v0.1
USB addition to PIE backend
Data Structures | Defines | Typedefs | Enumerations | Functions | Variables
only-pie/backend/pie.c File Reference
#include "../include/sane/config.h"
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/time.h>
#include <unistd.h>
#include <stdint.h>
#include <math.h>
#include "../include/byteorder.h"
#include "../include/sane/sane.h"
#include "../include/sane/sanei.h"
#include "../include/sane/saneopts.h"
#include "../include/sane/sanei_scsi.h"
#include "../include/sane/sanei_usb.h"
#include "../include/sane/sanei_debug.h"
#include "../include/sane/sanei_backend.h"
#include "../include/sane/sanei_config.h"
#include "../include/sane/sanei_thread.h"
#include "../include/sane/sanei_ir.h"
#include "../include/sane/sanei_magic.h"
#include "pie-scsidef.h"
#include "pie_usb.h"

Go to the source code of this file.

Data Structures

struct  Pie_cal_info
 This defines the information needed during calibration of SCSI scanners. More...
struct  Pie_Device
 This structure holds the information about a physical scanner. More...
struct  Pie_Scanner
 This structure holds information about an instance of an 'opened' scanner. More...

Defines

#define BACKEND_NAME   pie
#define DBG_error0   0
#define DBG_error   1
#define DBG_sense   2
#define DBG_warning   3
#define DBG_inquiry   4
#define DBG_info   5
#define DBG_info2   6
#define DBG_proc   7
#define DBG_read   8
#define DBG_sane_init   10
#define DBG_sane_proc   11
#define DBG_sane_info   12
#define DBG_sane_option   13
#define DBG_dump   14
#define DBG_image   15
#define DBG_poke   16
#define BUILD   10
#define PIE_CONFIG_FILE   "pie.conf"
#define LINEART_STR   SANE_VALUE_SCAN_MODE_LINEART
#define HALFTONE_STR   SANE_VALUE_SCAN_MODE_HALFTONE
#define GRAY_STR   SANE_VALUE_SCAN_MODE_GRAY
#define COLOR_STR   SANE_VALUE_SCAN_MODE_COLOR
#define COLOR_IR_STR   "RGBI"
#define IR_NAME_STR   "swired"
#define IR_TITLE_STR   "Infrared processing"
#define IR_DESC_STR   "What to do with infrared plane";
#define IR_SPECT_STR   "Reduce red overlap"
#define IR_CLEAN_STR   "Remove dirt"
#define THE_NONE_STR   "None"
#define CROP_NAME_STR   "swcrop"
#define CROP_TITLE_STR   "Cropping"
#define CROP_DESC_STR   "How to crop the image";
#define CROP_OUTER_STR   "Outside"
#define CROP_INNER_STR   "Inside"
#define LINEART   1
#define HALFTONE   2
#define GRAYSCALE   3
#define RGB   4
#define RGBI   8
#define POST_SW_COLORS   (1 << 0) /* gain, negatives, ..., can be done at any time */
#define POST_SW_IRED   (1 << 1) /* remove spectral overlap, needs complete scan */
#define POST_SW_DIRT   (1 << 2) /* our digital lavabo, needs complete scan */
#define POST_SW_GRAIN   (1 << 3) /* smoothen a bit */
#define POST_SW_CROP
#define POST_SW_IRED_MASK   (POST_SW_IRED | POST_SW_DIRT)
#define POST_SW_ACCUM_MASK   (POST_SW_IRED_MASK | POST_SW_GRAIN | POST_SW_CROP)
#define CAL_MODE_PREVIEW   (INQ_CAP_FAST_PREVIEW)
#define CAL_MODE_FLATBED   0x00
#define CAL_MODE_ADF   (INQ_OPT_DEV_ADF)
#define CAL_MODE_TRANPSARENCY   (INQ_OPT_DEV_TP)
#define CAL_MODE_TRANPSARENCY1   (INQ_OPT_DEV_TP1)
#define min(a, b)   (((a)<(b))?(a):(b))
#define max(a, b)   (((a)>(b))?(a):(b))
#define DOWNLOAD_GAMMA_WAIT_TIME   (1000000)
#define SCAN_WAIT_TIME   (1000000)
#define SCAN_WARMUP_WAIT_TIME   (500000)
#define TUR_WAIT_TIME   (500000)
#define NO_PID   -1
#define DBG_DUMP(level, buf, n)   { if (DBG_LEVEL >= (level)) pie_dump_buffer(level,buf,n); }

Typedefs

typedef struct Pie_Device Pie_Device
 This structure holds the information about a physical scanner.
typedef struct Pie_Scanner Pie_Scanner
 This structure holds information about an instance of an 'opened' scanner.

Enumerations

enum  Pie_Option {
  OPT_NUM_OPTS = 0, OPT_MODE_GROUP, OPT_MODE, OPT_BIT_DEPTH,
  OPT_RESOLUTION, OPT_GEOMETRY_GROUP, OPT_TL_X, OPT_TL_Y,
  OPT_BR_X, OPT_BR_Y, OPT_ENHANCEMENT_GROUP, OPT_HALFTONE_PATTERN,
  OPT_SPEED, OPT_THRESHOLD, OPT_SW_CROP, OPT_SW_IRED,
  OPT_SW_GRAIN, OPT_SW_SRGB, OPT_SW_NEGA, OPT_GAMMA_VECTOR,
  OPT_GAMMA_VECTOR_R, OPT_GAMMA_VECTOR_G, OPT_GAMMA_VECTOR_B, OPT_ADVANCED_GROUP,
  OPT_PREVIEW, NUM_OPTIONS
}

Functions

static SANE_Status pie_usb_read_status (int dn, unsigned char *buf)
SANE_Status pie_usb_scsi_wrapper (int fd, const void *src, size_t src_size, void *dst, size_t *dst_size)
 The one and only entry for SCSI over USB command wrapping.
static SANE_Status pie_sense_handler (int scsi_fd, unsigned char *result, void *arg)
static SANE_Status pie_wait_scanner (Pie_Scanner *scanner)
static SANE_Status pie_send_exposure (Pie_Scanner *scanner)
static SANE_Status pie_send_highlight_shadow (Pie_Scanner *scanner)
static SANE_Status pie_power_save (Pie_Scanner *scanner, int time)
static SANE_Status pie_attach_one (const char *name)
static void pie_dump_buffer (int level, unsigned char *buf, int n)
 Debug output dumping hexadecimal bytes.
static SANE_Status pie_usb_poke_ints (char *filename, int *nums, int *len)
 Read white space separated integers from a text file.
static SANE_Status pie_usb_poke_bytes (char *filename, unsigned char *nums, int *len)
 Read white space separated bytes from a text file.
static SANE_Status pie_usb_write_pnm_file (char *filename, uint8_t *data, int depth, int channels, int pixels_per_line, int lines)
 Write RGB or grey scale image to a pnm file , with big endian byte order.
static SANE_Status pie_usb_shades_to_pnm (Pie_Scanner *scanner, char *name, int lines)
 Write a set of gray scale pnm files from shading data.
static SANE_Status pie_usb_write_control_sequence (SANE_Int dn, PIE_USB_Value_Data sequ[])
 Write a control sequence of value-data pairs to the scanner.
static SANE_Status pie_usb_ready_state (SANE_Int dn)
 Query the scanners state after the last USB transaction.
static SANE_Status pie_usb_write_scsi_cmd (SANE_Int dn, const SANE_Byte cmnd[6])
 Send 6 byte SCSI command to scanner.
static SANE_Status pie_usb_bulk_read (SANE_Int dn, SANE_Byte *data, size_t len)
 Read a lot of data.
static SANE_Status pie_usb_read (int dn, const SANE_Byte *cmnd, void *buf, size_t *buf_len)
 Do a SCSI read transaction over USB.
static SANE_Status pie_usb_write (int dn, const SANE_Byte *cmnd, size_t length)
 Do a SCSI write transaction over USB.
static SANE_Status pie_usb_command (int dn, const SANE_Byte *cmnd)
 Send a simple SCSI command without data transfer.
static SANE_Status pie_usb_request_sense (int dn, uint32_t *kascq)
 Send a Request Sense SCSI command to the scanner.
static SANE_Status pie_sense_handler (__sane_unused__ int scsi_fd, unsigned char *result, __sane_unused__ void *arg)
 Called by sanei_scsi_cmd or pie_usb_request_sense.
static void pie_init (Pie_Device *dev, SANE_Int is_USB)
static void pie_print_inquiry (Pie_Device *dev)
static void pie_get_inquiry_values (Pie_Device *dev, unsigned char *buffer)
static void pie_do_inquiry (Pie_Device *dev, int sfd, unsigned char *buffer)
static int pie_identify_scanner (Pie_Device *dev, int sfd, int is_USB)
static void pie_get_speeds (Pie_Device *dev)
static void pie_get_halftones (Pie_Device *dev, int sfd)
static void pie_get_cal_info (Pie_Device *dev, int sfd)
static SANE_Status pie_usb_attach_open (SANE_String_Const devname, SANE_Int *dn)
 Try to open and identify an USB scanner class.
static SANE_Status pie_usb_try_attach (const char *name)
 Callback function for sanei_config_attach_matching_devices.
static SANE_Status pie_attach_scanner (const char *devicename, Pie_Device **devp)
static size_t max_string_size (SANE_String_Const strings[])
static SANE_Status pie_init_options (Pie_Scanner *scanner)
static SANE_Status pie_usb_wait_scanner (Pie_Scanner *scanner, int secs)
 TEST_UNIT_READY until ready or timed out.
static int pie_usb_release_scanner (void *passed)
 Release scanner after image aquisition.
static SANE_Status pie_usb_is_scanner_released (Pie_Scanner *scanner)
 Waits until a pie_usb_release_scanner has finished.
static SANE_Status pie_usb_is_scanner_initialized (int dn)
 Wait for internal initialization of scanner.
static SANE_Status pie_usb_copy_sensors (Pie_Scanner *scanner)
 Read a vector indicating which sensor elements are used.
static SANE_Status pie_usb_scan (Pie_Scanner *scanner, int start)
 Perform SCAN command.
static SANE_Status pie_usb_set_window (Pie_Scanner *scanner)
 Issue SET_SCAN_FRAME via a SCSI WRITE command.
static SANE_Status pie_usb_mode_select (Pie_Scanner *scanner)
 Setup and send MODE command.
static SANE_Status pie_usb_get_params (Pie_Scanner *scanner)
 Send SCSI PARAM command.
static void pie_usb_calicalc_hiqual (Pie_Scanner *scanner, PIE_USB_Calibration_Read *d7cal)
 Calculate gain and exposure for quality mode.
static void pie_usb_calicalc_normal (Pie_Scanner *scanner, PIE_USB_Calibration_Read *d7cal)
static unsigned char pie_usb_calicalc_slow_down (Pie_Scanner *scanner)
 Calculate coefficient for slowing down the scan.
static SANE_Status pie_usb_calibration_send (Pie_Scanner *scanner, int calc_cal)
 Read first and then send calibration.
static SANE_Status pie_usb_calibrate (Pie_Scanner *scanner)
 Do a full calibration of the scanner.
static void pie_usb_correct_shading (Pie_Scanner *scanner, unsigned char *in_buf[4], SANEI_IR_bufptr out_buf[4], int pixels, int bits, int start_plane, int end_plane)
 Do shading and mirror correction on an image line.
static void pie_usb_reader_reorder (Pie_Scanner *scanner, SANEI_IR_bufptr *in_img, SANEI_IR_bufptr out_img, int planes, int pixels)
 Interleave RGB(I) and do color lookup.
static SANE_Status pie_usb_sw_store (Pie_Scanner *scanner, SANEI_IR_bufptr *in_img, int planes)
 Interleave RGB(I), do color lookup and store data.
static SANE_Status pie_usb_reader_write (Pie_Scanner *scanner, FILE *fp, SANEI_IR_bufptr *in_img, int planes, int lines)
 Interleave RGB(I), do color lookup and write data to pipe.
static SANE_Status pie_usb_smoothen_rgb (const SANE_Parameters *params, SANEI_IR_bufptr *the_img, int win_size)
 Apply triangular blur to R, G, B image data.
static SANE_Status pie_usb_sw_crop_planes (SANE_Parameters *parameters, Pie_Scanner *scanner, SANEI_IR_bufptr *in_img, int top, int bot, int left, int right, int planes)
 Crop separate color planes of an image.
static SANE_Status pie_usb_sw_final_crop (Pie_Scanner *scanner)
 Crop the final complete RGB image.
static SANE_Status pie_usb_sw_post (Pie_Scanner *scanner, SANEI_IR_bufptr *in_img, int planes, int out_planes)
 Postprocess a scanned R, G, B(, I) image.
static SANE_Status pie_usb_reader_indexed (Pie_Scanner *scanner, FILE *fp)
 Read indexed image data from scanner.
static SANE_Status pie_usb_do_cancel (Pie_Scanner *scanner, int park)
 Perform actions necessary to abort scan.
static RETSIGTYPE pie_usb_reader_process_sigterm_handler (__sane_unused__ int signal)
 Set a variable to indicate cancel request.
static SANE_Status pie_usb_reader_unthreaded (Pie_Scanner *scanner)
 Read and store whole image.
static int pie_usb_reader_process (void *data)
 Setup child process / thread for reading and piping out an image.
static SANE_Status pie_usb_sane_control_option (SANE_Handle handle, SANE_Int option, SANE_Action action, void *val, SANE_Int *info)
 Set or inquire the current value of an option.
static SANE_Status pie_usb_sane_start (Pie_Scanner *scanner)
 Initiates aquisition of an image.
static SANE_Status pie_usb_sane_read (Pie_Scanner *scanner, SANE_Byte *buf, SANE_Int max_len, SANE_Int *len)
 Read image data out of buffer or from the device.
static SANE_Status pie_usb_sane_open (Pie_Scanner *scanner, SANE_Handle *handle)
 Establish a connection to a scanner.
static void pie_usb_sane_close (Pie_Scanner *scanner)
 Terminate the association between scanner and scanner structure.
static SANE_Status pie_send_exposure_one (Pie_Scanner *scanner, int filter, int value)
static SANE_Status pie_send_highlight_shadow_one (Pie_Scanner *scanner, int filter, int highlight, int shadow)
static SANE_Status pie_perform_cal (Pie_Scanner *scanner, int cal_index)
static SANE_Status pie_do_cal (Pie_Scanner *scanner)
static SANE_Status pie_dwnld_gamma_one (Pie_Scanner *scanner, int filter, SANE_Int *table)
static SANE_Status pie_dwnld_gamma (Pie_Scanner *scanner)
static SANE_Status pie_set_window (Pie_Scanner *scanner)
static SANE_Status pie_mode_select (Pie_Scanner *scanner)
static SANE_Status pie_scan (Pie_Scanner *scanner, int start)
static SANE_Status pie_get_params (Pie_Scanner *scanner)
static SANE_Status pie_grab_scanner (Pie_Scanner *scanner)
static SANE_Status pie_give_scanner (Pie_Scanner *scanner)
static int pie_reader_process_indexed (Pie_Scanner *scanner, FILE *fp)
static int pie_reader_process_fmtline (Pie_Scanner *scanner, FILE *fp)
static RETSIGTYPE pie_reader_process_sigterm_handler (int signal)
static int pie_reader_process (void *data)
static SANE_Status pie_close_pipe (Pie_Scanner *scanner)
static SANE_Status pie_do_cancel (Pie_Scanner *scanner)
SANE_Status sane_init (SANE_Int *version_code, SANE_Auth_Callback __sane_unused__ authorize)
void sane_exit (void)
SANE_Status sane_get_devices (const SANE_Device ***device_list, SANE_Bool __sane_unused__ local_only)
SANE_Status sane_open (SANE_String_Const devicename, SANE_Handle *handle)
void sane_close (SANE_Handle handle)
const SANE_Option_Descriptor * sane_get_option_descriptor (SANE_Handle handle, SANE_Int option)
SANE_Status sane_control_option (SANE_Handle handle, SANE_Int option, SANE_Action action, void *val, SANE_Int *info)
SANE_Status sane_get_parameters (SANE_Handle handle, SANE_Parameters *params)
SANE_Status sane_start (SANE_Handle handle)
SANE_Status sane_read (SANE_Handle handle, SANE_Byte *buf, SANE_Int max_len, SANE_Int *len)
void sane_cancel (SANE_Handle handle)
SANE_Status sane_set_io_mode (SANE_Handle handle, SANE_Bool non_blocking)
SANE_Status sane_get_select_fd (SANE_Handle handle, SANE_Int *fd)

Variables

static char * scanner_str []
static volatile sig_atomic_t cancel_requ
static const SANE_Range percentage_range_100
static Pie_Devicefirst_dev = NULL
static Pie_Scannerfirst_handle = NULL
static const SANE_Device ** devlist = NULL
static PIE_USB_Model crystalscan_7200_model
static PIE_USB_Model proscan_7200_model
static PIE_USB_Device_Entry pie_usb_device_list []

Detailed Description

Copyright (C) 2000 Simon Munton, based on the umax backend by Oliver Rauch

Copyright (C) 2012 Michael Rickmann <mrickma@gwdg.de> for initial SCSI over USB additions

This file is part of the SANE package.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

As a special exception, the authors of SANE give permission for additional uses of the libraries contained in this release of SANE.

The exception is that, if you link a SANE library with other files to produce an executable, this does not by itself cause the resulting executable to be covered by the GNU General Public License. Your use of that executable is in no way restricted on account of linking the SANE library code into it.

This exception does not, however, invalidate any other reasons why the executable file might be covered by the GNU General Public License.

If you submit changes to SANE to the maintainers to be included in a subsequent release, you agree by submitting the changes that those changes may be distributed with this exception intact.

If you write modifications of your own for SANE, it is your choice whether to permit this exception to apply to your modifications. If you do not wish that, delete this exception notice.


History

19-8-2012 add PIE "SF Scanner" USB film scanner support

19-8-2012 the names of all internal functions start with pie_ now

22-2-2003 set devlist to NULL in sane_exit() set first_dev to NULL in sane_exit() eliminated num_devices

23-7-2002 added TL_X > BR_X, TL_Y > BR_Y check in sane_start

17-9-2001 changed ADLIB to AdLib as the comparison is case sensitive and the scanner returns AdLib

7-5-2001 removed removal of '
' after sanei_config_read() free devlist allocated in sane_get_devices() on sane_exit()

2-3-2001 improved the reordering of RGB data in pie_reader_process()

11-11-2000 eliminated some warnings about signed/unsigned comparisons removed #undef NDEBUG and C++ style comments

1-10-2000 force gamma table to one to one mappping if lineart or halftone selected

30-9-2000 added ADLIB devices to scanner_str[]

29-9-2000 wasn't setting 'background is halftone bit' (BGHT) in halftone mode

27-9-2000 went public with build 4


The source code is divided in sections which you can find by searching for the tag "@@"

Definition in file pie.c.


Define Documentation

#define BACKEND_NAME   pie

Definition at line 122 of file pie.c.

#define BUILD   10

Definition at line 156 of file pie.c.

#define CAL_MODE_ADF   (INQ_OPT_DEV_ADF)

Definition at line 205 of file pie.c.

#define CAL_MODE_FLATBED   0x00

Definition at line 204 of file pie.c.

Definition at line 203 of file pie.c.

Definition at line 206 of file pie.c.

Definition at line 207 of file pie.c.

#define COLOR_IR_STR   "RGBI"

Definition at line 166 of file pie.c.

#define COLOR_STR   SANE_VALUE_SCAN_MODE_COLOR

Definition at line 165 of file pie.c.

#define CROP_DESC_STR   "How to crop the image";

Definition at line 178 of file pie.c.

#define CROP_INNER_STR   "Inside"

Definition at line 180 of file pie.c.

#define CROP_NAME_STR   "swcrop"

Definition at line 176 of file pie.c.

#define CROP_OUTER_STR   "Outside"

Definition at line 179 of file pie.c.

#define CROP_TITLE_STR   "Cropping"

Definition at line 177 of file pie.c.

#define DBG_dump   14

Definition at line 152 of file pie.c.

#define DBG_DUMP (   level,
  buf,
 
)    { if (DBG_LEVEL >= (level)) pie_dump_buffer(level,buf,n); }

Definition at line 469 of file pie.c.

#define DBG_error   1

Definition at line 139 of file pie.c.

#define DBG_error0   0

Definition at line 138 of file pie.c.

#define DBG_image   15

Definition at line 153 of file pie.c.

#define DBG_info   5

Definition at line 144 of file pie.c.

#define DBG_info2   6

Definition at line 145 of file pie.c.

#define DBG_inquiry   4

Definition at line 142 of file pie.c.

#define DBG_poke   16

Definition at line 154 of file pie.c.

#define DBG_proc   7

Definition at line 146 of file pie.c.

#define DBG_read   8

Definition at line 147 of file pie.c.

#define DBG_sane_info   12

Definition at line 150 of file pie.c.

#define DBG_sane_init   10

Definition at line 148 of file pie.c.

#define DBG_sane_option   13

Definition at line 151 of file pie.c.

#define DBG_sane_proc   11

Definition at line 149 of file pie.c.

#define DBG_sense   2

Definition at line 140 of file pie.c.

#define DBG_warning   3

Definition at line 141 of file pie.c.

#define DOWNLOAD_GAMMA_WAIT_TIME   (1000000)

Definition at line 242 of file pie.c.

#define GRAY_STR   SANE_VALUE_SCAN_MODE_GRAY

Definition at line 164 of file pie.c.

#define GRAYSCALE   3

Definition at line 186 of file pie.c.

#define HALFTONE   2

Definition at line 185 of file pie.c.

#define HALFTONE_STR   SANE_VALUE_SCAN_MODE_HALFTONE

Definition at line 163 of file pie.c.

#define IR_CLEAN_STR   "Remove dirt"

Definition at line 172 of file pie.c.

#define IR_DESC_STR   "What to do with infrared plane";

Definition at line 170 of file pie.c.

#define IR_NAME_STR   "swired"

Definition at line 168 of file pie.c.

#define IR_SPECT_STR   "Reduce red overlap"

Definition at line 171 of file pie.c.

#define IR_TITLE_STR   "Infrared processing"

Definition at line 169 of file pie.c.

#define LINEART   1

Definition at line 184 of file pie.c.

#define LINEART_STR   SANE_VALUE_SCAN_MODE_LINEART

Definition at line 162 of file pie.c.

#define max (   a,
 
)    (((a)>(b))?(a):(b))

Definition at line 210 of file pie.c.

#define min (   a,
 
)    (((a)<(b))?(a):(b))

Definition at line 209 of file pie.c.

#define NO_PID   -1

Definition at line 251 of file pie.c.

#define PIE_CONFIG_FILE   "pie.conf"

Definition at line 158 of file pie.c.

Definition at line 199 of file pie.c.

#define POST_SW_COLORS   (1 << 0) /* gain, negatives, ..., can be done at any time */

Definition at line 193 of file pie.c.

#define POST_SW_CROP
Value:
(1 << 4)        /* trim whole image in sane_start
                                                   before sane_get_parameters() is answered */

Definition at line 197 of file pie.c.

#define POST_SW_DIRT   (1 << 2) /* our digital lavabo, needs complete scan */

Definition at line 195 of file pie.c.

#define POST_SW_GRAIN   (1 << 3) /* smoothen a bit */

Definition at line 196 of file pie.c.

#define POST_SW_IRED   (1 << 1) /* remove spectral overlap, needs complete scan */

Definition at line 194 of file pie.c.

Definition at line 198 of file pie.c.

#define RGB   4

Definition at line 187 of file pie.c.

#define RGBI   8

Definition at line 189 of file pie.c.

#define SCAN_WAIT_TIME   (1000000)

Definition at line 243 of file pie.c.

#define SCAN_WARMUP_WAIT_TIME   (500000)

Definition at line 244 of file pie.c.

#define THE_NONE_STR   "None"

Definition at line 174 of file pie.c.

#define TUR_WAIT_TIME   (500000)

Definition at line 245 of file pie.c.


Typedef Documentation

typedef struct Pie_Device Pie_Device

This structure holds the information about a physical scanner.

typedef struct Pie_Scanner Pie_Scanner

This structure holds information about an instance of an 'opened' scanner.


Enumeration Type Documentation

enum Pie_Option

This option list has to contain all options for all SCSI and USB scanners supported by this driver. If a certain scanner cannot handle a certain option, there's the possibility to say so, later.

Enumerator:
OPT_NUM_OPTS 
OPT_MODE_GROUP 
OPT_MODE 
OPT_BIT_DEPTH 
OPT_RESOLUTION 
OPT_GEOMETRY_GROUP 
OPT_TL_X 
OPT_TL_Y 
OPT_BR_X 
OPT_BR_Y 
OPT_ENHANCEMENT_GROUP 
OPT_HALFTONE_PATTERN 
OPT_SPEED 
OPT_THRESHOLD 
OPT_SW_CROP 
OPT_SW_IRED 
OPT_SW_GRAIN 
OPT_SW_SRGB 
OPT_SW_NEGA 
OPT_GAMMA_VECTOR 
OPT_GAMMA_VECTOR_R 
OPT_GAMMA_VECTOR_G 
OPT_GAMMA_VECTOR_B 
OPT_ADVANCED_GROUP 
OPT_PREVIEW 
NUM_OPTIONS 

Definition at line 259 of file pie.c.


Function Documentation

static size_t max_string_size ( SANE_String_Const  strings[]) [static]

Definition at line 2459 of file pie.c.

static SANE_Status pie_attach_one ( const char *  name) [static]

Definition at line 7191 of file pie.c.

static SANE_Status pie_attach_scanner ( const char *  devicename,
Pie_Device **  devp 
) [static]

Definition at line 2272 of file pie.c.

static SANE_Status pie_close_pipe ( Pie_Scanner scanner) [static]

Definition at line 7201 of file pie.c.

static SANE_Status pie_do_cal ( Pie_Scanner scanner) [static]

Definition at line 6260 of file pie.c.

static SANE_Status pie_do_cancel ( Pie_Scanner scanner) [static]

Definition at line 7220 of file pie.c.

static void pie_do_inquiry ( Pie_Device dev,
int  sfd,
unsigned char *  buffer 
) [static]

Definition at line 1863 of file pie.c.

static void pie_dump_buffer ( int  level,
unsigned char *  buf,
int  n 
) [static]

Debug output dumping hexadecimal bytes.

Parameters:
[in]leveldebug level at which to dump
[in]bufcontains what to dump
[in]nnumber of bytes to dump

Definition at line 540 of file pie.c.

static SANE_Status pie_dwnld_gamma ( Pie_Scanner scanner) [static]

Definition at line 6355 of file pie.c.

static SANE_Status pie_dwnld_gamma_one ( Pie_Scanner scanner,
int  filter,
SANE_Int *  table 
) [static]

Definition at line 6286 of file pie.c.

static void pie_get_cal_info ( Pie_Device dev,
int  sfd 
) [static]

Definition at line 2118 of file pie.c.

static void pie_get_halftones ( Pie_Device dev,
int  sfd 
) [static]

Definition at line 2051 of file pie.c.

static void pie_get_inquiry_values ( Pie_Device dev,
unsigned char *  buffer 
) [static]

Definition at line 1796 of file pie.c.

static SANE_Status pie_get_params ( Pie_Scanner scanner) [static]

Definition at line 6714 of file pie.c.

static void pie_get_speeds ( Pie_Device dev) [static]

Definition at line 2018 of file pie.c.

static SANE_Status pie_give_scanner ( Pie_Scanner scanner) [static]

Definition at line 6832 of file pie.c.

static SANE_Status pie_grab_scanner ( Pie_Scanner scanner) [static]

Definition at line 6798 of file pie.c.

static int pie_identify_scanner ( Pie_Device dev,
int  sfd,
int  is_USB 
) [static]

Definition at line 1896 of file pie.c.

static void pie_init ( Pie_Device dev,
SANE_Int  is_USB 
) [static]

Definition at line 1659 of file pie.c.

static SANE_Status pie_init_options ( Pie_Scanner scanner) [static]

Definition at line 2481 of file pie.c.

static SANE_Status pie_mode_select ( Pie_Scanner scanner) [static]

Definition at line 6461 of file pie.c.

static SANE_Status pie_perform_cal ( Pie_Scanner scanner,
int  cal_index 
) [static]

Definition at line 5969 of file pie.c.

static SANE_Status pie_power_save ( Pie_Scanner scanner,
int  time 
) [static]

Definition at line 5797 of file pie.c.

static void pie_print_inquiry ( Pie_Device dev) [static]

Definition at line 1692 of file pie.c.

static int pie_reader_process ( void *  data) [static]

Definition at line 7132 of file pie.c.

static int pie_reader_process_fmtline ( Pie_Scanner scanner,
FILE *  fp 
) [static]

Definition at line 7038 of file pie.c.

static int pie_reader_process_indexed ( Pie_Scanner scanner,
FILE *  fp 
) [static]

Definition at line 6857 of file pie.c.

static RETSIGTYPE pie_reader_process_sigterm_handler ( int  signal) [static]

Definition at line 7113 of file pie.c.

static SANE_Status pie_scan ( Pie_Scanner scanner,
int  start 
) [static]

Definition at line 6632 of file pie.c.

static SANE_Status pie_send_exposure ( Pie_Scanner scanner) [static]

Definition at line 5877 of file pie.c.

static SANE_Status pie_send_exposure_one ( Pie_Scanner scanner,
int  filter,
int  value 
) [static]

Definition at line 5836 of file pie.c.

static SANE_Status pie_send_highlight_shadow ( Pie_Scanner scanner) [static]

Definition at line 5945 of file pie.c.

static SANE_Status pie_send_highlight_shadow_one ( Pie_Scanner scanner,
int  filter,
int  highlight,
int  shadow 
) [static]

Definition at line 5902 of file pie.c.

static SANE_Status pie_sense_handler ( int  scsi_fd,
unsigned char *  result,
void *  arg 
) [static]
static SANE_Status pie_sense_handler ( __sane_unused__ int  scsi_fd,
unsigned char *  result,
__sane_unused__ void *  arg 
) [static]

Called by sanei_scsi_cmd or pie_usb_request_sense.

Parameters:
[in]resultpoints to data returned by a request sense command
Returns:
  • SANE_STATUS_DEVICE_BUSY - sense key invalid
  • SANE_STATUS_IO_ERROR - no sense, hardware error, illegal request, unit attention or vendor specific

Except for debug output and the return value no major action.

Definition at line 1382 of file pie.c.

static SANE_Status pie_set_window ( Pie_Scanner scanner) [static]

Definition at line 6402 of file pie.c.

static SANE_Status pie_usb_attach_open ( SANE_String_Const  devname,
SANE_Int *  dn 
) [static]

Try to open and identify an USB scanner class.

Parameters:
[in]devnamename of the device to open
[out]dnUSB device number
Returns:
  • SANE_STATUS_GOOD - on success
  • SANE_STATUS_ACCESS_DENIED - no access to file due to permissions
  • SANE_STATUS_UNSUPPORTED - if the OS doesn't support detection of ids
  • SANE_STATUS_INVAL - not in our list of supported devices

Definition at line 2205 of file pie.c.

static SANE_Status pie_usb_bulk_read ( SANE_Int  dn,
SANE_Byte *  data,
size_t  len 
) [static]

Read a lot of data.

Parameters:
[in]dnUSB device number
[out]datapoints to buffer receiving data
lenRequested / received number of bytes
Returns:
  • SANE_STATUS_GOOD - on success
  • SANE_STATUS_IO_ERROR - if an error occurred during the write
  • SANE_STATUS_INVAL - unexpected value was read
  • SANE_STATUS_EOF - if zero bytes have been read
  • SANE_STATUS_INVAL - on every other error

Definition at line 989 of file pie.c.

static SANE_Status pie_usb_calibrate ( Pie_Scanner scanner) [static]

Do a full calibration of the scanner.

Parameters:
[in]scannerpoints to structure of opened scanner
Returns:
  • SANE_STATUS_GOOD - on success
  • SANE_STATUS_IO_ERROR - if an error occurred during the write
  • SANE_STATUS_INVAL - unexpected value was read
  • SANE_STATUS_EOF - if zero bytes have been read
  • SANE_STATUS_INVAL - on every other error
  • SANE_STATUS_DEVICE_BUSY - scanner is busy
  • SANE_STATUS_NO_MEM - buffer allocation failed
Note:
This routine is called in opm_quality mode and when modes have changed after the SCAN command. It acts as follows
  • 1 line of image data is read
  • test unit ready
  • 13 lines are read in indexed RGBI
  • something should be learned from that
  • calibration info is read, calculated and sent to the scanner
  • dump left over lines Number of all lines in scanner->device->cal_info[any].num_lines

Definition at line 3858 of file pie.c.

static SANE_Status pie_usb_calibration_send ( Pie_Scanner scanner,
int  calc_cal 
) [static]

Read first and then send calibration.

Parameters:
[in]scannerPointer to structure of opened scanner
[in]calc_calIf !=0, calculate parameters in between
Returns:
  • SANE_STATUS_GOOD - on success
  • SANE_STATUS_IO_ERROR - if an error occurred during the write
  • SANE_STATUS_INVAL - unexpected value was read
  • SANE_STATUS_EOF - if zero bytes have been read
  • SANE_STATUS_INVAL - on every other error
  • SANE_STATUS_DEVICE_BUSY - scanner is busy
Note:
This routine contains the vendor SCSI commands 0xd7 for reading and 0xdc for writing. As in the logs we first read 103 bytes and then write 23 bytes. Only R G and B exposure times (texp), gains and slow_down values are calibrated all other values are copied from the 0xd7 read.

Definition at line 3748 of file pie.c.

static void pie_usb_calicalc_hiqual ( Pie_Scanner scanner,
PIE_USB_Calibration_Read d7cal 
) [static]

Calculate gain and exposure for quality mode.

Parameters:
[in]scannerpoints to structure of opened scanner
[in]d7calpoints to calibration data read by a PIE_READ_CALIBRATION command
Note:
Empirical data show that in quality mode for a color (j) the illumination (Ij) reached with certain gain (gj) and exposure time (tj) settings can be described by (I) Ij = aj * exp (c * gj^2) * tj . The gain constants gj and desired brightness has to be provided. All other values can be derived from the calibration lines or the 0xd7 read. In quality mode maximal gain is limited and most of the calibration is done with exposure time. The result of this routine is stored in scanner->cal_data.

Definition at line 3491 of file pie.c.

static void pie_usb_calicalc_normal ( Pie_Scanner scanner,
PIE_USB_Calibration_Read d7cal 
) [static]

Definition at line 3600 of file pie.c.

static unsigned char pie_usb_calicalc_slow_down ( Pie_Scanner scanner) [static]

Calculate coefficient for slowing down the scan.

Parameters:
[in]scannerpoints to structure of opened scanner
Returns:
  • calculated coefficient
Note:
At high resolutions to much data seem to be delivered to the scanners' USB interface. So we have to slow down. As we do not have the results from the PARAMS call yet calculate from our internal values.

Definition at line 3686 of file pie.c.

static SANE_Status pie_usb_command ( int  dn,
const SANE_Byte *  cmnd 
) [static]

Send a simple SCSI command without data transfer.

Parameters:
[in]dnUSB device number
[in]cmndpoints to SCSI command bytes
Returns:
  • SANE_STATUS_GOOD - on success
  • SANE_STATUS_EOF - if zero bytes have been read
  • SANE_STATUS_IO_ERROR - something got screwed up
  • SANE_STATUS_INVAL - on every other error
  • SANE_STATUS_DEVICE_BUSY - scanner is busy

Definition at line 1165 of file pie.c.

static SANE_Status pie_usb_copy_sensors ( Pie_Scanner scanner) [static]

Read a vector indicating which sensor elements are used.

Parameters:
[in]scannerpoints to structure of opened scanner
Returns:
  • SANE_STATUS_GOOD - on success
  • SANE_STATUS_IO_ERROR - if an error occurred during the write
  • SANE_STATUS_INVAL - unexpected value was read
  • SANE_STATUS_EOF - if zero bytes have been read
  • SANE_STATUS_DEVICE_BUSY - scanner is busy, timed out
Note:
pie_usb_copy_sensors reads a vector consisting of 0x00 and 0x70 before image aquisition. 0x00 indicates that the sensor element is used for the following image. The vector is stored in the scanner structure and used for shading correction.

Definition at line 3049 of file pie.c.

static void pie_usb_correct_shading ( Pie_Scanner scanner,
unsigned char *  in_buf[4],
SANEI_IR_bufptr  out_buf[4],
int  pixels,
int  bits,
int  start_plane,
int  end_plane 
) [static]

Do shading and mirror correction on an image line.

Parameters:
[in]scannerpoints to structure of opened scanner
[in]in_bufArray of pointers to separate R, G, B, I input data
[out]out_bufArray of pointers to corrected data
[in]pixelsLine width
[in]bitsbit depth of data
[in]start_planecolor plane to start with
[in]end_planecolor plane to end with
Note:
This routine should be called as soon as possible after a line has been read as it provides the right endianess.

Definition at line 4017 of file pie.c.

static SANE_Status pie_usb_do_cancel ( Pie_Scanner scanner,
int  park 
) [static]

Perform actions necessary to abort scan.

Parameters:
[in]scannerpoints to structure of opened scanner
Returns:
  • SANE_STATUS_CANCELLED All done

Definition at line 5096 of file pie.c.

static SANE_Status pie_usb_get_params ( Pie_Scanner scanner) [static]

Send SCSI PARAM command.

Parameters:
[in]scannerpoints to structure of opened scanner
Returns:
  • SANE_STATUS_GOOD - success
  • SANE_STATUS_INVAL - received unexpected value
  • SANE_STATUS_DEVICE_BUSY - scanner is busy
  • SANE_STATUS_IO_ERROR - something got screwed up
  • SANE_STATUS_EOF - if zero bytes have been read
  • SANE_STATUS_UNSUPPORTED - if the feature is not supported
Todo:
Merge back with pie_get_params

Definition at line 3400 of file pie.c.

static SANE_Status pie_usb_is_scanner_initialized ( int  dn) [static]

Wait for internal initialization of scanner.

Parameters:
[in]dnUSB device number
Returns:
  • SANE_STATUS_GOOD - success
  • SANE_STATUS_INVAL - received unexpected value
  • SANE_STATUS_DEVICE_BUSY - scanner is busy
  • SANE_STATUS_IO_ERROR - something got screwed up
  • SANE_STATUS_EOF - if zero bytes have been read
  • SANE_STATUS_UNSUPPORTED - if the feature is not supported
Note:
During its initialization the scanner becomes easily screwed up. This series of commands, however, is answered reliably.

Definition at line 2968 of file pie.c.

static SANE_Status pie_usb_is_scanner_released ( Pie_Scanner scanner) [static]

Waits until a pie_usb_release_scanner has finished.

Parameters:
[in]scannerpoints to structure of opened scanner
Returns:
  • SANE_STATUS_GOOD - Gracefully finished
  • SANE_STATUS_IO_ERROR - Timed out

Definition at line 2913 of file pie.c.

static SANE_Status pie_usb_mode_select ( Pie_Scanner scanner) [static]

Setup and send MODE command.

Parameters:
[in]scannerpoints to structure of opened scanner
Returns:
  • SANE_STATUS_GOOD - success
  • SANE_STATUS_INVAL - received unexpected value
  • SANE_STATUS_DEVICE_BUSY - scanner is busy
  • SANE_STATUS_IO_ERROR - something got screwed up
  • SANE_STATUS_UNSUPPORTED - if the feature is not supported
Note:
data[9] sets what sort of calibration sequence the scanner will expect. Its value may differ between different types of scanners.

Definition at line 3255 of file pie.c.

static SANE_Status pie_usb_poke_bytes ( char *  filename,
unsigned char *  nums,
int *  len 
) [static]

Read white space separated bytes from a text file.

Parameters:
[in]filenamename of file to read from
[out]numsPointer to buffer to store the data
[in]lennumber of integers to read
Returns:
  • SANE_STATUS_GOOD - on success
  • SANE_STATUS_INVAL - if the file could not be read

Use this function to override and test calibration.

Definition at line 637 of file pie.c.

static SANE_Status pie_usb_poke_ints ( char *  filename,
int *  nums,
int *  len 
) [static]

Read white space separated integers from a text file.

Parameters:
[in]filenamename of file to read from
[out]numsPointer to buffer to store the data
[in]lennumber of integers to read
Returns:
  • SANE_STATUS_GOOD - on success
  • SANE_STATUS_INVAL - if the file could not be read

Use this function to override and test calibration.

Definition at line 577 of file pie.c.

static SANE_Status pie_usb_read ( int  dn,
const SANE_Byte *  cmnd,
void *  buf,
size_t *  buf_len 
) [static]

Do a SCSI read transaction over USB.

Parameters:
[in]dnUSB device number
[in]cmndSCSI command used for transaction
[out]bufpoints to buffer receiving
[in]buf_lenrequested number of bytes
Returns:
  • SANE_STATUS_GOOD - success
  • SANE_STATUS_INVAL - received unexpected value
  • SANE_STATUS_DEVICE_BUSY - scanner is busy
  • SANE_STATUS_IO_ERROR - something got screwed up
  • SANE_STATUS_EOF - if zero bytes have been read
  • SANE_STATUS_UNSUPPORTED - if the feature is not supported
Note:
The transfer length in a 6-byte READ command can have two meanings, Normally it means length in bytes, however, when an image is read it amounts to (lines * color-planes).

Definition at line 1073 of file pie.c.

static SANE_Status pie_usb_read_status ( int  dn,
unsigned char *  buf 
) [static]

Issue PIE vendor specific 0xdd PIE_READ_STATUS command

Parameters:
[in]dnUSB device number
[out]bufferPointer to buffer receiving 11 bytes
Returns:
  • SANE_STATUS_GOOD - on success
  • SANE_STATUS_IO_ERROR - if an error occurred during the write
  • SANE_STATUS_INVAL - unexpected value was read
  • SANE_STATUS_EOF - if zero bytes have been read
  • SANE_STATUS_INVAL - on every other error
  • SANE_STATUS_DEVICE_BUSY - scanner is busy

Definition at line 1636 of file pie.c.

static SANE_Status pie_usb_reader_indexed ( Pie_Scanner scanner,
FILE *  fp 
) [static]

Read indexed image data from scanner.

Parameters:
[in]scannerpoints to structure of opened scanner
[in]fppipe to write output
Returns:
  • SANE_STATUS_GOOD - success
  • SANE_STATUS_IO_ERROR - if an error occurred during I/O
  • SANE_STATUS_INVAL - unexpected value was read
  • SANE_STATUS_EOF - if zero bytes have been read
  • SANE_STATUS_DEVICE_BUSY - scanner is busy, timed out
  • SANE_STATUS_NO_MEM - could not allocate buffer
Note:
Necessarily can not be read from as the scanner does not sequentially send the R, G, B, I planes. Several lines may have to be stored before a complete one can be assembled.

Definition at line 4705 of file pie.c.

static int pie_usb_reader_process ( void *  data) [static]

Setup child process / thread for reading and piping out an image.

Parameters:
[in]dataPointer to structure of opened scanner

@ return

  • SANE_STATUS_GOOD - success
  • SANE_STATUS_IO_ERROR - if an error occurred during I/O
  • SANE_STATUS_INVAL - unexpected value was read
  • SANE_STATUS_EOF - if zero bytes have been read
  • SANE_STATUS_DEVICE_BUSY - scanner is busy, timed out
  • SANE_STATUS_NO_MEM - could not allocate buffer
  • SANE_STATUS_UNSUPPORTED - color format not supported
Note:
This routine is quite useful if data can be delivered continuously to the frontend, it is useless if the image has to be cropped.

Definition at line 5220 of file pie.c.

static RETSIGTYPE pie_usb_reader_process_sigterm_handler ( __sane_unused__ int  signal) [static]

Set a variable to indicate cancel request.

Definition at line 5148 of file pie.c.

static void pie_usb_reader_reorder ( Pie_Scanner scanner,
SANEI_IR_bufptr in_img,
SANEI_IR_bufptr  out_img,
int  planes,
int  pixels 
) [static]

Interleave RGB(I) and do color lookup.

Parameters:
[in]scannerPointer to structure of opened scanner
[in]in_imgPointer to separate R, G, B, (I) color planes
[out]out_imgPointer to interleaved RGB(I) data
[in]planesNumber of color planes to work on
[in]pixelsNumber of pixels to work on

Definition at line 4136 of file pie.c.

static SANE_Status pie_usb_reader_unthreaded ( Pie_Scanner scanner) [static]

Read and store whole image.

Parameters:
[in]scannerpoints to structure of opened scanner
Returns:
  • SANE_STATUS_GOOD - success
  • SANE_STATUS_IO_ERROR - if an error occurred during I/O
  • SANE_STATUS_INVAL - unexpected value was read
  • SANE_STATUS_EOF - if zero bytes have been read
  • SANE_STATUS_DEVICE_BUSY - scanner is busy, timed out
  • SANE_STATUS_NO_MEM - could not allocate buffer
  • SANE_STATUS_UNSUPPORTED - wrong color format requested

Definition at line 5171 of file pie.c.

static SANE_Status pie_usb_reader_write ( Pie_Scanner scanner,
FILE *  fp,
SANEI_IR_bufptr in_img,
int  planes,
int  lines 
) [static]

Interleave RGB(I), do color lookup and write data to pipe.

Parameters:
[in]scannerPointer to structure of opened scanner
[in]fpPipe to write to
[in]in_imgPointer to separate R, G, B, (I) color planes
[in]planesNumber of color planes
[in]linesNumber of lines to work on
Returns:
  • SANE_STATUS_GOOD - success
  • SANE_STATUS_IO_ERROR - pipe error
  • SANE_STATUS_NO_MEM - no buffer for reordering

Definition at line 4271 of file pie.c.

static SANE_Status pie_usb_ready_state ( SANE_Int  dn) [static]

Query the scanners state after the last USB transaction.

Parameters:
[in]dnDevice number
Returns:
  • SANE_STATUS_GOOD - success
  • SANE_STATUS_INVAL - received unexpected value
  • SANE_STATUS_DEVICE_BUSY - scanner is busy
  • SANE_STATUS_IO_ERROR - something got screwed up

Actually, there are two answers, a simple one where 1 byte with 0 or 1 is ok, and a more elaborate one in two bytes starting with 3. The second byte signals some condition, 0 is ready.

Definition at line 894 of file pie.c.

static int pie_usb_release_scanner ( void *  passed) [static]

Release scanner after image aquisition.

Parameters:
[in]datapoints to structure of opened scanner
Returns:
  • SANE_STATUS_GOOD - scanner is in parking position
  • SANE_STATUS_DEVICE_BUSY - scanner timed out
  • SANE_STATUS_IO_ERROR - on error
  • SANE_STATUS_UNSUPPORTED - if the feature is not supported
  • SANE_STATUS_INVAL - Received unexpected value
Todo:
The scanner does not accept the PIE_RELEASE_SCANNER command before it has reached the parking position. So this command should be called via sanei_begin_thread. However, that might not work if the Sane backends have been built with pthread support when the parent process, e.g. a forked one exits. It works with xsane and scanimage.

Definition at line 2851 of file pie.c.

static SANE_Status pie_usb_request_sense ( int  dn,
uint32_t *  kascq 
) [static]

Send a Request Sense SCSI command to the scanner.

Parameters:
[in]dnUSB device number
[out]kascqamalgam single Integer returning result
Returns:
  • SANE_STATUS_GOOD - success
  • SANE_STATUS_INVAL - received unexpected value
  • SANE_STATUS_DEVICE_BUSY - scanner is busy
  • SANE_STATUS_IO_ERROR - something got screwed up
  • SANE_STATUS_EOF - if zero bytes have been read
  • SANE_STATUS_UNSUPPORTED - if the feature is not supported
Note:
There are a few cases where a request sense may help the USB scanner to recover from an "error", e.g. "Not Ready - Warming Up", "calibration disable not granted".

Definition at line 1341 of file pie.c.

static void pie_usb_sane_close ( Pie_Scanner scanner) [static]

Terminate the association between scanner and scanner structure.

Parameters:
[in]scannerpoints to structure of to be closed scanner

Definition at line 5751 of file pie.c.

static SANE_Status pie_usb_sane_control_option ( SANE_Handle  handle,
SANE_Int  option,
SANE_Action  action,
void *  val,
SANE_Int *  info 
) [static]

Set or inquire the current value of an option.

Arguments and return are the same as required for sane_control_option.

Definition at line 5281 of file pie.c.

static SANE_Status pie_usb_sane_open ( Pie_Scanner scanner,
SANE_Handle *  handle 
) [static]

Establish a connection to a scanner.

Parameters:
[in]scannerpoints to structure of to be opened scanner
[out]handlepoints to structure of opened scanner
Returns:
  • SANE_STATUS_GOOD on success
  • SANE_STATUS_INVAL scanner could not be opened
  • SANE_STATUS_NO_MEM no buffer for precalculated data

Definition at line 5656 of file pie.c.

static SANE_Status pie_usb_sane_read ( Pie_Scanner scanner,
SANE_Byte *  buf,
SANE_Int  max_len,
SANE_Int *  len 
) [static]

Read image data out of buffer or from the device.

Parameters:
[in]scannerpoints to structure of opened scanner

Other arguments and return as required for sane_read.

Definition at line 5574 of file pie.c.

static SANE_Status pie_usb_sane_start ( Pie_Scanner scanner) [static]

Initiates aquisition of an image.

Parameters:
[in]scannerPointer to structure of opened scanner

Return is as required for sane_start.

Definition at line 5440 of file pie.c.

static SANE_Status pie_usb_scan ( Pie_Scanner scanner,
int  start 
) [static]

Perform SCAN command.

Parameters:
[in]scannerpoints to structure of opened scanner
Returns:
  • SANE_STATUS_GOOD - on success
  • SANE_STATUS_IO_ERROR - if an error occurred during the write
  • SANE_STATUS_INVAL - unexpected value was read
  • SANE_STATUS_EOF - if zero bytes have been read
  • SANE_STATUS_DEVICE_BUSY - scanner is busy, timed out
Note:
Not all errors after the SCAN command are fatal here.

Definition at line 3097 of file pie.c.

SANE_Status pie_usb_scsi_wrapper ( int  fd,
const void *  src,
size_t  src_size,
void *  dst,
size_t *  dst_size 
)

The one and only entry for SCSI over USB command wrapping.

Parameters:
[in]fdfile descriptor holds USB device number
[in]srcpoints to the SCSI command and appended write data (if any)
[in]src_sizelength of the command and data
[out]dstpoints to buffer receiving data, NULL if no data is returned
dst_sizerequested / received number of bytes
Returns:
  • SANE_STATUS_GOOD - success
  • SANE_STATUS_INVAL - received unexpected value
  • SANE_STATUS_DEVICE_BUSY - scanner is busy
  • SANE_STATUS_IO_ERROR - something got screwed up
  • SANE_STATUS_EOF - if zero bytes have been read
  • SANE_STATUS_UNSUPPORTED - if the feature is not supported

Currently all communication with the scanners is done via this function. Arguments are the same as for sanei_scsi_cmd.

Definition at line 1199 of file pie.c.

static SANE_Status pie_usb_set_window ( Pie_Scanner scanner) [static]

Issue SET_SCAN_FRAME via a SCSI WRITE command.

Parameters:
[in]scannerPointer to structure of opened scanner
Returns:
  • SANE_STATUS_GOOD - on success
  • SANE_STATUS_IO_ERROR - on error
  • SANE_STATUS_UNSUPPORTED - if the feature is not supported by the OS
Todo:
Merge back into pie_set_window

Definition at line 3169 of file pie.c.

static SANE_Status pie_usb_shades_to_pnm ( Pie_Scanner scanner,
char *  name,
int  lines 
) [static]

Write a set of gray scale pnm files from shading data.

Parameters:
[in]scannerpoints to structure holding the data
[in]namefirst part of file name
[in]linesheight of image
Returns:
  • SANE_STATUS_GOOD - on success
  • SANE_STATUS_NO_MEM - image buffer not allocated
  • SANE_STATUS_INVAL - file could not be written

Definition at line 780 of file pie.c.

static SANE_Status pie_usb_smoothen_rgb ( const SANE_Parameters *  params,
SANEI_IR_bufptr the_img,
int  win_size 
) [static]

Apply triangular blur to R, G, B image data.

Parameters:
[in]paramsdescribes image
the_imgpoints to R, G, B color planes
[in]win_sizewindow size for mean filtering
Returns:
  • SANE_STATUS_GOOD - success
  • SANE_STATUS_NO_MEM - could not allocate buffer
Note:
Two successive mean filters are applied as an approximation to gaussian smoothening. Routine may be used to reduce film grain. Input data is replaced.

Definition at line 4326 of file pie.c.

static SANE_Status pie_usb_sw_crop_planes ( SANE_Parameters *  parameters,
Pie_Scanner scanner,
SANEI_IR_bufptr in_img,
int  top,
int  bot,
int  left,
int  right,
int  planes 
) [static]

Crop separate color planes of an image.

Parameters:
[in]parametersdescribes one color plane of the image
[in]scannerPointer to structure of opened scanner
[in]in_imgPointer to R, G, B(, I) color planes
[in]topcropping position
[in]botcropping position
[in]leftcropping position
[in]rightcropping position
[in]planeshow many planes to crop
Note:
Updates scanner->params

Definition at line 4381 of file pie.c.

static SANE_Status pie_usb_sw_final_crop ( Pie_Scanner scanner) [static]

Crop the final complete RGB image.

Parameters:
[in]scannerPointer to structure of opened scanner
Returns:
  • SANE_STATUS_GOOD - success
  • SANE_STATUS_NO_MEM - could not allocate buffer
Note:
sanei_magic's crop routine works best on color corrected images and it has the tendency to crop outside the image edges. If cropping inside the edges is wanted have to estimate.

Definition at line 4426 of file pie.c.

static SANE_Status pie_usb_sw_post ( Pie_Scanner scanner,
SANEI_IR_bufptr in_img,
int  planes,
int  out_planes 
) [static]

Postprocess a scanned R, G, B(, I) image.

Parameters:
[in]scannerPointer to structure of opened scanner
[in]in_imgPointer to R, G, B(, I) color planes
[in]planesnumber planes to work on
[in]out_planesnumber of allowed output planes
Returns:
  • SANE_STATUS_GOOD - success
  • SANE_STATUS_NO_MEM - could not allocate buffer
Note:
Currently postprocessing does if applicable
  • clean the infrared plane from red spectral overlay
  • remove dirt
  • smoothen film grain
  • gain correct, invert colors
  • crop
After removing dirt special smoothening (all kinds of film) and cropping (only slide film) routines are used.

Definition at line 4515 of file pie.c.

static SANE_Status pie_usb_sw_store ( Pie_Scanner scanner,
SANEI_IR_bufptr in_img,
int  planes 
) [static]

Interleave RGB(I), do color lookup and store data.

Parameters:
[in]scannerPointer to structure of opened scanner
[in]in_imgPointer to separate R, G, B, (I) color planes
[in]planesNumber of color planes
Returns:
  • SANE_STATUS_GOOD - success
  • SANE_STATUS_NO_MEM - no buffer for storing

Definition at line 4219 of file pie.c.

static SANE_Status pie_usb_try_attach ( const char *  name) [static]

Callback function for sanei_config_attach_matching_devices.

Parameters:
[in]namedevice name pattern
Returns:
  • SANE_STATUS_GOOD

Definition at line 2262 of file pie.c.

static SANE_Status pie_usb_wait_scanner ( Pie_Scanner scanner,
int  secs 
) [static]

TEST_UNIT_READY until ready or timed out.

Parameters:
[in]scannerpoints to structure of opened scanner
[in]secsseconds to wait maximally
Returns:
  • SANE_STATUS_GOOD - scanner is ready
  • SANE_STATUS_DEVICE_BUSY - scanner timed out
  • SANE_STATUS_IO_ERROR - on error
  • SANE_STATUS_UNSUPPORTED - if the feature is not supported
  • SANE_STATUS_INVAL - received unexpected value

Definition at line 2799 of file pie.c.

static SANE_Status pie_usb_write ( int  dn,
const SANE_Byte *  cmnd,
size_t  length 
) [static]

Do a SCSI write transaction over USB.

Parameters:
[in]dnUSB device number
[in]cmndSCSI command appended with the data to be written
[in]lengthtotal length, i.e. command + data
Returns:
  • SANE_STATUS_GOOD - success
  • SANE_STATUS_INVAL - received unexpected value
  • SANE_STATUS_DEVICE_BUSY - scanner is busy
  • SANE_STATUS_IO_ERROR - something got screwed up
  • SANE_STATUS_UNSUPPORTED - if the feature is not supported
Note:
Data bytes are sent only one at a time, for SF scanners there seems to be no bulk write.

Definition at line 1114 of file pie.c.

static SANE_Status pie_usb_write_control_sequence ( SANE_Int  dn,
PIE_USB_Value_Data  sequ[] 
) [static]

Write a control sequence of value-data pairs to the scanner.

Parameters:
[in]dnUSB device number
[in]sequlist of value-data pairs terminated by a 0-0 pair
Returns:
  • SANE_STATUS_GOOD - on success
  • SANE_STATUS_EOF - if zero bytes have been read
  • SANE_STATUS_IO_ERROR - if an error occurred during the read
  • SANE_STATUS_INVAL - on every other error

Definition at line 856 of file pie.c.

static SANE_Status pie_usb_write_pnm_file ( char *  filename,
uint8_t *  data,
int  depth,
int  channels,
int  pixels_per_line,
int  lines 
) [static]

Write RGB or grey scale image to a pnm file , with big endian byte order.

Parameters:
[in]filenameName of file
[in]dataPointer to image data
[in]channelsNumber of interleaved color planes
[in]pixels_per_lineDimension in x
[in]linesDimension in y
Returns:
  • SANE_STATUS_GOOD - on success
  • SANE_STATUS_INVAL - file could not be written

Definition at line 698 of file pie.c.

static SANE_Status pie_usb_write_scsi_cmd ( SANE_Int  dn,
const SANE_Byte  cmnd[6] 
) [static]

Send 6 byte SCSI command to scanner.

Parameters:
[in]dnUSB device number
[in]cmndarray holding the six bytes
Returns:
  • SANE_STATUS_GOOD - on success
  • SANE_STATUS_EOF - if zero bytes have been read
  • SANE_STATUS_IO_ERROR - if an error occurred during the read
  • SANE_STATUS_INVAL - on every other error

Definition at line 951 of file pie.c.

static SANE_Status pie_wait_scanner ( Pie_Scanner scanner) [static]

Definition at line 6669 of file pie.c.

void sane_cancel ( SANE_Handle  handle)

Definition at line 8159 of file pie.c.

void sane_close ( SANE_Handle  handle)

Definition at line 7495 of file pie.c.

SANE_Status sane_control_option ( SANE_Handle  handle,
SANE_Int  option,
SANE_Action  action,
void *  val,
SANE_Int *  info 
)

Definition at line 7578 of file pie.c.

void sane_exit ( void  )

Definition at line 7315 of file pie.c.

SANE_Status sane_get_devices ( const SANE_Device ***  device_list,
SANE_Bool __sane_unused__  local_only 
)

Definition at line 7358 of file pie.c.

const SANE_Option_Descriptor* sane_get_option_descriptor ( SANE_Handle  handle,
SANE_Int  option 
)

Definition at line 7560 of file pie.c.

SANE_Status sane_get_parameters ( SANE_Handle  handle,
SANE_Parameters *  params 
)

Definition at line 7803 of file pie.c.

SANE_Status sane_get_select_fd ( SANE_Handle  handle,
SANE_Int *  fd 
)

Definition at line 8203 of file pie.c.

SANE_Status sane_init ( SANE_Int *  version_code,
SANE_Auth_Callback __sane_unused__  authorize 
)

Definition at line 7259 of file pie.c.

SANE_Status sane_open ( SANE_String_Const  devicename,
SANE_Handle *  handle 
)

Definition at line 7399 of file pie.c.

SANE_Status sane_read ( SANE_Handle  handle,
SANE_Byte *  buf,
SANE_Int  max_len,
SANE_Int *  len 
)

Definition at line 8109 of file pie.c.

SANE_Status sane_set_io_mode ( SANE_Handle  handle,
SANE_Bool  non_blocking 
)

Definition at line 8179 of file pie.c.

SANE_Status sane_start ( SANE_Handle  handle)

Definition at line 7894 of file pie.c.


Variable Documentation

volatile sig_atomic_t cancel_requ [static]

Definition at line 457 of file pie.c.

Initial value:
 {
  "PIE/Reflecta",               
  "CrystalScan 7200",           
  0x30,                         
  PIE_USB_FLAG_MIRROR_IMAGE |   
    PIE_USB_FLAG_XRES_FAKE,
  
  {0x00, 0x08, 0x0a},
  75000,                        
  
  {4.19682524E-04, 3.92060196E-04, 3.89647803E-04},
  
  {1.05, 1.05, 1.05},
  16,                           
  42,                           
  0x0f00,                       
  10,                           
  {{0x16e6, 0x0ff2, 0x0ff2},    
   0x16e6, {0x21, 0x21, 0x19}},
  {{0x0be2, 0x0bcf, 0x0b88},    
   0x0be2, {0x35, 0x2c, 0x27}}
}

Definition at line 474 of file pie.c.

const SANE_Device** devlist = NULL [static]

Definition at line 467 of file pie.c.

Pie_Device* first_dev = NULL [static]

Definition at line 465 of file pie.c.

Pie_Scanner* first_handle = NULL [static]

Definition at line 466 of file pie.c.

const SANE_Range percentage_range_100 [static]
Initial value:
 {
  0 << SANE_FIXED_SCALE_SHIFT,  
  100 << SANE_FIXED_SCALE_SHIFT,        
  0 << SANE_FIXED_SCALE_SHIFT   
}

Definition at line 459 of file pie.c.

Initial value:
 {
  {0x05e3, 0x0145, &crystalscan_7200_model},    
  {0x05e3, 0x0145, &proscan_7200_model},        
  {0, 0, 0}
}

Definition at line 521 of file pie.c.

Initial value:
 {
  "PIE/Reflecta",               
  "ProScan 7200",               
  0x36,                         
  PIE_USB_FLAG_MIRROR_IMAGE,    
  
  {0x00, 0x08, 0x02},
  75000,                        
  
  {4.19682524E-04, 3.92060196E-04, 3.89647803E-04},
  
  {1.2229896394, 1.0447735936, 0.9805181615},
  16,                           
  42,                           
  0x0f00,                       
  10,                           
  {{0x2c89, 0x1eb7, 0x17ca},    
   0x2c89, {0x25, 0x25, 0x28}},
  {{0x0e79, 0x0bff, 0x0c6c},    
   0x0e79, {0x3f, 0x3d, 0x39}}
}

Definition at line 497 of file pie.c.

char* scanner_str[] [static]
Initial value:
 {
  "DEVCOM", "9636PRO",
  "DEVCOM", "9636S",
  "DEVCOM", "9630S",
  "PIE", "ScanAce 1236S",
  "PIE", "ScanAce 1230S",
  "PIE", "ScanAce II",
  "PIE", "ScanAce III",
  "PIE", "ScanAce Plus",
  "PIE", "ScanAce II Plus",
  "PIE", "ScanAce III Plus",
  "PIE", "ScanAce V",
  "PIE", "ScanMedia",
  "PIE", "ScanMedia II",
  "PIE", "ScanAce 630S",
  "PIE", "ScanAce 636S",
  "AdLib", "JetScan 630",
  "AdLib", "JetScan 636PRO",
  
  "PIE", "SF Scanner",
  "END_OF_LIST"
}

Definition at line 216 of file pie.c.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines