third_party_backends:基于 SANE 的 OpenHarmony 扫描仪兼容后端项目

可帮助开发者在 OpenHarmony 系统中快速兼容存量扫描仪设备,降低驱动适配难度。项目集成 SANE 扫描系统,提供标准化 API 接口,支持扫描设备信息获取、参数设置及数据读取等核心功能。【此简介由AI生成】

Branch95Tags0

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

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

#include <sane/sane.h>

2、Add Compilation Dependency

Add in the bundle. json file

"deps": {
  "third_party": [
    "backends"
  ]
}

Add dependencies where needed in BUILD.gn

deps += [ "//third_party/backends:third_sane" ]

3、Example of interface usage

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, &parameters);
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

参与贡献

How to involve

Commit message spec

Introduction

可帮助开发者在 OpenHarmony 系统中快速兼容存量扫描仪设备,降低驱动适配难度。项目集成 SANE 扫描系统,提供标准化 API 接口,支持扫描设备信息获取、参数设置及数据读取等核心功能。【此简介由AI生成】

Customize your domain