-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImageProcessor.h
125 lines (102 loc) · 5.05 KB
/
ImageProcessor.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//
// Created by Kamil Rojewski on 16.07.2021.
//
#ifndef OPENRGB_AMBIENT_IMAGEPROCESSOR_H
#define OPENRGB_AMBIENT_IMAGEPROCESSOR_H
#include <string>
#include <vector>
#include <array>
#include <QtGlobal>
#include <RGBController.h>
#include "SdrHorizontalRegionProcessor.h"
#include "SdrVerticalRegionProcessor.h"
#include "HdrHorizontalRegionProcessor.h"
#include "HdrVerticalRegionProcessor.h"
#include "ColorPostProcessor.h"
#include "LedUpdateEvent.h"
#include "LedRange.h"
class QObject;
class ImageProcessorBase
{
public:
virtual void processSdrImage(const uchar *data, int width, int height) = 0;
virtual void processHdrImage(const uint *data, int width, int height) = 0;
};
template<ColorPostProcessor CPP>
class ImageProcessor final
: public ImageProcessorBase
{
public:
ImageProcessor(std::string controllerLocation,
LedRange topRange,
LedRange bottomRange,
LedRange rightRange,
LedRange leftRange,
std::array<float, 3> colorFactors,
CPP colorPostProcessor,
QObject *eventReceiver)
: controllerLocation{std::move(controllerLocation)}
, eventReceiver{eventReceiver}
, rightRange{rightRange}
, leftRange{leftRange}
, bottomRange{bottomRange}
, topRange{topRange}
, topSdrProcessor{topRange.getLength(), colorFactors, colorPostProcessor}
, bottomSdrProcessor{bottomRange.getLength(), colorFactors, colorPostProcessor}
, leftSdrProcessor{leftRange.getLength(), colorFactors, colorPostProcessor}
, rightSdrProcessor{rightRange.getLength(), colorFactors, colorPostProcessor}
, topHdrProcessor{topRange.getLength(), colorFactors, colorPostProcessor}
, bottomHdrProcessor{bottomRange.getLength(), colorFactors, colorPostProcessor}
, leftHdrProcessor{leftRange.getLength(), colorFactors, colorPostProcessor}
, rightHdrProcessor{rightRange.getLength(), colorFactors, colorPostProcessor}
, colors(topRange.getLength() + bottomRange.getLength() + leftRange.getLength() + rightRange.getLength())
{
}
void processSdrImage(const uchar *data, int width, int height) override
{
const auto sampleHeight = height / resolutionHeightDivisor;
const auto sampleWidth = width / resolutionWidthDivisor;
const auto realTop = std::min(topRange.from, topRange.to);
const auto realBottom = std::min(bottomRange.from, bottomRange.to);
const auto realRight = std::min(rightRange.from, rightRange.to);
const auto realLeft = std::min(leftRange.from, leftRange.to);
topSdrProcessor.processRegion(colors.data() + realTop, data, width, sampleHeight);
bottomSdrProcessor.processRegion(colors.data() + realBottom, data + 4 * width * (height - sampleHeight), width, sampleHeight);
leftSdrProcessor.processRegion(colors.data() + realLeft, data, sampleWidth, height, 0, width);
rightSdrProcessor.processRegion(colors.data() + realRight, data, sampleWidth, height, width - sampleWidth, width);
QCoreApplication::postEvent(eventReceiver, new LedUpdateEvent{controllerLocation, colors});
}
void processHdrImage(const uint *data, int width, int height) override
{
const auto sampleHeight = height / resolutionHeightDivisor;
const auto sampleWidth = width / resolutionHeightDivisor;
const auto realTop = std::min(topRange.from, topRange.to);
const auto realBottom = std::min(bottomRange.from, bottomRange.to);
const auto realRight = std::min(rightRange.from, rightRange.to);
const auto realLeft = std::min(leftRange.from, leftRange.to);
topHdrProcessor.processRegion(colors.data() + realTop, data, width, sampleHeight);
bottomHdrProcessor.processRegion(colors.data() + realBottom, data + width * (height - sampleHeight), width, sampleHeight);
leftHdrProcessor.processRegion(colors.data() + realLeft, data, sampleWidth, height, 0, width);
rightHdrProcessor.processRegion(colors.data() + realRight, data, sampleWidth, height, width - sampleWidth, width);
QCoreApplication::postEvent(eventReceiver, new LedUpdateEvent{controllerLocation, colors});
}
private:
static const int resolutionHeightDivisor = 10;
static const int resolutionWidthDivisor = 12;
std::string controllerLocation;
QObject *eventReceiver;
LedRange topRange;
LedRange bottomRange;
LedRange leftRange;
LedRange rightRange;
SdrHorizontalRegionProcessor<CPP> topSdrProcessor;
SdrHorizontalRegionProcessor<CPP> bottomSdrProcessor;
SdrVerticalRegionProcessor<CPP> leftSdrProcessor;
SdrVerticalRegionProcessor<CPP> rightSdrProcessor;
HdrHorizontalRegionProcessor<CPP> topHdrProcessor;
HdrHorizontalRegionProcessor<CPP> bottomHdrProcessor;
HdrVerticalRegionProcessor<CPP> leftHdrProcessor;
HdrVerticalRegionProcessor<CPP> rightHdrProcessor;
std::vector<RGBColor> colors;
};
#endif //OPENRGB_AMBIENT_IMAGEPROCESSOR_H