@@ -8,13 +8,15 @@ import 'package:flutter/material.dart' hide Image;
8
8
import 'package:flutter/material.dart' as m;
9
9
import 'package:flutter_test/flutter_test.dart' ;
10
10
import 'package:flutter_test_goldens/src/flutter/flutter_test_extensions.dart' ;
11
- import 'package:flutter_test_goldens/src/galleries/gallery.dart' ;
12
11
import 'package:flutter_test_goldens/src/goldens/golden_camera.dart' ;
13
12
import 'package:flutter_test_goldens/src/goldens/golden_collections.dart' ;
14
13
import 'package:flutter_test_goldens/src/goldens/golden_comparisons.dart' ;
15
14
import 'package:flutter_test_goldens/src/goldens/golden_rendering.dart' ;
16
15
import 'package:flutter_test_goldens/src/goldens/golden_scenes.dart' ;
16
+ import 'package:flutter_test_goldens/src/goldens/pixel_comparisons.dart' ;
17
17
import 'package:flutter_test_goldens/src/logging.dart' ;
18
+ import 'package:flutter_test_goldens/src/scenes/golden_scene.dart' ;
19
+ import 'package:flutter_test_goldens/src/scenes/scene_layout.dart' ;
18
20
import 'package:image/image.dart' ;
19
21
import 'package:qr_bar_code/code/code.dart' ;
20
22
@@ -119,7 +121,7 @@ class FilmStrip {
119
121
120
122
Future <void > renderOrCompareGolden ({
121
123
required String goldenName,
122
- required FilmStripLayout layout,
124
+ required SceneLayout layout,
123
125
Widget ? goldenBackground,
124
126
m.Color qrCodeColor = m.Colors .black,
125
127
m.Color qrCodeBackgroundColor = m.Colors .white,
@@ -231,7 +233,7 @@ class FilmStrip {
231
233
Future <GoldenSceneMetadata > _layoutPhotos (
232
234
List <GoldenPhoto > photos,
233
235
Map <GoldenPhoto , (Uint8List , GlobalKey )> renderablePhotos,
234
- FilmStripLayout layout, {
236
+ SceneLayout layout, {
235
237
Widget ? goldenBackground,
236
238
Widget ? qrCode,
237
239
required m.Color qrCodeBackgroundColor,
@@ -242,9 +244,9 @@ class FilmStrip {
242
244
243
245
late final Axis filmStripDirection;
244
246
switch (layout) {
245
- case FilmStripLayout .row:
247
+ case SceneLayout .row:
246
248
filmStripDirection = Axis .horizontal;
247
- case FilmStripLayout .column:
249
+ case SceneLayout .column:
248
250
filmStripDirection = Axis .vertical;
249
251
}
250
252
@@ -311,7 +313,7 @@ class FilmStrip {
311
313
mainAxisSize: MainAxisSize .min,
312
314
crossAxisAlignment: CrossAxisAlignment .stretch,
313
315
children: [
314
- GoldenGallery (
316
+ GoldenScene (
315
317
key: galleryKey,
316
318
direction: filmStripDirection,
317
319
renderablePhotos: renderablePhotos,
@@ -434,7 +436,7 @@ class FilmStrip {
434
436
failureImage.setPixel (x, maxHeight + y, absoluteDiffColor);
435
437
436
438
// Paint this pixel in the relative severity diff image.
437
- final mismatchPercent = _calculateColorMismatchPercent (goldenPixel, screenshotPixel);
439
+ final mismatchPercent = calculateColorMismatchPercent (goldenPixel, screenshotPixel);
438
440
final yellowAmount = ui.lerpDouble (0.2 , 1.0 , mismatchPercent)! ;
439
441
failureImage.setPixel (
440
442
goldenWidth + x,
@@ -456,49 +458,6 @@ class FilmStrip {
456
458
FtgLog .pipeline.info ("No golden mismatches found" );
457
459
}
458
460
}
459
-
460
- double _calculateColorMismatchPercent (Color c1, Color c2) {
461
- final doLog = false ; //c1.r == 255; //c1.r != c1.g;
462
- final color1 = m.Color .fromARGB (255 , c1.r.toInt (), c1.g.toInt (), c1.b.toInt ());
463
- final hsv1 = m.HSVColor .fromColor (color1);
464
-
465
- final color2 = m.Color .fromARGB (255 , c2.r.toInt (), c2.g.toInt (), c2.b.toInt ());
466
- final hsv2 = m.HSVColor .fromColor (color2);
467
-
468
- // Calculate per-component difference.
469
- var deltaHue = (hsv2.hue - hsv1.hue).abs ();
470
- final deltaSaturation = (hsv2.saturation - hsv2.saturation).abs ();
471
- final deltaValue = (hsv2.value - hsv1.value).abs ();
472
-
473
- // Handle hue circularity (i.e., fact that 360 degrees go back to 0 degrees)
474
- deltaHue = deltaHue > 180 ? 360 - deltaHue : deltaHue;
475
-
476
- // Normalize each component difference.
477
- deltaHue = deltaHue / 180 ;
478
- // Other components are already in range [0, 1].
479
-
480
- // Combine components instead single distance value.
481
- //
482
- // The difference formula is arbitrary, but the goal is to draw attention to differences that are likely
483
- // to be important, which means reducing differences between things that aren't. In this equation we treat
484
- // the value difference as the most important, such that black vs white goes directly to the max. Assuming
485
- // the difference in value doesn't eat up all the difference, the hue is then given 3 times the
486
- // weight of the saturation difference.
487
- //
488
- // This formula can easily exceed the max value of `1.0` so it's clamped. This means that many different
489
- // color variations will all be at the highest intensity, but that's OK, be there is more than one color
490
- // difference that's worthy of attention.
491
- final difference = (deltaValue + ((deltaHue * 3 ) + deltaSaturation) / 4 ).clamp (0.0 , 1.0 );
492
- if (doLog) {
493
- print (
494
- "Color 1 - red: ${c1 .r }, green: ${c1 .g }, blue: ${c1 .b } - h: ${hsv1 .hue }, s: ${hsv1 .saturation }, v: ${hsv1 .value }" );
495
- print (
496
- "Color 2 - red: ${c2 .r }, green: ${c2 .g }, blue: ${c2 .b } - h: ${hsv2 .hue }, s: ${hsv2 .saturation }, v: ${hsv2 .value }" );
497
- print ("Difference: $difference " );
498
- }
499
-
500
- return difference;
501
- }
502
461
}
503
462
504
463
class _FilmStripSetup {
@@ -532,8 +491,3 @@ class FilmStripTestContext {
532
491
533
492
final scratchPad = < String , dynamic > {};
534
493
}
535
-
536
- enum FilmStripLayout {
537
- row,
538
- column;
539
- }
0 commit comments