1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//! Color finder module - Screen region color searching
//!
//! Provides color searching functionality within pixel buffers.
//! This module contains pure Rust algorithms that can work with any pixel data source.
//!
//! # Features
//! - Fast color matching in pixel buffers
//! - Automatic AVX2 detection and optimization
//! - Falls back to scalar implementation when AVX2 is unavailable
//! - Returns coordinates within the buffer
//! - Integrated with DXGI for screen capture (automatically enabled)
//!
//! # Example (with pixel buffer)
//! ```no_run
//! use win_auto_utils::color_finder::algorithms::{find_color_in_buffer, FindResult};
//!
//! // Assume you have BGRA pixel data from some source
//! let pixels: Vec<u8> = vec![0; 100 * 100 * 4]; // 100x100 image
//!
//! // Search for a specific color
//! let result = find_color_in_buffer(&pixels, 100, 100, (255, 0, 0));
//! if result.matched {
//! println!("Found at local coordinates ({}, {})", result.x, result.y);
//! }
//! ```
//!
//! # Example (with screen capture - dxgi automatically enabled)
//! ```no_run
//! use win_auto_utils::color_finder::find_color;
//!
//! // Search for red color on screen at position (100, 100) with size 50x50
//! match find_color(100, 100, 50, 50, (0, 0, 255)) {
//! Ok(result) => {
//! if result.matched {
//! println!("Found at screen coordinates ({}, {})", result.x, result.y);
//! }
//! }
//! Err(e) => eprintln!("Error: {}", e),
//! }
//! ```
use Error;
// Re-export algorithms module (pure Rust, always available)
pub use ;
// dxgi feature is automatically enabled by color_finder, so we can always use it
use cratecapture_region_bytes;
/// Find color in screen region using DXGI capture
///
/// Captures a screen region using DXGI and searches for the specified color.
/// Automatically chooses between AVX2 SIMD and scalar implementations based on
/// CPU capabilities.
///
/// # Arguments
/// * `x` - Horizontal coordinate of region's top-left corner (screen coordinates)
/// * `y` - Vertical coordinate of region's top-left corner (screen coordinates)
/// * `w` - Width of the search region in pixels
/// * `h` - Height of the search region in pixels
/// * `target` - Target color as (B, G, R) tuple
///
/// # Returns
/// * `Ok(FindResult)` - Contains match status and absolute screen coordinates
/// * `Err(Box<dyn Error>)` - If DXGI capture fails
///
/// # Coordinate System
/// - Input coordinates (`x`, `y`) are in absolute screen space
/// - Output coordinates in `FindResult` are also in absolute screen space
///
/// # Performance Notes
/// - In debug mode, prints timing information for DXGI capture
/// - AVX2 path is ~4-8x faster than scalar on supported hardware
/// - First call may be slower due to DXGI initialization