Skip to content

cacheWidth/cacheHeight decode-time resize aliases large downscales (bilinear without mipmaps) #193779

Open

Description

@palmoni5

Steps to reproduce

  1. Take a large asset with thin, high-contrast details, e.g. a 1024×1024 PNG logo.
  2. Display it at ~120 logical pixels twice: once plain, once with cacheWidth set to the display size in physical pixels (the usage recommended for saving memory).
  3. Compare the two.

Expected results

Both images look the same (or nearly so). cacheWidth should only reduce memory, since the image is never drawn larger than the cache size.

Actual results

The cacheWidth version is visibly aliased: thin lines and curved edges are jagged ("pixelated"). The plain version, minified on the GPU with mipmaps (FilterQuality.medium), is smooth.

This was reported by users of our app: Otzaria/otzaria#1747 (logo decoded from 1024 px to ~120 px).

Cause

The decode-time resize uses bilinear sampling without mipmaps, so for large reduction ratios (~8× here) each output pixel samples only 2×2 of the ~8×8 source pixels it covers:

  • engine/src/flutter/lib/ui/painting/image_decoder_impeller.cc (ResizeOnCpu):
    scalePixels(..., SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kNone))
  • engine/src/flutter/lib/ui/painting/image_decoder_skia.cc (ResizeRasterImage): same sampling options.
  • The Impeller GPU path (blit_pass->ResizeTexture(dest_texture, resize_texture)) also resizes from the non-mipmapped source; mipmaps are generated only for the destination.

Possible fixes: use mipmapped sampling (SkMipmapMode::kLinear) or SkCubicResampler for the CPU path, or downscale in successive halving steps / generate source mipmaps before the GPU resize, at least when the reduction ratio is greater than 2.

This is the same problem as #56239, which was closed by #184549. That PR adds logical-pixel sizing to ResizeImage but does not change the resize quality, so the original quality issue is still present.

Code sample

Code sample
import 'package:flutter/material.dart';

// Any large asset with thin details, e.g. a 1024x1024 logo.
const asset = 'assets/logo_1024.png';
const size = 120.0;

void main() => runApp(const MaterialApp(home: Demo()));

class Demo extends StatelessWidget {
  const Demo({super.key});

  @override
  Widget build(BuildContext context) {
    final dpr = MediaQuery.devicePixelRatioOf(context);
    return Scaffold(
      body: Center(
        child: Row(
          mainAxisSize: MainAxisSize.min,
          children: [
            // Smooth: full decode, GPU minification with mipmaps.
            Image.asset(asset, width: size, height: size),
            const SizedBox(width: 24),
            // Jagged: decode-time resize, bilinear without mipmaps.
            Image.asset(
              asset,
              width: size,
              height: size,
              cacheWidth: (size * dpr).ceil(),
            ),
          ],
        ),
      ),
    );
  }
}

Flutter Doctor output

Doctor output
Flutter 3.47.2 • framework revision d3b14c8769 (2026-08-26)
Windows 11 x64

The resize code quoted above is identical on the current master.

Activity

  1. added
    engine
    a: images
    team-engine
    on Oct 5, 2026
  2. mbcorona commented on Oct 5, 2026

    @mbcorona
    Member

    Hi @palmoni5, thanks for the clear writeup and root cause.
    Routing to team-engine for evaluation.

  3. added
    P2
    on Oct 5, 2026
  4. gaaclarke commented on Oct 5, 2026

    @gaaclarke
    Member

    @palmoni5 can you provide an image of the aliasing you are seeing? Can you also please add an example image that demonstrates your problem with your provided code please?

  5. added
    waiting for response
    on Oct 5, 2026
  6. palmoni5 commented on Oct 5, 2026

    @palmoni5
    ContributorAuthor

    Thanks! Here is the output of the exact code sample above, rendered on a real Windows device (Flutter 3.47.2, debug, devicePixelRatio 1.0), captured with RenderRepaintBoundary.toImage.

    Source image (1024×1024 PNG): https://github.com/Otzaria/otzaria/blob/dev/assets/icon/iconnew.png

    1:1 capture — left: plain Image.asset, right: cacheWidth: 120:

    Image

    4× nearest-neighbor zoom of the same capture:

    Image

    The cacheWidth version shows stair-stepped edges along the curves and the thin outlines, while the plain version (full decode, GPU minification with mipmaps) is smooth.

  7. removed
    waiting for response
    on Oct 5, 2026
  8. added
    triaged-engine
    on Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2a: imagesenginefound in release: 3.47team-enginetriaged-engine

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions