#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "ui/gfx/color_analysis.h"
#include <limits.h>
#include <stdint.h>
#include <algorithm>
#include <cmath>
#include <limits>
#include <memory>
#include <queue>
#include <unordered_map>
#include <vector>
#include "base/check_op.h"
#include "base/containers/heap_array.h"
#include "base/containers/span.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/notreached.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkUnPreMultiply.h"
#include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/range/range.h"
namespace color_utils {
namespace {
const int kNumberOfClusters = …;
const int kNumberOfIterations = …;
const HSL kDefaultLowerHSLBound = …;
const HSL kDefaultUpperHSLBound = …;
const SkColor kDefaultBgColor = …;
class KMeanCluster { … };
class ColorBox { … };
bool IsInterestingColor(const SkColor& color) { … }
struct ColorBracket { … };
std::vector<Swatch> CalculateProminentColors(
const SkBitmap& bitmap,
const std::vector<ColorBracket>& color_brackets,
const gfx::Rect& region,
std::optional<ColorSwatchFilter> filter) { … }
}
KMeanImageSampler::KMeanImageSampler() { … }
KMeanImageSampler::~KMeanImageSampler() { … }
GridSampler::GridSampler() : … { … }
GridSampler::~GridSampler() { … }
int GridSampler::GetSample(int width, int height) { … }
SkColor FindClosestColor(base::span<const uint8_t> image,
int width,
int height,
SkColor color) { … }
SkColor CalculateKMeanColorOfBuffer(base::span<const uint8_t> decoded_data,
int img_width,
int img_height,
const HSL& lower_bound,
const HSL& upper_bound,
KMeanImageSampler* sampler,
bool find_closest) { … }
SkColor CalculateKMeanColorOfPNG(base::span<const uint8_t> png,
const HSL& lower_bound,
const HSL& upper_bound,
KMeanImageSampler* sampler) { … }
SkColor CalculateKMeanColorOfPNG(base::span<const uint8_t> png) { … }
SkColor CalculateKMeanColorOfBitmap(const SkBitmap& bitmap,
int height,
const HSL& lower_bound,
const HSL& upper_bound,
bool find_closest) { … }
SkColor CalculateKMeanColorOfBitmap(const SkBitmap& bitmap) { … }
const int kMaxConsideredPixelsForSwatches = …;
std::vector<Swatch> CalculateColorSwatches(
const SkBitmap& bitmap,
size_t max_swatches,
const gfx::Rect& region,
std::optional<ColorSwatchFilter> filter) { … }
std::vector<color_utils::Swatch> CalculateProminentColorsOfBitmap(
const SkBitmap& bitmap,
const std::vector<ColorProfile>& color_profiles,
gfx::Rect* region,
ColorSwatchFilter filter) { … }
}