headless: Allow screenshot to not be 512x272.

Ended up with a cropped screenshot for a frame dump, which just silently
crashed.  Could reject, but easy enough to support.
This commit is contained in:
Unknown W. Brackets 2022-10-18 21:33:47 -07:00
parent 7db6467af9
commit f009d15078
2 changed files with 9 additions and 5 deletions

View File

@ -399,6 +399,7 @@ double ScreenshotComparer::Compare(const Path &screenshotFilename) {
if (header[0] == 'B' && header[1] == 'M') {
reference_ = (u32 *)calloc(stride_ * h_, sizeof(u32));
referenceStride_ = stride_;
asBitmap_ = true;
// The bitmap header is 14 + 40 bytes. We could validate it but the test would fail either way.
if (reference_ && loader->ReadAt(14 + 40, sizeof(u32), stride_ * h_, reference_) != stride_ * h_) {
@ -424,6 +425,8 @@ double ScreenshotComparer::Compare(const Path &screenshotFilename) {
reference_ = nullptr;
return -1.0f;
}
referenceStride_ = width;
}
} else {
error_ = "Unable to read screenshot: " + screenshotFilename.ToVisualString();
@ -439,15 +442,15 @@ double ScreenshotComparer::Compare(const Path &screenshotFilename) {
if (asBitmap_) {
// The reference is flipped and BGRA by default for the common BMP compare case.
for (u32 y = 0; y < h_; ++y) {
u32 yoff = y * stride_;
u32 yoff = y * referenceStride_;
for (u32 x = 0; x < w_; ++x)
errors += ComparePixel(pixels_[y * stride_ + x], reference_[yoff + x]);
}
} else {
// Just convert to BGRA for simplicity.
ConvertRGBA8888ToBGRA8888(reference_, reference_, h_ * stride_);
ConvertRGBA8888ToBGRA8888(reference_, reference_, h_ * referenceStride_);
for (u32 y = 0; y < h_; ++y) {
u32 yoff = (h_ - y - 1) * stride_;
u32 yoff = (h_ - y - 1) * referenceStride_;
for (u32 x = 0; x < w_; ++x)
errors += ComparePixel(pixels_[y * stride_ + x], reference_[yoff + x]);
}
@ -486,7 +489,7 @@ bool ScreenshotComparer::SaveVisualComparisonPNG(const Path &resultFilename) {
if (asBitmap_) {
// The reference is flipped and BGRA by default for the common BMP compare case.
for (u32 y = 0; y < h_; ++y) {
u32 yoff = y * stride_;
u32 yoff = y * referenceStride_;
u32 comparisonRow = (h_ - y - 1) * 2 * w_ * 2;
for (u32 x = 0; x < w_; ++x) {
PlotVisualComparison(comparison.get(), comparisonRow + x * 2, pixels_[y * stride_ + x], reference_[yoff + x]);
@ -495,7 +498,7 @@ bool ScreenshotComparer::SaveVisualComparisonPNG(const Path &resultFilename) {
} else {
// Reference is already in BGRA either way.
for (u32 y = 0; y < h_; ++y) {
u32 yoff = (h_ - y - 1) * stride_;
u32 yoff = (h_ - y - 1) * referenceStride_;
u32 comparisonRow = (h_ - y - 1) * 2 * w_ * 2;
for (u32 x = 0; x < w_; ++x) {
PlotVisualComparison(comparison.get(), comparisonRow + x * 2, pixels_[y * stride_ + x], reference_[yoff + x]);

View File

@ -58,6 +58,7 @@ protected:
u32 *reference_ = nullptr;
bool asBitmap_ = false;
std::string error_;
u32 referenceStride_ = 0;
u32 stride_;
u32 w_;
u32 h_;