Skip to content

Implement better logic in golden file comparators #17258

Closed

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.

Activity

  1. added
    a: tests"flutter test", flutter_test, or one of our tests
    on May 3, 2018
  2. tomnewton commented on Jun 6, 2018

    @tomnewton

    The package:image stores pixels in aabbggrr format... which is a huge pain when working in Flutter.

    https://github.com/brendan-duncan/image/blob/master/lib/src/image.dart#L14

  3. added this to the milestone on Jan 22, 2019
  4. apaatsio commented on Mar 6, 2019

    @apaatsio
    Contributor

    matchesReferenceImage already compares pixels and it can report things like does not match as width or height do not match and does not match on N pixels. Maybe that code can be reused here. I think it would make sense that matchesReferenceImage and matchesGoldenFile worked in a similar fashion.

  5. self-assigned this
    on Apr 13, 2019
  6. modified the milestones: , August 2019 on Jun 12, 2019
  7. github-actions commented on Aug 28, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  8. locked as resolved and limited conversation to collaborators on Aug 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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