Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
screenshot_compare.hpp
Go to the documentation of this file.
1#pragma once
2
7
8#include <string>
9#include <vector>
10#include <cstdint>
11
12namespace pulp::view {
13
21inline constexpr float kDefaultSimilarityThreshold = 0.85f;
22
25 bool valid = false;
26 float similarity = 0.0f;
27 uint32_t total_pixels = 0;
28 uint32_t diff_pixels = 0;
29 float mean_error = 0.0f;
30 std::string error;
31
34 bool passes(float threshold = kDefaultSimilarityThreshold) const {
35 return valid && similarity >= threshold;
36 }
37};
38
40struct DiffBounds {
41 bool valid = false;
42 uint32_t x = 0;
43 uint32_t y = 0;
44 uint32_t width = 0;
45 uint32_t height = 0;
46 uint32_t diff_pixels = 0;
47};
48
53 bool valid = false;
54 uint32_t width = 0;
55 uint32_t height = 0;
56 uint32_t total_pixels = 0;
57 uint32_t unique_colors = 0;
59 double luminance_mean = 0.0;
60 double luminance_stddev = 0.0;
61 double alpha_mean = 0.0;
62 double opaque_coverage = 0.0;
67 std::string error;
68
69 bool passes_content_floor(uint32_t min_unique_colors = 16,
70 double min_luminance_stddev = 1.0,
71 double min_non_background_coverage = 0.05,
72 double min_opaque_coverage = 0.95) const {
73 return valid &&
74 unique_colors >= min_unique_colors &&
75 luminance_stddev >= min_luminance_stddev &&
76 non_background_coverage >= min_non_background_coverage &&
77 opaque_coverage >= min_opaque_coverage;
78 }
79};
80
86 bool valid = false;
87 uint32_t width = 0;
88 uint32_t height = 0;
89};
90
91PngMetadata inspect_png_metadata(const std::vector<uint8_t>& png);
92
101 const std::vector<uint8_t>& reference_png,
102 const std::vector<uint8_t>& rendered_png,
103 uint8_t tolerance = 32
104);
105
108 const std::string& reference_path,
109 const std::string& rendered_path,
110 uint8_t tolerance = 32
111);
112
116std::vector<uint8_t> generate_diff_image(
117 const std::vector<uint8_t>& reference_png,
118 const std::vector<uint8_t>& rendered_png,
119 uint8_t tolerance = 32
120);
121
125std::vector<uint8_t> crop_png(
126 const std::vector<uint8_t>& png,
127 uint32_t x,
128 uint32_t y,
129 uint32_t width,
130 uint32_t height
131);
132
136 const std::vector<uint8_t>& reference_png,
137 const std::vector<uint8_t>& rendered_png,
138 uint8_t tolerance = 32
139);
140
143ScreenshotContentStats analyze_screenshot_content(const std::vector<uint8_t>& png);
144
145} // namespace pulp::view
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
DiffBounds diff_bounds(const std::vector< uint8_t > &reference_png, const std::vector< uint8_t > &rendered_png, uint8_t tolerance=32)
Compute the bounding box of pixels that differ beyond the given tolerance.
constexpr float kDefaultSimilarityThreshold
The default similarity a render must reach to count as matching its reference, as a fraction (0....
Definition screenshot_compare.hpp:21
CompareResult compare_screenshot_files(const std::string &reference_path, const std::string &rendered_path, uint8_t tolerance=32)
Compare two PNG files for visual similarity.
PngMetadata inspect_png_metadata(const std::vector< uint8_t > &png)
std::vector< uint8_t > crop_png(const std::vector< uint8_t > &png, uint32_t x, uint32_t y, uint32_t width, uint32_t height)
Crop a rectangular region from a PNG image and return it as a new PNG.
CompareResult compare_screenshots(const std::vector< uint8_t > &reference_png, const std::vector< uint8_t > &rendered_png, uint8_t tolerance=32)
Compare two PNG images for visual similarity.
ScreenshotContentStats analyze_screenshot_content(const std::vector< uint8_t > &png)
Decode a PNG and compute content statistics suitable for catching empty or stable single-color captur...
@ y
Definition input_events.hpp:42
@ x
Definition input_events.hpp:41
@ height
Definition css_animation.hpp:128
@ width
Definition css_animation.hpp:127
std::vector< uint8_t > generate_diff_image(const std::vector< uint8_t > &reference_png, const std::vector< uint8_t > &rendered_png, uint8_t tolerance=32)
Generate a visual diff image highlighting differences between two PNGs.
Result of comparing two screenshots.
Definition screenshot_compare.hpp:24
bool valid
True if comparison completed successfully.
Definition screenshot_compare.hpp:25
float mean_error
Mean per-channel error (0-255 scale).
Definition screenshot_compare.hpp:29
bool passes(float threshold=kDefaultSimilarityThreshold) const
Returns true if similarity is at or above the given threshold, which defaults to kDefaultSimilarityTh...
Definition screenshot_compare.hpp:34
float similarity
0.0 = completely different, 1.0 = identical
Definition screenshot_compare.hpp:26
uint32_t total_pixels
Total pixels compared.
Definition screenshot_compare.hpp:27
std::string error
Error message if comparison failed.
Definition screenshot_compare.hpp:30
uint32_t diff_pixels
Pixels that differ beyond threshold.
Definition screenshot_compare.hpp:28
Bounding box of changed pixels between two screenshots.
Definition screenshot_compare.hpp:40
uint32_t diff_pixels
Definition screenshot_compare.hpp:46
bool valid
Definition screenshot_compare.hpp:41
uint32_t y
Definition screenshot_compare.hpp:43
uint32_t width
Definition screenshot_compare.hpp:44
uint32_t x
Definition screenshot_compare.hpp:42
uint32_t height
Definition screenshot_compare.hpp:45
Decoder-independent PNG structure and dimensions.
Definition screenshot_compare.hpp:85
bool valid
Definition screenshot_compare.hpp:86
uint32_t height
Definition screenshot_compare.hpp:88
uint32_t width
Definition screenshot_compare.hpp:87
Basic content statistics for a decoded PNG.
Definition screenshot_compare.hpp:52
uint32_t width
Definition screenshot_compare.hpp:54
double luminance_mean
Definition screenshot_compare.hpp:59
double luminance_stddev
Definition screenshot_compare.hpp:60
uint32_t total_pixels
Definition screenshot_compare.hpp:56
double opaque_coverage
Definition screenshot_compare.hpp:62
uint32_t height
Definition screenshot_compare.hpp:55
bool passes_content_floor(uint32_t min_unique_colors=16, double min_luminance_stddev=1.0, double min_non_background_coverage=0.05, double min_opaque_coverage=0.95) const
Definition screenshot_compare.hpp:69
bool unique_colors_capped
Definition screenshot_compare.hpp:58
double non_background_coverage
Fraction of pixels that differ from the dominant background color.
Definition screenshot_compare.hpp:66
uint32_t unique_colors
Exact count unless unique_colors_capped is true.
Definition screenshot_compare.hpp:57
bool valid
Definition screenshot_compare.hpp:53
double alpha_mean
Definition screenshot_compare.hpp:61
std::string error
Definition screenshot_compare.hpp:67