4 * Copyright (C) 1997-2011 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "histogramconfig.h"
30 HistogramConfig::HistogramConfig()
38 void HistogramConfig::reset(int do_mode)
40 for(int i = 0; i < HISTOGRAM_MODES; i++)
57 void HistogramConfig::reset_points(int colors_only)
59 for(int i = 0; i < HISTOGRAM_MODES; i++)
61 if(i != HISTOGRAM_VALUE || !colors_only)
70 void HistogramConfig::boundaries()
72 for(int i = 0; i < HISTOGRAM_MODES; i++)
74 CLAMP(low_input[i], HIST_MIN_INPUT, HIST_MAX_INPUT);
75 CLAMP(high_input[i], HIST_MIN_INPUT, HIST_MAX_INPUT);
76 CLAMP(low_output[i], HIST_MIN_INPUT, HIST_MAX_INPUT);
77 CLAMP(high_output[i], HIST_MIN_INPUT, HIST_MAX_INPUT);
78 CLAMP(gamma[i], MIN_GAMMA, MAX_GAMMA);
79 low_output[i] = Units::quantize(low_output[i], PRECISION);
80 high_output[i] = Units::quantize(high_output[i], PRECISION);
82 CLAMP(threshold, 0, 1);
85 int HistogramConfig::equivalent(HistogramConfig &that)
87 // EQUIV isn't precise enough to detect changes in points
88 for(int i = 0; i < HISTOGRAM_MODES; i++)
90 // if(!EQUIV(low_input[i], that.low_input[i]) ||
91 // !EQUIV(high_input[i], that.high_input[i]) ||
92 // !EQUIV(gamma[i], that.gamma[i]) ||
93 // !EQUIV(low_output[i], that.low_output[i]) ||
94 // !EQUIV(high_output[i], that.high_output[i])) return 0;
95 if(low_input[i] != that.low_input[i] ||
96 high_input[i] != that.high_input[i] ||
97 gamma[i] != that.gamma[i] ||
98 low_output[i] != that.low_output[i] ||
99 high_output[i] != that.high_output[i]) return 0;
102 if(automatic != that.automatic ||
103 automatic_v != that.automatic_v ||
104 threshold != that.threshold) return 0;
106 if(plot != that.plot ||
107 split != that.split) return 0;
112 void HistogramConfig::copy_from(HistogramConfig &that)
114 for(int i = 0; i < HISTOGRAM_MODES; i++)
116 low_input[i] = that.low_input[i];
117 high_input[i] = that.high_input[i];
118 gamma[i] = that.gamma[i];
119 low_output[i] = that.low_output[i];
120 high_output[i] = that.high_output[i];
123 automatic = that.automatic;
124 automatic_v = that.automatic_v;
125 threshold = that.threshold;
130 void HistogramConfig::interpolate(HistogramConfig &prev,
131 HistogramConfig &next,
134 int64_t current_frame)
136 double next_scale = (double)(current_frame - prev_frame) / (next_frame - prev_frame);
137 double prev_scale = 1.0 - next_scale;
139 for(int i = 0; i < HISTOGRAM_MODES; i++)
141 low_input[i] = prev.low_input[i] * prev_scale + next.low_input[i] * next_scale;
142 high_input[i] = prev.high_input[i] * prev_scale + next.high_input[i] * next_scale;
143 gamma[i] = prev.gamma[i] * prev_scale + next.gamma[i] * next_scale;
144 low_output[i] = prev.low_output[i] * prev_scale + next.low_output[i] * next_scale;
145 high_output[i] = prev.high_output[i] * prev_scale + next.high_output[i] * next_scale;
148 threshold = prev.threshold * prev_scale + next.threshold * next_scale;
149 automatic = prev.automatic;
150 automatic_v = prev.automatic_v;
158 void HistogramConfig::dump()
160 for(int j = 0; j < HISTOGRAM_MODES; j++)
162 printf("HistogramConfig::dump mode=%d plot=%d split=%d\n", j, plot, split);