#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "third_party/blink/renderer/platform/graphics/dark_mode_image_classifier.h"
#include <optional>
#include <set>
#include "base/memory/singleton.h"
#include "third_party/blink/renderer/platform/graphics/dark_mode_settings.h"
#include "third_party/blink/renderer/platform/graphics/darkmode/darkmode_classifier.h"
#include "ui/gfx/geometry/size.h"
namespace blink {
namespace {
const float kLowColorCountThreshold[2] = …;
const float kHighColorCountThreshold[2] = …;
bool IsColorGray(const SkColor& color) { … }
bool IsColorTransparent(const SkColor& color) { … }
const int kMaxSampledPixels = …;
const int kMaxBlocks = …;
const float kMinOpaquePixelPercentageForForeground = …;
}
DarkModeImageClassifier::DarkModeImageClassifier(
DarkModeImageClassifierPolicy image_classifier_policy)
: … { … }
DarkModeImageClassifier::~DarkModeImageClassifier() = default;
DarkModeResult DarkModeImageClassifier::Classify(const SkPixmap& pixmap,
const SkIRect& src) const { … }
std::optional<DarkModeImageClassifier::Features>
DarkModeImageClassifier::GetFeatures(const SkPixmap& pixmap,
const SkIRect& src) const { … }
void DarkModeImageClassifier::GetSamples(const SkPixmap& pixmap,
const SkIRect& src,
std::vector<SkColor>* sampled_pixels,
float* transparency_ratio,
float* background_ratio) const { … }
void DarkModeImageClassifier::GetBlockSamples(
const SkPixmap& pixmap,
const SkIRect& block,
const int required_samples_count,
std::vector<SkColor>* sampled_pixels,
int* transparent_pixels_count) const { … }
DarkModeImageClassifier::Features DarkModeImageClassifier::ComputeFeatures(
const std::vector<SkColor>& sampled_pixels,
const float transparency_ratio,
const float background_ratio) const { … }
float DarkModeImageClassifier::ComputeColorBucketsRatio(
const std::vector<SkColor>& sampled_pixels,
const ColorMode color_mode) const { … }
DarkModeResult DarkModeImageClassifier::ClassifyWithFeatures(
const Features& features) const { … }
DarkModeResult DarkModeImageClassifier::ClassifyUsingDecisionTree(
const DarkModeImageClassifier::Features& features) const { … }
}