pax_global_header 0000666 0000000 0000000 00000000064 14377724077 0014534 g ustar 00root root 0000000 0000000 52 comment=d466163a4e7ba8bd90644a2a6734395be5e51cd4
libinsane-1.0.10/ 0000775 0000000 0000000 00000000000 14377724077 0013557 5 ustar 00root root 0000000 0000000 libinsane-1.0.10/.gitignore 0000664 0000000 0000000 00000001037 14377724077 0015550 0 ustar 00root root 0000000 0000000 *~
.*
build_windows/
build_linux/
build/
generated/
venv/
*.gir
*.typelib
test_hw_out/
GPATH
GRTAGS
GTAGS
tags
# Prerequisites
*.d
# Object files
*.o
*.ko
*.obj
*.elf
# Linker output
*.ilk
*.map
*.exp
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lib
*.a
*.la
*.lo
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
# Debug files
*.dSYM/
*.su
*.idb
*.pdb
# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf
libinsane-1.0.10/.gitlab-ci.yml 0000664 0000000 0000000 00000007666 14377724077 0016232 0 ustar 00root root 0000000 0000000 image: debian:bullseye
stages:
- build
- test
# Do not run Linux and Windows tests at the same time. Test rigs share some scanners
# and both systems cannot access a scanner at the same time.
- test_hw_linux
- test_hw_windows
- deploy
.apt: &apt
before_script:
- apt-get update
# WORKAROUND: manpages is required to install some of the openjdk-jre
# and openjdk-jre is required for plantuml, which is required to generate
# documentation
- mkdir -p /usr/share/man/man1
- apt-get install -y -qq make meson build-essential
- apt-get install -y -qq libsane-dev
- apt-get install -y -qq libgirepository1.0-dev gobject-introspection
- apt-get install -y -qq libcunit1-ncurses-dev
- apt-get install -y -qq valgrind valac
- apt-get install --no-install-recommends -y -qq gtk-doc-tools doxygen plantuml graphviz
.msys: &msys
before_script:
- c:\msys64\usr\bin\pacman --needed --noconfirm -S make
- c:\msys64\usr\bin\pacman --needed --noconfirm -S mingw-w64-x86_64-cunit
- c:\msys64\usr\bin\pacman --needed --noconfirm -S mingw-w64-x86_64-doxygen
- c:\msys64\usr\bin\pacman --needed --noconfirm -S mingw-w64-x86_64-gcc
- c:\msys64\usr\bin\pacman --needed --noconfirm -S mingw-w64-x86_64-gobject-introspection
- c:\msys64\usr\bin\pacman --needed --noconfirm -S mingw-w64-x86_64-meson
- c:\msys64\usr\bin\pacman --needed --noconfirm -S mingw-w64-x86_64-python3-gobject
- c:\msys64\usr\bin\pacman --needed --noconfirm -S mingw-w64-x86_64-python3-pillow
- c:\msys64\usr\bin\pacman --needed --noconfirm -S mingw-w64-x86_64-vala
.msys64: &msys64
before_script:
- c:\msys64\usr\bin\pacman --needed --noconfirm -S make
- c:\msys64\usr\bin\pacman --needed --noconfirm -S mingw-w64-x86_64-cunit
- c:\msys64\usr\bin\pacman --needed --noconfirm -S mingw-w64-x86_64-doxygen
- c:\msys64\usr\bin\pacman --needed --noconfirm -S mingw-w64-x86_64-gcc
- c:\msys64\usr\bin\pacman --needed --noconfirm -S mingw-w64-x86_64-gobject-introspection
- c:\msys64\usr\bin\pacman --needed --noconfirm -S mingw-w64-x86_64-meson
- c:\msys64\usr\bin\pacman --needed --noconfirm -S mingw-w64-x86_64-python3-gobject
- c:\msys64\usr\bin\pacman --needed --noconfirm -S mingw-w64-x86_64-python3-pillow
- c:\msys64\usr\bin\pacman --needed --noconfirm -S mingw-w64-x86_64-vala
check:
stage: test
only:
- branches@World/OpenPaperwork/libinsane
- tags@World/OpenPaperwork/libinsane
<<: *apt
script:
- apt-get install -y -qq sparse clang-tidy-11
- make check
test:
stage: test
only:
- branches@World/OpenPaperwork/libinsane
- tags@World/OpenPaperwork/libinsane
<<: *apt
script:
- make test
doc:
stage: deploy
only:
- branches@World/OpenPaperwork/libinsane
- tags@World/OpenPaperwork/libinsane
<<: *apt
script:
- apt-get install -y -qq rclone
- make doc
- ./deliver_doc.sh
artifacts:
paths:
- doc/build
expire_in: 2 days
test_hw_linux:
stage: test_hw_linux
only:
- branches@World/OpenPaperwork/libinsane
- tags@World/OpenPaperwork/libinsane
tags:
- linux
- testhw
script:
# Keep in mind this one is a real system --> you're not root on it
# --> no APT commands here
- . ./activate_test_env.sh && make test_hw
artifacts:
paths:
- test_hw_out
expire_in: 2 days
test_hw_windows:
stage: test_hw_windows
only:
- branches@World/OpenPaperwork/libinsane
- tags@World/OpenPaperwork/libinsane
variables:
MSYSTEM: "MINGW64"
CHERE_INVOKING: "yes"
tags:
- windows
- testhw
# This one is a real system too, but it's a Windows, so nobody cares.
# Dependencies should already be installed, but still it's simpler and safer
# to ask pacman to install them anyway.
<<: *msys64
script:
- c:\msys64\usr\bin\bash -lc "make install PREFIX=/mingw64"
- c:\msys64\usr\bin\bash -lc "make test_hw"
artifacts:
paths:
- test_hw_out
expire_in: 2 days
libinsane-1.0.10/ChangeLog 0000664 0000000 0000000 00000017523 14377724077 0015341 0 ustar 00root root 0000000 0000000 2023/03/01 - 1.0.10:
- New error code: LIS_ERR_OFFLINE: returned when attempting to use the scanner
and the scanner is offline.
- normalizers/raw24: fix unpacking of 1bit images.
- New workaround for Sane: 'hide_source_auto':
remove sources 'Auto'|'Automatic':
those source behavior depends on the scanner and cannot be used reliably.
- New workaround for Sane + Brother scanners: 'invalid_page_size':
some Brother scanners/drivers report there is still a page in the feeder,
but when requesting the page, we get an absurd size (2500x0 for example).
- dedicated process: do not try to log messages through the log socket if one of the socket has just died
(happens if the master process crashes)
- dedicated_process: disable backtrace support when another Libc than GLIBC is used
(ex: musl) (thanks to Bernard Cafarelli)
- dedicated_process: fix build with some Libc (thanks to Bernard Cafarelli)
2021/01/01 - 1.0.9:
- Fix: dedicated_process: Don't hang when shutting down
(ea2e964392c9aa5d09465d71fc059d8689c311cb)
- dedicated_process: Reduce the trace level from the child process's stderr
from warning to info
2020/10/09 - 1.0.8:
- workaround 'dedicated_process': Fix crash on s390x architectures (thanks to
Elliott Sales de Andrade)
- Sane + normalizer 'min_one_source' + normalizer 'all_opts_on_all_sources':
Fix crash with scanner have no option 'source':
'min_one_source' creates a fake item, and this fake item must not return
any option when `get_options()` is called. Otherwise
'all_opts_on_all_sources' crashes.
- workaround 'dedicated_process': Fix reading from the stderr output of the
worker process.
2020/09/01 - 1.0.7:
- workaround 'dedicated_process': fix crash on 32bits systems.
2020/08/31 - 1.0.6:
- workaround 'dedicated_process': work around a GCC >=10 bug
2020/08/30 - 1.0.5:
- Sane: Implements new workaround: dedicated_process: run all the scanner
operations in a dedicated process. Avoid issues with Sane backends
crashing, corrupting the memory or closing file descriptors just for fun.
- Sane: disable assert when receiving the code SANE_STATUS_CANCELLED
unexpectidly.
- Workaround/opt_values: Add support for Sane + Samsung C48x
- Workaround/opt_values: Add support for Sane + Brother ADS-2100e
2020/03/13 - 1.0.4:
- TWAIN + WIA2: Add support for grayscale ("Gray") and black&white ("LineArt")
scans.
- Make sure "LineArt" is always capitalized the same way everywhere.
- New workaround 'lamp': Make sure the lamp is turned off at the end of scan
(Sane + Canon Lide 30).
- Safe_defaults: Fix value of 'page-height' to ensure we get the biggest scan
area possible by default (Sane + Fujitsu scanners).
- Build has been made reproducible (thanks to Thomas Perret)
2019/12/20 - 1.0.3:
- Various documentation improvements (many thanks to Vasilii Blazhnov
questions)
- Sane: Fix: When getting number lists (for instance the possible resolutions),
do not drop the last value.
- Safebet: Fix support of Canon Lide 30 (driver Sane plustek ; and possibly
other scanners with a similar problem): Reorder the workaround/normalizers
to make sure the Libinsane does not switch the option 'source' too many
times. Otherwise the (buggy) driver ends up using the wrong source, with a
wrong scan area.
- WIA2: Fix: Canon i-SENSYS MF3010: IStream.seek() can be called with argument
'plibNewPosition' set to NULL.
- WIA2: Fix crashes caused by drivers that keeps using the IStream after
releasing it (implies a small memory leak at each scanned page ... :/).
- WIA2: Fix: When an invalid device ID is passed as argument of
impl->get_device(), it now returns INVALID_VALUE instead of UNKNOWN_ERROR.
- WIA2: Fix: When requesting the children of a child item, return an empty list
instead of an error (like other implementations)
- WIA2: Handle correctly some other error codes that may be returned by the
driver.
- Sane: Fix support of Black&White output (mode=Lineart).
- All APIs: Fix impl->base_name (previously, multiplexer always set it to
NULL).
- Fix compilation as a 64bits library on Windows.
2019/10/14 - 1.0.2:
- Libinsane/gobject: Added mising flag Libinsane.CAPABILITY_INACTIVE.
- Sane: when the application expect one page, do not request a second one
(fix unittests timeout).
- WIA2: Use the option 'dev_name' to figure out the manufacturer name and the
device name. It is the only reliable option.
- WIA2: HP Photosmart C4200, Epson Perfection V30/V300:
When getting the scanned image, allow calls to
`seek(SEEK_SET, current_position)`.
https://openpaper.work/scannerdb/report/280/
https://openpaper.work/scannerdb/report/350/
- WIA2: Ignore sources that are not explicitely a flatbed or an ADF
(for instance 0000\\Root\\Auto: It is simply not supported by Libinsane).
- TWAIN: Fujitsu fi-6130 / fi-6130dj:
Keep reading Windows message queue while waiting for the DSM callback
to be called with the value 'ready'. If we don't, the DSM callback never gets
called.
- normalizers/opt_aliases: Fix: When using option aliases 'tl-x', 'tl-y',
'br-x' and 'br-y', with WIA2, if the lowest values for 'xpos', 'ypos',
'xextent' and 'yextent' don't have (0, 0) as minimum values, inaccurate
values were set in WIA2 frame options.
https://openpaper.work/fr/scanner_db/report/335/
- workarounds/cache: Fix: do not drop the item type (root, adf, flatbed, etc).
- normalizers/resolution: If the driver does not specify any constraint
for the option 'resolution', put one default constraint.
- normalizers/safe_defaults: Sane + Fujitsu fi-6130dj:
Cannot set the option 'page-height' to the maximum: Scanner rejects it.
Option must be set to slightly less than the maximum.
https://openpaper.work/fr/scanner_db/report/392/
- normalizers/safe_default: Sane + Epson Perfection 1250:
If the default value for an option is out of the range specified by the
option constraint, do not change it.
https://openpaper.work/fr/scanner_db/report/328/
- workaround/opt_names: Sane + Canon Pixma MX520:
Take into account that somes backend provide both an option 'resolution'
and 'scan-resolution'. In that case, do not generate an option 'resolution'
that would be an alias for 'scan-resolution', just keep 'resolution' as is.
- normalizers/source_names: Sane + Canon CanoScan Lide 30:
Normalize the weird source names specified by the plustek driver.
https://openpaper.work/fr/scanner_db/report/298/
- Sane + Canon Lide 220:
* https://openpaper.work/fr/scanner_db/report/279/
* workarounds/check_capabilty: Some options are marked as unreadable
(INACTIVE) but may still be writable (for instance the option 'source').
* normalizers/source_nodes: If the option 'source' is marked inactive, still
try to set it, but do not return an error if setting it fails.
2019/08/18 - 1.0.1:
- Sane: make sure sane_cancel() is called at the end of all scans (required
by some drivers)
- Sane: Fix memory leak when opening an invalid device. (thanks to
Elliott Sales de Andrade)
- WIA/Twain: Fix reading bits-per-pixel from BMP header on big-endian CPU
(thanks to Elliott Sales de Andrade)
2019/05/08 - 1.0:
- TWAIN: Add support for frame options (tl-x, tl-y, br-x, br-y)
- Sane: Fix: 'net' backend: when we get SANE_INFO_RELOAD_OPTIONS, we must call
we must first call sane_get_option_descriptor() before sane_control_option()
even if we just want to use sane_control_option() to get the number of
options.
- normalizer 'min_one_source': do not use the type of the root item on the
child, it's not a good value and prevents 'one_page_flatbed' from working
correctly.
- Documentation updated, completed and clarified
- Linux: .so files now include the version number (thanks to Eliott Sales de
Andrade)
- Fix various CI issues
- (unchanged) Known limitation: Only support scan of color images on Windows (24bits)
2019/03/10 - 0.9:
- First release: Test preview.
- Support of Sane, WIA2 and TWAIN.
- Known limitation: Only support scan of color images on Windows (24bits)
libinsane-1.0.10/LICENSE 0000664 0000000 0000000 00000016743 14377724077 0014577 0 ustar 00root root 0000000 0000000 GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
libinsane-1.0.10/Makefile 0000664 0000000 0000000 00000006065 14377724077 0015226 0 ustar 00root root 0000000 0000000 UNAME := $(shell uname)
PYTHON ?= python3
VERBOSE ?=
PREFIX ?= /usr/local
SRCS = $(wildcard src/libinsane/*.c)
HEADERS = $(wildcard include/libinsane/*.h)
ifeq ($(UNAME), Linux)
CFLAGS=-O2 -D_FORTIFY_SOURCE=2
else
CFLAGS=
endif
all: build check test
build: build_c build_py
install: install_py install_c
uninstall: uninstall_py uninstall_c
build_py:
build/build.ninja:
mkdir -p build
echo "Uname: " $(UNAME)
echo "CFLAGS: " $(CFLAGS)
(cd build && CFLAGS="$(CFLAGS)" meson --werror --warnlevel 2 --prefix=${PREFIX} ..)
build_c: build/build.ninja
(cd build && ninja)
version:
doc: build/build.ninja
# Libinsane doc
(cd build && ninja subprojects/libinsane/doc/doc_out)
# Libinsane-gobject doc (Meson 0.37.1 || Meson 0.47.1)
(cd build ; ninja libinsane-gobject-doc || ninja libinsane-gobject@@libinsane-gobject-doc)
rm -rf doc/build
mkdir -p doc/build
mv build/doc/html doc/build/libinsane
mv build/subprojects/libinsane-gobject/doc/html doc/build/libinsane-gobject
cp doc/index.html doc/build
echo "Documentation is available in doc/build/"
check: build_c
! command -v sparse || python3 ./check_sparse.py build/compile_commands.json
# Debian / Ubuntu
(cd build ; ! command -v run-clang-tidy-4.0.py || ! (run-clang-tidy-4.0.py | grep warning 2>&1))
(cd build ; ! command -v run-clang-tidy-7 || ! (run-clang-tidy-7 | grep warning 2>&1))
# Fedora
(cd build ; [ ! -f /usr/share/clang/run-clang-tidy.py ] || ! (/usr/share/clang/run-clang-tidy.py | grep warning 2>&1))
test: build/build.ninja
(cd build && ninja test)
test_hw:
rm -rf test_hw_out
subprojects/libinsane-gobject/tests/test_hw.py test_hw_out
linux_exe:
windows_exe:
release:
ifeq (${RELEASE}, )
@echo "You must specify a release version ($(MAKE) release RELEASE=1.2.3)"
else
@echo "Will release: ${RELEASE}"
@echo "Checking release is in ChangeLog ..."
grep ${RELEASE} ChangeLog
@echo "Checking release is in meson.build ..."
grep ${RELEASE} meson.build
@echo "Checking release is in subprojects/libinsane/meson.build ..."
grep ${RELEASE} subprojects/libinsane/meson.build
@echo "Checking release is in subprojects/libinsane-gobject/meson.build ..."
grep ${RELEASE} subprojects/libinsane-gobject/meson.build
@echo "Releasing ..."
git tag -a ${RELEASE} -m ${RELEASE}
git push origin ${RELEASE}
@echo "All done"
endif
clean:
rm -rf build
rm -rf doc/build
rm -rf subprojects/libinsane-gobject/generated
mkdir -p subprojects/libinsane-gobject/generated
touch subprojects/libinsane-gobject/generated/.notempty
install_py:
install_c: build/build.ninja
(cd build && ninja install)
uninstall_py:
uninstall_c:
(cd build && ninja uninstall)
help:
@echo "make build || make build_c || make build_py"
@echo "make check"
@echo "make doc"
@echo "make help: display this message"
@echo "make install || make install_py"
@echo "make release"
@echo "make test"
@echo "make uninstall || make uninstall_py"
.PHONY: \
build \
build_c \
build_py \
check \
doc \
linux_exe \
windows_exe \
help \
install \
install_c \
install_py \
release \
test \
uninstall \
uninstall_c \
uninstall_py \
version
libinsane-1.0.10/README.markdown 0000664 0000000 0000000 00000006205 14377724077 0016263 0 ustar 00root root 0000000 0000000 Libinsane
---------
Libinsane is *the* library to access scanners on both Linux and Windows.
Its main features are:
- Cross-platform: tested on Linux and Windows,
[by CI](https://gitlab.gnome.org/World/OpenPaperwork/libinsane/pipelines) and
[by users](https://openpaper.work/scanner_db/).
- [Cross-API](https://doc.openpaper.work/libinsane/latest/libinsane/scan_apis.html):
supports Sane (Linux), WIA2 (Windows) and TWAIN (Windows)
- Cross-scanners: takes care of all the
[quirks](https://doc.openpaper.work/libinsane/latest/libinsane/workarounds.html)
of all the platforms and all the scanners to provide a
[consistent behaviour](https://doc.openpaper.work/libinsane/latest/libinsane/behavior_normalizations.html)
everywhere.
- Cross-programming languages:
[Libinsane-GObject](https://doc.openpaper.work/libinsane/latest/libinsane-gobject/index.html)
provides bindings for
[many programming languages](https://wiki.gnome.org/Projects/GObjectIntrospection/Users)
(Python, Java, Ruby, etc) thanks to
[GObject Introspection](https://gi.readthedocs.io/en/latest/).
- Returns the scan as it goes: whenever possible, the image returned by the
scanner is returned to the application as the scan goes.
- Very few runtime dependencies: Libinsane itself is a pure C library with
the strict minimum of runtime dependencies. Only Libinsane-Gobject depends
on the [GLib](https://developer.gnome.org/glib/).
However it has some limitations:
- It is only designed to work with *scanners*, not webcams, not USB keys, etc
(think paper-eaters only)
- TWAIN API or drivers may display some dialogs. Libinsane cannot prevent them.
- Full page scan only: Presence of the options to set the scan area and their
consistency cannot be guaranteed. You are advised to crop the image later
in your own application (see [Paperwork](https://openpaper.work) for example).
- On Windows (both with WIA2 or TWAIN), images are often rotated by 180°. This
is because both APIs return the scan as a BMP (DIB), and by default, BMPs start
by the bottom of the image. Libinsane returns the top of the image first
(as Sane does). Since we want applications to be able to display the
scan as it goes, Libinsane has to rotate the image.
- We do our best to support as many scanners and drivers as possible. However not
all the scanners in the world are supported (nor even supportable). You can have
a look at the [Scanner database](https://openpaper.work/scannerdb/) to see the
scanners that are known to work and those that don't.
It is the successor of [Pyinsane2](https://gitlab.gnome.org/World/OpenPaperwork/pyinsane) but shares no code with it.
It is released under [LGPL v3+](https://www.gnu.org/licenses/lgpl-3.0.en.html).
- [Documentation](https://doc.openpaper.work/libinsane/latest/index.html)
- [Forum](https://forum.openpaper.work/)
- [Bug tracker](https://gitlab.gnome.org/World/OpenPaperwork/libinsane/issues)
- [Scanner database](https://openpaper.work/scannerdb/)
- [Donate](https://www.patreon.com/openpaper) (I also accept hardware donations
to fix specific issues)
Related third-party projects:
- [lisgo](https://github.com/foenixx/lisgo): Go bindings for Libinsane
libinsane-1.0.10/activate_test_env.sh 0000775 0000000 0000000 00000000353 14377724077 0017626 0 ustar 00root root 0000000 0000000 make build_c && \
export GI_TYPELIB_PATH="${PWD}/build/subprojects/libinsane-gobject/src" && \
export LD_LIBRARY_PATH="${PWD}/build/subprojects/libinsane-gobject/src:build/subprojects/libinsane/src" && \
export VIRTUAL_ENV="libinsane"
libinsane-1.0.10/check_sparse.py 0000775 0000000 0000000 00000003016 14377724077 0016566 0 ustar 00root root 0000000 0000000 #!/usr/bin/env python3
import json
import os
import subprocess
import sys
def get_cflags(compile_commands):
for cfile in compile_commands:
cflags = cfile['command']
cflags = cflags.split(" ")
out = []
for f in cflags:
if f == "":
continue
if f[0] == "'" and f[-1] == "'":
f = f[1:-1]
if f[:2] == "-D" or f[:2] == "-I":
out.append(f)
yield (out, cfile['file'])
if __name__ == "__main__":
with open(sys.argv[1], 'r') as fd:
compile_commands = json.load(fd)
os.chdir(os.path.dirname(sys.argv[1]))
for (cflags, filepath) in get_cflags(compile_commands):
if "libinsane-gobject" in filepath:
# gobject macros raise many warnings --> do not check
continue
cflags += [
'-O2', '-Wsparse-all', '-Wsparse-error', '-Wno-non-pointer-null'
]
# WORKAROUND(Jflesch):
# TODO(Jflesch): Why do I need to do that ?
cflags += ['-D_Float32=float']
cflags += ['-D_Float32x=float']
cflags += ['-D_Float64=double']
cflags += ['-D_Float64x=double']
cflags += ['-D_Float128=double']
cflags += ['-D_Float128x=double']
cflags += ['-D__ARM_PCS_VFP']
print("Running sparse on {}".format(filepath))
cmd = ['sparse', filepath] + cflags
r = subprocess.run(cmd)
if r.returncode != 0:
print("Command was: {}".format(cmd))
sys.exit(r.returncode)
libinsane-1.0.10/deliver_doc.sh 0000775 0000000 0000000 00000001340 14377724077 0016373 0 ustar 00root root 0000000 0000000 #!/bin/sh
directory=doc/build
if [ -z "$RCLONE_CONFIG_OPENPAPERWORK_ACCESS_KEY_ID" ] ; then
echo "Delivery: No rclone credentials provided."
exit 0
fi
if ! which rclone; then
echo "rclone not available."
exit 1
fi
echo "Delivering: ${directory} (${CI_COMMIT_REF_NAME} - ${CI_COMMIT_SHORT_SHA})"
out_name="$(date "+%Y%m%d_%H%M%S")_${CI_COMMIT_REF_NAME}_${CI_COMMIT_SHORT_SHA}"
latest_name="latest"
if ! rclone --config ./rclone.conf copy "${directory}/" "openpaperwork:openpaperwork-doc/libinsane/${out_name}" ; then
echo "rclone failed"
exit 1
fi
if ! rclone --config ./rclone.conf sync "${directory}/" "openpaperwork:openpaperwork-doc/libinsane/latest" ; then
echo "rclone failed"
exit 1
fi
echo Success
exit 0
libinsane-1.0.10/doc/ 0000775 0000000 0000000 00000000000 14377724077 0014324 5 ustar 00root root 0000000 0000000 libinsane-1.0.10/doc/index.html 0000664 0000000 0000000 00000000652 14377724077 0016324 0 ustar 00root root 0000000 0000000
LibInsane documentation
libinsane-1.0.10/meson.build 0000664 0000000 0000000 00000000250 14377724077 0015716 0 ustar 00root root 0000000 0000000 project('libinsane-global', 'c',
version: '1.0.10',
license: 'LGPLv3+',
meson_version: '>=0.37.1')
subproject('libinsane')
subproject('libinsane-gobject')
libinsane-1.0.10/rclone.conf 0000664 0000000 0000000 00000000230 14377724077 0015703 0 ustar 00root root 0000000 0000000 [openpaperwork]
type = s3
env_auth = false
region = us-east-1
endpoint = https://objects.openpaper.work/
location_constraint =
server_side_encryption =
libinsane-1.0.10/splint.rc 0000664 0000000 0000000 00000000021 14377724077 0015407 0 ustar 00root root 0000000 0000000 -Iinclude
+quiet
libinsane-1.0.10/subprojects/ 0000775 0000000 0000000 00000000000 14377724077 0016122 5 ustar 00root root 0000000 0000000 libinsane-1.0.10/subprojects/libinsane-gobject/ 0000775 0000000 0000000 00000000000 14377724077 0021501 5 ustar 00root root 0000000 0000000 libinsane-1.0.10/subprojects/libinsane-gobject/autogen.sh 0000775 0000000 0000000 00000000032 14377724077 0023475 0 ustar 00root root 0000000 0000000 #!/bin/sh
autoreconf -fvi
libinsane-1.0.10/subprojects/libinsane-gobject/doc/ 0000775 0000000 0000000 00000000000 14377724077 0022246 5 ustar 00root root 0000000 0000000 libinsane-1.0.10/subprojects/libinsane-gobject/doc/gtkdocentities.ent 0000664 0000000 0000000 00000000221 14377724077 0025771 0 ustar 00root root 0000000 0000000
libinsane-1.0.10/subprojects/libinsane-gobject/doc/libinsane_gobject-gtkdoc.xml 0000664 0000000 0000000 00000003331 14377724077 0027702 0 ustar 00root root 0000000 0000000
%gtkdocentities;
]>
&package_name; Reference Manual
For &package_string;.
The latest version of this documentation can be found on-line at
&doc_url;.
Libinsane GObject Bindings Documentation
API Index
Index of deprecated API
libinsane-1.0.10/subprojects/libinsane-gobject/doc/meson.build 0000664 0000000 0000000 00000000516 14377724077 0024412 0 ustar 00root root 0000000 0000000 ## Doc
if build_machine.system() == 'linux'
gnome.gtkdoc('libinsane-gobject',
src_dir: include_directories('../src', '../include'),
main_xml: 'libinsane_gobject-gtkdoc.xml',
content_files: 'gtkdocentities.ent',
# gobject_typesfile: 'libinsane.types',
dependencies: libinsane_gobject_dep)
endif
libinsane-1.0.10/subprojects/libinsane-gobject/examples/ 0000775 0000000 0000000 00000000000 14377724077 0023317 5 ustar 00root root 0000000 0000000 libinsane-1.0.10/subprojects/libinsane-gobject/examples/list_devices.py 0000775 0000000 0000000 00000002473 14377724077 0026357 0 ustar 00root root 0000000 0000000 #!/usr/bin/env python3
# source ./activate_test_env.sh
# subprojects/libinsane-gobject/examples/list_devices.py
import gi
gi.require_version('Libinsane', '1.0')
from gi.repository import GObject # noqa: E402
#! [Logger]
from gi.repository import Libinsane # noqa: E402
class ExampleLogger(GObject.GObject, Libinsane.Logger):
def do_log(self, lvl, msg):
if lvl <= Libinsane.LogLevel.WARNING:
return
print("{}: {}".format(lvl.value_nick, msg))
def main():
Libinsane.register_logger(ExampleLogger())
#! [Logger]
api = Libinsane.Api.new_safebet()
print("Looking for devices ...")
devs = api.list_devices(Libinsane.DeviceLocations.ANY)
print("Found {} devices".format(len(devs)))
for d in devs:
try:
dev = api.get_device(d.get_dev_id())
print("|")
print("|-- {} ({} ; {})".format(
d.get_dev_id(), d.to_string(), dev.get_name()
))
try:
for child in dev.get_children():
print("| |-- {}".format(child.get_name()))
finally:
dev.close()
except Exception as exc:
print("ERROR: failed to open device {}: {}".format(
d.get_dev_id(), str(exc)
))
if __name__ == "__main__":
main()
libinsane-1.0.10/subprojects/libinsane-gobject/examples/list_options.py 0000775 0000000 0000000 00000007216 14377724077 0026430 0 ustar 00root root 0000000 0000000 #!/usr/bin/env python3
# source ./activate_test_env.sh
# subprojects/libinsane-gobject/examples/list_options.py
import os
import gi
gi.require_version('Libinsane', '1.0')
from gi.repository import GObject # noqa: E402
from gi.repository import Libinsane # noqa: E402
class ExampleLogger(GObject.GObject, Libinsane.Logger):
def do_log(self, lvl, msg):
if lvl <= Libinsane.LogLevel.DEBUG:
return
print("{}: {}".format(lvl.value_nick, msg))
def main():
if True:
os.environ['LIBINSANE_NORMALIZER_ALL_OPTS_ON_ALL_SOURCES'] = "0"
os.environ['LIBINSANE_NORMALIZER_BMP2RAW'] = "0"
os.environ['LIBINSANE_NORMALIZER_CLEAN_DEV_DESCS'] = "0"
os.environ['LIBINSANE_NORMALIZER_MIN_ONE_SOURCE'] = "0"
os.environ['LIBINSANE_NORMALIZER_OPT_ALIASES'] = "0"
os.environ['LIBINSANE_NORMALIZER_RAW24'] = "0"
os.environ['LIBINSANE_NORMALIZER_RESOLUTION'] = "0"
os.environ['LIBINSANE_NORMALIZER_SAFE_DEFAULTS'] = "0"
os.environ['LIBINSANE_NORMALIZER_SOURCE_NAMES'] = "0"
os.environ['LIBINSANE_NORMALIZER_SOURCE_NODES'] = "0"
os.environ['LIBINSANE_NORMALIZER_SOURCE_TYPES'] = "0"
os.environ['LIBINSANE_WORKAROUND_CACHE'] = "0"
os.environ['LIBINSANE_WORKAROUND_CHECK_CAPABILITIES'] = "0"
os.environ['LIBINSANE_WORKAROUND_DEDICATED_PROCESS'] = "0"
os.environ['LIBINSANE_WORKAROUND_DEDICATED_THREAD'] = "0"
os.environ['LIBINSANE_WORKAROUND_LAMP'] = "0"
os.environ['LIBINSANE_WORKAROUND_ONE_PAGE_FLATBED'] = "0"
os.environ['LIBINSANE_WORKAROUND_OPT_NAMES'] = "0"
os.environ['LIBINSANE_WORKAROUND_OPT_VALUES'] = "0"
Libinsane.register_logger(ExampleLogger())
api = Libinsane.Api.new_safebet()
devs = api.list_devices(Libinsane.DeviceLocations.ANY)
print("Found {} devices".format(len(devs)))
for dev in devs:
print("")
print("")
print(dev.to_string())
try:
dev = api.get_device(dev.get_dev_id())
children = dev.get_children()
print("|-- Found {} sources".format(len(children)))
for item in [dev] + children:
print("|")
print("|-- {} ({})".format(
item.get_name(),
"device" if item == dev else "source"
))
opts = item.get_options()
for opt in opts:
print("| |-- {}".format(opt.get_name()))
print("| | |-- Title: {}".format(opt.get_title()))
print("| | |-- Description: {}".format(opt.get_desc()))
print("| | |-- Capabilities: {}".format(
opt.get_capabilities())
)
print("| | |-- Unit: {}".format(opt.get_value_unit()))
print("| | |-- Constraint type: {}".format(
opt.get_constraint_type()))
print("| | |-- Constraint: {}".format(
opt.get_constraint())
)
if opt.is_readable():
try:
print("| | |-- Value: {}".format(
opt.get_value())
)
except Exception as exc:
print("| | |-- Value: [{}]".format(str(exc)))
else:
print("| | |-- Value: (unavailable)")
print("")
dev.close()
except Exception as exc:
print("EXCEPTION: {}".format(exc))
if __name__ == "__main__":
main()
libinsane-1.0.10/subprojects/libinsane-gobject/examples/scan.py 0000775 0000000 0000000 00000017351 14377724077 0024627 0 ustar 00root root 0000000 0000000 #!/usr/bin/env python3
# source ./activate_test_env.sh
# subprojects/libinsane-gobject/examples/scan.py
import os
import PIL.Image
import sys
import traceback
import gi
gi.require_version('Libinsane', '1.0')
from gi.repository import GObject # noqa: E402
from gi.repository import Libinsane # noqa: E402
#! [ExampleLogger]
class ExampleLogger(GObject.GObject, Libinsane.Logger):
def do_log(self, lvl, msg):
if lvl <= Libinsane.LogLevel.INFO:
return
print("{}: {}".format(lvl.value_nick, msg))
sys.stdout.flush()
#! [ExampleLogger]
#! [ExampleListGetDevice]
def get_device(api, dev_id=None):
if dev_id is None:
print("Looking for scan devices ...")
devs = api.list_devices(Libinsane.DeviceLocations.ANY)
print("Found {} devices".format(len(devs)))
for dev in devs:
print("[{}] : [{}]".format(dev.get_dev_id(), dev.to_string()))
dev_id = devs[0].get_dev_id()
print("Will use device {}".format(dev_id))
dev = api.get_device(dev_id)
print("Using device {}".format(dev.get_name()))
return dev
#! [ExampleListGetDevice]
#! [ExampleListGetScanSource]
def get_source(dev, source_name):
print("Looking for scan sources ...")
sources = dev.get_children()
print("Available scan sources:")
for src in sources:
print("- {}".format(src.get_name()))
if src.get_name() == source_name:
source = src
break
else:
if source_name is None:
source = sources[0] if len(sources) > 0 else dev
elif source_name == "root":
source = dev
else:
print("Source '{}' not found".format(source_name))
sys.exit(2)
print("Will use scan source {}".format(source.get_name()))
return source
#! [ExampleListGetScanSource]
#! [ExampleSetOption]
def set_opt(item, opt_name, opt_value):
try:
print("Setting {} to {}".format(opt_name, opt_value))
opts = item.get_options()
opts = {opt.get_name(): opt for opt in opts}
if opt_name not in opts:
print("Option '{}' not found".format(opt_name))
return
print("- Old {}: {}".format(opt_name, opts[opt_name].get_value()))
print("- Allowed values: {}".format(opts[opt_name].get_constraint()))
set_flags = opts[opt_name].set_value(opt_value)
print("- Set flags: {}".format(set_flags))
opts = item.get_options()
opts = {opt.get_name(): opt for opt in opts}
print("- New {}: {}".format(opt_name, opts[opt_name].get_value()))
except Exception as exc:
print("Failed to set {} to {}: {}".format(
opt_name, opt_value, str(exc)
))
traceback.print_exc()
finally:
print("")
#! [ExampleSetOption]
#! [ExampleListOptions]
def list_opts(item):
opts = item.get_options()
print("Options:")
for opt in opts:
try:
print("- {}={} ({})".format(
opt.get_name(), opt.get_value(), opt.get_constraint()
))
except Exception as exc:
print("Failed to read option {}: {}".format(
opt.get_name(), str(exc)
))
print("")
#! [ExampleListOptions]
#! [ExampleRawToImg]
def raw_to_img(params, img_bytes):
fmt = params.get_format()
assert(fmt == Libinsane.ImgFormat.RAW_RGB_24)
(w, h) = (
params.get_width(),
int(len(img_bytes) / 3 / params.get_width())
)
print("Mode: RGB : Size: {}x{}".format(w, h))
return PIL.Image.frombuffer("RGB", (w, h), img_bytes, "raw", "RGB", 0, 1)
#! [ExampleRawToImg]
#! [ExampleScan]
def scan(source, output_file):
session = source.scan_start()
try:
page_nb = 0
while not session.end_of_feed() and page_nb < 20:
# Do not assume that all the pages will have the same size !
scan_params = session.get_scan_parameters()
print("Expected scan parameters: {} ; {}x{} = {} bytes".format(
scan_params.get_format(),
scan_params.get_width(), scan_params.get_height(),
scan_params.get_image_size()))
total = scan_params.get_image_size()
img = []
r = 0
if output_file is not None:
out = output_file.format(page_nb)
else:
out = None
print("Scanning page {} --> {}".format(page_nb, out))
while not session.end_of_page():
data = session.read_bytes(128 * 1024)
data = data.get_data()
img.append(data)
r += len(data)
print("Got {} bytes => {}/{} bytes".format(
len(data), r, total)
)
img = b"".join(img)
print("Got {} bytes".format(len(img)))
if out is not None:
print("Saving page as {} ...".format(out))
if scan_params.get_format() == Libinsane.ImgFormat.RAW_RGB_24:
img = raw_to_img(scan_params, img)
img.save(out, format="PNG")
else:
print("Warning: output format is {}".format(
scan_params.get_format()
))
with open(out, 'wb') as fd:
fd.write(img)
page_nb += 1
print("Page {} scanned".format(page_nb))
if page_nb == 0:
print("No page in feeder ?")
finally:
session.cancel()
#! [ExampleScan]
def main():
if False:
os.environ['LIBINSANE_NORMALIZER_ALL_OPTS_ON_ALL_SOURCES'] = "0"
os.environ['LIBINSANE_NORMALIZER_BMP2RAW'] = "0"
os.environ['LIBINSANE_NORMALIZER_CLEAN_DEV_DESCS'] = "0"
os.environ['LIBINSANE_NORMALIZER_MIN_ONE_SOURCE'] = "0"
os.environ['LIBINSANE_NORMALIZER_OPT_ALIASES'] = "0"
os.environ['LIBINSANE_NORMALIZER_RAW24'] = "0"
os.environ['LIBINSANE_NORMALIZER_RESOLUTION'] = "0"
os.environ['LIBINSANE_NORMALIZER_SAFE_DEFAULTS'] = "0"
os.environ['LIBINSANE_NORMALIZER_SOURCE_NAMES'] = "0"
os.environ['LIBINSANE_NORMALIZER_SOURCE_NODES'] = "0"
os.environ['LIBINSANE_NORMALIZER_SOURCE_TYPES'] = "0"
os.environ['LIBINSANE_WORKAROUND_CACHE'] = "0"
os.environ['LIBINSANE_WORKAROUND_CHECK_CAPABILITIES'] = "0"
os.environ['LIBINSANE_WORKAROUND_DEDICATED_THREAD'] = "0"
os.environ['LIBINSANE_WORKAROUND_LAMP'] = "0"
os.environ['LIBINSANE_WORKAROUND_ONE_PAGE_FLATBED'] = "0"
os.environ['LIBINSANE_WORKAROUND_OPT_NAMES'] = "0"
os.environ['LIBINSANE_WORKAROUND_OPT_VALUES'] = "0"
#! [ExampleSetLogger]
Libinsane.register_logger(ExampleLogger())
#! [ExampleSetLogger]
if len(sys.argv) <= 1 or (sys.argv[1] == "-h" or sys.argv[1] == "--help"):
print(
"Syntax: {}"
" "
" [ []]".format(sys.argv[0])
)
sys.exit(1)
output_file = sys.argv[1]
dev_id = None
source = None
source_name = None
if len(sys.argv) > 2:
dev_id = sys.argv[2]
if len(sys.argv) > 3:
source_name = sys.argv[3]
print("Will write the scan result into {}".format(output_file))
#! [ExampleInit]
api = Libinsane.Api.new_safebet()
#! [ExampleInit]
dev = get_device(api, dev_id)
try:
source = get_source(dev, source_name)
list_opts(source)
# set the options
#! [ExampleOptsToSet]
set_opt(source, 'resolution', 300)
# set_opt(source, 'mode', "LineArt")
# set_opt(source, 'depth', 1)
#! [ExampleOptsToSet]
print("Scanning ...")
scan(source, output_file)
print("Scan done")
finally:
dev.close()
if __name__ == "__main__":
main()
libinsane-1.0.10/subprojects/libinsane-gobject/generated/ 0000775 0000000 0000000 00000000000 14377724077 0023437 5 ustar 00root root 0000000 0000000 libinsane-1.0.10/subprojects/libinsane-gobject/generated/.notempty 0000664 0000000 0000000 00000000000 14377724077 0025305 0 ustar 00root root 0000000 0000000 libinsane-1.0.10/subprojects/libinsane-gobject/include/ 0000775 0000000 0000000 00000000000 14377724077 0023124 5 ustar 00root root 0000000 0000000 libinsane-1.0.10/subprojects/libinsane-gobject/include/libinsane-gobject/ 0000775 0000000 0000000 00000000000 14377724077 0026503 5 ustar 00root root 0000000 0000000 libinsane-1.0.10/subprojects/libinsane-gobject/include/libinsane-gobject/capability.h 0000664 0000000 0000000 00000000672 14377724077 0031002 0 ustar 00root root 0000000 0000000 #ifndef __LIBINSANE_GOBJECT_CAPABILITY_H
#define __LIBINSANE_GOBJECT_CAPABILITY_H
/**
* LibinsaneCapability:
* Not actually an enum but a bit field.
*/
typedef enum
{
LIBINSANE_CAPABILITY_NONE = 0,
LIBINSANE_CAPABILITY_EMULATED = 1 << 0,
LIBINSANE_CAPABILITY_AUTOMATIC = 1 << 1,
LIBINSANE_CAPABILITY_HW_SELECT = 1 << 2,
LIBINSANE_CAPABILITY_SW_SELECT = 1 << 3,
LIBINSANE_CAPABILITY_INACTIVE = 1 << 4,
} LibinsaneCapability;
#endif
libinsane-1.0.10/subprojects/libinsane-gobject/include/libinsane-gobject/constraint.h 0000664 0000000 0000000 00000000445 14377724077 0031043 0 ustar 00root root 0000000 0000000 #ifndef __LIBINSANE_GOBJECT_CONSTRAINT_TYPE
#define __LIBINSANE_GOBJECT_CONSTRAINT_TYPE
#include
G_BEGIN_DECLS
typedef enum
{
LIBINSANE_CONSTRAINT_TYPE_NONE,
LIBINSANE_CONSTRAINT_TYPE_RANGE,
LIBINSANE_CONSTRAINT_TYPE_LIST,
} LibinsaneConstraintType;
G_END_DECLS
#endif
libinsane-1.0.10/subprojects/libinsane-gobject/include/libinsane-gobject/device_descriptor.h 0000664 0000000 0000000 00000003263 14377724077 0032355 0 ustar 00root root 0000000 0000000 #ifndef __LIBINSANE_GOBJECT_DEVICE_DESCRIPTOR_H
#define __LIBINSANE_GOBJECT_DEVICE_DESCRIPTOR_H
#include
G_BEGIN_DECLS
#define LIBINSANE_DEVICE_DESCRIPTOR_TYPE \
(libinsane_device_descriptor_get_type())
#define LIBINSANE_DEVICE_DESCRIPTOR(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), LIBINSANE_DEVICE_DESCRIPTOR_TYPE, LibinsaneDeviceDescriptor))
#define LIBINSANE_DEVICE_DESCRIPTOR_CLASS(cls) \
(G_TYPE_CHECK_CLASS_CAST ((cls), LIBINSANE_DEVICE_DESCRIPTOR_TYPE, LibinsaneDeviceDescriptorClass))
#define LIBINSANE_IS_DEVICE_DESCRIPTOR(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), LIBINSANE_DEVICE_DESCRIPTOR_TYPE))
#define LIBINSANE_DEVICE_DESCRIPTOR_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), LIBINSANE_DEVICE_DESCRIPTOR_TYPE, LibinsaneDeviceDescriptorClass))
typedef struct _LibinsaneDeviceDescriptor LibinsaneDeviceDescriptor;
typedef struct _LibinsaneDeviceDescriptorPrivate LibinsaneDeviceDescriptorPrivate;
typedef struct _LibinsaneDeviceDescriptorClass LibinsaneDeviceDescriptorClass;
struct _LibinsaneDeviceDescriptor {
GObject parent;
};
struct _LibinsaneDeviceDescriptorClass {
GObjectClass parent;
};
GType libinsane_device_descriptor_get_type(void) G_GNUC_CONST;
/* no public constructor */
const char *libinsane_device_descriptor_get_dev_id(LibinsaneDeviceDescriptor *self);
const char *libinsane_device_descriptor_get_dev_vendor(LibinsaneDeviceDescriptor *self);
const char *libinsane_device_descriptor_get_dev_model(LibinsaneDeviceDescriptor *self);
const char *libinsane_device_descriptor_get_dev_type(LibinsaneDeviceDescriptor *self);
const char *libinsane_device_descriptor_to_string(LibinsaneDeviceDescriptor *self);
G_END_DECLS
#endif
libinsane-1.0.10/subprojects/libinsane-gobject/include/libinsane-gobject/device_descriptor_private.h0000664 0000000 0000000 00000000437 14377724077 0034107 0 ustar 00root root 0000000 0000000 #ifndef __LIBINSANE_DEVICE_DESCRIPTOR_PRIVATE_H
#define __LIBINSANE_DEVICE_DESCRIPTOR_PRIVATE_H
#include
#include "device_descriptor.h"
LibinsaneDeviceDescriptor *libinsane_device_descriptor_new_from_libinsane(
const struct lis_device_descriptor *desc
);
#endif
libinsane-1.0.10/subprojects/libinsane-gobject/include/libinsane-gobject/error.h 0000664 0000000 0000000 00000001332 14377724077 0030004 0 ustar 00root root 0000000 0000000 #ifndef __LIBINSANE_GOBJECT_ERROR_H
#define __LIBINSANE_GOBJECT_ERROR_H
#include
G_BEGIN_DECLS
GQuark libinsane_error_quark(void);
#define LIBINSANE_ERROR libinsane_error_quark()
typedef enum {
LIBINSANE_ERROR_OK = 0,
LIBINSANE_ERROR_CANCELLED,
LIBINSANE_ERROR_DEVICE_BUSY,
LIBINSANE_ERROR_UNSUPPORTED,
LIBINSANE_ERROR_INVALID_VALUE,
LIBINSANE_ERROR_JAMMED,
LIBINSANE_ERROR_COVER_OPEN,
LIBINSANE_ERROR_IO_ERROR,
LIBINSANE_ERROR_NO_MEM,
LIBINSANE_ERROR_ACCESS_DENIED,
LIBINSANE_ERROR_HW_IS_LOCKED,
LIBINSANE_ERROR_INTERNAL_IMG_FORMAT_NOT_SUPPORTED,
LIBINSANE_ERROR_INTERNAL_NOT_IMPLEMENTED,
LIBINSANE_ERROR_INTERNAL_UNKNOWN_ERROR,
LIBINSANE_ERROR_OFFLINE,
} LibinsaneError;
G_END_DECLS
#endif
libinsane-1.0.10/subprojects/libinsane-gobject/include/libinsane-gobject/error_private.h 0000664 0000000 0000000 00000000605 14377724077 0031540 0 ustar 00root root 0000000 0000000 #ifndef __LIBINSANE_GOBJECT_ERROR_PRIVATE_H
#define __LIBINSANE_GOBJECT_ERROR_PRIVATE_H
#include
#include "error.h"
#define SET_LIBINSANE_GOBJECT_ERROR(gerror, libinsane_err, msg, ...) \
g_set_error( \
(gerror), \
LIBINSANE_ERROR, lis_error_to_gobject(libinsane_err), \
msg, __VA_ARGS__ \
);
LibinsaneError lis_error_to_gobject(enum lis_error err);
#endif
libinsane-1.0.10/subprojects/libinsane-gobject/include/libinsane-gobject/img_format.h 0000664 0000000 0000000 00000001167 14377724077 0031005 0 ustar 00root root 0000000 0000000 #ifndef __LIBINSANE_GOBJECT_IMG_FORMAT_H
#define __LIBINSANE_GOBJECT_IMG_FORMAT_H
typedef enum
{
LIBINSANE_IMG_FORMAT_RAW_RGB_24,
LIBINSANE_IMG_FORMAT_GRAYSCALE_8,
LIBINSANE_IMG_FORMAT_BW_1,
LIBINSANE_IMG_FORMAT_BMP,
LIBINSANE_IMG_FORMAT_GIF,
LIBINSANE_IMG_FORMAT_JPEG,
LIBINSANE_IMG_FORMAT_PNG,
LIBINSANE_IMG_FORMAT_CIFF,
LIBINSANE_IMG_FORMAT_EXIF,
LIBINSANE_IMG_FORMAT_FLASHPIX,
LIBINSANE_IMG_FORMAT_ICO,
LIBINSANE_IMG_FORMAT_JPEG2K,
LIBINSANE_IMG_FORMAT_JPEG2KX,
LIBINSANE_IMG_FORMAT_MEMORYBMP,
LIBINSANE_IMG_FORMAT_PHOTOCD,
LIBINSANE_IMG_FORMAT_PICT,
LIBINSANE_IMG_FORMAT_TIFF,
} LibinsaneImgFormat;
#endif
libinsane-1.0.10/subprojects/libinsane-gobject/include/libinsane-gobject/item.h 0000664 0000000 0000000 00000002703 14377724077 0027614 0 ustar 00root root 0000000 0000000 #ifndef __LIBINSANE_GOBJECT_ITEM_H
#define __LIBINSANE_GOBJECT_ITEM_H
#include
#include "item_type.h"
#include "scan_session.h"
G_BEGIN_DECLS
#define LIBINSANE_ITEM_TYPE \
(libinsane_item_get_type())
#define LIBINSANE_ITEM(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), LIBINSANE_ITEM_TYPE, LibinsaneItem))
#define LIBINSANE_ITEM_CLASS(cls) \
(G_TYPE_CHECK_CLASS_CAST ((cls), LIBINSANE_ITEM_TYPE, LibinsaneItemClass))
#define LIBINSANE_IS_ITEM(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), LIBINSANE_ITEM_TYPE))
#define LIBINSANE_ITEM_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), LIBINSANE_ITEM_TYPE, LibinsaneItemClass))
typedef struct _LibinsaneItem LibinsaneItem;
typedef struct _LibinsaneItemPrivate LibinsaneItemPrivate;
typedef struct _LibinsaneItemClass LibinsaneItemClass;
struct _LibinsaneItem {
GObject parent;
};
struct _LibinsaneItemClass {
GObjectClass parent;
};
GType libinsane_item_get_type(void) G_GNUC_CONST;
/* no public constructor */
const char *libinsane_item_get_name(LibinsaneItem *self);
LibinsaneItemType libinsane_item_get_item_type(LibinsaneItem *self);
void libinsane_item_close(LibinsaneItem *self, GError **error);
GList *libinsane_item_get_children(LibinsaneItem *self, GError **error);
GList *libinsane_item_get_options(LibinsaneItem *self, GError **error); /* TODO */
LibinsaneScanSession *libinsane_item_scan_start(LibinsaneItem *self, GError **error); /* TODO */
G_END_DECLS
#endif
libinsane-1.0.10/subprojects/libinsane-gobject/include/libinsane-gobject/item_private.h 0000664 0000000 0000000 00000000357 14377724077 0031351 0 ustar 00root root 0000000 0000000 #ifndef __LIBINSANE_ITEM_PRIVATE_H
#define __LIBINSANE_ITEM_PRIVATE_H
#include
#include "item.h"
LibinsaneItem *libinsane_item_new_from_libinsane(
GObject *parent, gboolean root, struct lis_item *lis_item
);
#endif
libinsane-1.0.10/subprojects/libinsane-gobject/include/libinsane-gobject/item_type.h 0000664 0000000 0000000 00000000372 14377724077 0030655 0 ustar 00root root 0000000 0000000 #ifndef __LIBINSANE_GOBJECT_ITEM_TYPE_H
#define __LIBINSANE_GOBJECT_ITEM_TYPE_H
typedef enum
{
LIBINSANE_ITEM_TYPE_DEVICE,
LIBINSANE_ITEM_TYPE_FLATBED,
LIBINSANE_ITEM_TYPE_ADF,
LIBINSANE_ITEM_TYPE_UNIDENTIFIED = -1,
} LibinsaneItemType;
#endif
libinsane-1.0.10/subprojects/libinsane-gobject/include/libinsane-gobject/libinsane-api.h 0000664 0000000 0000000 00000002740 14377724077 0031372 0 ustar 00root root 0000000 0000000 #ifndef __LIBINSANE_GOBJECT_API_H
#define __LIBINSANE_GOBJECT_API_H
#include
#include "item.h"
G_BEGIN_DECLS
typedef enum {
LIBINSANE_DEVICE_LOCATIONS_ANY = 0,
LIBINSANE_DEVICE_LOCATIONS_LOCAL_ONLY,
} LibinsaneDeviceLocations;
#define LIBINSANE_API_TYPE \
(libinsane_api_get_type())
#define LIBINSANE_API(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), LIBINSANE_API_TYPE, LibinsaneApi))
#define LIBINSANE_API_CLASS(cls) \
(G_TYPE_CHECK_CLASS_CAST ((cls), LIBINSANE_API_TYPE, LibinsaneApiClass))
#define LIBINSANE_IS_API(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), LIBINSANE_API_TYPE))
#define LIBINSANE_API_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), LIBINSANE_API_TYPE, LibinsaneApiClass))
typedef struct _LibinsaneApi LibinsaneApi;
typedef struct _LibinsaneApiPrivate LibinsaneApiPrivate;
typedef struct _LibinsaneApiClass LibinsaneApiClass;
struct _LibinsaneApi {
GObject parent;
};
struct _LibinsaneApiClass {
GObjectClass parent;
};
GType libinsane_api_get_type(void) G_GNUC_CONST;
const char *libinsane_api_get_version(void);
LibinsaneApi *libinsane_api_new_safebet(GError **error);
LibinsaneApi *libinsane_api_new_from_string(const char *desc, GError **error);
GList *libinsane_api_list_devices(
LibinsaneApi *self, LibinsaneDeviceLocations locations, GError **error
);
LibinsaneItem *libinsane_api_get_device(LibinsaneApi *self, const char *dev_id, GError **error);
void libinsane_api_cleanup(LibinsaneApi *self);
G_END_DECLS
#endif
libinsane-1.0.10/subprojects/libinsane-gobject/include/libinsane-gobject/log.h 0000664 0000000 0000000 00000001354 14377724077 0027440 0 ustar 00root root 0000000 0000000 #ifndef __LIBINSANE_GOBJECT_LOG_H
#define __LIBINSANE_GOBJECT_LOG_H
#include
G_BEGIN_DECLS
typedef enum {
LIBINSANE_LOG_LEVEL_DEBUG,
LIBINSANE_LOG_LEVEL_INFO,
LIBINSANE_LOG_LEVEL_WARNING,
LIBINSANE_LOG_LEVEL_ERROR,
} LibinsaneLogLevel;
#define LIBINSANE_TYPE_LOGGER libinsane_logger_get_type()
G_DECLARE_INTERFACE(LibinsaneLogger, libinsane_logger, LIBINSANE, LOGGER, GObject)
struct _LibinsaneLoggerInterface
{
GTypeInterface parent;
void (*log)(LibinsaneLogger *self, LibinsaneLogLevel lvl, const char *msg);
};
void libinsane_logger_log(LibinsaneLogger *self, LibinsaneLogLevel lvl, const char *msg);
void libinsane_register_logger(LibinsaneLogger *logger);
void libinsane_unregister_logger();
G_END_DECLS
#endif
libinsane-1.0.10/subprojects/libinsane-gobject/include/libinsane-gobject/option_descriptor.h 0000664 0000000 0000000 00000005116 14377724077 0032425 0 ustar 00root root 0000000 0000000 #ifndef __LIBINSANE_GOBJECT_OPTION_DESCRIPTOR_H
#define __LIBINSANE_GOBJECT_OPTION_DESCRIPTOR_H
#include
#include "capability.h"
#include "constraint.h"
#include "unit.h"
G_BEGIN_DECLS
typedef enum {
LIBINSANE_SET_FLAG_NONE = 0,
LIBINSANE_SET_FLAG_INEXACT = (1<<0),
LIBINSANE_SET_FLAG_MUST_RELOAD_OPTIONS = (1<<1),
LIBINSANE_SET_FLAG_MUST_RELOAD_PARAMS = (1<<2),
} LibinsaneSetFlag;
#define LIBINSANE_OPTION_DESCRIPTOR_TYPE \
(libinsane_option_descriptor_get_type())
#define LIBINSANE_OPTION_DESCRIPTOR(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), LIBINSANE_OPTION_DESCRIPTOR_TYPE, LibinsaneOptionDescriptor))
#define LIBINSANE_OPTION_DESCRIPTOR_CLASS(cls) \
(G_TYPE_CHECK_CLASS_CAST ((cls), LIBINSANE_OPTION_DESCRIPTOR_TYPE, LibinsaneOptionDescriptorClass))
#define LIBINSANE_IS_OPTION_DESCRIPTOR(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), LIBINSANE_OPTION_DESCRIPTOR_TYPE))
#define LIBINSANE_OPTION_DESCRIPTOR_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), LIBINSANE_OPTION_DESCRIPTOR_TYPE, LibinsaneOptionDescriptorClass))
typedef struct _LibinsaneOptionDescriptor LibinsaneOptionDescriptor;
typedef struct _LibinsaneOptionDescriptorPrivate LibinsaneOptionDescriptorPrivate;
typedef struct _LibinsaneOptionDescriptorClass LibinsaneOptionDescriptorClass;
struct _LibinsaneOptionDescriptor {
GObject parent;
};
struct _LibinsaneOptionDescriptorClass {
GObjectClass parent;
};
GType libinsane_option_descriptor_get_type(void) G_GNUC_CONST;
const char *libinsane_option_descriptor_get_name(LibinsaneOptionDescriptor *self);
const char *libinsane_option_descriptor_get_title(LibinsaneOptionDescriptor *self);
const char *libinsane_option_descriptor_get_desc(LibinsaneOptionDescriptor *self);
LibinsaneCapability libinsane_option_descriptor_get_capabilities(LibinsaneOptionDescriptor *self);
GType libinsane_option_descriptor_get_value_type(LibinsaneOptionDescriptor *self);
LibinsaneUnit libinsane_option_descriptor_get_value_unit(LibinsaneOptionDescriptor *self);
LibinsaneConstraintType libinsane_option_descriptor_get_constraint_type(LibinsaneOptionDescriptor *self);
GArray *libinsane_option_descriptor_get_constraint(LibinsaneOptionDescriptor *self);
gboolean libinsane_option_descriptor_is_readable(LibinsaneOptionDescriptor *self);
gboolean libinsane_option_descriptor_is_writable(LibinsaneOptionDescriptor *self);
const GValue *libinsane_option_descriptor_get_value(LibinsaneOptionDescriptor *self, GError **error);
LibinsaneSetFlag libinsane_option_descriptor_set_value(LibinsaneOptionDescriptor *self, GValue *value, GError **error);
G_END_DECLS
#endif
libinsane-1.0.10/subprojects/libinsane-gobject/include/libinsane-gobject/option_descriptor_private.h0000664 0000000 0000000 00000000475 14377724077 0034162 0 ustar 00root root 0000000 0000000 #ifndef __LIBINSANE_GOBJECT_OPTION_DESCRIPTOR_PRIVATE_H
#define __LIBINSANE_GOBJECT_OPTION_DESCRIPTOR_PRIVATE_H
#include
#include "option_descriptor.h"
LibinsaneOptionDescriptor *libinsane_option_descriptor_new_from_libinsane(
GObject *parent,
struct lis_option_descriptor *desc
);
#endif
libinsane-1.0.10/subprojects/libinsane-gobject/include/libinsane-gobject/scan_parameters.h 0000664 0000000 0000000 00000003044 14377724077 0032024 0 ustar 00root root 0000000 0000000 #ifndef __LIBINSANE_GOBJECT_SCAN_PARAMETERS_H
#define __LIBINSANE_GOBJECT_SCAN_PARAMETERS_H
#include
#include "img_format.h"
G_BEGIN_DECLS
#define LIBINSANE_SCAN_PARAMETERS_TYPE \
(libinsane_scan_parameters_get_type())
#define LIBINSANE_SCAN_PARAMETERS(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), LIBINSANE_SCAN_PARAMETERS_TYPE, LibinsaneScanParameters))
#define LIBINSANE_SCAN_PARAMETERS_CLASS(cls) \
(G_TYPE_CHECK_CLASS_CAST ((cls), LIBINSANE_SCAN_PARAMETERS_TYPE, LibinsaneScanParametersClass))
#define LIBINSANE_IS_SCAN_PARAMETERS(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), LIBINSANE_SCAN_PARAMETERS_TYPE))
#define LIBINSANE_SCAN_PARAMETERS_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), LIBINSANE_SCAN_PARAMETERS_TYPE, LibinsaneScanParametersClass))
typedef struct _LibinsaneScanParameters LibinsaneScanParameters;
typedef struct _LibinsaneScanParametersPrivate LibinsaneScanParametersPrivate;
typedef struct _LibinsaneScanParametersClass LibinsaneScanParametersClass;
struct _LibinsaneScanParameters {
GObject parent;
};
struct _LibinsaneScanParametersClass {
GObjectClass parent;
};
GType libinsane_scan_parameters_get_type(void) G_GNUC_CONST;
/* no public constructor */
LibinsaneImgFormat libinsane_scan_parameters_get_format(LibinsaneScanParameters *self);
int libinsane_scan_parameters_get_width(LibinsaneScanParameters *self);
int libinsane_scan_parameters_get_height(LibinsaneScanParameters *self);
gsize libinsane_scan_parameters_get_image_size(LibinsaneScanParameters *self);
G_END_DECLS
#endif
libinsane-1.0.10/subprojects/libinsane-gobject/include/libinsane-gobject/scan_parameters_private.h 0000664 0000000 0000000 00000000400 14377724077 0033547 0 ustar 00root root 0000000 0000000 #ifndef __LIBINSANE_SCAN_PARAMETERS_PRIVATE_H
#define __LIBINSANE_SCAN_PARAMETERS_PRIVATE_H
#include
#include "item.h"
LibinsaneScanParameters *libinsane_scan_parameters_new_from_libinsane(struct lis_scan_parameters *params);
#endif
libinsane-1.0.10/subprojects/libinsane-gobject/include/libinsane-gobject/scan_session.h 0000664 0000000 0000000 00000003325 14377724077 0031346 0 ustar 00root root 0000000 0000000 #ifndef __LIBINSANE_GOBJECT_SCAN_SESSION_H
#define __LIBINSANE_GOBJECT_SCAN_SESSION_H
#include
#include
#include "scan_parameters.h"
G_BEGIN_DECLS
#define LIBINSANE_SCAN_SESSION_TYPE \
(libinsane_scan_session_get_type())
#define LIBINSANE_SCAN_SESSION(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), LIBINSANE_SCAN_SESSION_TYPE, LibinsaneScanSession))
#define LIBINSANE_SCAN_SESSION_CLASS(cls) \
(G_TYPE_CHECK_CLASS_CAST ((cls), LIBINSANE_SCAN_SESSION_TYPE, LibinsaneScanSessionClass))
#define LIBINSANE_IS_SCAN_SESSION(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), LIBINSANE_SCAN_SESSION_TYPE))
#define LIBINSANE_SCAN_SESSION_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), LIBINSANE_SCAN_SESSION_TYPE, LibinsaneScanSessionClass))
typedef struct _LibinsaneScanSession LibinsaneScanSession;
typedef struct _LibinsaneScanSessionPrivate LibinsaneScanSessionPrivate;
typedef struct _LibinsaneScanSessionClass LibinsaneScanSessionClass;
struct _LibinsaneScanSession {
GInputStream parent;
};
struct _LibinsaneScanSessionClass {
GInputStreamClass parent;
};
GType libinsane_scan_session_get_type(void) G_GNUC_CONST;
/* no public constructor */
LibinsaneScanParameters *libinsane_scan_session_get_scan_parameters(LibinsaneScanSession *self, GError **error);
gboolean libinsane_scan_session_end_of_feed(LibinsaneScanSession *self);
gboolean libinsane_scan_session_end_of_page(LibinsaneScanSession *self);
gssize libinsane_scan_session_read(LibinsaneScanSession *self, void *buffer, gsize lng, GError **error);
GBytes *libinsane_scan_session_read_bytes(LibinsaneScanSession *self, gsize lng, GError **error);
void libinsane_scan_session_cancel(LibinsaneScanSession *self);
G_END_DECLS
#endif
libinsane-1.0.10/subprojects/libinsane-gobject/include/libinsane-gobject/scan_session_private.h 0000664 0000000 0000000 00000000423 14377724077 0033074 0 ustar 00root root 0000000 0000000 #ifndef __LIBINSANE_SCAN_SESSION_PRIVATE_H
#define __LIBINSANE_SCAN_SESSION_PRIVATE_H
#include
#include "scan_session.h"
LibinsaneScanSession *libinsane_scan_session_new_from_libinsane(
GObject *parent, struct lis_scan_session *scan_session
);
#endif
libinsane-1.0.10/subprojects/libinsane-gobject/include/libinsane-gobject/unit.h 0000664 0000000 0000000 00000000424 14377724077 0027633 0 ustar 00root root 0000000 0000000 #ifndef __LIBINSANE_GOBJECT_UNIT_H
#define __LIBINSANE_GOBJECT_UNIT_H
typedef enum
{
LIBINSANE_UNIT_NONE = 0,
LIBINSANE_UNIT_PIXEL,
LIBINSANE_UNIT_BIT,
LIBINSANE_UNIT_MM,
LIBINSANE_UNIT_DPI,
LIBINSANE_UNIT_PERCENT,
LIBINSANE_UNIT_MICROSECOND,
} LibinsaneUnit;
#endif
libinsane-1.0.10/subprojects/libinsane-gobject/include/meson.build 0000664 0000000 0000000 00000001206 14377724077 0025265 0 ustar 00root root 0000000 0000000 INSANE_GOBJECT_HEADERS = files(
'libinsane-gobject/capability.h',
'libinsane-gobject/constraint.h',
'libinsane-gobject/device_descriptor.h',
'libinsane-gobject/error.h',
'libinsane-gobject/img_format.h',
'libinsane-gobject/item.h',
'libinsane-gobject/item_type.h',
'libinsane-gobject/libinsane-api.h',
'libinsane-gobject/log.h',
'libinsane-gobject/option_descriptor.h',
'libinsane-gobject/scan_parameters.h',
'libinsane-gobject/scan_session.h',
'libinsane-gobject/unit.h',
)
install_headers(INSANE_GOBJECT_HEADERS, subdir: 'libinsane-gobject')
libinsane_gobject_inc = include_directories('.')
libinsane-1.0.10/subprojects/libinsane-gobject/meson.build 0000664 0000000 0000000 00000000335 14377724077 0023644 0 ustar 00root root 0000000 0000000 project('libinsane-gobject', 'c',
version: '1.0.10',
license: 'LGPLv3+',
meson_version: '>=0.37.1')
gnome = import('gnome')
LIBINSANE = subproject('libinsane')
subdir('include')
subdir('src')
subdir('doc')
libinsane-1.0.10/subprojects/libinsane-gobject/src/ 0000775 0000000 0000000 00000000000 14377724077 0022270 5 ustar 00root root 0000000 0000000 libinsane-1.0.10/subprojects/libinsane-gobject/src/device_descriptor.c 0000664 0000000 0000000 00000006175 14377724077 0026142 0 ustar 00root root 0000000 0000000 #include
#include
#include
#include
struct _LibinsaneDeviceDescriptorPrivate
{
char *dev_id;
char *vendor;
char *model;
char *type;
char *to_string;
};
G_DEFINE_TYPE_WITH_PRIVATE(LibinsaneDeviceDescriptor, libinsane_device_descriptor, G_TYPE_OBJECT)
static void libinsane_device_descriptor_finalize(GObject *object)
{
LibinsaneDeviceDescriptor *self = LIBINSANE_DEVICE_DESCRIPTOR(object);
LibinsaneDeviceDescriptorPrivate *private = \
libinsane_device_descriptor_get_instance_private(self);
lis_log_debug("[gobject] Finalizing");
g_free(private->dev_id);
g_free(private->vendor);
g_free(private->model);
g_free(private->type);
g_free(private->to_string);
}
static void libinsane_device_descriptor_class_init(LibinsaneDeviceDescriptorClass *cls)
{
GObjectClass *go_cls;
go_cls = G_OBJECT_CLASS(cls);
go_cls->finalize = libinsane_device_descriptor_finalize;
}
static void libinsane_device_descriptor_init(LibinsaneDeviceDescriptor *self)
{
LIS_UNUSED(self);
lis_log_debug("[gobject] Initializing");
}
LibinsaneDeviceDescriptor *libinsane_device_descriptor_new_from_libinsane(
const struct lis_device_descriptor *lis_desc
)
{
LibinsaneDeviceDescriptor *desc;
LibinsaneDeviceDescriptorPrivate *private;
lis_log_debug("[gobject] enter");
desc = g_object_new(LIBINSANE_DEVICE_DESCRIPTOR_TYPE, NULL);
private = libinsane_device_descriptor_get_instance_private(desc);
private->dev_id = g_strdup(lis_desc->dev_id);
private->vendor = g_strdup(lis_desc->vendor);
private->model = g_strdup(lis_desc->model);
private->type = g_strdup(lis_desc->type);
private->to_string = g_strdup_printf(
"%s %s (%s ; %s)",
private->vendor, private->model, private->type, private->dev_id
);
lis_log_debug("[gobject] leave");
return desc;
}
const char *libinsane_device_descriptor_get_dev_id(LibinsaneDeviceDescriptor *self)
{
LibinsaneDeviceDescriptorPrivate *private;
private = libinsane_device_descriptor_get_instance_private(self);
return private->dev_id;
}
const char *libinsane_device_descriptor_get_dev_vendor(LibinsaneDeviceDescriptor *self)
{
LibinsaneDeviceDescriptorPrivate *private;
private = libinsane_device_descriptor_get_instance_private(self);
return private->vendor;
}
const char *libinsane_device_descriptor_get_dev_model(LibinsaneDeviceDescriptor *self)
{
LibinsaneDeviceDescriptorPrivate *private;
private = libinsane_device_descriptor_get_instance_private(self);
return private->model;
}
const char *libinsane_device_descriptor_get_dev_type(LibinsaneDeviceDescriptor *self)
{
LibinsaneDeviceDescriptorPrivate *private;
private = libinsane_device_descriptor_get_instance_private(self);
return private->type;
}
/**
* libinsane_device_descriptor_to_string:
* Convenience method: allow to see quickly which device is designated by this object.
* Do not use in production code.
*/
const char *libinsane_device_descriptor_to_string(LibinsaneDeviceDescriptor *self)
{
LibinsaneDeviceDescriptorPrivate *private;
private = libinsane_device_descriptor_get_instance_private(self);
return private->to_string;
}
libinsane-1.0.10/subprojects/libinsane-gobject/src/enums.c.template 0000664 0000000 0000000 00000001555 14377724077 0025403 0 ustar 00root root 0000000 0000000 /*** BEGIN file-header ***/
#include "enums.h"
/*** END file-header ***/
/*** BEGIN file-production ***/
/* enumerations from "@basename@" */
#include
/*** END file-production ***/
/*** BEGIN value-header ***/
GType
@enum_name@_get_type (void)
{
static GType type_once = 0;
if (g_once_init_enter (&type_once))
{
static const G@Type@Value values[] = {
/*** END value-header ***/
/*** BEGIN value-production ***/
{ @VALUENAME@, "@VALUENAME@", "@valuenick@" },
/*** END value-production ***/
/*** BEGIN value-tail ***/
{ 0, NULL, NULL }
};
GType type = g_@type@_register_static (g_intern_static_string ("@EnumName@"), values);
g_once_init_leave (&type_once, type);
}
return type_once;
}
/*** END value-tail ***/
/*** BEGIN file-tail ***/
/*** END file-tail ***/
libinsane-1.0.10/subprojects/libinsane-gobject/src/enums.h.template 0000664 0000000 0000000 00000000740 14377724077 0025403 0 ustar 00root root 0000000 0000000 /*** BEGIN file-header ***/
#ifndef __LIBINSANE_ENUMS_H
#define __LIBINSANE_ENUMS_H
#include
G_BEGIN_DECLS
/*** END file-header ***/
/*** BEGIN file-production ***/
/*** END file-production ***/
/*** BEGIN value-header ***/
GType @enum_name@_get_type (void) G_GNUC_CONST;
#define LIBINSANE_TYPE_@ENUMSHORT@ (@enum_name@_get_type ())
/*** END value-header ***/
/*** BEGIN file-tail ***/
G_END_DECLS
#endif /* !__LIBINSANE_ENUMS_H */
/*** END file-tail ***/
libinsane-1.0.10/subprojects/libinsane-gobject/src/error.c 0000664 0000000 0000000 00000003257 14377724077 0023574 0 ustar 00root root 0000000 0000000 #include
#include
#include
/**
* LIBINSANE_ERROR:
*
* Error domain for libinsane operations. Errors in this domain will
* be from the #LibinsaneError enumeration. See #GError for information
* on error domains.
*/
GQuark libinsane_error_quark(void)
{
static GQuark q = 0;
if (q == 0) {
q = g_quark_from_static_string("libinsane-quark");
}
return q;
}
LibinsaneError lis_error_to_gobject(enum lis_error err)
{
switch(err) {
case LIS_OK:
return LIBINSANE_ERROR_OK;
case LIS_ERR_CANCELLED:
return LIBINSANE_ERROR_CANCELLED;
case LIS_WARMING_UP:
/* shouldn't be here */
assert(err != LIS_WARMING_UP);
break;
case LIS_ERR_DEVICE_BUSY:
return LIBINSANE_ERROR_DEVICE_BUSY;
case LIS_ERR_UNSUPPORTED:
return LIBINSANE_ERROR_UNSUPPORTED;
case LIS_ERR_INVALID_VALUE:
return LIBINSANE_ERROR_INVALID_VALUE;
case LIS_ERR_JAMMED:
return LIBINSANE_ERROR_JAMMED;
case LIS_ERR_COVER_OPEN:
return LIBINSANE_ERROR_COVER_OPEN;
case LIS_ERR_IO_ERROR:
return LIBINSANE_ERROR_IO_ERROR;
case LIS_ERR_NO_MEM:
return LIBINSANE_ERROR_NO_MEM;
case LIS_ERR_ACCESS_DENIED:
return LIBINSANE_ERROR_ACCESS_DENIED;
case LIS_ERR_HW_IS_LOCKED:
return LIBINSANE_ERROR_HW_IS_LOCKED;
case LIS_ERR_INTERNAL_IMG_FORMAT_NOT_SUPPORTED:
return LIBINSANE_ERROR_INTERNAL_IMG_FORMAT_NOT_SUPPORTED;
case LIS_ERR_INTERNAL_NOT_IMPLEMENTED:
return LIBINSANE_ERROR_INTERNAL_NOT_IMPLEMENTED;
case LIS_ERR_INTERNAL_UNKNOWN_ERROR:
return LIBINSANE_ERROR_INTERNAL_UNKNOWN_ERROR;
case LIS_ERR_OFFLINE:
return LIBINSANE_ERROR_OFFLINE;
}
return LIBINSANE_ERROR_INTERNAL_NOT_IMPLEMENTED;
}
libinsane-1.0.10/subprojects/libinsane-gobject/src/item.c 0000664 0000000 0000000 00000014403 14377724077 0023374 0 ustar 00root root 0000000 0000000 #include
#include
#include
#include
#include
#include
#include
#include
#include
#include
struct _LibinsaneItemPrivate
{
GObject *parent_ref;
struct lis_item *item;
gboolean root;
gboolean closed;
};
G_DEFINE_TYPE_WITH_PRIVATE(LibinsaneItem, libinsane_item, G_TYPE_OBJECT)
static void libinsane_item_dispose(GObject *self)
{
lis_log_debug("[gobject] Disposing");
libinsane_item_close(LIBINSANE_ITEM(self), NULL);
}
static void libinsane_item_finalize(GObject *self)
{
LIS_UNUSED(self);
lis_log_debug("[gobject] Finalizing");
}
static void libinsane_item_class_init(LibinsaneItemClass *cls)
{
GObjectClass *go_cls;
go_cls = G_OBJECT_CLASS(cls);
go_cls->dispose = libinsane_item_dispose;
go_cls->finalize = libinsane_item_finalize;
}
static void libinsane_item_init(LibinsaneItem *self)
{
LIS_UNUSED(self);
lis_log_debug("[gobject] Initializing");
}
LibinsaneItem *libinsane_item_new_from_libinsane(
GObject *parent_ref, gboolean root, struct lis_item *lis_item
)
{
LibinsaneItem *item;
LibinsaneItemPrivate *private;
lis_log_debug("[gobject] enter");
g_object_ref(parent_ref);
item = g_object_new(LIBINSANE_ITEM_TYPE, NULL);
private = libinsane_item_get_instance_private(item);
private->item = lis_item;
private->parent_ref = parent_ref;
private->closed = FALSE;
private->root = root;
lis_log_debug("[gobject] leave");
return item;
}
/**
* libinsane_item_get_name:
* @self: current item
*
* Returns: (transfer none): Item's name
*/
const char *libinsane_item_get_name(LibinsaneItem *self)
{
LibinsaneItemPrivate *private = libinsane_item_get_instance_private(self);
return private->item->name;
}
LibinsaneItemType libinsane_item_get_item_type(LibinsaneItem *self)
{
LibinsaneItemPrivate *private = libinsane_item_get_instance_private(self);
switch(private->item->type)
{
case LIS_ITEM_DEVICE:
return LIBINSANE_ITEM_TYPE_DEVICE;
case LIS_ITEM_FLATBED:
return LIBINSANE_ITEM_TYPE_FLATBED;
case LIS_ITEM_ADF:
return LIBINSANE_ITEM_TYPE_ADF;
case LIS_ITEM_UNIDENTIFIED:
return LIBINSANE_ITEM_TYPE_UNIDENTIFIED;
}
lis_log_warning("Unexpected item type: %d", private->item->type);
return LIBINSANE_ITEM_TYPE_UNIDENTIFIED;
}
void libinsane_item_close(LibinsaneItem *self, GError **error)
{
LibinsaneItemPrivate *private = libinsane_item_get_instance_private(self);
LIS_UNUSED(error);
if (private->closed) {
return;
}
private->closed = TRUE;
if (private->root) {
lis_log_debug("Closing item '%s'", private->item->name);
// only the root item must be closed
private->item->close(private->item);
private->item = NULL;
}
g_clear_object(&private->parent_ref);
}
/**
* libinsane_item_get_children:
* @self: current item. Should be a root item (not a result #libinsane_item_get_children()),
* not a children.
* @error: in case an error occurred while looking for children items
*
* See [C-API](../doxygen/html/structlis__item.html#ae4039acefa6acf85a110dec491340411)
*
* Returns: (element-type Libinsane.Item) (transfer full):
* list of children items (usually scan sources)
*/
GList *libinsane_item_get_children(LibinsaneItem *self, GError **error)
{
LibinsaneItemPrivate *private = libinsane_item_get_instance_private(self);
struct lis_item **children;
GList *out = NULL;
enum lis_error err;
LibinsaneItem *item;
int i;
if (private->closed) {
lis_log_error("item->get_children() called on closed item !");
return NULL;
}
lis_log_debug("enter");
err = private->item->get_children(private->item, &children);
if (LIS_IS_ERROR(err)) {
SET_LIBINSANE_GOBJECT_ERROR(error, err,
"Libinsane item->get_children() error: 0x%X, %s",
err, lis_strerror(err));
lis_log_debug("error");
return NULL;
}
for (i = 0 ; children[i] != NULL ; i++) {
item = libinsane_item_new_from_libinsane(
G_OBJECT(self), FALSE /* !root */, children[i]
);
out = g_list_prepend(out, item);
}
lis_log_debug("leave");
return g_list_reverse(out);
}
/**
* libinsane_item_get_options:
* @self: current item. Can be either a root or child item.
* @error: in case an error occurred while looking for options.
*
* See [C-API](../doxygen/html/structlis__item.html#aa2e301604accfe64461b36e28365bf9e)
*
* Returns: (element-type Libinsane.OptionDescriptor) (transfer full): item scan options.
*/
GList *libinsane_item_get_options(LibinsaneItem *self, GError **error)
{
LibinsaneItemPrivate *private = libinsane_item_get_instance_private(self);
enum lis_error err;
struct lis_option_descriptor **opts;
LibinsaneOptionDescriptor *desc;
int i;
GList *out = NULL;
if (private->closed) {
lis_log_error("item->get_options() called on closed item !");
return NULL;
}
lis_log_debug("enter");
err = private->item->get_options(private->item, &opts);
if (LIS_IS_ERROR(err)) {
SET_LIBINSANE_GOBJECT_ERROR(error, err,
"Libinsane item->get_options() error: 0x%X, %s",
err, lis_strerror(err));
lis_log_debug("error");
return NULL;
}
for (i = 0 ; opts[i] != NULL ; i++) {
desc = libinsane_option_descriptor_new_from_libinsane(
G_OBJECT(self), opts[i]
);
out = g_list_prepend(out, desc);
}
lis_log_debug("leave");
return g_list_reverse(out);
}
/**
* libinsane_item_scan_start:
* Returns: (transfer full): item scan parameters.
*/
LibinsaneScanSession *libinsane_item_scan_start(LibinsaneItem *self, GError **error)
{
LibinsaneItemPrivate *private = libinsane_item_get_instance_private(self);
enum lis_error err;
struct lis_scan_session *lis_scan_session = NULL;
LibinsaneScanSession *scan_session;
if (private->closed) {
lis_log_error("item->scan_start() called on closed item !");
return NULL;
}
lis_log_debug("enter");
err = private->item->scan_start(private->item, &lis_scan_session);
if (LIS_IS_ERROR(err)) {
SET_LIBINSANE_GOBJECT_ERROR(error, err,
"Libinsane item->scan_start() error: 0x%X, %s",
err, lis_strerror(err));
lis_log_debug("error");
return NULL;
}
scan_session = libinsane_scan_session_new_from_libinsane(
G_OBJECT(self), lis_scan_session
);
lis_log_debug("leave");
return scan_session;
}
libinsane-1.0.10/subprojects/libinsane-gobject/src/libinsane-api.c 0000664 0000000 0000000 00000014525 14377724077 0025156 0 ustar 00root root 0000000 0000000 #include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
struct _LibinsaneApiPrivate
{
struct lis_api *impl;
int closed;
};
G_DEFINE_TYPE_WITH_PRIVATE(LibinsaneApi, libinsane_api, G_TYPE_OBJECT)
static void libinsane_api_finalize(GObject *self)
{
lis_log_debug("Finalizing");
libinsane_api_cleanup(LIBINSANE_API(self));
}
static void str2img_format(const GValue *src_value, GValue *dest_value)
{
const char *str;
LibinsaneImgFormat format;
assert(G_VALUE_HOLDS_STRING(src_value));
str = g_value_get_string(src_value);
if (strcasecmp(str, "raw24") == 0 || strcasecmp(str, "raw") == 0) {
format = LIBINSANE_IMG_FORMAT_RAW_RGB_24;
} else if (strcasecmp(str, "raw_grayscale") == 0) {
format = LIBINSANE_IMG_FORMAT_GRAYSCALE_8;
} else if (strcasecmp(str, "raw_bw") == 0) {
format = LIBINSANE_IMG_FORMAT_BW_1;
} else if (strcasecmp(str, "bmp") == 0) {
format = LIBINSANE_IMG_FORMAT_BMP;
} else if (strcasecmp(str, "gif") == 0) {
format = LIBINSANE_IMG_FORMAT_GIF;
} else if (strcasecmp(str, "jpeg") == 0 || strcasecmp(str, "jpg") == 0) {
format = LIBINSANE_IMG_FORMAT_JPEG;
} else if (strcasecmp(str, "png") == 0) {
format = LIBINSANE_IMG_FORMAT_PNG;
} else {
lis_log_warning("Unknown image format '%s'. Assuming raw RGB 24bits", str);
format = LIBINSANE_IMG_FORMAT_RAW_RGB_24;
}
g_value_set_enum(dest_value, format);
}
static void libinsane_api_class_init(LibinsaneApiClass *cls)
{
GObjectClass *go_cls;
go_cls = G_OBJECT_CLASS(cls);
go_cls->finalize = libinsane_api_finalize;
g_value_register_transform_func(G_TYPE_STRING, LIBINSANE_TYPE_IMG_FORMAT, str2img_format);
}
static void libinsane_api_init(LibinsaneApi *self)
{
LIS_UNUSED(self);
lis_log_debug("Initializing");
}
/**
* libinsane_api_new_safebet:
*
* Instantiate the safest list of API for most cases.
* See [lis_safebet](../doxygen/html/safebet_8h.html)
*
* Returns: (transfer full): the new reference to @self.
*/
LibinsaneApi *libinsane_api_new_safebet(GError **error)
{
LibinsaneApi *api = g_object_new(LIBINSANE_API_TYPE, NULL);
LibinsaneApiPrivate *priv = libinsane_api_get_instance_private(api);
enum lis_error err;
lis_log_debug("enter");
err = lis_safebet(&priv->impl);
if (LIS_IS_ERROR(err)) {
SET_LIBINSANE_GOBJECT_ERROR(error, err,
"Libinsane init error: 0x%X, %s",
err, lis_strerror(err));
lis_log_debug("error");
return NULL;
}
priv->closed = 0;
assert(priv->impl != NULL);
lis_log_debug("leave");
return api;
}
/**
* libinsane_api_new_from_string:
*
* Instantiate a new list of API based on a provided string.
*
* @param desc see [lis_str2impls()](../doxygen/html/str2impls_8h.html)
*
* Returns: (transfer full): the new reference to @self.
*/
LibinsaneApi *libinsane_api_new_from_string(const char *desc, GError **error)
{
LibinsaneApi *impl;
LIS_UNUSED(desc);
LIS_UNUSED(error);
lis_log_debug("enter");
impl = g_object_new(LIBINSANE_API_TYPE, NULL);
/* TODO */
lis_log_debug("leave");
return impl;
}
void libinsane_api_cleanup(LibinsaneApi *self)
{
LibinsaneApiPrivate *priv;
lis_log_debug("enter");
priv = libinsane_api_get_instance_private(self);
if (priv->closed) {
return;
}
if (priv->impl != NULL) {
lis_log_debug("cleanup");
priv->impl->cleanup(priv->impl);
priv->impl = NULL;
}
priv->closed = 1;
lis_log_debug("leave");
}
/**
* libinsane_api_list_devices:
*
* Returns: (element-type Libinsane.DeviceDescriptor) (transfer full):
* list of available devices (LibinsaneDeviceDescriptors objects)
*/
GList *libinsane_api_list_devices(
LibinsaneApi *self, LibinsaneDeviceLocations locations, GError **error
)
{
LibinsaneApiPrivate *priv;
enum lis_error err;
struct lis_device_descriptor **dev_infos;
LibinsaneDeviceDescriptor *dev_info;
GList *out = NULL;
int i;
enum lis_device_locations lis_locations = LIS_DEVICE_LOCATIONS_ANY;
lis_log_debug("enter");
priv = libinsane_api_get_instance_private(self);
if (priv->closed) {
err = LIS_ERR_CANCELLED;
SET_LIBINSANE_GOBJECT_ERROR(error, err,
"Libinsane list devices error: 0x%X, %s",
err, lis_strerror(err));
lis_log_error(
"API->list_devices() called on closed implementation"
);
return NULL;
}
switch(locations) {
case LIBINSANE_DEVICE_LOCATIONS_ANY:
lis_locations = LIS_DEVICE_LOCATIONS_ANY;
break;
case LIBINSANE_DEVICE_LOCATIONS_LOCAL_ONLY:
lis_locations = LIS_DEVICE_LOCATIONS_LOCAL_ONLY;
break;
}
err = priv->impl->list_devices(priv->impl, lis_locations, &dev_infos);
if (LIS_IS_ERROR(err)) {
SET_LIBINSANE_GOBJECT_ERROR(error, err,
"Libinsane list devices error: 0x%X, %s",
err, lis_strerror(err));
lis_log_error("error");
return NULL;
}
for (i = 0 ; dev_infos[i] != NULL ; i++) {
dev_info = libinsane_device_descriptor_new_from_libinsane(dev_infos[i]);
out = g_list_prepend(out, dev_info);
}
lis_log_debug("leave");
return g_list_reverse(out);
}
/**
* libinsane_api_get_device:
*
* Returns: (transfer full): LibinsaneItem object
*/
LibinsaneItem *libinsane_api_get_device(LibinsaneApi *self, const char *dev_id, GError **error) {
LibinsaneApiPrivate *priv;
struct lis_item *lis_item;
LibinsaneItem *item;
enum lis_error lis_err;
lis_log_debug("enter");
priv = libinsane_api_get_instance_private(self);
if (priv->closed) {
lis_err = LIS_ERR_CANCELLED;
SET_LIBINSANE_GOBJECT_ERROR(error, lis_err,
"Libinsane get device error: 0x%X, %s",
lis_err, lis_strerror(lis_err));
lis_log_error(
"API->get_device() called on closed implementation"
);
return NULL;
}
lis_err = priv->impl->get_device(priv->impl, dev_id, &lis_item);
if (LIS_IS_ERROR(lis_err)) {
SET_LIBINSANE_GOBJECT_ERROR(error, lis_err,
"Libinsane get device error: 0x%X, %s",
lis_err, lis_strerror(lis_err));
lis_log_debug("error");
return NULL;
}
item = libinsane_item_new_from_libinsane(
G_OBJECT(self), TRUE /* root*/, lis_item
);
lis_log_debug("leave");
return item;
}
const char *libinsane_api_get_version(void)
{
return lis_get_version();
}
libinsane-1.0.10/subprojects/libinsane-gobject/src/log.c 0000664 0000000 0000000 00000004144 14377724077 0023220 0 ustar 00root root 0000000 0000000 #include
#include
#include
#include
G_DEFINE_INTERFACE(LibinsaneLogger, libinsane_logger, G_TYPE_OBJECT)
static LibinsaneLogger *g_logger = NULL;
static lis_log_callback log_callback;
static void libinsane_logger_real_log(LibinsaneLogger *self, LibinsaneLogLevel lvl, const char *msg);
static struct lis_log_callbacks g_callbacks = {
.callbacks = {
[LIS_LOG_LVL_DEBUG] = log_callback,
[LIS_LOG_LVL_INFO] = log_callback,
[LIS_LOG_LVL_WARNING] = log_callback,
[LIS_LOG_LVL_ERROR] = log_callback,
}
};
static void libinsane_logger_default_init(LibinsaneLoggerInterface *iface)
{
iface->log = libinsane_logger_real_log;
}
static void libinsane_logger_real_log(LibinsaneLogger *self, LibinsaneLogLevel lvl, const char *msg)
{
LIS_UNUSED(self);
fprintf(stderr, "[missing log callback] %d: %s\n", lvl, msg);
}
void libinsane_logger_log(LibinsaneLogger *self, LibinsaneLogLevel lvl, const char *msg)
{
LibinsaneLoggerInterface *iface;
g_return_if_fail(LIBINSANE_IS_LOGGER(self));
iface = LIBINSANE_LOGGER_GET_IFACE(self);
iface->log(self, lvl, msg);
}
static void log_callback(enum lis_log_level lis_lvl, const char *msg)
{
LibinsaneLogLevel lvl = LIBINSANE_LOG_LEVEL_ERROR;
if (g_logger == NULL) {
fprintf(stderr, "Warning: no log callback defined. Defaulting to stderr\n");
fprintf(stderr, "[missing logger object] %d: %s\n", lis_lvl, msg);
return;
}
switch(lis_lvl)
{
case LIS_LOG_LVL_DEBUG:
lvl = LIBINSANE_LOG_LEVEL_DEBUG;
break;
case LIS_LOG_LVL_INFO:
lvl = LIBINSANE_LOG_LEVEL_INFO;
break;
case LIS_LOG_LVL_WARNING:
lvl = LIBINSANE_LOG_LEVEL_WARNING;
break;
case LIS_LOG_LVL_ERROR:
lvl = LIBINSANE_LOG_LEVEL_ERROR;
break;
}
libinsane_logger_log(g_logger, lvl, msg);
}
void libinsane_register_logger(LibinsaneLogger *logger)
{
if (logger != NULL) {
g_object_ref(logger);
g_logger = logger;
lis_set_log_callbacks(&g_callbacks);
} else {
libinsane_unregister_logger();
}
}
void libinsane_unregister_logger()
{
if (g_logger != NULL) {
g_object_unref(g_logger);
}
g_logger = NULL;
}
libinsane-1.0.10/subprojects/libinsane-gobject/src/meson.build 0000664 0000000 0000000 00000003237 14377724077 0024437 0 ustar 00root root 0000000 0000000 INSANE_GOBJECT_SRCS = files(
'device_descriptor.c',
'error.c',
'item.c',
'libinsane-api.c',
'log.c',
'option_descriptor.c',
'scan_parameters.c',
'scan_session.c',
)
GOBJECT = dependency('gobject-2.0')
libinsane_dep = LIBINSANE.get_variable('libinsane_dep')
## Generate enums.h / enums.c
enums = gnome.mkenums('enums',
c_template: 'enums.c.template',
h_template: 'enums.h.template',
sources: INSANE_GOBJECT_HEADERS,
install_header: true,
install_dir: join_paths(get_option('includedir'), 'libinsane-gobject'))
## Build libinsane_gobject itself
if host_machine.system() == 'windows'
libinsane_gobject = library('insane_gobject', INSANE_GOBJECT_SRCS + enums,
include_directories: libinsane_gobject_inc,
dependencies: [libinsane_dep, GOBJECT],
install: true)
else
libinsane_gobject = library('insane_gobject', INSANE_GOBJECT_SRCS + enums,
include_directories: libinsane_gobject_inc,
dependencies: [libinsane_dep, GOBJECT],
version: meson.project_version(),
install: true)
endif
libinsane_gobject_dep = declare_dependency(
include_directories: libinsane_gobject_inc,
link_with: libinsane_gobject,
dependencies: [GOBJECT])
## Introspection
gir = gnome.generate_gir(libinsane_gobject,
sources: INSANE_GOBJECT_SRCS + INSANE_GOBJECT_HEADERS,
namespace: 'Libinsane',
# Not a typo: This is the GObject API version. Not the Libinsane
# version.
nsversion: '1.0',
includes: 'GObject-2.0',
install: true)
## Vala support
gnome.generate_vapi('libinsane',
sources: [gir.get(0)],
install: true,
packages: ['glib-2.0', 'gobject-2.0'])
libinsane-1.0.10/subprojects/libinsane-gobject/src/option_descriptor.c 0000664 0000000 0000000 00000031177 14377724077 0026213 0 ustar 00root root 0000000 0000000 #include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
struct _LibinsaneOptionDescriptorPrivate
{
GObject *parent_ref;
struct lis_option_descriptor *opt;
GValue last_value;
};
G_DEFINE_TYPE_WITH_PRIVATE(
LibinsaneOptionDescriptor, libinsane_option_descriptor, G_TYPE_OBJECT
)
static void libinsane_option_descriptor_dispose(GObject *self)
{
LibinsaneOptionDescriptorPrivate *private = (
libinsane_option_descriptor_get_instance_private(
LIBINSANE_OPTION_DESCRIPTOR(self)
)
);
lis_log_debug("[gobject] Disposing");
g_clear_object(&private->parent_ref);
}
static void libinsane_option_descriptor_finalize(GObject *object)
{
LIS_UNUSED(object);
lis_log_debug("[gobject] Finalizing");
}
static void libinsane_option_descriptor_class_init(LibinsaneOptionDescriptorClass *cls)
{
GObjectClass *go_cls;
go_cls = G_OBJECT_CLASS(cls);
go_cls->dispose = libinsane_option_descriptor_dispose;
go_cls->finalize = libinsane_option_descriptor_finalize;
}
static void libinsane_option_descriptor_init(LibinsaneOptionDescriptor *self)
{
LIS_UNUSED(self);
lis_log_debug("[gobject] Initializing");
}
LibinsaneOptionDescriptor *libinsane_option_descriptor_new_from_libinsane(
GObject *parent_ref,
struct lis_option_descriptor *lis_opt
)
{
LibinsaneOptionDescriptor *opt;
LibinsaneOptionDescriptorPrivate *private;
lis_log_debug("[gobject] enter");
g_object_ref(parent_ref);
opt = g_object_new(LIBINSANE_OPTION_DESCRIPTOR_TYPE, NULL);
private = libinsane_option_descriptor_get_instance_private(opt);
private->opt = lis_opt;
private->parent_ref = parent_ref;
/* set a default 'last_value' ; won't be actually used ; just here to be freed */
g_value_init(&private->last_value, G_TYPE_INT);
g_value_set_int(&private->last_value, 0);
lis_log_debug("[gobject] leave");
return opt;
}
const char *libinsane_option_descriptor_get_name(LibinsaneOptionDescriptor *self)
{
LibinsaneOptionDescriptorPrivate *private = libinsane_option_descriptor_get_instance_private(self);
return private->opt->name;
}
const char *libinsane_option_descriptor_get_title(LibinsaneOptionDescriptor *self)
{
LibinsaneOptionDescriptorPrivate *private = libinsane_option_descriptor_get_instance_private(self);
return private->opt->title;
}
const char *libinsane_option_descriptor_get_desc(LibinsaneOptionDescriptor *self)
{
LibinsaneOptionDescriptorPrivate *private = libinsane_option_descriptor_get_instance_private(self);
return private->opt->desc;
}
LibinsaneCapability libinsane_option_descriptor_get_capabilities(LibinsaneOptionDescriptor *self)
{
LibinsaneOptionDescriptorPrivate *private = libinsane_option_descriptor_get_instance_private(self);
int cap = private->opt->capabilities;
LibinsaneCapability out = 0;
if (cap & LIS_CAP_EMULATED) {
out |= LIBINSANE_CAPABILITY_EMULATED;
}
if (cap & LIS_CAP_AUTOMATIC) {
out |= LIBINSANE_CAPABILITY_AUTOMATIC;
}
if (cap & LIS_CAP_HW_SELECT) {
out |= LIBINSANE_CAPABILITY_HW_SELECT;
}
if (cap & LIS_CAP_SW_SELECT) {
out |= LIBINSANE_CAPABILITY_SW_SELECT;
}
if (cap & LIS_CAP_INACTIVE) {
out |= LIBINSANE_CAPABILITY_INACTIVE;
}
return out;
}
GType libinsane_option_descriptor_get_value_type(LibinsaneOptionDescriptor *self)
{
LibinsaneOptionDescriptorPrivate *private = libinsane_option_descriptor_get_instance_private(self);
switch(private->opt->value.type) {
case LIS_TYPE_BOOL:
return G_TYPE_BOOLEAN;
case LIS_TYPE_INTEGER:
return G_TYPE_INT;
case LIS_TYPE_DOUBLE:
return G_TYPE_DOUBLE;
case LIS_TYPE_STRING:
return G_TYPE_STRING;
case LIS_TYPE_IMAGE_FORMAT:
return LIBINSANE_TYPE_IMG_FORMAT;
}
return G_TYPE_INVALID;
}
LibinsaneUnit libinsane_option_descriptor_get_value_unit(LibinsaneOptionDescriptor *self)
{
LibinsaneOptionDescriptorPrivate *private = libinsane_option_descriptor_get_instance_private(self);
switch(private->opt->value.unit) {
case LIS_UNIT_NONE:
return LIBINSANE_UNIT_NONE;
case LIS_UNIT_PIXEL:
return LIBINSANE_UNIT_PIXEL;
case LIS_UNIT_BIT:
return LIBINSANE_UNIT_BIT;
case LIS_UNIT_MM:
return LIBINSANE_UNIT_MM;
case LIS_UNIT_DPI:
return LIBINSANE_UNIT_DPI;
case LIS_UNIT_PERCENT:
return LIBINSANE_UNIT_PERCENT;
case LIS_UNIT_MICROSECOND:
return LIBINSANE_UNIT_MICROSECOND;
}
return -1;
}
LibinsaneConstraintType libinsane_option_descriptor_get_constraint_type(LibinsaneOptionDescriptor *self)
{
LibinsaneOptionDescriptorPrivate *private = libinsane_option_descriptor_get_instance_private(self);
switch(private->opt->constraint.type) {
case LIS_CONSTRAINT_NONE:
return LIBINSANE_CONSTRAINT_TYPE_NONE;
case LIS_CONSTRAINT_RANGE:
return LIBINSANE_CONSTRAINT_TYPE_RANGE;
case LIS_CONSTRAINT_LIST:
return LIBINSANE_CONSTRAINT_TYPE_LIST;
}
return -1;
}
static LibinsaneImgFormat lis_format_to_gobject_format(enum lis_img_format fmt)
{
switch(fmt) {
case LIS_IMG_FORMAT_RAW_RGB_24:
return LIBINSANE_IMG_FORMAT_RAW_RGB_24;
case LIS_IMG_FORMAT_GRAYSCALE_8:
return LIBINSANE_IMG_FORMAT_GRAYSCALE_8;
case LIS_IMG_FORMAT_BW_1:
return LIBINSANE_IMG_FORMAT_BW_1;
case LIS_IMG_FORMAT_BMP:
return LIBINSANE_IMG_FORMAT_BMP;
case LIS_IMG_FORMAT_GIF:
return LIBINSANE_IMG_FORMAT_GIF;
case LIS_IMG_FORMAT_JPEG:
return LIBINSANE_IMG_FORMAT_JPEG;
case LIS_IMG_FORMAT_PNG:
return LIBINSANE_IMG_FORMAT_PNG;
case LIS_IMG_FORMAT_CIFF:
return LIBINSANE_IMG_FORMAT_CIFF;
case LIS_IMG_FORMAT_EXIF:
return LIBINSANE_IMG_FORMAT_EXIF;
case LIS_IMG_FORMAT_FLASHPIX:
return LIBINSANE_IMG_FORMAT_FLASHPIX;
case LIS_IMG_FORMAT_ICO:
return LIBINSANE_IMG_FORMAT_ICO;
case LIS_IMG_FORMAT_JPEG2K:
return LIBINSANE_IMG_FORMAT_JPEG2K;
case LIS_IMG_FORMAT_JPEG2KX:
return LIBINSANE_IMG_FORMAT_JPEG2KX;
case LIS_IMG_FORMAT_MEMORYBMP:
return LIBINSANE_IMG_FORMAT_MEMORYBMP;
case LIS_IMG_FORMAT_PHOTOCD:
return LIBINSANE_IMG_FORMAT_PHOTOCD;
case LIS_IMG_FORMAT_PICT:
return LIBINSANE_IMG_FORMAT_PICT;
case LIS_IMG_FORMAT_TIFF:
return LIBINSANE_IMG_FORMAT_TIFF;
}
return LIS_ENUM_ERROR;
}
static void lis_value_to_gvalue(enum lis_value_type type, union lis_value value, GValue *out)
{
g_value_unset(out);
switch(type) {
case LIS_TYPE_BOOL:
g_value_init(out, G_TYPE_BOOLEAN);
g_value_set_boolean(out, value.boolean > 0);
return;
case LIS_TYPE_INTEGER:
g_value_init(out, G_TYPE_INT);
g_value_set_int(out, value.integer);
return;
case LIS_TYPE_DOUBLE:
g_value_init(out, G_TYPE_DOUBLE);
g_value_set_double(out, value.dbl);
return;
case LIS_TYPE_STRING:
g_value_init(out, G_TYPE_STRING);
g_value_set_static_string(out, value.string);
return;
case LIS_TYPE_IMAGE_FORMAT:
g_value_init(out, LIBINSANE_TYPE_IMG_FORMAT);
g_value_set_enum(out, lis_format_to_gobject_format(value.format));
return;
}
lis_log_error("Unknown value type: %d", type);
}
/**
* libinsane_option_descriptor_get_constraint:
* @self option for which we want the constraint
*
* Returns: (element-type GValue) (transfer container): item scan options.
*/
GArray *libinsane_option_descriptor_get_constraint(LibinsaneOptionDescriptor *self)
{
LibinsaneOptionDescriptorPrivate *private = libinsane_option_descriptor_get_instance_private(self);
GArray *out = NULL;
GValue val = G_VALUE_INIT;
int i;
switch(private->opt->constraint.type) {
case LIS_CONSTRAINT_NONE:
return NULL;
case LIS_CONSTRAINT_RANGE:
out = g_array_sized_new(FALSE /* !zero terminated */,
TRUE /* cleared to 0 when allocated */,
sizeof(GValue),
3 /* nb elements */);
lis_value_to_gvalue(private->opt->value.type,
private->opt->constraint.possible.range.min,
&val);
out = g_array_append_val(out, val);
lis_value_to_gvalue(private->opt->value.type,
private->opt->constraint.possible.range.max,
&val);
out = g_array_append_val(out, val);
lis_value_to_gvalue(private->opt->value.type,
private->opt->constraint.possible.range.interval,
&val);
out = g_array_append_val(out, val);
return out;
case LIS_CONSTRAINT_LIST:
out = g_array_sized_new(FALSE /* !zero terminated */,
TRUE /* cleared to 0 when allocated */,
sizeof(GValue),
/* nb elements */
private->opt->constraint.possible.list.nb_values);
for (i = 0 ; i < private->opt->constraint.possible.list.nb_values ; i++) {
lis_value_to_gvalue(private->opt->value.type,
private->opt->constraint.possible.list.values[i],
&val);
out = g_array_append_val(out, val);
}
return out;
}
return NULL;
}
gboolean libinsane_option_descriptor_is_readable(LibinsaneOptionDescriptor *self)
{
LibinsaneOptionDescriptorPrivate *private;
private = libinsane_option_descriptor_get_instance_private(self);
return LIS_OPT_IS_READABLE(private->opt);
}
gboolean libinsane_option_descriptor_is_writable(LibinsaneOptionDescriptor *self)
{
LibinsaneOptionDescriptorPrivate *private;
private = libinsane_option_descriptor_get_instance_private(self);
return LIS_OPT_IS_WRITABLE(private->opt);
}
const GValue *libinsane_option_descriptor_get_value(LibinsaneOptionDescriptor *self, GError **error)
{
LibinsaneOptionDescriptorPrivate *private;
enum lis_error err;
union lis_value val;
lis_log_debug("enter");
private = libinsane_option_descriptor_get_instance_private(self);
err = private->opt->fn.get_value(private->opt, &val);
if (LIS_IS_ERROR(err)) {
SET_LIBINSANE_GOBJECT_ERROR(error, err,
"Libinsane opt[%s]->get_value() error: 0x%X, %s",
private->opt->name, err, lis_strerror(err));
lis_log_debug("error");
return NULL;
}
lis_value_to_gvalue(private->opt->value.type, val, &private->last_value);
lis_log_debug("enter");
return &private->last_value;
}
static int gvalue_to_lis_value(const GValue *in, enum lis_value_type type, union lis_value *out)
{
GValue converted = G_VALUE_INIT;
switch(type) {
case LIS_TYPE_BOOL:
g_value_init(&converted, G_TYPE_BOOLEAN);
if (!g_value_transform(in, &converted)) {
lis_log_error("Failed to convert value to boolean");
return 0;
}
out->boolean = g_value_get_boolean(&converted);
return 1;
case LIS_TYPE_INTEGER:
g_value_init(&converted, G_TYPE_INT);
if (!g_value_transform(in, &converted)) {
lis_log_error("Failed to convert value to integer");
return 0;
}
out->integer = g_value_get_int(&converted);
return 1;
case LIS_TYPE_DOUBLE:
g_value_init(&converted, G_TYPE_DOUBLE);
if (!g_value_transform(in, &converted)) {
lis_log_error("Failed to convert value to double");
return 0;
}
out->dbl = g_value_get_double(&converted);
return 1;
case LIS_TYPE_STRING:
g_value_init(&converted, G_TYPE_STRING);
g_value_transform(in, &converted);
if (!g_value_transform(in, &converted)) {
lis_log_error("Failed to convert value to string");
return 0;
}
out->string = g_value_get_string(&converted);
return 1;
case LIS_TYPE_IMAGE_FORMAT:
g_value_init(&converted, LIBINSANE_TYPE_IMG_FORMAT);
g_value_transform(in, &converted);
if (!g_value_transform(in, &converted)) {
lis_log_error("Failed to convert value to string");
return 0;
}
out->format = g_value_get_enum(&converted);
return 1;
}
assert(0);
lis_log_error("Unknown type: %d", type);
return 0;
}
LibinsaneSetFlag libinsane_option_descriptor_set_value(LibinsaneOptionDescriptor *self,
GValue *value, GError **error
)
{
LibinsaneOptionDescriptorPrivate *private;
enum lis_error err;
union lis_value val;
int set_flags = 0;
LibinsaneSetFlag out;
lis_log_debug("enter");
private = libinsane_option_descriptor_get_instance_private(self);
if (!gvalue_to_lis_value(value, private->opt->value.type, &val)) {
err = LIS_ERR_INVALID_VALUE;
SET_LIBINSANE_GOBJECT_ERROR(error, err,
"Libinsane opt[%s]->set_value() conversion error: 0x%X, %s",
private->opt->name, err, lis_strerror(err));
lis_log_debug("conversion error");
return LIBINSANE_SET_FLAG_NONE;
}
err = private->opt->fn.set_value(private->opt, val, &set_flags);
if (!LIS_IS_OK(err)) {
SET_LIBINSANE_GOBJECT_ERROR(error, err,
"Libinsane opt[%s]->set_value() error: 0x%X, %s",
private->opt->name, err, lis_strerror(err));
lis_log_debug("error");
return LIBINSANE_SET_FLAG_NONE;
}
out = LIBINSANE_SET_FLAG_NONE;
if (set_flags & LIS_SET_FLAG_INEXACT) {
out |= LIBINSANE_SET_FLAG_INEXACT;
}
if (set_flags & LIS_SET_FLAG_MUST_RELOAD_OPTIONS) {
out |= LIBINSANE_SET_FLAG_MUST_RELOAD_OPTIONS;
}
if (set_flags & LIS_SET_FLAG_MUST_RELOAD_PARAMS) {
out |= LIBINSANE_SET_FLAG_MUST_RELOAD_PARAMS;
}
lis_log_debug("leave");
return out;
}
libinsane-1.0.10/subprojects/libinsane-gobject/src/scan_parameters.c 0000664 0000000 0000000 00000006606 14377724077 0025613 0 ustar 00root root 0000000 0000000 #include
#include
#include
#include
#include
struct _LibinsaneScanParametersPrivate
{
struct lis_scan_parameters parameters;
};
G_DEFINE_TYPE_WITH_PRIVATE(LibinsaneScanParameters, libinsane_scan_parameters, G_TYPE_OBJECT)
static void libinsane_scan_parameters_finalize(GObject *object)
{
LIS_UNUSED(object);
lis_log_debug("[gobject] Finalizing");
}
static void libinsane_scan_parameters_class_init(LibinsaneScanParametersClass *cls)
{
GObjectClass *go_cls;
go_cls = G_OBJECT_CLASS(cls);
go_cls->finalize = libinsane_scan_parameters_finalize;
}
static void libinsane_scan_parameters_init(LibinsaneScanParameters *self)
{
LIS_UNUSED(self);
lis_log_debug("[gobject] Initializing");
}
LibinsaneScanParameters *libinsane_scan_parameters_new_from_libinsane(struct lis_scan_parameters *lis_params)
{
LibinsaneScanParameters *params;
LibinsaneScanParametersPrivate *private;
lis_log_debug("[gobject] enter");
params = g_object_new(LIBINSANE_SCAN_PARAMETERS_TYPE, NULL);
private = libinsane_scan_parameters_get_instance_private(params);
memcpy(&private->parameters, lis_params, sizeof(private->parameters));
lis_log_debug("[gobject] leave");
return params;
}
LibinsaneImgFormat libinsane_scan_parameters_get_format(LibinsaneScanParameters *self)
{
LibinsaneScanParametersPrivate *private = libinsane_scan_parameters_get_instance_private(self);
switch(private->parameters.format) {
case LIS_IMG_FORMAT_RAW_RGB_24:
return LIBINSANE_IMG_FORMAT_RAW_RGB_24;
case LIS_IMG_FORMAT_GRAYSCALE_8:
return LIBINSANE_IMG_FORMAT_GRAYSCALE_8;
case LIS_IMG_FORMAT_BW_1:
return LIBINSANE_IMG_FORMAT_BW_1;
case LIS_IMG_FORMAT_BMP:
return LIBINSANE_IMG_FORMAT_BMP;
case LIS_IMG_FORMAT_GIF:
return LIBINSANE_IMG_FORMAT_GIF;
case LIS_IMG_FORMAT_JPEG:
return LIBINSANE_IMG_FORMAT_JPEG;
case LIS_IMG_FORMAT_PNG:
return LIBINSANE_IMG_FORMAT_PNG;
case LIS_IMG_FORMAT_CIFF:
return LIBINSANE_IMG_FORMAT_CIFF;
case LIS_IMG_FORMAT_EXIF:
return LIBINSANE_IMG_FORMAT_EXIF;
case LIS_IMG_FORMAT_FLASHPIX:
return LIBINSANE_IMG_FORMAT_FLASHPIX;
case LIS_IMG_FORMAT_ICO:
return LIBINSANE_IMG_FORMAT_ICO;
case LIS_IMG_FORMAT_JPEG2K:
return LIBINSANE_IMG_FORMAT_JPEG2K;
case LIS_IMG_FORMAT_JPEG2KX:
return LIBINSANE_IMG_FORMAT_JPEG2KX;
case LIS_IMG_FORMAT_MEMORYBMP:
return LIBINSANE_IMG_FORMAT_MEMORYBMP;
case LIS_IMG_FORMAT_PHOTOCD:
return LIBINSANE_IMG_FORMAT_PHOTOCD;
case LIS_IMG_FORMAT_PICT:
return LIBINSANE_IMG_FORMAT_PICT;
case LIS_IMG_FORMAT_TIFF:
return LIBINSANE_IMG_FORMAT_TIFF;
}
lis_log_warning("Unknown image format: %d", private->parameters.format);
return LIBINSANE_IMG_FORMAT_RAW_RGB_24;
}
int libinsane_scan_parameters_get_width(LibinsaneScanParameters *self)
{
LibinsaneScanParametersPrivate *private;
private = libinsane_scan_parameters_get_instance_private(self);
return private->parameters.width;
}
int libinsane_scan_parameters_get_height(LibinsaneScanParameters *self)
{
LibinsaneScanParametersPrivate *private;
private = libinsane_scan_parameters_get_instance_private(self);
return private->parameters.height;
}
gsize libinsane_scan_parameters_get_image_size(LibinsaneScanParameters *self)
{
LibinsaneScanParametersPrivate *private;
private = libinsane_scan_parameters_get_instance_private(self);
return private->parameters.image_size;
}
libinsane-1.0.10/subprojects/libinsane-gobject/src/scan_session.c 0000664 0000000 0000000 00000011666 14377724077 0025135 0 ustar 00root root 0000000 0000000 #include
#include
#include
#include
#include
#include
#include
#include
struct _LibinsaneScanSessionPrivate
{
GObject *parent_ref;
struct lis_scan_session *session;
int finished;
};
G_DEFINE_TYPE_WITH_PRIVATE(LibinsaneScanSession, libinsane_scan_session, G_TYPE_OBJECT)
static void libinsane_scan_session_dispose(GObject *self)
{
LibinsaneScanSession *session = LIBINSANE_SCAN_SESSION(self);
lis_log_debug("[gobject] Disposing");
libinsane_scan_session_cancel(session);
}
static void libinsane_scan_session_finalize(GObject *self)
{
lis_log_debug("[gobject] Finalizing");
LIS_UNUSED(self);
}
static void libinsane_scan_session_class_init(LibinsaneScanSessionClass *cls)
{
GObjectClass *go_cls;
go_cls = G_OBJECT_CLASS(cls);
go_cls->dispose = libinsane_scan_session_dispose;
go_cls->finalize = libinsane_scan_session_finalize;
}
static void libinsane_scan_session_init(LibinsaneScanSession *self)
{
LIS_UNUSED(self);
lis_log_debug("[gobject] Initializing");
}
LibinsaneScanSession *libinsane_scan_session_new_from_libinsane(
GObject *parent_ref, struct lis_scan_session *scan_session
)
{
LibinsaneScanSession *session;
LibinsaneScanSessionPrivate *private;
g_object_ref(parent_ref);
lis_log_debug("[gobject] enter");
session = g_object_new(LIBINSANE_SCAN_SESSION_TYPE, NULL);
private = libinsane_scan_session_get_instance_private(session);
private->session = scan_session;
private->finished = 0;
private->parent_ref = parent_ref;
lis_log_debug("[gobject] leave");
return session;
}
/**
* libinsane_scan_session_get_scan_parameters:
* Returns: (transfer full): item scan parameters.
*/
LibinsaneScanParameters *libinsane_scan_session_get_scan_parameters(
LibinsaneScanSession *self, GError **error
)
{
LibinsaneScanSessionPrivate *private = libinsane_scan_session_get_instance_private(self);
struct lis_scan_parameters lis_params;
enum lis_error err;
LibinsaneScanParameters *params;
lis_log_debug("enter");
err = private->session->get_scan_parameters(private->session, &lis_params);
if (LIS_IS_ERROR(err)) {
SET_LIBINSANE_GOBJECT_ERROR(error, err,
"Libinsane scan_session->get_scan_parameters() error: 0x%X, %s",
err, lis_strerror(err));
lis_log_debug("error");
return NULL;
}
params = libinsane_scan_parameters_new_from_libinsane(&lis_params);
lis_log_debug("leave");
return params;
}
gboolean libinsane_scan_session_end_of_feed(LibinsaneScanSession *self)
{
LibinsaneScanSessionPrivate *private = libinsane_scan_session_get_instance_private(self);
return private->session->end_of_feed(private->session) > 0;
}
gboolean libinsane_scan_session_end_of_page(LibinsaneScanSession *self)
{
LibinsaneScanSessionPrivate *private = libinsane_scan_session_get_instance_private(self);
return private->session->end_of_page(private->session) > 0;
}
/**
* libinsane_scan_session_read:
* @self: Scan session
* @buffer: (array length=lng) (element-type guint8): buffer to read data
* @lng: length of buffer
* @error: location to store the error if any occurs
*
* You must call libinsane_scan_session_end_of_feed() and libinsane_scan_session_end_of_page()
* after each call to this function before calling it again.
*
* Returns: Number of bytes read, or -1 on error
*/
gssize libinsane_scan_session_read(LibinsaneScanSession *self, void *buffer, gsize lng, GError **error)
{
LibinsaneScanSessionPrivate *private = libinsane_scan_session_get_instance_private(self);
size_t buf_length = lng;
enum lis_error err;
lis_log_debug("enter");
err = private->session->scan_read(private->session, buffer, &buf_length);
if (LIS_IS_ERROR(err)) {
SET_LIBINSANE_GOBJECT_ERROR(error, err,
"Libinsane scan_session->read() error: 0x%X, %s",
err, lis_strerror(err));
lis_log_debug("error");
return -1;
}
lis_log_debug("leave: %lu bytes", (long unsigned)buf_length);
return buf_length;
}
/**
* libinsane_scan_session_read_bytes:
* @self: scan session
* @lng: number of bytes wanted
* @error: set if an error occurs
*
* Returns: (transfer full): a new #GBytes, or %NULL if an error occured
*/
GBytes *libinsane_scan_session_read_bytes(LibinsaneScanSession *self, gsize lng, GError **error)
{
guchar *buf;
gssize nread;
buf = g_malloc(lng);
nread = libinsane_scan_session_read(self, buf, lng, error);
if (nread < 0) {
g_free(buf);
return NULL;
} else if (nread == 0) {
g_free(buf);
return g_bytes_new_static("", 0);
} else {
return g_bytes_new_take(buf, nread);
}
}
void libinsane_scan_session_cancel(LibinsaneScanSession *self)
{
LibinsaneScanSessionPrivate *private = libinsane_scan_session_get_instance_private(self);
if (private->finished) {
return;
}
private->session->cancel(private->session);
private->finished = 1;
g_clear_object(&private->parent_ref);
}
libinsane-1.0.10/subprojects/libinsane-gobject/tests/ 0000775 0000000 0000000 00000000000 14377724077 0022643 5 ustar 00root root 0000000 0000000 libinsane-1.0.10/subprojects/libinsane-gobject/tests/test_hw.py 0000775 0000000 0000000 00000013375 14377724077 0024706 0 ustar 00root root 0000000 0000000 #!/usr/bin/env python3
# source ./activate_test_env.sh
# subprojects/libinsane-gobject/examples/test_hw.py
import os
import re
import sys
import PIL.Image
import gi
gi.require_version('Libinsane', '1.0')
from gi.repository import GObject # noqa: E402
from gi.repository import Libinsane # noqa: E402
class Logger(GObject.GObject, Libinsane.Logger):
def do_log(self, lvl, msg):
if lvl < Libinsane.LogLevel.WARNING:
return
print("{}: {}".format(lvl.value_nick, msg))
def get_devices(api):
print("Looking for scan devices ...")
dev_descs = api.list_devices(Libinsane.DeviceLocations.ANY)
print("Found {} devices".format(len(dev_descs)))
for dev in dev_descs:
print("[{}] : [{}]".format(dev.get_dev_id(), dev.to_string()))
devs = []
for dev in dev_descs:
print("")
dev_id = dev.get_dev_id()
devs.append(dev_id)
return devs
def get_source(dev, source_name):
print("Looking for scan sources ...")
sources = dev.get_children()
print("Found {} scan sources:".format(len(sources)))
for src in sources:
print("- {}".format(src.get_name()))
for src in sources:
if src.get_name().lower() == source_name.lower():
print("Will use scan source {}".format(src.get_name()))
return src
for src in sources:
if src.get_name().lower().startswith(source_name.lower()):
print("Will use scan source {}".format(src.get_name()))
return src
raise Exception("Source '{}' not found".format(source_name))
def list_opts(item):
opts = item.get_options()
print("Options:")
for opt in opts:
try:
print("- {}={} ({})".format(
opt.get_name(), opt.get_value(), opt.get_constraint()
))
except Exception as exc:
print("Failed to read option {}: {}".format(
opt.get_name(), str(exc)
))
def set_opt(item, opt_name, opt_values):
print("Setting {} to {}".format(opt_name, opt_values))
opts = item.get_options()
opts = {opt.get_name(): opt for opt in opts}
if opt_name not in opts:
raise Exception("Option '{}' not found".format(opt_name))
print("- Old {}: {}".format(opt_name, opts[opt_name].get_value()))
print("- Allowed values: {}".format(opts[opt_name].get_constraint()))
for opt_value in opt_values:
if opt_value not in opts[opt_name].get_constraint():
continue
opts[opt_name].set_value(opt_value)
opts = item.get_options()
opts = {opt.get_name(): opt for opt in opts}
print("- New {}: {}".format(opt_name, opts[opt_name].get_value()))
return
raise Exception(
"Failed to set option {}: No value match constraint".format(opt_name)
)
def raw_to_img(params, img_bytes):
fmt = params.get_format()
assert(fmt == Libinsane.ImgFormat.RAW_RGB_24)
(w, h) = (
params.get_width(),
int(len(img_bytes) / 3 / params.get_width())
)
mode = "RGB"
print("Mode: {} : Size: {}x{}".format(mode, w, h))
return PIL.Image.frombuffer(mode, (w, h), img_bytes, "raw", mode, 0, 1)
def scan(source, output_file):
session = source.scan_start()
scan_params = session.get_scan_parameters()
print("Expected scan parameters: {} ; {}x{} = {} bytes".format(
scan_params.get_format(),
scan_params.get_width(), scan_params.get_height(),
scan_params.get_image_size()))
try:
page_nb = 0
assert(not session.end_of_feed())
img = []
print("Scanning page --> {} ...".format(output_file))
while not session.end_of_page():
data = session.read_bytes(32 * 1024)
data = data.get_data()
img.append(data)
img = b"".join(img)
img = raw_to_img(scan_params, img)
print("Saving page as {} ...".format(output_file))
img.save(output_file)
print("Page scanned".format(page_nb))
assert(session.end_of_page())
# TODO(Jflesch): HP ScanJet 4300C
# assert(session.end_of_feed())
finally:
session.cancel()
def clean_filename(filename):
return re.sub("[^0-9a-zA-Z.]", "_", filename)
def main():
Libinsane.register_logger(Logger())
if len(sys.argv) <= 1 or (sys.argv[1] == "-h" or sys.argv[1] == "--help"):
print("Syntax: {}