9 #ifndef DUNE_SUMMED_AREA_TABLES
10 #define DUNE_SUMMED_AREA_TABLES
16 #include <DirectXMath.h>
21 T luminance(
const T& r,
const T& g,
const T& b)
23 T v =
static_cast<T
>(0.2126*r + 0.7152*g + 0.0722*b);
27 struct environment_light
30 DirectX::XMFLOAT2 pos;
31 DirectX::XMFLOAT3 flux;
34 class summed_area_table
38 std::vector<float> sat_;
40 float I(
int x,
int y)
const;
44 void create_lum(
const BYTE* rgb,
size_t width,
size_t height,
int nc)
48 width_ =
static_cast<int>(width); height_ =
static_cast<int>(height);
51 sat_.resize(width_ * height_);
53 for (
int y = 0; y < height_; ++y)
54 for (
int x = 0; x < width_; ++x)
56 size_t i = y*width_ + x;
58 float r =
static_cast<float>(rgb[i*nc + 0]);
59 float g =
static_cast<float>(rgb[i*nc + 1]);
60 float b =
static_cast<float>(rgb[i*nc + 2]);
62 float ixy = luminance(r,g,b);
64 sat_[i] = ixy + I(x-1, y) + I(x, y-1) - I(x-1, y-1);
68 int width()
const {
return width_; }
69 int height()
const {
return height_; }
79 float sum(
int ax,
int ay,
int bx,
int by,
int cx,
int cy,
int dx,
int dy)
const;
86 const summed_area_table* sat_;
88 void create(
int x,
int y,
int w,
int h,
const summed_area_table* sat,
float init_sum = -1);
91 void split_w(sat_region& A, sat_region& B)
const;
92 void split_w(sat_region& A)
const;
95 void split_h(sat_region& A, sat_region& B)
const;
96 void split_h(sat_region& A)
const;
98 DirectX::XMFLOAT2 centroid()
const;
101 void median_cut(
const BYTE* rgba,
size_t width,
size_t height,
size_t n, std::vector<sat_region>& regions, summed_area_table& img);
102 void median_cut(
const BYTE* rgba,
size_t width,
size_t height,
size_t n, std::vector<environment_light>& lights);