Switch to FilterQuality.medium for images (#148799)

https://github.com/flutter/flutter/issues/148253
This commit is contained in:
Michael Goderbauer 2024-05-30 20:50:30 -07:00 committed by GitHub
parent 1658e2af26
commit 8bed1cbe42
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 29 additions and 35 deletions

View File

@ -918,7 +918,7 @@ void _drawImageScaledAndCentered(PaintingContext context, ui.Image image, double
return;
}
final Paint paint = Paint()
..filterQuality = ui.FilterQuality.low
..filterQuality = ui.FilterQuality.medium
..color = Color.fromRGBO(0, 0, 0, opacity);
final double logicalWidth = image.width / pixelRatio;
final double logicalHeight = image.height / pixelRatio;
@ -1267,7 +1267,7 @@ class _ZoomEnterTransitionNoCache extends StatelessWidget {
opacity: fadeTransition,
child: ScaleTransition(
scale: scaleTransition,
filterQuality: FilterQuality.none,
filterQuality: FilterQuality.medium,
child: child,
),
),
@ -1300,7 +1300,7 @@ class _ZoomExitTransitionNoCache extends StatelessWidget {
opacity: fadeTransition,
child: ScaleTransition(
scale: scaleTransition,
filterQuality: FilterQuality.none,
filterQuality: FilterQuality.medium,
child: child,
),
);

View File

@ -51,7 +51,7 @@ class DecorationImage {
this.matchTextDirection = false,
this.scale = 1.0,
this.opacity = 1.0,
this.filterQuality = FilterQuality.low,
this.filterQuality = FilterQuality.medium,
this.invertColors = false,
this.isAntiAlias = false,
});
@ -148,8 +148,7 @@ class DecorationImage {
/// Used to set the filterQuality of the image.
///
/// Defaults to [FilterQuality.low] to scale the image, which corresponds to
/// bilinear interpolation.
/// Defaults to [FilterQuality.medium].
final FilterQuality filterQuality;
/// Whether the colors of the image are inverted when drawn.
@ -508,9 +507,7 @@ void debugFlushLastFrameImageSizeInfo() {
/// smart invert on iOS.
///
/// * `filterQuality`: Use this to change the quality when scaling an image.
/// Use the [FilterQuality.low] quality setting to scale the image, which corresponds to
/// bilinear interpolation, rather than the default [FilterQuality.none] which corresponds
/// to nearest-neighbor.
/// Defaults to [FilterQuality.medium].
///
/// See also:
///
@ -531,7 +528,7 @@ void paintImage({
ImageRepeat repeat = ImageRepeat.noRepeat,
bool flipHorizontally = false,
bool invertColors = false,
FilterQuality filterQuality = FilterQuality.low,
FilterQuality filterQuality = FilterQuality.medium,
bool isAntiAlias = false,
BlendMode blendMode = BlendMode.srcOver,
}) {

View File

@ -43,7 +43,7 @@ class RenderImage extends RenderBox {
TextDirection? textDirection,
bool invertColors = false,
bool isAntiAlias = false,
FilterQuality filterQuality = FilterQuality.low,
FilterQuality filterQuality = FilterQuality.medium,
}) : _image = image,
_width = width,
_height = height,
@ -188,9 +188,7 @@ class RenderImage extends RenderBox {
/// Used to set the filterQuality of the image.
///
/// Use the [FilterQuality.low] quality setting to scale the image, which corresponds to
/// bilinear interpolation, rather than the default [FilterQuality.none] which corresponds
/// to nearest-neighbor.
/// Defaults to [FilterQuality.medium].
FilterQuality get filterQuality => _filterQuality;
FilterQuality _filterQuality;
set filterQuality(FilterQuality value) {

View File

@ -5959,7 +5959,7 @@ class RawImage extends LeafRenderObjectWidget {
this.centerSlice,
this.matchTextDirection = false,
this.invertColors = false,
this.filterQuality = FilterQuality.low,
this.filterQuality = FilterQuality.medium,
this.isAntiAlias = false,
});
@ -6002,8 +6002,7 @@ class RawImage extends LeafRenderObjectWidget {
/// Used to set the filterQuality of the image.
///
/// Defaults to [FilterQuality.low] to scale the image, which corresponds to
/// bilinear interpolation.
/// Defaults to [FilterQuality.medium].
final FilterQuality filterQuality;
/// Used to combine [color] with this image.

View File

@ -92,7 +92,7 @@ class FadeInImage extends StatefulWidget {
this.height,
this.fit,
this.placeholderFit,
this.filterQuality = FilterQuality.low,
this.filterQuality = FilterQuality.medium,
this.placeholderFilterQuality,
this.alignment = Alignment.center,
this.repeat = ImageRepeat.noRepeat,
@ -149,7 +149,7 @@ class FadeInImage extends StatefulWidget {
this.placeholderColor,
this.placeholderColorBlendMode,
this.placeholderFit,
this.filterQuality = FilterQuality.low,
this.filterQuality = FilterQuality.medium,
this.placeholderFilterQuality,
this.alignment = Alignment.center,
this.repeat = ImageRepeat.noRepeat,
@ -211,7 +211,7 @@ class FadeInImage extends StatefulWidget {
this.placeholderColor,
this.placeholderColorBlendMode,
this.placeholderFit,
this.filterQuality = FilterQuality.low,
this.filterQuality = FilterQuality.medium,
this.placeholderFilterQuality,
this.alignment = Alignment.center,
this.repeat = ImageRepeat.noRepeat,

View File

@ -366,7 +366,7 @@ class Image extends StatefulWidget {
this.matchTextDirection = false,
this.gaplessPlayback = false,
this.isAntiAlias = false,
this.filterQuality = FilterQuality.low,
this.filterQuality = FilterQuality.medium,
});
/// Creates a widget that displays an [ImageStream] obtained from the network.
@ -414,7 +414,7 @@ class Image extends StatefulWidget {
this.centerSlice,
this.matchTextDirection = false,
this.gaplessPlayback = false,
this.filterQuality = FilterQuality.low,
this.filterQuality = FilterQuality.medium,
this.isAntiAlias = false,
Map<String, String>? headers,
int? cacheWidth,
@ -471,7 +471,7 @@ class Image extends StatefulWidget {
this.matchTextDirection = false,
this.gaplessPlayback = false,
this.isAntiAlias = false,
this.filterQuality = FilterQuality.low,
this.filterQuality = FilterQuality.medium,
int? cacheWidth,
int? cacheHeight,
}) :
@ -631,7 +631,7 @@ class Image extends StatefulWidget {
this.gaplessPlayback = false,
this.isAntiAlias = false,
String? package,
this.filterQuality = FilterQuality.low,
this.filterQuality = FilterQuality.medium,
int? cacheWidth,
int? cacheHeight,
}) : image = ResizeImage.resizeIfNeeded(
@ -693,7 +693,7 @@ class Image extends StatefulWidget {
this.matchTextDirection = false,
this.gaplessPlayback = false,
this.isAntiAlias = false,
this.filterQuality = FilterQuality.low,
this.filterQuality = FilterQuality.medium,
int? cacheWidth,
int? cacheHeight,
}) : image = ResizeImage.resizeIfNeeded(cacheWidth, cacheHeight, MemoryImage(bytes, scale: scale)),
@ -873,6 +873,8 @@ class Image extends StatefulWidget {
/// improve the rendered image quality in this case. Pixels may be misaligned
/// with the screen pixels as a result of transforms or scaling.
///
/// Defaults to [FilterQuality.medium].
///
/// See also:
///
/// * [FilterQuality], the enum containing all possible filter quality

View File

@ -777,7 +777,7 @@ class _StretchingOverscrollIndicatorState extends State<StretchingOverscrollIndi
final Widget transform = Transform(
alignment: alignment,
transform: Matrix4.diagonal3Values(x, y, 1.0),
filterQuality: stretch == 0 ? null : FilterQuality.low,
filterQuality: stretch == 0 ? null : FilterQuality.medium,
child: widget.child,
);

View File

@ -381,7 +381,7 @@ class _RenderSnapshotWidget extends RenderProxyBox {
/// final Rect src = Rect.fromLTWH(0, 0, image.width.toDouble(), image.height.toDouble());
/// final Rect dst = Rect.fromLTWH(offset.dx, offset.dy, size.width, size.height);
/// final Paint paint = Paint()
/// ..filterQuality = FilterQuality.low;
/// ..filterQuality = FilterQuality.medium;
/// context.canvas.drawImageRect(image, src, dst, paint);
/// }
/// ```
@ -414,7 +414,7 @@ abstract class SnapshotPainter extends ChangeNotifier {
/// final Rect src = Rect.fromLTWH(0, 0, sourceSize.width, sourceSize.height);
/// final Rect dst = Rect.fromLTWH(offset.dx, offset.dy, size.width, size.height);
/// final Paint paint = Paint()
/// ..filterQuality = FilterQuality.low;
/// ..filterQuality = FilterQuality.medium;
/// context.canvas.drawImageRect(image, src, dst, paint);
/// }
/// ```
@ -482,7 +482,7 @@ class _DefaultSnapshotPainter implements SnapshotPainter {
final Rect src = Rect.fromLTWH(0, 0, sourceSize.width, sourceSize.height);
final Rect dst = Rect.fromLTWH(offset.dx, offset.dy, size.width, size.height);
final Paint paint = Paint()
..filterQuality = FilterQuality.low;
..filterQuality = FilterQuality.medium;
context.canvas.drawImageRect(image, src, dst, paint);
}

View File

@ -341,7 +341,7 @@ void main() {
opacity: 0.99,
scale: 2.01,
).toString(),
'DecorationImage(SynchronousTestImageProvider(), Alignment.center, scale 2.0, opacity 1.0, FilterQuality.low)',
'DecorationImage(SynchronousTestImageProvider(), Alignment.center, scale 2.0, opacity 1.0, FilterQuality.medium)',
);
});
@ -389,7 +389,7 @@ void main() {
' BoxFit.contain, Alignment.center, centerSlice:\n'
' Rect.fromLTRB(10.0, 20.0, 40.0, 60.0), ImageRepeat.repeatY,\n'
' match text direction, scale 0.5, opacity 0.5,\n'
' FilterQuality.low, invert colors, use anti-aliasing)\n'
' FilterQuality.medium, invert colors, use anti-aliasing)\n'
' The ImageConfiguration was:\n'
' ImageConfiguration(size: Size(100.0, 100.0))\n',
);

View File

@ -40,7 +40,7 @@ Future<void> main() async {
' image: $squareImage\n'
' alignment: Alignment.center\n'
' invertColors: false\n'
' filterQuality: low\n',
' filterQuality: medium\n',
),
);

View File

@ -47,7 +47,7 @@ void main() {
expect(renderObject.centerSlice, null);
expect(renderObject.matchTextDirection, false);
expect(renderObject.invertColors, false);
expect(renderObject.filterQuality, FilterQuality.low);
expect(renderObject.filterQuality, FilterQuality.medium);
expect(renderObject.isAntiAlias, false);
final ui.Image image2 = (await tester.runAsync<ui.Image>(() => createTestImage(width: 2, height: 2)))!;

View File

@ -590,7 +590,6 @@ void main() {
await tester.pumpWidget(FadeInImage(
placeholder: placeholderProvider,
image: imageProvider,
filterQuality: FilterQuality.medium,
));
expect(findFadeInImage(tester).placeholder!.filterQuality, equals(findFadeInImage(tester).target.filterQuality));
@ -604,7 +603,6 @@ void main() {
await tester.pumpWidget(FadeInImage(
placeholder: placeholderProvider,
image: imageProvider,
filterQuality: FilterQuality.medium,
placeholderFilterQuality: FilterQuality.high,
));