-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHdrHorizontalRegionProcessor.h
73 lines (59 loc) · 2.14 KB
/
HdrHorizontalRegionProcessor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
// Created by Kamil Rojewski on 18.07.2021.
//
#ifndef OPENRGB_AMBIENT_HDRHORIZONTALREGIONPROCESSOR_H
#define OPENRGB_AMBIENT_HDRHORIZONTALREGIONPROCESSOR_H
#include <array>
#include <QtGlobal>
#include <RGBController.h>
#include "ColorPostProcessor.h"
template<ColorPostProcessor CPP>
class HdrHorizontalRegionProcessor final
{
public:
HdrHorizontalRegionProcessor(int samples, std::array<float, 3> colorFactors, CPP colorPostProcessor)
: samples{samples}
, colorFactors(colorFactors)
, colorPostProcessor{colorPostProcessor}
{
}
void processRegion(RGBColor *result, const std::uint32_t *data, int width, int height) const
{
if (samples <= 0) {
return;
}
const auto sampleWidth = width / samples;
const auto samplePixels = sampleWidth * height;
for (auto sample = 0; sample < samples; ++sample)
{
uint red = 0;
uint green = 0;
uint blue = 0;
for (auto y = 0; y < height; ++y)
{
const auto currentWidth = (sample + 1) * sampleWidth;
for (auto x = sample * sampleWidth; x < currentWidth; ++x)
{
const auto colors = data[y * width + x];
const ushort curRed = colors & 0x3ff;
const ushort curGreen = (colors >> 10) & 0x3ff;
const ushort curBlue = (colors >> 20) & 0x3ff;
red += curRed;
green += curGreen;
blue += curBlue;
}
}
result[samples - sample - 1] = colorPostProcessor.process(
static_cast<uchar>(red * colorFactors[0] / samplePixels / 4),
static_cast<uchar>(green * colorFactors[1] / samplePixels / 4),
static_cast<uchar>(blue * colorFactors[2] / samplePixels / 4),
result[samples - sample - 1]
);
}
}
private:
int samples = 0;
std::array<float, 3> colorFactors;
CPP colorPostProcessor;
};
#endif //OPENRGB_AMBIENT_HDRHORIZONTALREGIONPROCESSOR_H