The Pixel Engine provides advanced pixel detection, color matching, and screen capture capabilities for the Game Macro system, with optimized performance through frame-level caching and ROI (Region of Interest) acceleration.
| English Version | 中文版本 |
The Pixel Engine provides:
The pixel engine is designed for maximum performance with intelligent fallback mechanisms:
Core pixel detection and color management system.
Handles color conversion and matching operations.
; Color conversion utilities
Pixel_ColorToHex(colorInt) ; Integer → Hex string
Pixel_HexToInt(hexStr) ; Hex string → Integer
Pixel_ColorMatch(curInt, targetInt, tol) ; Color matching with tolerance
ColorMatchConfig := {
Tolerance: 10, ; Color tolerance (0-255)
RGBMode: true, ; Use RGB color space
FastMode: false ; Enable fast matching (less accurate)
}
Optimizes pixel detection by caching frame data.
FrameCache := {
id: 0, ; Frame identifier
cache: Map(), ; Pixel cache: "x|y" → color
stats: {
hits: 0, ; Cache hit count
misses: 0, ; Cache miss count
dxgi: 0, ; DXGI path usage
roi: 0, ; ROI path usage
gdi: 0 ; GDI path usage
}
}
Accelerates pixel detection by focusing on specific screen regions.
ROIConfig := {
enabled: true, ; Enable/disable ROI
rects: [], ; ROI rectangles
autoMode: true, ; Auto-detect ROI from profile
padding: 8, ; Padding around detected points
maxArea: 1000000, ; Maximum ROI area
minCount: 3 ; Minimum points for auto-ROI
}
ROIRect := {
L: 100, ; Left coordinate
T: 200, ; Top coordinate
W: 300, ; Width
H: 200, ; Height
R: 399, ; Right coordinate (L + W - 1)
B: 399, ; Bottom coordinate (T + H - 1)
hDC: 0, ; Device context handle
hBmp: 0, ; Bitmap handle
hOld: 0, ; Old object handle
pBits: 0, ; Pixel data pointer
stride: 1200 ; Stride (W * 4)
}
The engine uses multiple detection paths in priority order:
Converts color integer to hex string.
Parameters:
colorInt (Integer): Color value (0xRRGGBB)Returns: Hex color string (e.g., “0xFF0000”)
Converts hex string to color integer.
Parameters:
hexStr (String): Hex color stringReturns: Color integer (0xRRGGBB)
Checks if two colors match within tolerance.
Parameters:
curInt (Integer): Current colortargetInt (Integer): Target colortol (Integer): Tolerance value (0-255)Returns: Boolean indicating color match
Starts a new frame for pixel detection.
Parameters: None
Returns: Boolean indicating success
Gets pixel color at specified coordinates.
Parameters:
x (Integer): X coordinatey (Integer): Y coordinateReturns: Color integer (0xRRGGBB)
Enables or disables ROI system.
Parameters:
flag (Boolean): Enable/disable flagReturns: Current ROI enabled state
Clears all ROI regions and resources.
Parameters: None
Returns: Boolean indicating success
Disposes ROI system and releases resources.
Parameters: None
Returns: Boolean indicating success
Sets a single ROI rectangle.
Parameters:
l (Integer): Left coordinatet (Integer): Top coordinatew (Integer): Widthh (Integer): HeightReturns: Boolean indicating success
Automatically sets ROI from profile data.
Parameters:
prof (Map): Profile datapad (Integer): Padding around pointsincludePoints (Boolean): Include point coordinatesmaxArea (Integer): Maximum ROI areaminCount (Integer): Minimum points requiredReturns: Boolean indicating success
Captures snapshot of ROI regions.
Parameters: None
Returns: Boolean indicating success
Gets pixel color from ROI if coordinates inside.
Parameters:
x (Integer): X coordinatey (Integer): Y coordinateReturns: Color integer or -1 if outside ROI
Interactive pixel picking tool.
Parameters:
parentGui (Object): Parent GUI object (optional)offsetY (Integer): Mouse offset Y (avoidance)dwellMs (Integer): Dwell time before captureconfirmKey (String): Confirmation keyReturns: Pixel information map or 0 on cancel
Gets pixel color with mouse avoidance.
Parameters:
x (Integer): X coordinatey (Integer): Y coordinateoffsetY (Integer): Mouse offset YdwellMs (Integer): Dwell timeReturns: Color integer
; Initialize pixel detection
Pixel_FrameBegin()
; Get pixel color at specific coordinates
color := Pixel_FrameGet(100, 200)
hexColor := Pixel_ColorToHex(color)
; Check if color matches target
targetColor := Pixel_HexToInt("0xFF0000")
matches := Pixel_ColorMatch(color, targetColor, 10)
if (matches) {
Logger_Info("Pixel", "Color match detected", Map("color", hexColor))
}
; Enable ROI system
Pixel_ROI_Enable(true)
; Auto-detect ROI from profile skills
if (Pixel_ROI_SetAutoFromProfile(App["ProfileData"], 8, false, 1000000, 3)) {
Logger_Info("ROI", "Auto ROI configured successfully")
} else {
Logger_Warn("ROI", "Auto ROI configuration failed, using fallback")
}
; In frame processing loop
Pixel_FrameBegin()
Pixel_ROI_BeginSnapshot() ; Capture ROI regions
; Pixel detection will now use ROI optimization
for skill in App["ProfileData"].Skills {
color := Pixel_FrameGet(skill.X, skill.Y)
; Process skill color...
}
; Simple pixel picking
pixelInfo := Pixel_PickPixel()
if (pixelInfo != 0) {
Logger_Info("Pixel", "Pixel picked", Map(
"x", pixelInfo.X,
"y", pixelInfo.Y,
"color", Pixel_ColorToHex(pixelInfo.Color)
))
}
; Advanced pixel picking with mouse avoidance
pixelInfo := Pixel_PickPixel(0, 50, 100, "RButton")
if (pixelInfo != 0) {
; Use picked pixel coordinates
skillX := pixelInfo.X
skillY := pixelInfo.Y
skillColor := pixelInfo.Color
}
; Optimized detection with frame caching
function OptimizedPixelDetection() {
Pixel_FrameBegin()
if (Pixel_ROI_Enabled()) {
Pixel_ROI_BeginSnapshot()
}
; Process all skills with optimized detection
for skill in App["ProfileData"].Skills {
color := Pixel_FrameGet(skill.X, skill.Y)
targetColor := Pixel_HexToInt(skill.Color)
if (Pixel_ColorMatch(color, targetColor, skill.Tolerance)) {
; Skill is ready for execution
CastEngine_ExecuteSkill(skill.Id)
}
}
; Get performance statistics
stats := Pixel_GetFrameStats()
if (stats["misses"] > stats["hits"] * 0.1) {
Logger_Warn("Pixel", "High cache miss rate", stats)
}
}
; Analyze color variations
function AnalyzeColorStability(x, y, sampleCount) {
colors := []
for i in Range(1, sampleCount) {
Pixel_FrameBegin()
color := Pixel_FrameGet(x, y)
colors.Push(color)
Sleep(10)
}
; Calculate color stability
avgColor := CalculateAverageColor(colors)
stability := CalculateColorStability(colors, avgColor)
return {
average: avgColor,
stability: stability,
samples: colors
}
}
; Validate skill color configuration
function ValidateSkillColors(profile) {
issues := []
for skill in profile.Skills {
targetColor := Pixel_HexToInt(skill.Color)
if (targetColor = 0) {
issues.Push(Map(
"skill", skill.Name,
"issue", "Invalid color format",
"color", skill.Color
))
}
; Test color detection at skill coordinates
Pixel_FrameBegin()
currentColor := Pixel_FrameGet(skill.X, skill.Y)
if (!Pixel_ColorMatch(currentColor, targetColor, skill.Tolerance)) {
issues.Push(Map(
"skill", skill.Name,
"issue", "Color mismatch at coordinates",
"expected", skill.Color,
"actual", Pixel_ColorToHex(currentColor)
))
}
}
return issues
}
Pixel engine settings are configured in the main application:
App["PixelConfig"] := {
FrameCaching: true, ; Enable frame-level caching
ROIOptimization: true, ; Enable ROI optimization
ColorTolerance: 10, ; Default color tolerance
DetectionPaths: ["DXGI", "ROI", "GDI"], ; Detection path priority
PerformanceMonitoring: true, ; Enable performance stats
CacheValidation: false ; Enable cache validation
}
Skill-specific color settings:
Skill["ColorConfig"] := {
Color: "0xFF0000", ; Target color in hex
Tolerance: 15, ; Color tolerance
CheckReady: true, ; Enable color checking
Coordinates: {
X: 100, ; Screen X coordinate
Y: 200 ; Screen Y coordinate
}
}
; Get performance statistics
stats := Pixel_GetPerformanceStats()
; Monitor cache efficiency
cacheEfficiency := stats["hits"] / (stats["hits"] + stats["misses"])
if (cacheEfficiency < 0.8) {
Logger_Warn("Pixel", "Low cache efficiency", Map("efficiency", cacheEfficiency))
}
; Monitor detection path usage
if (stats["gdi"] > stats["dxgi"] * 2) {
Logger_Info("Pixel", "High GDI usage, consider ROI optimization")
}
The pixel engine includes comprehensive error handling:
The engine provides debugging capabilities:
; Enable pixel debugging
Pixel_EnableDebug()
; Get debug information
debugInfo := Pixel_GetDebugInfo()
; Test pixel detection at specific coordinates
testResult := Pixel_TestDetection(100, 200, "0xFF0000", 10)
; Validate ROI configuration
roiStatus := Pixel_ValidateROI()
Built-in tools for performance analysis:
; Start performance profiling
Pixel_StartProfiling()
; Run detection operations
for i in Range(1, 1000) {
Pixel_FrameGet(100 + i, 200)
}
; Get profiling results
profile := Pixel_GetProfileResults()
; Analyze detection path efficiency
pathEfficiency := AnalyzeDetectionPaths(profile)