Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImageFilter.blur bright edges and clip when resizing #64828

Open
markusaksli-nc opened this issue Aug 28, 2020 · 9 comments
Open

ImageFilter.blur bright edges and clip when resizing #64828

markusaksli-nc opened this issue Aug 28, 2020 · 9 comments
Labels
a: images Loading, displaying, rendering images a: quality A truly polished experience c: rendering UI glitches reported at the engine/skia rendering level engine flutter/engine repository. See also e: labels. found in release: 3.3 Found to occur in 3.3 found in release: 3.7 Found to occur in 3.7 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on P2 Important issues not at the top of the work list team-engine Owned by Engine team triaged-engine Triaged by Engine team

Comments

@markusaksli-nc
Copy link
Member

markusaksli-nc commented Aug 28, 2020

ImageFiltered with ImageFilter.blur has this strange clip/border effect that is affected by size. This causes some jank when resizing a desktop window on both macOS and Windows:

And jank when resizing the filtered widget in general:

Reproducible on master 1.22.0-2.0.pre.105 on Windows, macOS and Android. The desktop resizing issue could maybe be chalked up to #44136 on macOS for now but on Windows that was supposedly fixed #30671 (comment)? Related to layout moving the widget across sub-pixel boundaries when resizing rather than any desktop-specific issue.

The expected behavior can actually be seen with flutter run -d chrome --dart-define=FLUTTER_WEB_USE_SKIA=true

Minimal reproducible code sample
import 'dart:ui';
import 'dart:math';
import 'package:flutter/material.dart';

void main() => runApp(MaterialApp(
      title: 'Sample',
      home: HomePage(),
    ));

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  var width = 100.0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      bottomNavigationBar: Card(
        child: Container(
          height: 50,
          child: Slider(
            max: min(MediaQuery.of(context).size.width, MediaQuery.of(context).size.height),
            min: 10,
            value: width,
            onChanged: (double value) => setState(() => width = value),
          ),
        ),
      ),
      appBar: AppBar(
        title: Text('Sample'),
      ),
      body: Center(
        child: SizedBox(
          width: width,
          child: ImageFiltered(
            imageFilter: ImageFilter.blur(sigmaX: 7.0, sigmaY: 7.0),
            child: Image.network(
                "https://cdna.artstation.com/p/assets/images/images/028/571/260/large/lower-third-logo-dark.jpg?1594844508"),
          ),
        ),
      ),
    );
  }
}
Desktop resizing sample
import 'dart:ui';

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Sample',
      home: Scaffold(
        appBar: AppBar(
          title: Text('Sample'),
        ),
        body: Center(
          child: ImageFiltered(
            imageFilter: ImageFilter.blur(sigmaX: 3.0, sigmaY: 3.0),
            child: Container(
              width: 50,
              height: 50,
              color: Colors.red,
            ),
          ),
        ),
      ),
    );
  }
}
flutter doctor -v
[√] Flutter (Channel master, 1.22.0-2.0.pre.105, on Microsoft Windows [Version 10.0.19041.450], locale en-US)
    • Flutter version 1.22.0-2.0.pre.105 at C:\Development\flutter_master
    • Framework revision cad4d1333e (11 hours ago), 2020-08-27 17:48:05 -0700
    • Engine revision 77dd1c05b9
    • Dart version 2.10.0 (build 2.10.0-67.0.dev)


[√] Android toolchain - develop for Android devices (Android SDK version 30.0.1)
    • Android SDK at C:\Users\marku\AppData\Local\Android\sdk
    • Platform android-30, build-tools 30.0.1
    • Java binary at: C:\Users\marku\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\193.6626763\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.6.5)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
    • Visual Studio Community 2019 version 16.6.30320.27
    • Windows 10 SDK version 10.0.18362.0

[√] Android Studio (version 4.0)
    • Android Studio at C:\Users\marku\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\193.6626763
    • Flutter plugin version 47.1.2
    • Dart plugin version 193.7361
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] Connected device (4 available)
    • sdk gphone x86 arm (mobile) • emulator-5554 • android-x86    • Android 11 (API 30) (emulator)
    • Windows (desktop)           • windows       • windows-x64    • Microsoft Windows [Version 10.0.19041.450]
    • Web Server (web)            • web-server    • web-javascript • Flutter Tools
    • Chrome (web)                • chrome        • web-javascript • Google Chrome 85.0.4183.83

• No issues found!

cc @flar

@markusaksli-nc markusaksli-nc added a: images Loading, displaying, rendering images framework flutter/packages/flutter repository. See also f: labels. c: rendering UI glitches reported at the engine/skia rendering level found in release: 1.22 Found to occur in 1.22 has reproducible steps The issue has been confirmed reproducible and is ready to work on labels Aug 28, 2020
@flar
Copy link
Contributor

flar commented Aug 28, 2020

Judging from the dynamic behavior, I believe what we are seeing is that the underlying blurred object is rendered on pixel boundaries in some frames, leading to crisp borders when blurred, and on sub-pixel boundaries in other frames, leading to the edge pixels having a non-opaque alpha which then gets blurred into the edge pixels.

This would also explain why it sometimes happens on only horizontal or vertical edges and sometimes happens on both since each of the horizontal and vertical positions can independently land on a pixel boundary. It appears that the width/height is an even number of (DPI scaled) pixels across as each pair of edges respond identically to each other.

Flutter has a devicePixelRatio that you can query to try to make things sized on a multiple of real pixels, but if you are using layout widgets like "Center" then you are at the mercy of it's calculation as to where you are positioned on the screen.

Non-web flutter may differ here in that the child to be blurred is usually rendered in an off-screen texture and then blurred so it will always land on 0,0 in the texture and never have an anti-aliased edge. The web code may not have a matching implementation.

@markusaksli-nc
Copy link
Member Author

markusaksli-nc commented Aug 28, 2020

This is supported by the fact that it happens at regular intervals. Also when removing the layout widgets, the sub-pixel boundaries don't get tossed around when resizing the window on desktop so the non-opaque bleed stays constant.

Modified code sample
import 'dart:ui';
import 'package:flutter/material.dart';

void main() => runApp(MaterialApp(
      title: 'Sample',
      home: HomePage(),
    ));

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  var width = 100.0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      bottomNavigationBar: Card(
        child: Container(
          height: 50,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              IconButton(icon: const Icon(Icons.remove), onPressed: () => setState(()=> width -= 2)),
              IconButton(icon: const Icon(Icons.add), onPressed: () => setState(()=> width += 2)),
            ],
          )
        ),
      ),
      appBar: AppBar(
        title: Text('Sample'),
      ),
      body: ImageFiltered(
        imageFilter: ImageFilter.blur(sigmaX: 7.0, sigmaY: 7.0),
        child: SizedBox(
          width: width,
          height: 100.0,
          child: Image.network(
              "https://cdna.artstation.com/p/assets/images/images/028/571/260/large/lower-third-logo-dark.jpg?1594844508", fit: BoxFit.fill,),
        ),
      ),
    );
  }
}

@TahaTesser
Copy link
Member

I can reproduce the issue

flutter doctor -v
[✓] Flutter (Channel master, 1.22.0-2.0.pre.139, on Microsoft Windows [Version 10.0.19041.450], locale en-US)
    • Flutter version 1.22.0-2.0.pre.139 at C:\Code\flutter_master
    • Framework revision c0ea00ed3f (3 hours ago), 2020-08-30 22:20:16 -0700
    • Engine revision bada9fc5f3
    • Dart version 2.10.0 (build 2.10.0-76.0.dev)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at C:\Code\sdk
    • Platform android-30, build-tools 30.0.2
    • ANDROID_HOME = C:\Code\sdk
    • Java binary at: C:\Code\android-studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[✓] Visual Studio - develop for Windows (Visual Studio Community 2019 16.7.2)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
    • Visual Studio Community 2019 version 16.7.30413.136
    • Windows 10 SDK version 10.0.18362.0

[✓] Android Studio (version 4.0)
    • Android Studio at C:\Code\android-studio
    • Flutter plugin version 48.1.2
    • Dart plugin version 193.7547
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[✓] VS Code (version 1.48.2)
    • VS Code at C:\Users\Taha\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.13.2

[✓] Connected device (3 available)
    • Windows (desktop) • windows    • windows-x64    • Microsoft Windows [Version 10.0.19041.450]
    • Web Server (web)  • web-server • web-javascript • Flutter Tools
    • Chrome (web)      • chrome     • web-javascript • Google Chrome 84.0.4147.135

• No issues found!

@flar
Copy link
Contributor

flar commented Dec 8, 2020

I think I've found the reason that it can sometimes appear more pronounced. If the radius is large then Skia will down-sample the image and use a smaller convolution kernel for speed. It appears that they don't take into account the fact that if the blur filter is using a clamp tile mode then they need to make sure that the edge pixel remains pure. Smaller radii will avoid the down-sampling and so the transparency of the edge pixels that arises from non-pixel aligned placement will be more pronounced than with larger blur radii.

https://fiddle.skia.org/c/d521a7712cccc7ed81133a7fd7fcff0f

@flar flar self-assigned this Dec 11, 2020
@kf6gpe kf6gpe added a: quality A truly polished experience P2 Important issues not at the top of the work list labels Dec 11, 2020
@cohenadair
Copy link

I am also seeing this behaviour when used inside a scroll view.

@darshankawar
Copy link
Member

Verified this issue using latest versions and observed that the resizing the filtered widget behavior still persists:

64828.mov

Whereas, the desktop resizing jank is not replicable after verifying on macOS desktop, as below:

64828_d.mov
stable, master flutter doctor -v
[✓] Flutter (Channel stable, 3.3.9, on macOS 12.2.1 21D62 darwin-x64, locale
    en-GB)
    • Flutter version 3.3.9 on channel stable at
      /Users/dhs/documents/fluttersdk/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision b8f7f1f986 (12 days ago), 2022-11-23 06:43:51 +0900
    • Engine revision 8f2221fbef
    • Dart version 2.18.5
    • DevTools version 2.15.0

[!] Xcode - develop for iOS and macOS (Xcode 12.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    ! Flutter recommends a minimum Xcode version of 13.
      Download the latest version or update via the Mac App Store.
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] VS Code (version 1.62.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.21.0

[✓] Connected device (5 available)
    • SM G975F (mobile)       • RZ8M802WY0X • android-arm64   • Android 11 (API 30)
    • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
      ios            • iOS 14.4.1 18D61
    • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
      ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
    • macOS (desktop)            • macos                                    •
      darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
    • Chrome (web)               • chrome                                   •
      web-javascript • Google Chrome 98.0.4758.80

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.

[!] Flutter (Channel master, 3.7.0-9.0.pre.11, on macOS 12.2.1 21D62 darwin-x64,
    locale en-GB)
    • Flutter version 3.7.0-9.0.pre.11 on channel master at
      /Users/dhs/documents/fluttersdk/flutter
    ! Warning: `flutter` on your path resolves to
      /Users/dhs/Documents/Fluttersdk/flutter/bin/flutter, which is not inside
      your current Flutter SDK checkout at
      /Users/dhs/documents/fluttersdk/flutter. Consider adding
      /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path.
    ! Warning: `dart` on your path resolves to
      /Users/dhs/Documents/Fluttersdk/flutter/bin/dart, which is not inside your
      current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter.
      Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front
      of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision dbc9306380 (7 hours ago), 2022-12-14 13:53:20 -0800
    • Engine revision 0a6a4a58f4
    • Dart version 3.0.0 (build 3.0.0-21.0.dev)
    • DevTools version 2.20.0
    • If those were intentional, you can disregard the above warnings; however
      it is recommended to use "git" directly to perform update checks and
      upgrades.


[!] Xcode - develop for iOS and macOS (Xcode 12.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    ! Flutter recommends a minimum Xcode version of 13.
      Download the latest version or update via the Mac App Store.
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] VS Code (version 1.62.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.21.0

[✓] Connected device (5 available)
    • SM G975F (mobile)       • RZ8M802WY0X • android-arm64   • Android 11 (API 30)
    • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
      ios            • iOS 14.4.1 18D61
    • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
      ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
    • macOS (desktop)            • macos                                    •
      darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
    • Chrome (web)               • chrome                                   •
      web-javascript • Google Chrome 98.0.4758.80

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.



Keeping this issue open, as the mobile platform behavior persists and also for team's attention.

/cc @flar

@darshankawar darshankawar added found in release: 3.3 Found to occur in 3.3 found in release: 3.7 Found to occur in 3.7 and removed found in release: 1.22 Found to occur in 1.22 labels Dec 15, 2022
@flutter-triage-bot flutter-triage-bot bot added multiteam-retriage-candidate team-engine Owned by Engine team triaged-engine Triaged by Engine team and removed triaged-engine Triaged by Engine team labels Jul 8, 2023
@flutter-triage-bot
Copy link

This issue is assigned but has had no recent status updates. Please consider unassigning this issue if it is not going to be addressed in the near future. This allows people to have a clearer picture of what work is actually planned. Thanks!

@chinmaygarde chinmaygarde added the triaged-engine Triaged by Engine team label Jul 17, 2023
@flutter-triage-bot flutter-triage-bot bot added the Bot is counting down the days until it unassigns the issue label Dec 4, 2023
@flutter-triage-bot
Copy link

This issue is assigned to @flar but has had no recent status updates. Please consider unassigning this issue if it is not going to be addressed in the near future. This allows people to have a clearer picture of what work is actually planned. Thanks!

@flar flar removed their assignment Dec 4, 2023
@flutter-triage-bot flutter-triage-bot bot removed the Bot is counting down the days until it unassigns the issue label Dec 4, 2023
@Andrekarma
Copy link

I dont know if this is related, but i have a problem with ImageFilter.blur only on the web
It seems to have like a strange padding at the edges of the screen

Container(
clipBehavior: Clip.hardEdge,
decoration: const BoxDecoration(),
child: ImageFiltered(
imageFilter: ImageFilter.blur(
sigmaX: 25.0,
sigmaY: 25.0,
),
child: image
),
),

You can see the difference from Windows to WEB
Windows:
image

WEB:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: images Loading, displaying, rendering images a: quality A truly polished experience c: rendering UI glitches reported at the engine/skia rendering level engine flutter/engine repository. See also e: labels. found in release: 3.3 Found to occur in 3.3 found in release: 3.7 Found to occur in 3.7 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on P2 Important issues not at the top of the work list team-engine Owned by Engine team triaged-engine Triaged by Engine team
Projects
None yet
Development

No branches or pull requests

9 participants