diff --git a/README.OpenSource b/README.OpenSource new file mode 100644 index 0000000000000000000000000000000000000000..9e7cc95b94ad76b8036b296180745c8902501847 --- /dev/null +++ b/README.OpenSource @@ -0,0 +1,11 @@ +[ + { + "Name" : "backends", + "License" : "GPL v2", + "License File" : "LICENSE", + "Version Number" : "1.1.1", + "Owner" : "guoshengbang@huawei.com", + "Upstream URL" : "https://gitlab.com/sane-project/backends/-/releases/1.1.1", + "Description" : "SANE stands is an application programming interface (API) that provides standardized access to any raster image scanner hardware. " + } +] diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..305ca07e98a6673b542d10ae54507cbd671ec33c --- /dev/null +++ b/README.md @@ -0,0 +1,120 @@ +# SANE +## Introduction +SANE is an application programming interface (API) that provides standardized access to any raster image scanner hardware (flatbed scanner, hand-held scanner, video- and still-cameras, frame-grabbers, etc.). + +You can also learn more about the SANE project through [the official website](http://sane-project.org/) + +## Background Brief +In the process of OpenHarmony's southward ecological development, it is necessary to be compatible with printers in the stock market. The use of CUPS printing system can directly connect with most printers in the market, which also reduces the difficulty for printer manufacturers to adapt to OpenHarmony. + +## Directory structure +``` +- LICENSE Copyright File +- OAT.xml OAT.XML filtering configuration file +- README.OpenSource Project README OpenSource files +- README.md English Description +- README_zh.md Chinese Description +- backend scanning device backend source code +- include SANE API interface +- lib SANE library source code +- sanei SANE internal utility functions and tools +- doc documents and instruction files +``` + +## How to use +### 1、Header file import +```c +#include +``` +### 2、Add Compilation Dependency +Add in the bundle. json file +```json +"deps": { + "third_party": [ + "backends" + ] +} +``` +Add dependencies where needed in BUILD.gn + +```json +deps += [ "//third_party/backends:third_sane" ] +``` +### 3、Example of interface usage +```c +SANE_Status status; +SANE_Handle handle; + +// Initialize SANE +status = sane_init(NULL, NULL); +if (status != SANE_STATUS_GOOD) { + fprintf(stderr, "Failed to initialize SANE: %s\n", sane_strstatus(status)); + return 1; +} + +// Open the first scanner device +status = sane_open("your_scanner_device_name", &handle); +if (status != SANE_STATUS_GOOD) { + fprintf(stderr, "Failed to open scanner: %s\n", sane_strstatus(status)); + return 1; +} + +// Get scanner device information +const SANE_Device *device_info; +status = sane_get_devices(&device_info, SANE_FALSE); +if (status != SANE_STATUS_GOOD) { + fprintf(stderr, "Failed to get scanner device information: %s\n", sane_strstatus(status)); + return 1; +} + +// Set scan parameters +SANE_Parameters parameters; +status = sane_get_parameters(handle, ¶meters); +if (status != SANE_STATUS_GOOD) { + fprintf(stderr, "Failed to get scan parameters: %s\n", sane_strstatus(status)); + return 1; +} + +// Start scanning +SANE_Image image; +status = sane_start(handle); +if (status != SANE_STATUS_GOOD) { + fprintf(stderr, "Failed to start scanning: %s\n", sane_strstatus(status)); + return 1; +} + +// Read scan data +do { + status = sane_read(handle, &image); + if (status != SANE_STATUS_GOOD) { + fprintf(stderr, "Failed to read scan data: %s\n", sane_strstatus(status)); + break; + } + +} while (status == SANE_STATUS_GOOD); + +// Finish scanning +status = sane_cancel(handle); +if (status != SANE_STATUS_GOOD) { + fprintf(stderr, "Failed to cancel scanning: %s\n", sane_strstatus(status)); + return 1; +} + +// Close the scanner device +status = sane_close(handle); +if (status != SANE_STATUS_GOOD) { + fprintf(stderr, "Failed to close scanner: %s\n", sane_strstatus(status)); + return 1; +} + +// Exit SANE +sane_exit(); +``` + +### 相关仓 +[print_print_fwk](https://gitee.com/openharmony/print_print_fwk) + +### 参与贡献 +[How to involve](https://gitee.com/openharmony/docs/blob/HEAD/zh-cn/contribute/参与贡献.md) + +[Commit message spec](https://gitee.com/openharmony/device_qemu/wikis/Commit%20message%E8%A7%84%E8%8C%83) \ No newline at end of file diff --git a/README_zh.md b/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..d5d7a11e61ad4275cd3952922431dbfb55d12b5b --- /dev/null +++ b/README_zh.md @@ -0,0 +1,118 @@ +# 三方开源软件sane-backends +## SANE简介 +SANE是一个应用程序编程接口(API),它提供对任何光栅图像扫描仪硬件(平板扫描仪、手持式扫描仪、视频和静态摄像机、帧处理器等)的标准化访问。 + +您也可以通过[CUPS官网主页](https://github.com/OpenPrinting/cups)了解更多关于SANE项目的信息。 + +## 引入背景简述 +OpenHarmony南向生态发展过程中,需要对存量市场的扫描仪进行兼容。使用SANE扫描系统能直接对接市场上大部分的扫描仪,也减少了扫描仪驱动适配OpenHarmony系统的难度。 + +## 目录结构 +``` +- LICENSE 版权文件 +- OAT.xml OAT.xml过滤配置文件 +- README.OpenSource 项目README.OpenSource文件 +- README.md 英文说明 +- README_zh.md 中文说明 +- backend 扫描设备后端源码 +- include SANE API接口 +- lib SANE 库源码 +- sanei SANE 内部实用函数和工具 +- doc 文档和说明文件 +``` + +## 如何使用 +### 1、头文件引入 +```c +#include +``` +### 2、添加编译依赖 +在您的 bundle.json 文件 添加 +```json +"deps": { + "third_party": [ + "backends" + ] +} +``` +在您的BUILD.gn需要的地方添加依赖 +```json +deps += [ "//third_party/backends:third_sane" ] +```c +SANE_Status status; +SANE_Handle handle; + +// Initialize SANE +status = sane_init(NULL, NULL); +if (status != SANE_STATUS_GOOD) { + fprintf(stderr, "Failed to initialize SANE: %s\n", sane_strstatus(status)); + return 1; +} + +// Open the first scanner device +status = sane_open("your_scanner_device_name", &handle); +if (status != SANE_STATUS_GOOD) { + fprintf(stderr, "Failed to open scanner: %s\n", sane_strstatus(status)); + return 1; +} + +// Get scanner device information +const SANE_Device *device_info; +status = sane_get_devices(&device_info, SANE_FALSE); +if (status != SANE_STATUS_GOOD) { + fprintf(stderr, "Failed to get scanner device information: %s\n", sane_strstatus(status)); + return 1; +} + +// Set scan parameters +SANE_Parameters parameters; +status = sane_get_parameters(handle, ¶meters); +if (status != SANE_STATUS_GOOD) { + fprintf(stderr, "Failed to get scan parameters: %s\n", sane_strstatus(status)); + return 1; +} + +// Start scanning +SANE_Image image; +status = sane_start(handle); +if (status != SANE_STATUS_GOOD) { + fprintf(stderr, "Failed to start scanning: %s\n", sane_strstatus(status)); + return 1; +} + +// Read scan data +do { + status = sane_read(handle, &image); + if (status != SANE_STATUS_GOOD) { + fprintf(stderr, "Failed to read scan data: %s\n", sane_strstatus(status)); + break; + } + +} while (status == SANE_STATUS_GOOD); + +// Finish scanning +status = sane_cancel(handle); +if (status != SANE_STATUS_GOOD) { + fprintf(stderr, "Failed to cancel scanning: %s\n", sane_strstatus(status)); + return 1; +} + +// Close the scanner device +status = sane_close(handle); +if (status != SANE_STATUS_GOOD) { + fprintf(stderr, "Failed to close scanner: %s\n", sane_strstatus(status)); + return 1; +} + +// Exit SANE +sane_exit(); +``` + +### 相关仓 +[print_print_fwk](https://gitee.com/openharmony/print_print_fwk) + +### 参与贡献 +[如何贡献](https://gitee.com/openharmony/docs/blob/HEAD/zh-cn/contribute/参与贡献.md) + +[Commit message规范](https://gitee.com/openharmony/device_qemu/wikis/Commit%20message%E8%A7%84%E8%8C%83) + diff --git a/bundle.json b/bundle.json index a13a0ff149ab6a00b76902cb124aa0a82739683d..bc514030d9d7e9ceea8b219aace85ae5c3063505 100644 --- a/bundle.json +++ b/bundle.json @@ -32,7 +32,18 @@ "sub_component": [ "//third_party/backends:third_sane" ], - "inner_kits": [], + "inner_kits": [ + { + "name": "//third_party/backends:third_sane", + "header": { + "header_files": [ + "sane/sane.h", + "sane/saneopts.h" + ], + "header_base": "//third_party/backends/include" + } + } + ], "test": [] } } diff --git a/include/sane/sanei_debug.h b/include/sane/sanei_debug.h index 465d3e25e5e3848069a4baaaeb65ad3ef1a4501d..f948f7dec351de580498035e7abb2f7e5bdf3e92 100644 --- a/include/sane/sanei_debug.h +++ b/include/sane/sanei_debug.h @@ -9,6 +9,7 @@ #include +#include "hilog/log.h" #ifdef __cplusplus extern "C" { #endif @@ -79,7 +80,11 @@ extern void sanei_debug_ndebug (int level, const char *msg, ...); # define DBG_LEVEL (0) # define DBG_INIT() +#ifndef ENABLE_HILOG # define DBG sanei_debug_ndebug +#else +# define DBG(level, ...) ((void)HiLogPrint(LOG_APP, LOG_INFO, 0, "sanekit", __VA_ARGS__)) +#endif # define IF_DBG(x) #else /* !NDEBUG */ diff --git a/sanei/sanei_init_debug.c b/sanei/sanei_init_debug.c index 690cc2ecafd08019a206da30c5f13330d26626c3..fe21f7756d6ca6db6694a0fc9a63b873ac9e671e 100644 --- a/sanei/sanei_init_debug.c +++ b/sanei/sanei_init_debug.c @@ -107,6 +107,7 @@ sanei_init_debug (const char * backend, int * var) DBG (0, "Setting debug level of %s to %d.\n", backend, *var); } +#if defined(LOG_DEBUG) static int is_socket (int fd) { @@ -122,6 +123,7 @@ is_socket (int fd) return 0; #endif } +#endif void sanei_debug_msg