1# SANE 2## Introduction 3SANE 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.). 4 5You can also learn more about the SANE project through [the official website](http://sane-project.org/) 6 7## Background Brief 8In 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. 9 10## Directory structure 11``` 12- LICENSE Copyright File 13- OAT.xml OAT.XML filtering configuration file 14- README.OpenSource Project README OpenSource files 15- README.md English Description 16- README_zh.md Chinese Description 17- backend scanning device backend source code 18- include SANE API interface 19- lib SANE library source code 20- sanei SANE internal utility functions and tools 21- doc documents and instruction files 22``` 23 24## How to use 25### 1、Header file import 26```c 27#include <sane/sane.h> 28``` 29### 2、Add Compilation Dependency 30Add in the bundle. json file 31```json 32"deps": { 33 "third_party": [ 34 "backends" 35 ] 36} 37``` 38Add dependencies where needed in BUILD.gn 39 40```json 41deps += [ "//third_party/backends:third_sane" ] 42``` 43### 3、Example of interface usage 44```c 45SANE_Status status; 46SANE_Handle handle; 47 48// Initialize SANE 49status = sane_init(NULL, NULL); 50if (status != SANE_STATUS_GOOD) { 51 fprintf(stderr, "Failed to initialize SANE: %s\n", sane_strstatus(status)); 52 return 1; 53} 54 55// Open the first scanner device 56status = sane_open("your_scanner_device_name", &handle); 57if (status != SANE_STATUS_GOOD) { 58 fprintf(stderr, "Failed to open scanner: %s\n", sane_strstatus(status)); 59 return 1; 60} 61 62// Get scanner device information 63const SANE_Device *device_info; 64status = sane_get_devices(&device_info, SANE_FALSE); 65if (status != SANE_STATUS_GOOD) { 66 fprintf(stderr, "Failed to get scanner device information: %s\n", sane_strstatus(status)); 67 return 1; 68} 69 70// Set scan parameters 71SANE_Parameters parameters; 72status = sane_get_parameters(handle, ¶meters); 73if (status != SANE_STATUS_GOOD) { 74 fprintf(stderr, "Failed to get scan parameters: %s\n", sane_strstatus(status)); 75 return 1; 76} 77 78// Start scanning 79SANE_Image image; 80status = sane_start(handle); 81if (status != SANE_STATUS_GOOD) { 82 fprintf(stderr, "Failed to start scanning: %s\n", sane_strstatus(status)); 83 return 1; 84} 85 86// Read scan data 87do { 88 status = sane_read(handle, &image); 89 if (status != SANE_STATUS_GOOD) { 90 fprintf(stderr, "Failed to read scan data: %s\n", sane_strstatus(status)); 91 break; 92 } 93 94} while (status == SANE_STATUS_GOOD); 95 96// Finish scanning 97status = sane_cancel(handle); 98if (status != SANE_STATUS_GOOD) { 99 fprintf(stderr, "Failed to cancel scanning: %s\n", sane_strstatus(status)); 100 return 1; 101} 102 103// Close the scanner device 104status = sane_close(handle); 105if (status != SANE_STATUS_GOOD) { 106 fprintf(stderr, "Failed to close scanner: %s\n", sane_strstatus(status)); 107 return 1; 108} 109 110// Exit SANE 111sane_exit(); 112``` 113 114### 相关仓 115[print_print_fwk](https://gitee.com/openharmony/print_print_fwk) 116 117### 参与贡献 118[How to involve](https://gitee.com/openharmony/docs/blob/HEAD/zh-cn/contribute/参与贡献.md) 119 120[Commit message spec](https://gitee.com/openharmony/device_qemu/wikis/Commit%20message%E8%A7%84%E8%8C%83)