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++)
60 void HistogramConfig::reset_points(int colors_only)
62 for(int i = 0; i < HISTOGRAM_MODES; i++)
64 if(i != HISTOGRAM_VALUE || !colors_only)
73 void HistogramConfig::boundaries()
75 for(int i = 0; i < HISTOGRAM_MODES; i++)
77 CLAMP(low_input[i], HIST_MIN_INPUT, HIST_MAX_INPUT);
78 CLAMP(high_input[i], HIST_MIN_INPUT, HIST_MAX_INPUT);
79 CLAMP(low_output[i], HIST_MIN_INPUT, HIST_MAX_INPUT);
80 CLAMP(high_output[i], HIST_MIN_INPUT, HIST_MAX_INPUT);
81 CLAMP(gamma[i], MIN_GAMMA, MAX_GAMMA);
82 low_output[i] = Units::quantize(low_output[i], PRECISION);
83 high_output[i] = Units::quantize(high_output[i], PRECISION);
85 CLAMP(threshold, 0, 1);
86 CLAMP(log_slider, 0, 1);
87 CLAMP(frames, 0, 65535);
90 int HistogramConfig::equivalent(HistogramConfig &that)
92 // EQUIV isn't precise enough to detect changes in points
93 for(int i = 0; i < HISTOGRAM_MODES; i++)
95 // if(!EQUIV(low_input[i], that.low_input[i]) ||
96 // !EQUIV(high_input[i], that.high_input[i]) ||
97 // !EQUIV(gamma[i], that.gamma[i]) ||
98 // !EQUIV(low_output[i], that.low_output[i]) ||
99 // !EQUIV(high_output[i], that.high_output[i])) return 0;
100 if(low_input[i] != that.low_input[i] ||
101 high_input[i] != that.high_input[i] ||
102 gamma[i] != that.gamma[i] ||
103 low_output[i] != that.low_output[i] ||
104 high_output[i] != that.high_output[i]) return 0;
107 if(automatic != that.automatic ||
108 automatic_v != that.automatic_v ||
109 threshold != that.threshold) return 0;
111 if(plot != that.plot ||
112 split != that.split ||
113 frames != that.frames ||
114 log_slider != that.log_slider ) return 0;
119 void HistogramConfig::copy_from(HistogramConfig &that)
121 for(int i = 0; i < HISTOGRAM_MODES; i++)
123 low_input[i] = that.low_input[i];
124 high_input[i] = that.high_input[i];
125 gamma[i] = that.gamma[i];
126 low_output[i] = that.low_output[i];
127 high_output[i] = that.high_output[i];
130 automatic = that.automatic;
131 automatic_v = that.automatic_v;
132 threshold = that.threshold;
135 frames = that.frames;
136 log_slider = that.log_slider;
139 void HistogramConfig::interpolate(HistogramConfig &prev,
140 HistogramConfig &next,
143 int64_t current_frame)
145 double next_scale = (double)(current_frame - prev_frame) / (next_frame - prev_frame);
146 double prev_scale = 1.0 - next_scale;
148 for(int i = 0; i < HISTOGRAM_MODES; i++)
150 low_input[i] = prev.low_input[i] * prev_scale + next.low_input[i] * next_scale;
151 high_input[i] = prev.high_input[i] * prev_scale + next.high_input[i] * next_scale;
152 gamma[i] = prev.gamma[i] * prev_scale + next.gamma[i] * next_scale;
153 low_output[i] = prev.low_output[i] * prev_scale + next.low_output[i] * next_scale;
154 high_output[i] = prev.high_output[i] * prev_scale + next.high_output[i] * next_scale;
157 threshold = prev.threshold * prev_scale + next.threshold * next_scale;
158 automatic = prev.automatic;
159 automatic_v = prev.automatic_v;
162 frames = prev.frames;
163 log_slider = prev.log_slider;
167 void HistogramConfig::dump()
169 for(int j = 0; j < HISTOGRAM_MODES; j++)
171 printf("HistogramConfig::dump mode=%d plot=%d split=%d frames=%d\n", j, plot, split, frames);