2 #include "histogramconfig.h"
11 HistogramPoint::HistogramPoint()
12 : ListItem<HistogramPoint>()
16 HistogramPoint::~HistogramPoint()
20 int HistogramPoint::equivalent(HistogramPoint *src)
22 return EQUIV(x, src->x) && EQUIV(y, src->y);
28 HistogramPoints::HistogramPoints()
29 : List<HistogramPoint>()
33 HistogramPoints::~HistogramPoints()
37 HistogramPoint* HistogramPoints::insert(float x, float y)
39 HistogramPoint *current = first;
41 // Get existing point after new point
50 // Insert new point before current point
51 HistogramPoint *new_point = new HistogramPoint;
54 insert_before(current, new_point);
57 // Append new point to list
69 void HistogramPoints::boundaries()
71 HistogramPoint *current = first;
74 CLAMP(current->x, 0.0, 1.0);
75 CLAMP(current->y, 0.0, 1.0);
80 int HistogramPoints::equivalent(HistogramPoints *src)
82 HistogramPoint *current_this = first;
83 HistogramPoint *current_src = src->first;
84 while(current_this && current_src)
86 if(!current_this->equivalent(current_src)) return 0;
87 current_this = current_this->next;
88 current_src = current_src->next;
91 if(!current_this && current_src ||
92 current_this && !current_src)
97 void HistogramPoints::copy_from(HistogramPoints *src)
101 HistogramPoint *current = src->first;
104 HistogramPoint *new_point = new HistogramPoint;
105 new_point->x = current->x;
106 new_point->y = current->y;
112 void HistogramPoints::interpolate(HistogramPoints *prev,
113 HistogramPoints *next,
117 HistogramPoint *current = first;
118 HistogramPoint *current_prev = prev->first;
119 HistogramPoint *current_next = next->first;
121 while(current && current_prev && current_next)
123 current->x = current_prev->x * prev_scale +
124 current_next->x * next_scale;
125 current->y = current_prev->y * prev_scale +
126 current_next->y * next_scale;
128 current_prev = current_prev->next;
129 current_next = current_next->next;
146 HistogramConfig::HistogramConfig()
153 void HistogramConfig::reset(int do_mode)
158 for(int i = 0; i < HISTOGRAM_MODES; i++)
171 void HistogramConfig::reset_points(int colors_only)
173 for(int i = 0; i < HISTOGRAM_MODES; i++)
175 if(i != HISTOGRAM_VALUE || !colors_only)
176 while(points[i].last) delete points[i].last;
181 void HistogramConfig::boundaries()
183 for(int i = 0; i < HISTOGRAM_MODES; i++)
185 points[i].boundaries();
186 CLAMP(output_min[i], MIN_INPUT, MAX_INPUT);
187 CLAMP(output_max[i], MIN_INPUT, MAX_INPUT);
188 output_min[i] = Units::quantize(output_min[i], PRECISION);
189 output_max[i] = Units::quantize(output_max[i], PRECISION);
191 CLAMP(threshold, 0, 1);
194 int HistogramConfig::equivalent(HistogramConfig &that)
196 for(int i = 0; i < HISTOGRAM_MODES; i++)
198 if(!points[i].equivalent(&that.points[i]) ||
199 !EQUIV(output_min[i], that.output_min[i]) ||
200 !EQUIV(output_max[i], that.output_max[i])) return 0;
203 if(automatic != that.automatic ||
204 !EQUIV(threshold, that.threshold)) return 0;
206 if(plot != that.plot ||
207 split != that.split) return 0;
211 void HistogramConfig::copy_from(HistogramConfig &that)
213 for(int i = 0; i < HISTOGRAM_MODES; i++)
215 points[i].copy_from(&that.points[i]);
216 output_min[i] = that.output_min[i];
217 output_max[i] = that.output_max[i];
220 automatic = that.automatic;
221 threshold = that.threshold;
226 void HistogramConfig::interpolate(HistogramConfig &prev,
227 HistogramConfig &next,
230 int64_t current_frame)
232 double next_scale = (double)(current_frame - prev_frame) / (next_frame - prev_frame);
233 double prev_scale = 1.0 - next_scale;
235 for(int i = 0; i < HISTOGRAM_MODES; i++)
237 points[i].interpolate(&prev.points[i], &next.points[i], prev_scale, next_scale);
238 output_min[i] = prev.output_min[i] * prev_scale + next.output_min[i] * next_scale;
239 output_max[i] = prev.output_max[i] * prev_scale + next.output_max[i] * next_scale;
242 threshold = prev.threshold * prev_scale + next.threshold * next_scale;
243 automatic = prev.automatic;
249 void HistogramConfig::dump()
251 for(int j = 0; j < HISTOGRAM_MODES; j++)
253 printf("HistogramConfig::dump mode=%d plot=%d split=%d\n", j, plot, split);
254 HistogramPoints *points = &this->points[j];
255 HistogramPoint *current = points->first;
258 printf("%f,%f ", current->x, current->y);