Flutter Engine
GoldenImage Class Reference

#import <GoldenImage.h>

Inheritance diagram for GoldenImage:

Instance Methods

(instancetype) - initWithGoldenNamePrefix:
 
(BOOL) - compareGoldenToImage:
 

Properties

NSString * goldenName
 
UIImage * image
 

Detailed Description

Definition at line 9 of file GoldenImage.h.

Method Documentation

◆ compareGoldenToImage:()

- (BOOL) compareGoldenToImage: (UIImage*)  image

Definition at line 30 of file GoldenImage.m.

References image, kRmseThreshold, and fml::size().

30  :(UIImage*)image {
31  if (!self.image || !image) {
32  return NO;
33  }
34  CGImageRef imageRefA = [self.image CGImage];
35  CGImageRef imageRefB = [image CGImage];
36 
37  NSUInteger widthA = CGImageGetWidth(imageRefA);
38  NSUInteger heightA = CGImageGetHeight(imageRefA);
39  NSUInteger widthB = CGImageGetWidth(imageRefB);
40  NSUInteger heightB = CGImageGetHeight(imageRefB);
41 
42  if (widthA != widthB || heightA != heightB) {
43  return NO;
44  }
45  NSUInteger bytesPerPixel = 4;
46  NSUInteger size = widthA * heightA * bytesPerPixel;
47  NSMutableData* rawA = [NSMutableData dataWithLength:size];
48  NSMutableData* rawB = [NSMutableData dataWithLength:size];
49 
50  if (!rawA || !rawB) {
51  return NO;
52  }
53 
54  CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
55 
56  NSUInteger bytesPerRow = bytesPerPixel * widthA;
57  NSUInteger bitsPerComponent = 8;
58  CGContextRef contextA =
59  CGBitmapContextCreate(rawA.mutableBytes, widthA, heightA, bitsPerComponent, bytesPerRow,
60  colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
61 
62  CGContextDrawImage(contextA, CGRectMake(0, 0, widthA, heightA), imageRefA);
63  CGContextRelease(contextA);
64 
65  CGContextRef contextB =
66  CGBitmapContextCreate(rawB.mutableBytes, widthA, heightA, bitsPerComponent, bytesPerRow,
67  colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
68  CGColorSpaceRelease(colorSpace);
69 
70  CGContextDrawImage(contextB, CGRectMake(0, 0, widthA, heightA), imageRefB);
71  CGContextRelease(contextB);
72 
73  const char* apos = rawA.mutableBytes;
74  const char* bpos = rawB.mutableBytes;
75  double sum = 0.0;
76  for (size_t i = 0; i < size; ++i, ++apos, ++bpos) {
77  // Skip transparent pixels.
78  if (*apos == 0 && *bpos == 0 && i % 4 == 0) {
79  i += 3;
80  apos += 3;
81  bpos += 3;
82  } else {
83  double aval = *apos;
84  double bval = *bpos;
85  double diff = aval - bval;
86  sum += diff * diff;
87  }
88  }
89  double rmse = sqrt(sum / size);
90  return rmse <= kRmseThreshold;
91 }
static const double kRmseThreshold
Definition: GoldenImage.m:10
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
UIImage * image
Definition: GoldenImage.h:12

◆ initWithGoldenNamePrefix:()

- (instancetype) initWithGoldenNamePrefix: (NSString*)  prefix

Definition at line 18 of file GoldenImage.m.

18  :(NSString*)prefix {
19  self = [super init];
20  if (self) {
21  _goldenName = [prefix stringByAppendingString:_platformName()];
22  NSBundle* bundle = [NSBundle bundleForClass:[self class]];
23  NSURL* goldenURL = [bundle URLForResource:_goldenName withExtension:@"png"];
24  NSData* data = [NSData dataWithContentsOfURL:goldenURL];
25  _image = [[UIImage alloc] initWithData:data];
26  }
27  return self;
28 }
DEF_SWITCHES_START snapshot asset Path to the directory containing the four files specified by VmSnapshotInstructions and IsolateSnapshotInstructions vm snapshot The VM instructions snapshot that will be memory mapped as read and executable SnapshotAssetPath must be present isolate snapshot The isolate instructions snapshot that will be memory mapped as read and executable SnapshotAssetPath must be present icu symbol prefix
Definition: switches.h:59

Property Documentation

◆ goldenName

- (NSString*) goldenName
readnonatomiccopy

Definition at line 11 of file GoldenImage.h.

Referenced by GoldenPlatformViewTests::checkGolden.

◆ image

- (UIImage*) image
readnonatomicstrong

Definition at line 12 of file GoldenImage.h.

Referenced by GoldenPlatformViewTests::checkGolden, and compareGoldenToImage:.


The documentation for this class was generated from the following files: