sane

package
v0.0.0-...-d48ed85 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 27, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrGood         = StatusGood
	ErrUnsupported  = StatusUnsupported
	ErrCancelled    = StatusCancelled
	ErrDeviceBusy   = StatusDeviceBusy
	ErrInval        = StatusInval
	ErrEOF          = StatusEOF
	ErrJammed       = StatusJammed
	ErrNoDocs       = StatusNoDocs
	ErrCoverOpen    = StatusCoverOpen
	ErrIOError      = StatusIOError
	ErrNoMem        = StatusNoMem
	ErrAccessDenied = StatusAccessDenied

	// Wrapper specific errors
	ErrClosed         = errors.New("sane: handle is closed")
	ErrInvalidType    = errors.New("sane: invalid option type")
	ErrNotFound       = errors.New("sane: option not found")
	ErrBufferTooSmall = errors.New("sane: buffer too small")
)

Sentinel errors corresponding to SANE status codes.

Functions

func FixedToFloat

func FixedToFloat(v int32) float64

FixedToFloat converts a SANE 16.16 fixed-point representation to float64.

func FloatToFixed

func FloatToFixed(v float64) int32

FloatToFixed converts a float64 to SANE 16.16 fixed-point representation.

Types

type Capability

type Capability int

Capability flags for SANE options.

type ConstraintType

type ConstraintType int

ConstraintType describes how the value of an option is constrained.

const (
	ConstraintNone       ConstraintType = C.SANE_CONSTRAINT_NONE
	ConstraintRange      ConstraintType = C.SANE_CONSTRAINT_RANGE
	ConstraintWordList   ConstraintType = C.SANE_CONSTRAINT_WORD_LIST
	ConstraintStringList ConstraintType = C.SANE_CONSTRAINT_STRING_LIST
)

type Context

type Context struct {
	// contains filtered or unexported fields
}

Context manages the lifecycle of the SANE library session.

func Init

func Init() (*Context, error)

Init initializes the SANE library and returns a Context.

func (*Context) Close

func (c *Context) Close() error

Close terminates the SANE session and releases associated resources.

func (*Context) GetDevices

func (c *Context) GetDevices(localOnly bool) ([]DeviceInfo, error)

GetDevices returns a list of available SANE devices. If localOnly is true, only locally connected devices are queried.

func (*Context) Open

func (c *Context) Open(deviceName string) (*Device, error)

Open opens a device by its name.

func (*Context) Version

func (c *Context) Version() (major, minor, build int)

Version returns the SANE library version code (Major, Minor, Build).

type Device

type Device struct {
	// contains filtered or unexported fields
}

Device represents an opened SANE device.

func (*Device) Cancel

func (d *Device) Cancel()

Cancel cancels the current scan operation immediately.

func (*Device) Close

func (d *Device) Close() error

Close closes the SANE device handle and releases device resources.

func (*Device) FindOption

func (d *Device) FindOption(name string) (int, *OptionDescriptor, error)

FindOption finds an option descriptor and its index by its name (e.g. "mode", "resolution", "source").

func (*Device) GetOptionBool

func (d *Device) GetOptionBool(index int) (bool, error)

GetOptionBool reads a boolean option value.

func (*Device) GetOptionDescriptor

func (d *Device) GetOptionDescriptor(index int) (*OptionDescriptor, error)

GetOptionDescriptor retrieves the descriptor for the option at the given index.

func (*Device) GetOptionDescriptors

func (d *Device) GetOptionDescriptors() ([]OptionDescriptor, error)

GetOptionDescriptors returns all option descriptors for the device.

func (*Device) GetOptionFixed

func (d *Device) GetOptionFixed(index int) (float64, error)

GetOptionFixed reads a fixed-point option value as float64.

func (*Device) GetOptionInt

func (d *Device) GetOptionInt(index int) (int, error)

GetOptionInt reads an integer option value.

func (*Device) GetOptionString

func (d *Device) GetOptionString(index int) (string, error)

GetOptionString reads a string option value.

func (*Device) GetParameters

func (d *Device) GetParameters() (Parameters, error)

GetParameters fetches the current scan parameters from the device.

func (*Device) GetSelectFD

func (d *Device) GetSelectFD() (int, error)

GetSelectFD returns a file descriptor suitable for select/poll/epoll when non-blocking mode is enabled.

func (*Device) Name

func (d *Device) Name() string

Name returns the device name string.

func (*Device) OptionCount

func (d *Device) OptionCount() (int, error)

OptionCount returns the total number of options available on the device.

func (*Device) PressButton

func (d *Device) PressButton(index int) (Info, error)

PressButton activates a button-type option.

func (*Device) ScanImage

func (d *Device) ScanImage() (image.Image, error)

ScanImage executes a full scan and decodes the image into an image.Image. Supports Gray (1-bit, 8-bit, 16-bit) and RGB (8-bit, 16-bit), including multi-frame RGB.

func (*Device) SetNonBlocking

func (d *Device) SetNonBlocking(nonBlocking bool) error

SetNonBlocking enables or disables non-blocking I/O mode for sane_read.

func (*Device) SetOptionAuto

func (d *Device) SetOptionAuto(index int) (Info, error)

SetOptionAuto requests the backend to automatically set the option value.

func (*Device) SetOptionBool

func (d *Device) SetOptionBool(index int, val bool) (Info, error)

SetOptionBool sets a boolean option value.

func (*Device) SetOptionByName

func (d *Device) SetOptionByName(name string, value any) (Info, error)

SetOptionByName sets an option value by its name dynamically resolving the type.

func (*Device) SetOptionFixed

func (d *Device) SetOptionFixed(index int, val float64) (Info, error)

SetOptionFixed sets a fixed-point option value from float64.

func (*Device) SetOptionInt

func (d *Device) SetOptionInt(index int, val int) (Info, error)

SetOptionInt sets an integer option value.

func (*Device) SetOptionString

func (d *Device) SetOptionString(index int, val string) (Info, error)

SetOptionString sets a string option value.

func (*Device) Start

func (d *Device) Start() error

Start initiates the acquisition of an image from the device.

type DeviceInfo

type DeviceInfo struct {
	Name   string
	Vendor string
	Model  string
	Type   string
}

DeviceInfo represents the information of a discovered SANE device.

type Frame

type Frame int

Frame specifies the image frame format.

const (
	FrameGray  Frame = C.SANE_FRAME_GRAY
	FrameRGB   Frame = C.SANE_FRAME_RGB
	FrameRed   Frame = C.SANE_FRAME_RED
	FrameGreen Frame = C.SANE_FRAME_GREEN
	FrameBlue  Frame = C.SANE_FRAME_BLUE
)

func (Frame) String

func (f Frame) String() string

type Info

type Info int

Info flags returned by sane_control_option.

const (
	InfoInexact       Info = C.SANE_INFO_INEXACT
	InfoReloadOptions Info = C.SANE_INFO_RELOAD_OPTIONS
	InfoReloadParams  Info = C.SANE_INFO_RELOAD_PARAMS
)

type OptionDescriptor

type OptionDescriptor struct {
	Index          int
	Name           string
	Title          string
	Description    string
	Type           ValueType
	Unit           Unit
	Size           int
	Capabilities   Capability
	ConstraintType ConstraintType
	StringList     []string
	WordList       []int
	WordListFixed  []float64
	Range          *Range
	RangeFixed     *RangeFixed
}

OptionDescriptor describes an option of a SANE device.

func (*OptionDescriptor) IsActive

func (o *OptionDescriptor) IsActive() bool

IsActive returns true if the option is active.

func (*OptionDescriptor) IsSettable

func (o *OptionDescriptor) IsSettable() bool

IsSettable returns true if the option value can be set by software.

type Parameters

type Parameters struct {
	Format        Frame
	LastFrame     bool
	BytesPerLine  int
	PixelsPerLine int
	Lines         int
	Depth         int
}

Parameters holds the scan acquisition parameters.

type Range

type Range struct {
	Min   int
	Max   int
	Quant int
}

Range defines min, max, and quantization step for integer or fixed-point values.

type RangeFixed

type RangeFixed struct {
	Min   float64
	Max   float64
	Quant float64
}

RangeFixed defines min, max, and quantization step in float64 for fixed-point options.

type ScanReader

type ScanReader struct {
	// contains filtered or unexported fields
}

ScanReader implements io.Reader streaming image bytes directly from sane_read.

func NewScanReader

func NewScanReader(device *Device) *ScanReader

NewScanReader creates a ScanReader for an active scan on device.

func (*ScanReader) Close

func (r *ScanReader) Close() error

Close cancels any ongoing scan on the reader.

func (*ScanReader) Read

func (r *ScanReader) Read(p []byte) (n int, err error)

Read reads image bytes from the SANE device into buffer p. Returns io.EOF when the current frame/image scan is completed.

type Status

type Status int

Status represents the SANE status code.

const (
	StatusGood         Status = C.SANE_STATUS_GOOD
	StatusUnsupported  Status = C.SANE_STATUS_UNSUPPORTED
	StatusCancelled    Status = C.SANE_STATUS_CANCELLED
	StatusDeviceBusy   Status = C.SANE_STATUS_DEVICE_BUSY
	StatusInval        Status = C.SANE_STATUS_INVAL
	StatusEOF          Status = C.SANE_STATUS_EOF
	StatusJammed       Status = C.SANE_STATUS_JAMMED
	StatusNoDocs       Status = C.SANE_STATUS_NO_DOCS
	StatusCoverOpen    Status = C.SANE_STATUS_COVER_OPEN
	StatusIOError      Status = C.SANE_STATUS_IO_ERROR
	StatusNoMem        Status = C.SANE_STATUS_NO_MEM
	StatusAccessDenied Status = C.SANE_STATUS_ACCESS_DENIED
)

func (Status) Error

func (s Status) Error() string

type Unit

type Unit int

Unit specifies the physical unit of an option.

const (
	UnitNone        Unit = C.SANE_UNIT_NONE
	UnitPixel       Unit = C.SANE_UNIT_PIXEL
	UnitBit         Unit = C.SANE_UNIT_BIT
	UnitMM          Unit = C.SANE_UNIT_MM
	UnitDPI         Unit = C.SANE_UNIT_DPI
	UnitPercent     Unit = C.SANE_UNIT_PERCENT
	UnitMicrosecond Unit = C.SANE_UNIT_MICROSECOND
)

func (Unit) String

func (u Unit) String() string

type ValueType

type ValueType int

ValueType specifies the data type of an option.

const (
	TypeBool   ValueType = C.SANE_TYPE_BOOL
	TypeInt    ValueType = C.SANE_TYPE_INT
	TypeFixed  ValueType = C.SANE_TYPE_FIXED
	TypeString ValueType = C.SANE_TYPE_STRING
	TypeButton ValueType = C.SANE_TYPE_BUTTON
	TypeGroup  ValueType = C.SANE_TYPE_GROUP
)

func (ValueType) String

func (vt ValueType) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL