@@ -3137,10 +3137,11 @@ class _ColorFilter extends NativeFieldWrapperClass2 {
31373137/// this class as a child layer filter.
31383138abstract class ImageFilter {
31393139 /// Creates an image filter that applies a Gaussian blur.
3140- factory ImageFilter .blur ({ double sigmaX = 0.0 , double sigmaY = 0.0 }) {
3140+ factory ImageFilter .blur ({ double sigmaX = 0.0 , double sigmaY = 0.0 , TileMode tileMode = TileMode .clamp }) {
31413141 assert (sigmaX != null ); // ignore: unnecessary_null_comparison
31423142 assert (sigmaY != null ); // ignore: unnecessary_null_comparison
3143- return _GaussianBlurImageFilter (sigmaX: sigmaX, sigmaY: sigmaY);
3143+ assert (tileMode != null ); // ignore: unnecessary_null_comparison
3144+ return _GaussianBlurImageFilter (sigmaX: sigmaX, sigmaY: sigmaY, tileMode: tileMode);
31443145 }
31453146
31463147 /// Creates an image filter that applies a matrix transformation.
@@ -3206,29 +3207,40 @@ class _MatrixImageFilter implements ImageFilter {
32063207}
32073208
32083209class _GaussianBlurImageFilter implements ImageFilter {
3209- _GaussianBlurImageFilter ({ required this .sigmaX, required this .sigmaY });
3210+ _GaussianBlurImageFilter ({ required this .sigmaX, required this .sigmaY, required this .tileMode });
32103211
32113212 final double sigmaX;
32123213 final double sigmaY;
3214+ final TileMode tileMode;
32133215
32143216 // MakeBlurFilter
32153217 late final _ImageFilter nativeFilter = _ImageFilter .blur (this );
32163218 @override
32173219 _ImageFilter _toNativeImageFilter () => nativeFilter;
32183220
3221+ String get _modeString {
3222+ switch (tileMode) {
3223+ case TileMode .clamp: return 'clamp' ;
3224+ case TileMode .mirror: return 'mirror' ;
3225+ case TileMode .repeated: return 'repeated' ;
3226+ case TileMode .decal: return 'decal' ;
3227+ }
3228+ }
3229+
32193230 @override
3220- String get _shortDescription => 'blur($sigmaX , $sigmaY )' ;
3231+ String get _shortDescription => 'blur($sigmaX , $sigmaY , $ _modeString )' ;
32213232
32223233 @override
3223- String toString () => 'ImageFilter.blur($sigmaX , $sigmaY )' ;
3234+ String toString () => 'ImageFilter.blur($sigmaX , $sigmaY , $ _modeString )' ;
32243235
32253236 @override
32263237 bool operator == (Object other) {
32273238 if (other.runtimeType != runtimeType)
32283239 return false ;
32293240 return other is _GaussianBlurImageFilter
32303241 && other.sigmaX == sigmaX
3231- && other.sigmaY == sigmaY;
3242+ && other.sigmaY == sigmaY
3243+ && other.tileMode == tileMode;
32323244 }
32333245
32343246 @override
@@ -3278,9 +3290,9 @@ class _ImageFilter extends NativeFieldWrapperClass2 {
32783290 : assert (filter != null ), // ignore: unnecessary_null_comparison
32793291 creator = filter { // ignore: prefer_initializing_formals
32803292 _constructor ();
3281- _initBlur (filter.sigmaX, filter.sigmaY);
3293+ _initBlur (filter.sigmaX, filter.sigmaY, filter.tileMode.index );
32823294 }
3283- void _initBlur (double sigmaX, double sigmaY) native 'ImageFilter_initBlur' ;
3295+ void _initBlur (double sigmaX, double sigmaY, int tileMode ) native 'ImageFilter_initBlur' ;
32843296
32853297 /// Creates an image filter that applies a matrix transformation.
32863298 ///
@@ -3330,14 +3342,22 @@ class Shader extends NativeFieldWrapperClass2 {
33303342 Shader ._();
33313343}
33323344
3333- /// Defines what happens at the edge of the gradient.
3345+ /// Defines what happens at the edge of a gradient or the sampling of a source image
3346+ /// in an [ImageFilter] .
33343347///
33353348/// A gradient is defined along a finite inner area. In the case of a linear
33363349/// gradient, it's between the parallel lines that are orthogonal to the line
33373350/// drawn between two points. In the case of radial gradients, it's the disc
33383351/// that covers the circle centered on a particular point up to a given radius.
33393352///
3340- /// This enum is used to define how the gradient should paint the regions
3353+ /// An image filter reads source samples from a source image and performs operations
3354+ /// on those samples to produce a result image. An image defines color samples only
3355+ /// for pixels within the bounds of the image but some filter operations, such as a blur
3356+ /// filter, read samples over a wide area to compute the output for a given pixel. Such
3357+ /// a filter would need to combine samples from inside the image with hypothetical
3358+ /// color values from outside the image.
3359+ ///
3360+ /// This enum is used to define how the gradient or image filter should treat the regions
33413361/// outside that defined inner area.
33423362///
33433363/// See also:
@@ -3349,36 +3369,60 @@ class Shader extends NativeFieldWrapperClass2 {
33493369/// * [dart:ui.Gradient] , the low-level class used when dealing with the
33503370/// [Paint.shader] property directly, with its [Gradient.linear] and
33513371/// [Gradient.radial] constructors.
3352- // These enum values must be kept in sync with SkShader::TileMode.
3372+ /// * [dart:ui.ImageFilter.blur] , an ImageFilter that may sometimes need to
3373+ /// read samples from outside an image to combine with the pixels near the
3374+ /// edge of the image.
3375+ // These enum values must be kept in sync with SkTileMode.
33533376enum TileMode {
3354- /// Edge is clamped to the final color.
3377+ /// Samples beyond the edge are clamped to the nearest color in the defined inner area.
3378+ ///
3379+ /// A gradient will paint all the regions outside the inner area with the
3380+ /// color at the end of the color stop list closest to that region.
33553381 ///
3356- /// The gradient will paint the all the regions outside the inner area with
3357- /// the color of the point closest to that region .
3382+ /// An image filter will substitute the nearest edge pixel for any samples taken from
3383+ /// outside its source image .
33583384 ///
3385+ /// ![] (https://flutter.github.io/assets-for-api-docs/assets/dart-ui/tile_mode_clamp_linear.png)
33593386 /// ![] (https://flutter.github.io/assets-for-api-docs/assets/dart-ui/tile_mode_clamp_radial.png)
33603387 clamp,
33613388
3362- /// Edge is repeated from first color to last .
3389+ /// Samples beyond the edge are repeated from the far end of the defined area .
33633390 ///
3364- /// This is as if the stop points from 0.0 to 1.0 were then repeated from 1.0
3365- /// to 2.0, 2.0 to 3.0, and so forth (and for linear gradients, similarly from
3366- /// -1.0 to 0.0, -2.0 to -1.0, etc).
3391+ /// For a gradient, this technique is as if the stop points from 0.0 to 1.0 were then
3392+ /// repeated from 1.0 to 2.0, 2.0 to 3.0, and so forth (and for linear gradients, similarly
3393+ /// from -1.0 to 0.0, -2.0 to -1.0, etc).
3394+ ///
3395+ /// An image filter will treat its source image as if it were tiled across the enlarged
3396+ /// sample space from which it reads, each tile in the same orientation as the base image.
33673397 ///
33683398 /// ![] (https://flutter.github.io/assets-for-api-docs/assets/dart-ui/tile_mode_repeated_linear.png)
33693399 /// ![] (https://flutter.github.io/assets-for-api-docs/assets/dart-ui/tile_mode_repeated_radial.png)
33703400 repeated,
33713401
3372- /// Edge is mirrored from last color to first .
3402+ /// Samples beyond the edge are mirrored back and forth across the defined area .
33733403 ///
3374- /// This is as if the stop points from 0.0 to 1.0 were then repeated backwards
3375- /// from 2.0 to 1.0, then forwards from 2.0 to 3.0, then backwards again from
3376- /// 4.0 to 3.0, and so forth (and for linear gradients, similarly from in the
3404+ /// For a gradient, this technique is as if the stop points from 0.0 to 1.0 were then
3405+ /// repeated backwards from 2.0 to 1.0, then forwards from 2.0 to 3.0, then backwards
3406+ /// again from 4.0 to 3.0, and so forth (and for linear gradients, similarly in the
33773407 /// negative direction).
33783408 ///
3409+ /// An image filter will treat its source image as tiled in an alternating forwards and
3410+ /// backwards or upwards and downwards direction across the sample space from which
3411+ /// it is reading.
3412+ ///
33793413 /// ![] (https://flutter.github.io/assets-for-api-docs/assets/dart-ui/tile_mode_mirror_linear.png)
33803414 /// ![] (https://flutter.github.io/assets-for-api-docs/assets/dart-ui/tile_mode_mirror_radial.png)
33813415 mirror,
3416+
3417+ /// Samples beyond the edge are treated as transparent black.
3418+ ///
3419+ /// A gradient will render transparency over any region that is outside the circle of a
3420+ /// radial gradient or outside the parallel lines that define the inner area of a linear
3421+ /// gradient.
3422+ ///
3423+ /// An image filter will substitute transparent black for any sample it must read from
3424+ /// outside its source image.
3425+ decal,
33823426}
33833427
33843428Int32List _encodeColorList (List <Color > colors) {
0 commit comments