Skip to content

Implement better logic in golden file comparators #17258

@tvolkert

Description

@tvolkert

Follow-up work to #16859:

The current golden file comparator (both LocalFileComparator and FlutterGoldenFileComparator ) are very simplistic. They compare encoded PNG bytes and report failure if the byte-for-byte comparison turned up any differences.

What would be more useful would to be for the comparator to decode the PNG to raw pixels and reporting which pixels differ - optionally being configurable to allow for a tolerance of N number of pixel differences allowed before it reports as a failure (or even N RGB allowable differences per pixel, and M allowable pixels different outside of the N tolerance).

To do this, we would either need to:

  1. Use package:image to decode the PNG bytes.

    PngDecoder decoder = new PngDecoder();
    Image image = decoder.decodeImage(pngBytes);
    Uint8List rawPixels = image.data;
  2. Use dart:ui to decode the PNG bytes:

    Codec codec = await instantiateImageCodec(pngBytes);
    assert(codec.frameCount == 0);
    FrameInfo frameInfo = await codec.getNextFrame();
    ByteData rawPixels = await frameInfo.image.toByteData();

We probably also want to allow the augment the GoldenFileComparator API to allow it to declare the preferred format in which it receives image bytes during the call to compare(). Then the matcher would consult the comparator and request the appropriate format up-front, thus saving the comparator from having to convert the recorded image.

Metadata

Metadata

Assignees

Labels

a: tests"flutter test", flutter_test, or one of our tests

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions