mirror of
https://github.com/flutter/packages.git
synced 2025-06-30 14:47:22 +08:00
enable lints unnecessary_new and unnecessary_const (#4)
This commit is contained in:

committed by
GitHub

parent
983a50d2ba
commit
14ff267dc5
@ -134,8 +134,10 @@ linter:
|
||||
- type_init_formals
|
||||
# - unawaited_futures # https://github.com/flutter/flutter/issues/5793
|
||||
- unnecessary_brace_in_string_interps
|
||||
- unnecessary_const
|
||||
- unnecessary_getters_setters
|
||||
# - unnecessary_lambdas # https://github.com/dart-lang/linter/issues/498
|
||||
- unnecessary_new
|
||||
- unnecessary_null_aware_assignments
|
||||
- unnecessary_null_in_if_null_operators
|
||||
- unnecessary_overrides
|
||||
|
@ -10,27 +10,27 @@ import 'package:flutter/rendering.dart';
|
||||
|
||||
import 'package:palette_generator/palette_generator.dart';
|
||||
|
||||
void main() => runApp(new MyApp());
|
||||
void main() => runApp(MyApp());
|
||||
|
||||
const Color _kBackgroundColor = const Color(0xffa0a0a0);
|
||||
const Color _kSelectionRectangleBackground = const Color(0x15000000);
|
||||
const Color _kSelectionRectangleBorder = const Color(0x80000000);
|
||||
const Color _kPlaceholderColor = const Color(0x80404040);
|
||||
const Color _kBackgroundColor = Color(0xffa0a0a0);
|
||||
const Color _kSelectionRectangleBackground = Color(0x15000000);
|
||||
const Color _kSelectionRectangleBorder = Color(0x80000000);
|
||||
const Color _kPlaceholderColor = Color(0x80404040);
|
||||
|
||||
/// The main Application class.
|
||||
class MyApp extends StatelessWidget {
|
||||
// This widget is the root of your application.
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new MaterialApp(
|
||||
return MaterialApp(
|
||||
title: 'Image Colors',
|
||||
theme: new ThemeData(
|
||||
theme: ThemeData(
|
||||
primarySwatch: Colors.green,
|
||||
),
|
||||
home: const ImageColors(
|
||||
title: 'Image Colors',
|
||||
image: const AssetImage('assets/landscape.png'),
|
||||
imageSize: const Size(256.0, 170.0),
|
||||
image: AssetImage('assets/landscape.png'),
|
||||
imageSize: Size(256.0, 170.0),
|
||||
),
|
||||
);
|
||||
}
|
||||
@ -58,7 +58,7 @@ class ImageColors extends StatefulWidget {
|
||||
|
||||
@override
|
||||
_ImageColorsState createState() {
|
||||
return new _ImageColorsState();
|
||||
return _ImageColorsState();
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,7 +69,7 @@ class _ImageColorsState extends State<ImageColors> {
|
||||
Offset currentDrag;
|
||||
PaletteGenerator paletteGenerator;
|
||||
|
||||
final GlobalKey imageKey = new GlobalKey();
|
||||
final GlobalKey imageKey = GlobalKey();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -95,7 +95,7 @@ class _ImageColorsState extends State<ImageColors> {
|
||||
setState(() {
|
||||
startDrag = localPosition;
|
||||
currentDrag = startDrag;
|
||||
dragRegion = new Rect.fromPoints(startDrag, currentDrag);
|
||||
dragRegion = Rect.fromPoints(startDrag, currentDrag);
|
||||
});
|
||||
}
|
||||
|
||||
@ -103,7 +103,7 @@ class _ImageColorsState extends State<ImageColors> {
|
||||
void _onPanUpdate(DragUpdateDetails details) {
|
||||
setState(() {
|
||||
currentDrag += details.delta;
|
||||
dragRegion = new Rect.fromPoints(startDrag, currentDrag);
|
||||
dragRegion = Rect.fromPoints(startDrag, currentDrag);
|
||||
});
|
||||
}
|
||||
|
||||
@ -133,38 +133,38 @@ class _ImageColorsState extends State<ImageColors> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new Scaffold(
|
||||
return Scaffold(
|
||||
backgroundColor: _kBackgroundColor,
|
||||
appBar: new AppBar(
|
||||
title: new Text(widget.title),
|
||||
appBar: AppBar(
|
||||
title: Text(widget.title),
|
||||
),
|
||||
body: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
new Padding(
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
// GestureDetector is used to handle the selection rectangle.
|
||||
child: new GestureDetector(
|
||||
child: GestureDetector(
|
||||
onPanDown: _onPanDown,
|
||||
onPanUpdate: _onPanUpdate,
|
||||
onPanCancel: _onPanCancel,
|
||||
onPanEnd: _onPanEnd,
|
||||
child: new Stack(children: <Widget>[
|
||||
new Image(
|
||||
child: Stack(children: <Widget>[
|
||||
Image(
|
||||
key: imageKey,
|
||||
image: widget.image,
|
||||
width: widget.imageSize.width,
|
||||
height: widget.imageSize.height,
|
||||
),
|
||||
// This is the selection rectangle.
|
||||
new Positioned.fromRect(
|
||||
Positioned.fromRect(
|
||||
rect: dragRegion ?? region ?? Rect.zero,
|
||||
child: new Container(
|
||||
decoration: new BoxDecoration(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: _kSelectionRectangleBackground,
|
||||
border: new Border.all(
|
||||
border: Border.all(
|
||||
width: 1.0,
|
||||
color: _kSelectionRectangleBorder,
|
||||
style: BorderStyle.solid,
|
||||
@ -175,7 +175,7 @@ class _ImageColorsState extends State<ImageColors> {
|
||||
),
|
||||
// Use a FutureBuilder so that the palettes will be displayed when
|
||||
// the palette generator is done generating its data.
|
||||
new PaletteSwatches(generator: paletteGenerator),
|
||||
PaletteSwatches(generator: paletteGenerator),
|
||||
],
|
||||
),
|
||||
);
|
||||
@ -199,32 +199,30 @@ class PaletteSwatches extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final List<Widget> swatches = <Widget>[];
|
||||
if (generator == null || generator.colors.isEmpty) {
|
||||
return new Container();
|
||||
return Container();
|
||||
}
|
||||
for (Color color in generator.colors) {
|
||||
swatches.add(new PaletteSwatch(color: color));
|
||||
swatches.add(PaletteSwatch(color: color));
|
||||
}
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
new Wrap(
|
||||
Wrap(
|
||||
children: swatches,
|
||||
),
|
||||
new Container(height: 30.0),
|
||||
new PaletteSwatch(
|
||||
label: 'Dominant', color: generator.dominantColor?.color),
|
||||
new PaletteSwatch(
|
||||
Container(height: 30.0),
|
||||
PaletteSwatch(label: 'Dominant', color: generator.dominantColor?.color),
|
||||
PaletteSwatch(
|
||||
label: 'Light Vibrant', color: generator.lightVibrantColor?.color),
|
||||
new PaletteSwatch(
|
||||
label: 'Vibrant', color: generator.vibrantColor?.color),
|
||||
new PaletteSwatch(
|
||||
PaletteSwatch(label: 'Vibrant', color: generator.vibrantColor?.color),
|
||||
PaletteSwatch(
|
||||
label: 'Dark Vibrant', color: generator.darkVibrantColor?.color),
|
||||
new PaletteSwatch(
|
||||
PaletteSwatch(
|
||||
label: 'Light Muted', color: generator.lightMutedColor?.color),
|
||||
new PaletteSwatch(label: 'Muted', color: generator.mutedColor?.color),
|
||||
new PaletteSwatch(
|
||||
PaletteSwatch(label: 'Muted', color: generator.mutedColor?.color),
|
||||
PaletteSwatch(
|
||||
label: 'Dark Muted', color: generator.darkMutedColor?.color),
|
||||
],
|
||||
);
|
||||
@ -268,13 +266,13 @@ class PaletteSwatch extends StatelessWidget {
|
||||
? const Placeholder(
|
||||
fallbackWidth: 34.0,
|
||||
fallbackHeight: 20.0,
|
||||
color: const Color(0xff404040),
|
||||
color: Color(0xff404040),
|
||||
strokeWidth: 2.0,
|
||||
)
|
||||
: new Container(
|
||||
decoration: new BoxDecoration(
|
||||
: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: color,
|
||||
border: new Border.all(
|
||||
border: Border.all(
|
||||
width: 1.0,
|
||||
color: _kPlaceholderColor,
|
||||
style: colorDistance < 0.2
|
||||
@ -293,8 +291,8 @@ class PaletteSwatch extends StatelessWidget {
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
swatch,
|
||||
new Container(width: 5.0),
|
||||
new Text(label),
|
||||
Container(width: 5.0),
|
||||
Text(label),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
@ -114,14 +114,14 @@ class PaletteGenerator extends Diagnosticable {
|
||||
|
||||
filters ??= <PaletteFilter>[avoidRedBlackWhitePaletteFilter];
|
||||
maximumColorCount ??= _defaultCalculateNumberColors;
|
||||
final _ColorCutQuantizer quantizer = new _ColorCutQuantizer(
|
||||
final _ColorCutQuantizer quantizer = _ColorCutQuantizer(
|
||||
image,
|
||||
maxColors: maximumColorCount,
|
||||
filters: filters,
|
||||
region: region,
|
||||
);
|
||||
final List<PaletteColor> colors = await quantizer.quantizedColors;
|
||||
return new PaletteGenerator.fromColors(
|
||||
return PaletteGenerator.fromColors(
|
||||
colors,
|
||||
targets: targets,
|
||||
);
|
||||
@ -179,9 +179,9 @@ class PaletteGenerator extends Diagnosticable {
|
||||
region.bottomRight.dy <= size.height),
|
||||
'Region $region is outside the image $size');
|
||||
final ImageStream stream = imageProvider.resolve(
|
||||
new ImageConfiguration(size: size, devicePixelRatio: 1.0),
|
||||
ImageConfiguration(size: size, devicePixelRatio: 1.0),
|
||||
);
|
||||
final Completer<ui.Image> imageCompleter = new Completer<ui.Image>();
|
||||
final Completer<ui.Image> imageCompleter = Completer<ui.Image>();
|
||||
Timer loadFailureTimeout;
|
||||
void imageListener(ImageInfo info, bool synchronousCall) {
|
||||
loadFailureTimeout?.cancel();
|
||||
@ -189,10 +189,10 @@ class PaletteGenerator extends Diagnosticable {
|
||||
}
|
||||
|
||||
if (timeout != Duration.zero) {
|
||||
loadFailureTimeout = new Timer(timeout, () {
|
||||
loadFailureTimeout = Timer(timeout, () {
|
||||
stream.removeListener(imageListener);
|
||||
imageCompleter.completeError(
|
||||
new TimeoutException(
|
||||
TimeoutException(
|
||||
'Timeout occurred trying to load from $imageProvider'),
|
||||
);
|
||||
});
|
||||
@ -274,9 +274,9 @@ class PaletteGenerator extends Diagnosticable {
|
||||
}
|
||||
|
||||
void _selectSwatches() {
|
||||
final Set<PaletteTarget> allTargets = new Set<PaletteTarget>.from(
|
||||
final Set<PaletteTarget> allTargets = Set<PaletteTarget>.from(
|
||||
(targets ?? <PaletteTarget>[]) + PaletteTarget.baseTargets);
|
||||
final Set<Color> usedColors = new Set<Color>();
|
||||
final Set<Color> usedColors = Set<Color>();
|
||||
for (PaletteTarget target in allTargets) {
|
||||
target._normalizeWeights();
|
||||
selectedSwatches[target] = _generateScoredTarget(target, usedColors);
|
||||
@ -315,7 +315,7 @@ class PaletteGenerator extends Diagnosticable {
|
||||
PaletteColor paletteColor, PaletteTarget target, Set<Color> usedColors) {
|
||||
// Check whether the HSL lightness is within the correct range, and that
|
||||
// this color hasn't been used yet.
|
||||
final HSLColor hslColor = new HSLColor.fromColor(paletteColor.color);
|
||||
final HSLColor hslColor = HSLColor.fromColor(paletteColor.color);
|
||||
return hslColor.saturation >= target.minimumSaturation &&
|
||||
hslColor.saturation <= target.maximumSaturation &&
|
||||
hslColor.lightness >= target.minimumLightness &&
|
||||
@ -324,7 +324,7 @@ class PaletteGenerator extends Diagnosticable {
|
||||
}
|
||||
|
||||
double _generateScore(PaletteColor paletteColor, PaletteTarget target) {
|
||||
final HSLColor hslColor = new HSLColor.fromColor(paletteColor.color);
|
||||
final HSLColor hslColor = HSLColor.fromColor(paletteColor.color);
|
||||
|
||||
double saturationScore = 0.0;
|
||||
double valueScore = 0.0;
|
||||
@ -349,10 +349,10 @@ class PaletteGenerator extends Diagnosticable {
|
||||
@override
|
||||
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
|
||||
super.debugFillProperties(properties);
|
||||
properties.add(new IterableProperty<PaletteColor>(
|
||||
properties.add(IterableProperty<PaletteColor>(
|
||||
'paletteColors', paletteColors,
|
||||
defaultValue: <PaletteColor>[]));
|
||||
properties.add(new IterableProperty<PaletteTarget>('targets', targets,
|
||||
properties.add(IterableProperty<PaletteTarget>('targets', targets,
|
||||
defaultValue: PaletteTarget.baseTargets));
|
||||
}
|
||||
}
|
||||
@ -444,7 +444,7 @@ class PaletteTarget extends Diagnosticable {
|
||||
/// in luminance.
|
||||
///
|
||||
/// One of the base set of `targets` for [PaletteGenerator.fromImage], in [baseTargets].
|
||||
static final PaletteTarget lightVibrant = new PaletteTarget(
|
||||
static final PaletteTarget lightVibrant = PaletteTarget(
|
||||
targetLightness: _targetLightLightness,
|
||||
minimumLightness: _minLightLightness,
|
||||
minimumSaturation: _minVibrantSaturation,
|
||||
@ -455,7 +455,7 @@ class PaletteTarget extends Diagnosticable {
|
||||
/// light or dark.
|
||||
///
|
||||
/// One of the base set of `targets` for [PaletteGenerator.fromImage], in [baseTargets].
|
||||
static final PaletteTarget vibrant = new PaletteTarget(
|
||||
static final PaletteTarget vibrant = PaletteTarget(
|
||||
minimumLightness: _minNormalLightness,
|
||||
targetLightness: _targetNormalLightness,
|
||||
maximumLightness: _maxNormalLightness,
|
||||
@ -467,7 +467,7 @@ class PaletteTarget extends Diagnosticable {
|
||||
/// luminance.
|
||||
///
|
||||
/// One of the base set of `targets` for [PaletteGenerator.fromImage], in [baseTargets].
|
||||
static final PaletteTarget darkVibrant = new PaletteTarget(
|
||||
static final PaletteTarget darkVibrant = PaletteTarget(
|
||||
targetLightness: _targetDarkLightness,
|
||||
maximumLightness: _maxDarkLightness,
|
||||
minimumSaturation: _minVibrantSaturation,
|
||||
@ -478,7 +478,7 @@ class PaletteTarget extends Diagnosticable {
|
||||
/// luminance.
|
||||
///
|
||||
/// One of the base set of `targets` for [PaletteGenerator.fromImage], in [baseTargets].
|
||||
static final PaletteTarget lightMuted = new PaletteTarget(
|
||||
static final PaletteTarget lightMuted = PaletteTarget(
|
||||
targetLightness: _targetLightLightness,
|
||||
minimumLightness: _minLightLightness,
|
||||
targetSaturation: _targetMutedSaturation,
|
||||
@ -489,7 +489,7 @@ class PaletteTarget extends Diagnosticable {
|
||||
/// light or dark.
|
||||
///
|
||||
/// One of the base set of `targets` for [PaletteGenerator.fromImage], in [baseTargets].
|
||||
static final PaletteTarget muted = new PaletteTarget(
|
||||
static final PaletteTarget muted = PaletteTarget(
|
||||
minimumLightness: _minNormalLightness,
|
||||
targetLightness: _targetNormalLightness,
|
||||
maximumLightness: _maxNormalLightness,
|
||||
@ -501,7 +501,7 @@ class PaletteTarget extends Diagnosticable {
|
||||
/// luminance.
|
||||
///
|
||||
/// One of the base set of `targets` for [PaletteGenerator.fromImage], in [baseTargets].
|
||||
static final PaletteTarget darkMuted = new PaletteTarget(
|
||||
static final PaletteTarget darkMuted = PaletteTarget(
|
||||
targetLightness: _targetDarkLightness,
|
||||
maximumLightness: _maxDarkLightness,
|
||||
targetSaturation: _targetMutedSaturation,
|
||||
@ -560,24 +560,24 @@ class PaletteTarget extends Diagnosticable {
|
||||
@override
|
||||
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
|
||||
super.debugFillProperties(properties);
|
||||
final PaletteTarget defaultTarget = new PaletteTarget();
|
||||
properties.add(new DoubleProperty('minimumSaturation', minimumSaturation,
|
||||
final PaletteTarget defaultTarget = PaletteTarget();
|
||||
properties.add(DoubleProperty('minimumSaturation', minimumSaturation,
|
||||
defaultValue: defaultTarget.minimumSaturation));
|
||||
properties.add(new DoubleProperty('targetSaturation', targetSaturation,
|
||||
properties.add(DoubleProperty('targetSaturation', targetSaturation,
|
||||
defaultValue: defaultTarget.targetSaturation));
|
||||
properties.add(new DoubleProperty('maximumSaturation', maximumSaturation,
|
||||
properties.add(DoubleProperty('maximumSaturation', maximumSaturation,
|
||||
defaultValue: defaultTarget.maximumSaturation));
|
||||
properties.add(new DoubleProperty('minimumLightness', minimumLightness,
|
||||
properties.add(DoubleProperty('minimumLightness', minimumLightness,
|
||||
defaultValue: defaultTarget.minimumLightness));
|
||||
properties.add(new DoubleProperty('targetLightness', targetLightness,
|
||||
properties.add(DoubleProperty('targetLightness', targetLightness,
|
||||
defaultValue: defaultTarget.targetLightness));
|
||||
properties.add(new DoubleProperty('maximumLightness', maximumLightness,
|
||||
properties.add(DoubleProperty('maximumLightness', maximumLightness,
|
||||
defaultValue: defaultTarget.maximumLightness));
|
||||
properties.add(new DoubleProperty('saturationWeight', saturationWeight,
|
||||
properties.add(DoubleProperty('saturationWeight', saturationWeight,
|
||||
defaultValue: defaultTarget.saturationWeight));
|
||||
properties.add(new DoubleProperty('lightnessWeight', lightnessWeight,
|
||||
properties.add(DoubleProperty('lightnessWeight', lightnessWeight,
|
||||
defaultValue: defaultTarget.lightnessWeight));
|
||||
properties.add(new DoubleProperty('populationWeight', populationWeight,
|
||||
properties.add(DoubleProperty('populationWeight', populationWeight,
|
||||
defaultValue: defaultTarget.populationWeight));
|
||||
}
|
||||
}
|
||||
@ -633,8 +633,8 @@ class PaletteColor extends Diagnosticable {
|
||||
|
||||
void _ensureTextColorsGenerated() {
|
||||
if (_titleTextColor == null || _bodyTextColor == null) {
|
||||
const Color white = const Color(0xffffffff);
|
||||
const Color black = const Color(0xff000000);
|
||||
const Color white = Color(0xffffffff);
|
||||
const Color black = Color(0xff000000);
|
||||
// First check white, as most colors will be dark
|
||||
final int lightBodyAlpha =
|
||||
_calculateMinimumAlpha(white, color, _minContrastBodyText);
|
||||
@ -683,10 +683,8 @@ class PaletteColor extends Diagnosticable {
|
||||
// background
|
||||
foreground = Color.alphaBlend(foreground, background);
|
||||
}
|
||||
final double lightness1 =
|
||||
new HSLColor.fromColor(foreground).lightness + 0.05;
|
||||
final double lightness2 =
|
||||
new HSLColor.fromColor(background).lightness + 0.05;
|
||||
final double lightness1 = HSLColor.fromColor(foreground).lightness + 0.05;
|
||||
final double lightness2 = HSLColor.fromColor(background).lightness + 0.05;
|
||||
return math.max(lightness1, lightness2) / math.min(lightness1, lightness2);
|
||||
}
|
||||
|
||||
@ -763,12 +761,11 @@ class PaletteColor extends Diagnosticable {
|
||||
@override
|
||||
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
|
||||
super.debugFillProperties(properties);
|
||||
properties.add(new DiagnosticsProperty<Color>('color', color));
|
||||
properties.add(DiagnosticsProperty<Color>('color', color));
|
||||
properties
|
||||
.add(new DiagnosticsProperty<Color>('titleTextColor', titleTextColor));
|
||||
properties
|
||||
.add(new DiagnosticsProperty<Color>('bodyTextColor', bodyTextColor));
|
||||
properties.add(new IntProperty('population', population, defaultValue: 0));
|
||||
.add(DiagnosticsProperty<Color>('titleTextColor', titleTextColor));
|
||||
properties.add(DiagnosticsProperty<Color>('bodyTextColor', bodyTextColor));
|
||||
properties.add(IntProperty('population', population, defaultValue: 0));
|
||||
}
|
||||
|
||||
@override
|
||||
@ -922,7 +919,7 @@ class _ColorVolumeBox {
|
||||
// find median along the longest dimension
|
||||
final int splitPoint = _findSplitPoint();
|
||||
final _ColorVolumeBox newBox =
|
||||
new _ColorVolumeBox(splitPoint + 1, _upperIndex, histogram, colors);
|
||||
_ColorVolumeBox(splitPoint + 1, _upperIndex, histogram, colors);
|
||||
// Now change this box's upperIndex and recompute the color boundaries
|
||||
_upperIndex = splitPoint;
|
||||
_fitMinimumBox();
|
||||
@ -1009,8 +1006,8 @@ class _ColorVolumeBox {
|
||||
final int redMean = (redSum / totalPopulation).round();
|
||||
final int greenMean = (greenSum / totalPopulation).round();
|
||||
final int blueMean = (blueSum / totalPopulation).round();
|
||||
return new PaletteColor(
|
||||
new Color.fromARGB(0xff, redMean, greenMean, blueMean),
|
||||
return PaletteColor(
|
||||
Color.fromARGB(0xff, redMean, greenMean, blueMean),
|
||||
totalPopulation,
|
||||
);
|
||||
}
|
||||
@ -1070,7 +1067,7 @@ class _ColorCutQuantizer {
|
||||
final int position = row * rowStride + col * 4;
|
||||
// Convert from RGBA to ARGB.
|
||||
final int pixel = pixels.getUint32(position);
|
||||
final Color result = new Color((pixel << 24) | (pixel >> 8));
|
||||
final Color result = Color((pixel << 24) | (pixel >> 8));
|
||||
byteCount += 4;
|
||||
yield result;
|
||||
}
|
||||
@ -1098,7 +1095,7 @@ class _ColorCutQuantizer {
|
||||
((1 << quantizeWordWidth) - 1) << quantizeShift;
|
||||
|
||||
Color quantizeColor(Color color) {
|
||||
return new Color.fromARGB(
|
||||
return Color.fromARGB(
|
||||
color.alpha,
|
||||
color.red & quantizeWordMask,
|
||||
color.green & quantizeWordMask,
|
||||
@ -1131,7 +1128,7 @@ class _ColorCutQuantizer {
|
||||
// the colors.
|
||||
_paletteColors.clear();
|
||||
for (Color color in hist.keys) {
|
||||
_paletteColors.add(new PaletteColor(color, hist[color]));
|
||||
_paletteColors.add(PaletteColor(color, hist[color]));
|
||||
}
|
||||
} else {
|
||||
// We need use quantization to reduce the number of colors
|
||||
@ -1152,9 +1149,9 @@ class _ColorCutQuantizer {
|
||||
// Create the priority queue which is sorted by volume descending. This
|
||||
// means we always split the largest box in the queue
|
||||
final PriorityQueue<_ColorVolumeBox> priorityQueue =
|
||||
new HeapPriorityQueue<_ColorVolumeBox>(volumeComparator);
|
||||
HeapPriorityQueue<_ColorVolumeBox>(volumeComparator);
|
||||
// To start, offer a box which contains all of the colors
|
||||
priorityQueue.add(new _ColorVolumeBox(
|
||||
priorityQueue.add(_ColorVolumeBox(
|
||||
0, histogram.length - 1, histogram, histogram.keys.toList()));
|
||||
// Now go through the boxes, splitting them until we have reached maxColors
|
||||
// or there are no more boxes to split
|
||||
|
@ -26,29 +26,29 @@ class FakeImageProvider extends ImageProvider<FakeImageProvider> {
|
||||
|
||||
@override
|
||||
Future<FakeImageProvider> obtainKey(ImageConfiguration configuration) {
|
||||
return new SynchronousFuture<FakeImageProvider>(this);
|
||||
return SynchronousFuture<FakeImageProvider>(this);
|
||||
}
|
||||
|
||||
@override
|
||||
ImageStreamCompleter load(FakeImageProvider key) {
|
||||
assert(key == this);
|
||||
return new OneFrameImageStreamCompleter(
|
||||
new SynchronousFuture<ImageInfo>(
|
||||
new ImageInfo(image: _image, scale: scale),
|
||||
return OneFrameImageStreamCompleter(
|
||||
SynchronousFuture<ImageInfo>(
|
||||
ImageInfo(image: _image, scale: scale),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<ImageProvider> loadImage(String name) async {
|
||||
File imagePath = new File(path.joinAll(<String>['assets', name]));
|
||||
File imagePath = File(path.joinAll(<String>['assets', name]));
|
||||
if (path.split(Directory.current.absolute.path).last != 'test') {
|
||||
imagePath = new File(path.join('test', imagePath.path));
|
||||
imagePath = File(path.join('test', imagePath.path));
|
||||
}
|
||||
final Uint8List data = new Uint8List.fromList(imagePath.readAsBytesSync());
|
||||
final Uint8List data = Uint8List.fromList(imagePath.readAsBytesSync());
|
||||
final ui.Codec codec = await ui.instantiateImageCodec(data);
|
||||
final ui.FrameInfo frameInfo = await codec.getNextFrame();
|
||||
return new FakeImageProvider(frameInfo.image);
|
||||
return FakeImageProvider(frameInfo.image);
|
||||
}
|
||||
|
||||
void main() async {
|
||||
@ -102,8 +102,8 @@ void main() async {
|
||||
|
||||
test('PaletteGenerator works with regions', () async {
|
||||
final ImageProvider imageProvider = testImages['dominant'];
|
||||
Rect region = new Rect.fromLTRB(0.0, 0.0, 100.0, 100.0);
|
||||
const Size size = const Size(100.0, 100.0);
|
||||
Rect region = Rect.fromLTRB(0.0, 0.0, 100.0, 100.0);
|
||||
const Size size = Size(100.0, 100.0);
|
||||
PaletteGenerator palette = await PaletteGenerator.fromImageProvider(
|
||||
imageProvider,
|
||||
region: region,
|
||||
@ -112,14 +112,14 @@ void main() async {
|
||||
expect(palette.dominantColor.color,
|
||||
within<Color>(distance: 8, from: const Color(0xff0000ff)));
|
||||
|
||||
region = new Rect.fromLTRB(0.0, 0.0, 10.0, 10.0);
|
||||
region = Rect.fromLTRB(0.0, 0.0, 10.0, 10.0);
|
||||
palette = await PaletteGenerator.fromImageProvider(imageProvider,
|
||||
region: region, size: size);
|
||||
expect(palette.paletteColors.length, equals(1));
|
||||
expect(palette.dominantColor.color,
|
||||
within<Color>(distance: 8, from: const Color(0xffff0000)));
|
||||
|
||||
region = new Rect.fromLTRB(0.0, 0.0, 30.0, 20.0);
|
||||
region = Rect.fromLTRB(0.0, 0.0, 30.0, 20.0);
|
||||
palette = await PaletteGenerator.fromImageProvider(imageProvider,
|
||||
region: region, size: size);
|
||||
expect(palette.paletteColors.length, equals(3));
|
||||
@ -131,22 +131,22 @@ void main() async {
|
||||
final PaletteGenerator palette =
|
||||
await PaletteGenerator.fromImageProvider(testImages['landscape']);
|
||||
final List<PaletteColor> expectedSwatches = <PaletteColor>[
|
||||
new PaletteColor(const Color(0xff3f630c), 10137),
|
||||
new PaletteColor(const Color(0xff3c4b2a), 4773),
|
||||
new PaletteColor(const Color(0xff81b2e9), 4762),
|
||||
new PaletteColor(const Color(0xffc0d6ec), 4714),
|
||||
new PaletteColor(const Color(0xff4c4f50), 2465),
|
||||
new PaletteColor(const Color(0xff5c635b), 2463),
|
||||
new PaletteColor(const Color(0xff6e80a2), 2421),
|
||||
new PaletteColor(const Color(0xff9995a3), 1214),
|
||||
new PaletteColor(const Color(0xff676c4d), 1213),
|
||||
new PaletteColor(const Color(0xffc4b2b2), 1173),
|
||||
new PaletteColor(const Color(0xff445166), 1040),
|
||||
new PaletteColor(const Color(0xff475d83), 1019),
|
||||
new PaletteColor(const Color(0xff7e7360), 589),
|
||||
new PaletteColor(const Color(0xfff6b835), 286),
|
||||
new PaletteColor(const Color(0xffb9983d), 152),
|
||||
new PaletteColor(const Color(0xffe3ab35), 149),
|
||||
PaletteColor(const Color(0xff3f630c), 10137),
|
||||
PaletteColor(const Color(0xff3c4b2a), 4773),
|
||||
PaletteColor(const Color(0xff81b2e9), 4762),
|
||||
PaletteColor(const Color(0xffc0d6ec), 4714),
|
||||
PaletteColor(const Color(0xff4c4f50), 2465),
|
||||
PaletteColor(const Color(0xff5c635b), 2463),
|
||||
PaletteColor(const Color(0xff6e80a2), 2421),
|
||||
PaletteColor(const Color(0xff9995a3), 1214),
|
||||
PaletteColor(const Color(0xff676c4d), 1213),
|
||||
PaletteColor(const Color(0xffc4b2b2), 1173),
|
||||
PaletteColor(const Color(0xff445166), 1040),
|
||||
PaletteColor(const Color(0xff475d83), 1019),
|
||||
PaletteColor(const Color(0xff7e7360), 589),
|
||||
PaletteColor(const Color(0xfff6b835), 286),
|
||||
PaletteColor(const Color(0xffb9983d), 152),
|
||||
PaletteColor(const Color(0xffe3ab35), 149),
|
||||
];
|
||||
final Iterable<Color> expectedColors =
|
||||
expectedSwatches.map<Color>((PaletteColor swatch) => swatch.color);
|
||||
@ -191,22 +191,22 @@ void main() async {
|
||||
imageProvider,
|
||||
filters: filters);
|
||||
final List<PaletteColor> expectedSwatches = <PaletteColor>[
|
||||
new PaletteColor(const Color(0xff3f630c), 10137),
|
||||
new PaletteColor(const Color(0xff3c4b2a), 4773),
|
||||
new PaletteColor(const Color(0xff81b2e9), 4762),
|
||||
new PaletteColor(const Color(0xffc0d6ec), 4714),
|
||||
new PaletteColor(const Color(0xff4c4f50), 2465),
|
||||
new PaletteColor(const Color(0xff5c635b), 2463),
|
||||
new PaletteColor(const Color(0xff6e80a2), 2421),
|
||||
new PaletteColor(const Color(0xff9995a3), 1214),
|
||||
new PaletteColor(const Color(0xff676c4d), 1213),
|
||||
new PaletteColor(const Color(0xffc4b2b2), 1173),
|
||||
new PaletteColor(const Color(0xff445166), 1040),
|
||||
new PaletteColor(const Color(0xff475d83), 1019),
|
||||
new PaletteColor(const Color(0xff7e7360), 589),
|
||||
new PaletteColor(const Color(0xfff6b835), 286),
|
||||
new PaletteColor(const Color(0xffb9983d), 152),
|
||||
new PaletteColor(const Color(0xffe3ab35), 149),
|
||||
PaletteColor(const Color(0xff3f630c), 10137),
|
||||
PaletteColor(const Color(0xff3c4b2a), 4773),
|
||||
PaletteColor(const Color(0xff81b2e9), 4762),
|
||||
PaletteColor(const Color(0xffc0d6ec), 4714),
|
||||
PaletteColor(const Color(0xff4c4f50), 2465),
|
||||
PaletteColor(const Color(0xff5c635b), 2463),
|
||||
PaletteColor(const Color(0xff6e80a2), 2421),
|
||||
PaletteColor(const Color(0xff9995a3), 1214),
|
||||
PaletteColor(const Color(0xff676c4d), 1213),
|
||||
PaletteColor(const Color(0xffc4b2b2), 1173),
|
||||
PaletteColor(const Color(0xff445166), 1040),
|
||||
PaletteColor(const Color(0xff475d83), 1019),
|
||||
PaletteColor(const Color(0xff7e7360), 589),
|
||||
PaletteColor(const Color(0xfff6b835), 286),
|
||||
PaletteColor(const Color(0xffb9983d), 152),
|
||||
PaletteColor(const Color(0xffe3ab35), 149),
|
||||
];
|
||||
final Iterable<Color> expectedColors =
|
||||
expectedSwatches.map<Color>((PaletteColor swatch) => swatch.color);
|
||||
@ -220,22 +220,22 @@ void main() async {
|
||||
palette = await PaletteGenerator.fromImageProvider(imageProvider,
|
||||
filters: filters);
|
||||
final List<PaletteColor> blueSwatches = <PaletteColor>[
|
||||
new PaletteColor(const Color(0xff4c5c75), 1515),
|
||||
new PaletteColor(const Color(0xff7483a1), 1505),
|
||||
new PaletteColor(const Color(0xff515661), 1476),
|
||||
new PaletteColor(const Color(0xff769dd4), 1470),
|
||||
new PaletteColor(const Color(0xff3e4858), 777),
|
||||
new PaletteColor(const Color(0xff98a3bc), 760),
|
||||
new PaletteColor(const Color(0xffb4c7e0), 760),
|
||||
new PaletteColor(const Color(0xff99bbe5), 742),
|
||||
new PaletteColor(const Color(0xffcbdef0), 701),
|
||||
new PaletteColor(const Color(0xff1c212b), 429),
|
||||
new PaletteColor(const Color(0xff393c46), 417),
|
||||
new PaletteColor(const Color(0xff526483), 394),
|
||||
new PaletteColor(const Color(0xff61708b), 372),
|
||||
new PaletteColor(const Color(0xff5e8ccc), 345),
|
||||
new PaletteColor(const Color(0xff587ab4), 194),
|
||||
new PaletteColor(const Color(0xff5584c8), 182),
|
||||
PaletteColor(const Color(0xff4c5c75), 1515),
|
||||
PaletteColor(const Color(0xff7483a1), 1505),
|
||||
PaletteColor(const Color(0xff515661), 1476),
|
||||
PaletteColor(const Color(0xff769dd4), 1470),
|
||||
PaletteColor(const Color(0xff3e4858), 777),
|
||||
PaletteColor(const Color(0xff98a3bc), 760),
|
||||
PaletteColor(const Color(0xffb4c7e0), 760),
|
||||
PaletteColor(const Color(0xff99bbe5), 742),
|
||||
PaletteColor(const Color(0xffcbdef0), 701),
|
||||
PaletteColor(const Color(0xff1c212b), 429),
|
||||
PaletteColor(const Color(0xff393c46), 417),
|
||||
PaletteColor(const Color(0xff526483), 394),
|
||||
PaletteColor(const Color(0xff61708b), 372),
|
||||
PaletteColor(const Color(0xff5e8ccc), 345),
|
||||
PaletteColor(const Color(0xff587ab4), 194),
|
||||
PaletteColor(const Color(0xff5584c8), 182),
|
||||
];
|
||||
final Iterable<Color> expectedBlues =
|
||||
blueSwatches.map<Color>((PaletteColor swatch) => swatch.color);
|
||||
@ -250,22 +250,22 @@ void main() async {
|
||||
palette = await PaletteGenerator.fromImageProvider(imageProvider,
|
||||
filters: filters);
|
||||
final List<PaletteColor> blueGreenSwatches = <PaletteColor>[
|
||||
new PaletteColor(const Color(0xffc8e8f8), 87),
|
||||
new PaletteColor(const Color(0xff5c6c74), 73),
|
||||
new PaletteColor(const Color(0xff6f8088), 49),
|
||||
new PaletteColor(const Color(0xff687880), 49),
|
||||
new PaletteColor(const Color(0xff506068), 45),
|
||||
new PaletteColor(const Color(0xff485860), 39),
|
||||
new PaletteColor(const Color(0xff405058), 21),
|
||||
new PaletteColor(const Color(0xffd6ebf3), 11),
|
||||
new PaletteColor(const Color(0xff2f3f47), 7),
|
||||
new PaletteColor(const Color(0xff0f1f27), 6),
|
||||
new PaletteColor(const Color(0xffc0e0f0), 6),
|
||||
new PaletteColor(const Color(0xff203038), 3),
|
||||
new PaletteColor(const Color(0xff788890), 2),
|
||||
new PaletteColor(const Color(0xff384850), 2),
|
||||
new PaletteColor(const Color(0xff98a8b0), 1),
|
||||
new PaletteColor(const Color(0xffa8b8c0), 1),
|
||||
PaletteColor(const Color(0xffc8e8f8), 87),
|
||||
PaletteColor(const Color(0xff5c6c74), 73),
|
||||
PaletteColor(const Color(0xff6f8088), 49),
|
||||
PaletteColor(const Color(0xff687880), 49),
|
||||
PaletteColor(const Color(0xff506068), 45),
|
||||
PaletteColor(const Color(0xff485860), 39),
|
||||
PaletteColor(const Color(0xff405058), 21),
|
||||
PaletteColor(const Color(0xffd6ebf3), 11),
|
||||
PaletteColor(const Color(0xff2f3f47), 7),
|
||||
PaletteColor(const Color(0xff0f1f27), 6),
|
||||
PaletteColor(const Color(0xffc0e0f0), 6),
|
||||
PaletteColor(const Color(0xff203038), 3),
|
||||
PaletteColor(const Color(0xff788890), 2),
|
||||
PaletteColor(const Color(0xff384850), 2),
|
||||
PaletteColor(const Color(0xff98a8b0), 1),
|
||||
PaletteColor(const Color(0xffa8b8c0), 1),
|
||||
];
|
||||
final Iterable<Color> expectedBlueGreens =
|
||||
blueGreenSwatches.map<Color>((PaletteColor swatch) => swatch.color);
|
||||
@ -301,8 +301,8 @@ void main() async {
|
||||
|
||||
// Passing targets augments the baseTargets, and those targets are found.
|
||||
final List<PaletteTarget> saturationExtremeTargets = <PaletteTarget>[
|
||||
new PaletteTarget(minimumSaturation: 0.85),
|
||||
new PaletteTarget(maximumSaturation: .25),
|
||||
PaletteTarget(minimumSaturation: 0.85),
|
||||
PaletteTarget(maximumSaturation: .25),
|
||||
];
|
||||
palette = await PaletteGenerator.fromImageProvider(imageProvider,
|
||||
targets: saturationExtremeTargets);
|
||||
|
Reference in New Issue
Block a user