Skip to content

Commit

Permalink
tests: add feature check for img
Browse files Browse the repository at this point in the history
  • Loading branch information
WanzenBug committed Mar 14, 2024
1 parent 1185d1d commit 2620346
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 26 deletions.
53 changes: 27 additions & 26 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,33 @@
//! QR-Codes in images and decode them.
//!
//!
//! # Usage
//! The most basic usage is shown below:
//!
//! ```rust
//! use image;
//!
//! # fn main() -> Result<(), Box<dyn ::std::error::Error>> {
//! // Load on image to search, convert it to grayscale
//! let img = image::open("tests/data/github.gif")?.to_luma8();
//! // Prepare for detection
//! let mut img = rqrr::PreparedImage::prepare(img);
//! // Search for grids, without decoding
//! let grids = img.detect_grids();
//! assert_eq!(grids.len(), 1);
//! // Decode the grid
//! let (meta, content) = grids[0].decode()?;
//! assert_eq!(meta.ecc_level, 0);
//! assert_eq!(content, "https://github.com/WanzenBug/rqrr");
//! # Ok(())
//! # }
//! ```
//!
//! If you have some other form of picture storage, you can use
//! [`PreparedImage::prepare_from_*`](struct.PreparedImage.html). This allows
//! you define your own source for images.

#![cfg_attr(feature = "img", doc = r##"
# Usage
The most basic usage is shown below:
```rust
use image;
# fn main() -> Result<(), Box<dyn ::std::error::Error>> {
// Load on image to search, convert it to grayscale
let img = image::open("tests/data/github.gif")?.to_luma8();
// Prepare for detection
let mut img = rqrr::PreparedImage::prepare(img);
// Search for grids, without decoding
let grids = img.detect_grids();
assert_eq!(grids.len(), 1);
// Decode the grid
let (meta, content) = grids[0].decode()?;
assert_eq!(meta.ecc_level, 0);
assert_eq!(content, "https://github.com/WanzenBug/rqrr");
# Ok(())
# }
```
If you have some other form of picture storage, you can use
[`PreparedImage::prepare_from_*`](struct.PreparedImage.html). This allows
you to define your own source for images.
"##)]
pub use self::decode::{MetaData, Version};
pub(crate) use self::detect::{capstones_from_image, CapStone};
pub use self::identify::Point;
Expand Down
2 changes: 2 additions & 0 deletions tests/test_errors.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(feature = "img")]

use rqrr::{DeQRError, PreparedImage};

use std::io::{Error, ErrorKind, Write};
Expand Down
2 changes: 2 additions & 0 deletions tests/test_full.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(feature = "img")]

use std::collections::HashSet;

#[test]
Expand Down
2 changes: 2 additions & 0 deletions tests/test_load.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(feature = "img")]

use rqrr::{BitGrid, PreparedImage};

fn test_data(buffer: &[u8]) -> PreparedImage<image::GrayImage> {
Expand Down

0 comments on commit 2620346

Please sign in to comment.