1 #include "histogramengine.h"
2 #include "../colors/plugincolors.h"
8 HistogramPackage::HistogramPackage()
15 HistogramUnit::HistogramUnit(HistogramEngine *server)
18 for(int i = 0; i < 5; i++)
19 accum[i] = new int64_t[HISTOGRAM_RANGE];
22 HistogramUnit::~HistogramUnit()
24 for(int i = 0; i < 5; i++)
28 void HistogramUnit::process_package(LoadPackage *package)
30 HistogramPackage *pkg = (HistogramPackage*)package;
31 HistogramEngine *server = (HistogramEngine*)get_server();
34 #define HISTOGRAM_HEAD(type) \
36 for(int i = pkg->start; i < pkg->end; i++) \
38 type *row = (type*)data->get_rows()[i]; \
39 for(int j = 0; j < w; j++) \
42 #define HISTOGRAM_TAIL(components) \
43 v = (r * 76 + g * 150 + b * 29) >> 8; \
44 /* v = MAX(r, g); */ \
45 /* v = MAX(v, b); */ \
46 r += -(int)(HISTOGRAM_MIN * 0xffff); \
47 g += -(int)(HISTOGRAM_MIN * 0xffff); \
48 b += -(int)(HISTOGRAM_MIN * 0xffff); \
49 v += -(int)(HISTOGRAM_MIN * 0xffff); \
50 CLAMP(r, 0, HISTOGRAM_RANGE); \
51 CLAMP(g, 0, HISTOGRAM_RANGE); \
52 CLAMP(b, 0, HISTOGRAM_RANGE); \
53 CLAMP(v, 0, HISTOGRAM_RANGE); \
58 /* if(components == 4) accum_a[row[3]]++; */ \
66 VFrame *data = server->data;
68 int w = data->get_w();
69 int h = data->get_h();
70 int64_t *accum_r = accum[HISTOGRAM_RED];
71 int64_t *accum_g = accum[HISTOGRAM_GREEN];
72 int64_t *accum_b = accum[HISTOGRAM_BLUE];
73 int64_t *accum_a = accum[HISTOGRAM_ALPHA];
74 int64_t *accum_v = accum[HISTOGRAM_VALUE];
75 int r, g, b, a, y, u, v;
77 switch(data->get_color_model())
80 HISTOGRAM_HEAD(unsigned char)
81 r = (row[0] << 8) | row[0];
82 g = (row[1] << 8) | row[1];
83 b = (row[2] << 8) | row[2];
88 r = (int)(row[0] * 0xffff);
89 g = (int)(row[1] * 0xffff);
90 b = (int)(row[2] * 0xffff);
94 HISTOGRAM_HEAD(unsigned char)
95 y = (row[0] << 8) | row[0];
96 u = (row[1] << 8) | row[1];
97 v = (row[2] << 8) | row[2];
98 server->yuv->yuv_to_rgb_16(r, g, b, y, u, v);
102 HISTOGRAM_HEAD(unsigned char)
103 r = (row[0] << 8) | row[0];
104 g = (row[1] << 8) | row[1];
105 b = (row[2] << 8) | row[2];
109 HISTOGRAM_HEAD(float)
110 r = (int)(row[0] * 0xffff);
111 g = (int)(row[1] * 0xffff);
112 b = (int)(row[2] * 0xffff);
116 HISTOGRAM_HEAD(unsigned char)
117 y = (row[0] << 8) | row[0];
118 u = (row[1] << 8) | row[1];
119 v = (row[2] << 8) | row[2];
120 server->yuv->yuv_to_rgb_16(r, g, b, y, u, v);
124 HISTOGRAM_HEAD(uint16_t)
131 HISTOGRAM_HEAD(uint16_t)
135 server->yuv->yuv_to_rgb_16(r, g, b, y, u, v);
138 case BC_RGBA16161616:
139 HISTOGRAM_HEAD(uint16_t)
145 case BC_YUVA16161616:
146 HISTOGRAM_HEAD(uint16_t)
150 server->yuv->yuv_to_rgb_16(r, g, b, y, u, v);
163 HistogramEngine::HistogramEngine(int total_clients, int total_packages)
164 : LoadServer(total_clients, total_packages)
168 for(int i = 0; i < 5; i++)
169 accum[i] = new int64_t[HISTOGRAM_RANGE];
172 HistogramEngine::~HistogramEngine()
175 for(int i = 0; i < 5; i++)
179 void HistogramEngine::process_packages(VFrame *data)
182 LoadServer::process_packages();
183 for(int i = 0; i < 5; i++)
185 bzero(accum[i], sizeof(int64_t) * HISTOGRAM_RANGE);
188 for(int i = 0; i < get_total_clients(); i++)
190 HistogramUnit *unit = (HistogramUnit*)get_client(i);
191 for(int k = 0; k < 5; k++)
193 for(int j = 0; j < HISTOGRAM_RANGE; j++)
195 accum[k][j] += unit->accum[k][j];
202 void HistogramEngine::init_packages()
204 for(int i = 0; i < get_total_packages(); i++)
206 HistogramPackage *package = (HistogramPackage*)get_package(i);
207 package->start = data->get_h() * i / get_total_packages();
208 package->end = data->get_h() * (i + 1) / get_total_packages();
211 // Initialize clients here in case some don't get run.
212 for(int i = 0; i < get_total_clients(); i++)
214 HistogramUnit *unit = (HistogramUnit*)get_client(i);
215 for(int i = 0; i < 5; i++)
216 bzero(unit->accum[i], sizeof(int64_t) * HISTOGRAM_RANGE);
220 LoadClient* HistogramEngine::new_client()
222 return (LoadClient*)new HistogramUnit(this);
225 LoadPackage* HistogramEngine::new_package()
227 return (LoadPackage*)new HistogramPackage;