High-level visual comparison engine for gRPC/MCP integration. More...
#include <visual_diff_engine.h>

Public Member Functions | |
| VisualDiffEngine () | |
| VisualDiffEngine (const VisualDiffConfig &config) | |
| ~VisualDiffEngine ()=default | |
| void | SetConfig (const VisualDiffConfig &config) |
| const VisualDiffConfig & | GetConfig () const |
| void | SetTolerance (float tolerance) |
| absl::StatusOr< VisualDiffResult > | ComparePngFiles (const std::string &path_a, const std::string &path_b) |
| Compare two PNG files. | |
| absl::StatusOr< VisualDiffResult > | ComparePngData (const std::vector< uint8_t > &png_a, const std::vector< uint8_t > &png_b) |
| Compare two PNG images from raw data. | |
| absl::StatusOr< VisualDiffResult > | CompareWithReference (const std::vector< uint8_t > &png_data, const std::string &reference_path) |
| Compare PNG data against a reference file. | |
| VisualDiffResult | CompareScreenshots (const Screenshot &a, const Screenshot &b) |
| Compare two Screenshot objects directly. | |
| absl::StatusOr< VisualDiffResult > | CompareRegion (const std::vector< uint8_t > &png_a, const std::vector< uint8_t > &png_b, const ScreenRegion ®ion) |
| Compare a specific region of two images. | |
| absl::StatusOr< std::vector< uint8_t > > | GenerateDiffPng (const Screenshot &a, const Screenshot &b) |
| Generate a diff image highlighting differences. | |
| absl::Status | SaveDiffImage (const VisualDiffResult &result, const std::string &output_path) |
| Save diff image to file. | |
Static Public Member Functions | |
| static absl::StatusOr< Screenshot > | DecodePng (const std::vector< uint8_t > &png_data) |
| Decode PNG data to Screenshot. | |
| static absl::StatusOr< std::vector< uint8_t > > | EncodePng (const Screenshot &screenshot) |
| Encode Screenshot to PNG. | |
| static absl::StatusOr< Screenshot > | LoadPng (const std::string &path) |
| Load PNG from file. | |
| static absl::Status | SavePng (const Screenshot &screenshot, const std::string &path) |
| Save screenshot to PNG file. | |
| static float | CalculateSSIM (const Screenshot &a, const Screenshot &b) |
| Calculate Structural Similarity Index. | |
| static float | CalculateRegionSSIM (const Screenshot &a, const Screenshot &b, const ScreenRegion ®ion) |
| Calculate SSIM for a specific region. | |
Private Member Functions | |
| VisualDiffResult | CompareImpl (const Screenshot &a, const Screenshot &b, const ScreenRegion ®ion) |
| VisualDiffResult | ComparePixelExact (const Screenshot &a, const Screenshot &b, const ScreenRegion ®ion) |
| VisualDiffResult | CompareSSIM (const Screenshot &a, const Screenshot &b, const ScreenRegion ®ion) |
| std::vector< uint8_t > | GenerateRedHighlightDiff (const Screenshot &a, const Screenshot &b, const VisualDiffResult &result) |
| std::vector< uint8_t > | GenerateHeatmapDiff (const Screenshot &a, const Screenshot &b) |
| std::vector< uint8_t > | GenerateSideBySideDiff (const Screenshot &a, const Screenshot &b, const VisualDiffResult &result) |
| std::vector< VisualDiffResult::DiffRegion > | FindSignificantRegions (const Screenshot &a, const Screenshot &b, int threshold) |
| void | MergeNearbyRegions (std::vector< VisualDiffResult::DiffRegion > ®ions) |
| bool | ColorsMatch (const uint8_t *pixel_a, const uint8_t *pixel_b) const |
| float | PixelDifference (const uint8_t *pixel_a, const uint8_t *pixel_b) const |
Private Attributes | |
| VisualDiffConfig | config_ |
High-level visual comparison engine for gRPC/MCP integration.
Provides PNG-to-PNG comparison with structured results suitable for:
Usage:
Definition at line 123 of file visual_diff_engine.h.
|
default |
|
explicit |
Definition at line 136 of file visual_diff_engine.cc.
|
default |
|
inline |
Definition at line 130 of file visual_diff_engine.h.
References config_.
|
inline |
Definition at line 131 of file visual_diff_engine.h.
References config_.
|
inline |
Definition at line 132 of file visual_diff_engine.h.
References config_, and yaze::test::VisualDiffConfig::tolerance.
| absl::StatusOr< VisualDiffResult > yaze::test::VisualDiffEngine::ComparePngFiles | ( | const std::string & | path_a, |
| const std::string & | path_b ) |
Compare two PNG files.
| path_a | Path to first PNG image |
| path_b | Path to second PNG image |
Definition at line 139 of file visual_diff_engine.cc.
References CompareScreenshots(), and LoadPng().

| absl::StatusOr< VisualDiffResult > yaze::test::VisualDiffEngine::ComparePngData | ( | const std::vector< uint8_t > & | png_a, |
| const std::vector< uint8_t > & | png_b ) |
Compare two PNG images from raw data.
| png_a | First PNG image data (raw bytes) |
| png_b | Second PNG image data (raw bytes) |
Definition at line 154 of file visual_diff_engine.cc.
References CompareScreenshots(), and DecodePng().

| absl::StatusOr< VisualDiffResult > yaze::test::VisualDiffEngine::CompareWithReference | ( | const std::vector< uint8_t > & | png_data, |
| const std::string & | reference_path ) |
Compare PNG data against a reference file.
| png_data | Current PNG image data |
| reference_path | Path to reference PNG file |
Definition at line 169 of file visual_diff_engine.cc.
References CompareScreenshots(), DecodePng(), and LoadPng().

| VisualDiffResult yaze::test::VisualDiffEngine::CompareScreenshots | ( | const Screenshot & | a, |
| const Screenshot & | b ) |
Compare two Screenshot objects directly.
| a | First screenshot |
| b | Second screenshot |
Definition at line 184 of file visual_diff_engine.cc.
References CompareImpl(), and yaze::test::ScreenRegion::FullScreen().
Referenced by ComparePngData(), ComparePngFiles(), CompareWithReference(), and GenerateDiffPng().

| absl::StatusOr< VisualDiffResult > yaze::test::VisualDiffEngine::CompareRegion | ( | const std::vector< uint8_t > & | png_a, |
| const std::vector< uint8_t > & | png_b, | ||
| const ScreenRegion & | region ) |
Compare a specific region of two images.
| png_a | First PNG image data |
| png_b | Second PNG image data |
| region | Region to compare |
Definition at line 189 of file visual_diff_engine.cc.
References CompareImpl(), and DecodePng().

| absl::StatusOr< std::vector< uint8_t > > yaze::test::VisualDiffEngine::GenerateDiffPng | ( | const Screenshot & | a, |
| const Screenshot & | b ) |
Generate a diff image highlighting differences.
| a | First screenshot |
| b | Second screenshot |
Definition at line 636 of file visual_diff_engine.cc.
References CompareScreenshots(), yaze::test::VisualDiffResult::diff_image_png, and GenerateRedHighlightDiff().

| absl::Status yaze::test::VisualDiffEngine::SaveDiffImage | ( | const VisualDiffResult & | result, |
| const std::string & | output_path ) |
Save diff image to file.
| result | Comparison result containing diff image |
| output_path | Path to save the diff PNG |
Definition at line 645 of file visual_diff_engine.cc.
References yaze::test::VisualDiffResult::diff_image_png.
|
static |
Decode PNG data to Screenshot.
| png_data | Raw PNG bytes |
Definition at line 663 of file visual_diff_engine.cc.
References yaze::test::Screenshot::data, yaze::test::Screenshot::height, and yaze::test::Screenshot::width.
Referenced by ComparePngData(), CompareRegion(), CompareWithReference(), and LoadPng().
|
static |
Encode Screenshot to PNG.
| screenshot | Screenshot to encode |
Definition at line 735 of file visual_diff_engine.cc.
References yaze::test::Screenshot::data, yaze::test::Screenshot::height, yaze::test::Screenshot::IsValid(), and yaze::test::Screenshot::width.
Referenced by GenerateHeatmapDiff(), GenerateRedHighlightDiff(), GenerateSideBySideDiff(), and SavePng().

|
static |
Load PNG from file.
| path | Path to PNG file |
Definition at line 782 of file visual_diff_engine.cc.
References DecodePng().
Referenced by ComparePngFiles(), and CompareWithReference().

|
static |
Save screenshot to PNG file.
| screenshot | Screenshot to save |
| path | Output path |
Definition at line 802 of file visual_diff_engine.cc.
References EncodePng().

|
static |
Calculate Structural Similarity Index.
| a | First screenshot |
| b | Second screenshot |
Definition at line 351 of file visual_diff_engine.cc.
References CalculateRegionSSIM(), and yaze::test::ScreenRegion::FullScreen().
Referenced by CompareSSIM().

|
static |
Calculate SSIM for a specific region.
| a | First screenshot |
| b | Second screenshot |
| region | Region to analyze |
Definition at line 355 of file visual_diff_engine.cc.
References yaze::test::Screenshot::data, yaze::test::Screenshot::GetPixelIndex(), yaze::test::ScreenRegion::height, yaze::test::Screenshot::height, yaze::test::ScreenRegion::IsFullScreen(), yaze::test::ScreenRegion::width, yaze::test::Screenshot::width, yaze::test::ScreenRegion::x, and yaze::test::ScreenRegion::y.
Referenced by CalculateSSIM(), and CompareSSIM().

|
private |
Definition at line 205 of file visual_diff_engine.cc.
References yaze::test::VisualDiffConfig::algorithm, yaze::test::VisualDiffConfig::color_threshold, ComparePixelExact(), CompareSSIM(), config_, yaze::test::VisualDiffResult::diff_description, yaze::test::VisualDiffResult::diff_image_png, yaze::test::VisualDiffConfig::diff_style, yaze::test::VisualDiffResult::error_message, FindSignificantRegions(), yaze::test::VisualDiffConfig::generate_diff_image, GenerateHeatmapDiff(), GenerateRedHighlightDiff(), GenerateSideBySideDiff(), yaze::test::Screenshot::height, yaze::test::VisualDiffResult::height, yaze::test::VisualDiffResult::identical, yaze::test::Screenshot::IsValid(), yaze::test::VisualDiffConfig::kHeatmap, yaze::test::VisualDiffConfig::kPerceptualHash, yaze::test::VisualDiffConfig::kPixelExact, yaze::test::VisualDiffConfig::kRedHighlight, yaze::test::VisualDiffConfig::kSideBySide, yaze::test::VisualDiffConfig::kSSIM, MergeNearbyRegions(), yaze::test::VisualDiffResult::passed, yaze::test::VisualDiffResult::significant_regions, yaze::test::VisualDiffResult::similarity, yaze::test::VisualDiffConfig::tolerance, yaze::test::Screenshot::width, and yaze::test::VisualDiffResult::width.
Referenced by CompareRegion(), and CompareScreenshots().
|
private |
Definition at line 287 of file visual_diff_engine.cc.
References ColorsMatch(), config_, yaze::test::Screenshot::data, yaze::test::VisualDiffResult::difference_pct, yaze::test::VisualDiffResult::differing_pixels, yaze::test::Screenshot::GetPixelIndex(), yaze::test::ScreenRegion::height, yaze::test::Screenshot::height, yaze::test::VisualDiffResult::height, yaze::test::VisualDiffResult::identical, yaze::test::VisualDiffConfig::ignore_regions, yaze::test::ScreenRegion::IsFullScreen(), yaze::test::VisualDiffResult::similarity, yaze::test::VisualDiffResult::total_pixels, yaze::test::ScreenRegion::width, yaze::test::Screenshot::width, yaze::test::VisualDiffResult::width, yaze::test::ScreenRegion::x, and yaze::test::ScreenRegion::y.
Referenced by CompareImpl(), and CompareSSIM().

|
private |
Definition at line 336 of file visual_diff_engine.cc.
References CalculateRegionSSIM(), CalculateSSIM(), ComparePixelExact(), yaze::test::ScreenRegion::IsFullScreen(), and yaze::test::VisualDiffResult::similarity.
Referenced by CompareImpl().

|
private |
Definition at line 424 of file visual_diff_engine.cc.
References ColorsMatch(), yaze::test::Screenshot::data, EncodePng(), yaze::test::Screenshot::GetPixelIndex(), yaze::test::Screenshot::height, and yaze::test::Screenshot::width.
Referenced by CompareImpl(), and GenerateDiffPng().

|
private |
Definition at line 458 of file visual_diff_engine.cc.
References yaze::test::Screenshot::data, EncodePng(), yaze::test::Screenshot::GetPixelIndex(), yaze::test::Screenshot::height, PixelDifference(), and yaze::test::Screenshot::width.
Referenced by CompareImpl().

|
private |
Definition at line 500 of file visual_diff_engine.cc.
References ColorsMatch(), yaze::test::Screenshot::data, EncodePng(), yaze::test::Screenshot::GetPixelIndex(), yaze::test::Screenshot::height, and yaze::test::Screenshot::width.
Referenced by CompareImpl().

|
private |
Definition at line 547 of file visual_diff_engine.cc.
References ColorsMatch(), yaze::test::Screenshot::data, yaze::test::Screenshot::GetPixelIndex(), yaze::test::Screenshot::height, yaze::test::VisualDiffResult::DiffRegion::height, yaze::test::VisualDiffResult::DiffRegion::local_diff_pct, yaze::test::Screenshot::width, yaze::test::VisualDiffResult::DiffRegion::width, yaze::test::VisualDiffResult::DiffRegion::x, and yaze::test::VisualDiffResult::DiffRegion::y.
Referenced by CompareImpl().

|
private |
Definition at line 594 of file visual_diff_engine.cc.
References config_, and yaze::test::VisualDiffConfig::region_merge_distance.
Referenced by CompareImpl().
|
private |
Definition at line 408 of file visual_diff_engine.cc.
References yaze::test::VisualDiffConfig::color_threshold, and config_.
Referenced by ComparePixelExact(), FindSignificantRegions(), GenerateRedHighlightDiff(), and GenerateSideBySideDiff().
|
private |
Definition at line 416 of file visual_diff_engine.cc.
Referenced by GenerateHeatmapDiff().
|
private |
Definition at line 272 of file visual_diff_engine.h.
Referenced by ColorsMatch(), CompareImpl(), ComparePixelExact(), GetConfig(), MergeNearbyRegions(), SetConfig(), and SetTolerance().