Flutter Engine
The Flutter Engine
Functions
image_diff_metric.cpp File Reference
#include "include/codec/SkCodec.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkData.h"
#include "include/core/SkPixmap.h"
#include "include/core/SkSize.h"
#include <cmath>
#include <cstdio>

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 18 of file image_diff_metric.cpp.

18 {
19 if (argc != 3) {
20 const char usage[] = "\nUsage:\n %s {FILE1}.png {FILE2}.png\n\n";
21 fprintf(stderr, usage, argv[0]);
22 return 1;
23 }
24 SkBitmap bm[2];
25 for (int i = 0; i < 2; ++i) {
26 const char* path = argv[i + 1];
27 if (std::unique_ptr<SkCodec> codec =
29 bm[i].allocN32Pixels(codec->dimensions().fWidth, codec->dimensions().fHeight);
30 if (SkCodec::kSuccess == codec->getPixels(bm[i].pixmap())) {
31 continue;
32 }
33 }
34 fprintf(stderr, "\nBad file: '%s'.\n\n", path);
35 return 2;
36 }
37 SkISize dim = bm[0].dimensions();
38 if (dim != bm[1].dimensions()) {
39 fprintf(stderr, "\nImages must be same size: (%d,%d) != (%d,%d)\n\n",
40 dim.fWidth, dim.fHeight, bm[1].dimensions().fWidth, bm[1].dimensions().fHeight);
41 return 3;
42 }
43 int64_t totalDiffs = 0; // Manhattan distance in ARGB color-space.
44 for (int y = 0; y < dim.fHeight; ++y) {
45 const uint8_t* row1 = reinterpret_cast<const uint8_t*>(bm[0].pixmap().addr32(0, y));
46 const uint8_t* row2 = reinterpret_cast<const uint8_t*>(bm[1].pixmap().addr32(0, y));
47 for (size_t i = 0; i < (size_t)dim.fWidth * (size_t)4; ++i) {
48 totalDiffs += std::abs((int)row1[i] - (int)row2[i]);
49 }
50 }
51 printf("%g\n", (double)totalDiffs /
52 ((uint64_t)255 * 4 * (uint64_t)dim.fWidth * (uint64_t)dim.fHeight));
53 return 0;
54}
SkISize dimensions() const
Definition: SkBitmap.h:388
const SkPixmap & pixmap() const
Definition: SkBitmap.h:133
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition: SkBitmap.cpp:232
static std::unique_ptr< SkCodec > MakeFromData(sk_sp< SkData >, SkSpan< const SkCodecs::Decoder > decoders, SkPngChunkReader *=nullptr)
Definition: SkCodec.cpp:241
@ kSuccess
Definition: SkCodec.h:80
static sk_sp< SkData > MakeFromFileName(const char path[])
Definition: SkData.cpp:148
const uint32_t * addr32() const
Definition: SkPixmap.h:352
char ** argv
Definition: library.h:9
double y
std::string printf(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: SkSLString.cpp:83
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
SIN Vec< N, float > abs(const Vec< N, float > &x)
Definition: SkVx.h:707
static void usage(char *argv0)
Definition: SkSize.h:16
int32_t fHeight
Definition: SkSize.h:18
int32_t fWidth
Definition: SkSize.h:17