chromium/tools/imagediff/image_diff.cc

// Copyright 2011 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// This file input format is based loosely on
// Tools/DumpRenderTree/ImageDiff.m

// The exact format of this tool's output to stdout is important, to match
// what the run_web_tests.py script expects.

#include <stddef.h>
#include <stdint.h>

#include <algorithm>
#include <iostream>
#include <memory>
#include <optional>
#include <string>
#include <unordered_map>
#include <vector>

#include "base/check.h"
#include "base/command_line.h"
#include "base/containers/heap_array.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/numerics/safe_conversions.h"
#include "base/process/memory.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "tools/imagediff/image_diff_png.h"

#if BUILDFLAG(IS_WIN)
#include "windows.h"
#endif

// Causes the app to remain open, waiting for pairs of filenames on stdin.
// The caller is then responsible for terminating this app.
static const char kOptionPollStdin[] =;
// Causes the app to additionally calculate a diff of the color histograms
// (which is resistant to shifts in layout).
static const char kOptionCompareHistograms[] =;
// Causes the app to output an image that visualizes the difference.
static const char kOptionGenerateDiff[] =;
// Causes the app to have a tolerance for difference in output. To account for
// differences which occur when running vs hardware GPU output.
static const char kOptionFuzzyDiff[] =;
// Causes the app to use the WPT fuzzy-matching algorithm. Both arguments are
// ranges of the form "x-y", where x and y are integers. If either of these
// arguments are used, both must be.
//
// https://web-platform-tests.org/writing-tests/reftests.html#fuzzy-matching
static const char kOptionFuzzyMaxChannelDiff[] =;
static const char kOptionFuzzyMaxPixelsDiff[] =;

// Return codes used by this utility.
static const int kStatusSame =;
static const int kStatusDifferent =;
static const int kStatusError =;

// Color codes.
static const uint32_t RGBA_RED =;
static const uint32_t RGBA_ALPHA =;

class Image {};

float PercentageDifferent(const Image& baseline,
                          const Image& actual,
                          bool fuzzy_diff) {}

RgbaToCountMap;

float HistogramPercentageDifferent(const Image& baseline, const Image& actual) {}

void PrintHelp() {}

int CompareImages(const base::FilePath& file1,
                  const base::FilePath& file2,
                  bool compare_histograms,
                  bool fuzzy_diff) {}

// Calculate the absolute difference between two pixels in a specified channel
// c, assuming the pixels are encoded with four 8-bit channels.
uint8_t GetChannelDiff(int c, uint32_t base_pixel, uint32_t actual_pixel) {}

bool CreateImageDiff(const Image& image1,
                     const Image& image2,
                     bool fuzzy_diff,
                     std::vector<int> fuzzy_allowed_max_channel_diff,
                     std::vector<int> fuzzy_allowed_pixels_diff,
                     Image* out) {}

int DiffImages(const base::FilePath& file1,
               const base::FilePath& file2,
               bool fuzzy_diff,
               std::vector<int> max_per_channel,
               std::vector<int> max_pixels_different,
               const base::FilePath& out_file) {}

// It isn't strictly correct to only support ASCII paths, but this
// program reads paths on stdin and the program that spawns it outputs
// paths as non-wide strings anyway.
base::FilePath FilePathFromASCII(const std::string& str) {}

// Parses a range command line option of the form "x-y", where x and y are both
// integers. If the range cannot be parsed, returns kStatusError.
int ParseRangeOption(const std::string& range, std::vector<int>& parsed_range) {}

int main(int argc, const char* argv[]) {}