History

Merge "Optimize vp9_get_sub_block_energy."

James Zern committed 6 years ago

Commit eda6b922 parents 5e065cf 81374531 file · +28 −13Browse files

Unified · Split

vp9/encoder/vp9_aq_variance.c+28−13
@@ -186,6 +186,17 @@ double vp9_log_block_var(VP9_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bs) { · 185 unmodified lines
186186 return log(var + 1.0);
187187 }
188188
189+#define DEFAULT_E_MIDPOINT 10.0
190+static int scale_block_energy(VP9_COMP *cpi, unsigned int block_var) {
191+ double energy;
192+ double energy_midpoint;
193+ energy_midpoint =
194+ (cpi->oxcf.pass == 2) ? cpi->twopass.mb_av_energy : DEFAULT_E_MIDPOINT;
195+ energy = log(block_var + 1.0) - energy_midpoint;
196+ return clamp((int)round(energy), ENERGY_MIN, ENERGY_MAX);
197+}
198+#undef DEFAULT_E_MIDPOINT
199+
189200 // Get the range of sub block energy values;
190201 void vp9_get_sub_block_energy(VP9_COMP *cpi, MACROBLOCK *mb, int mi_row,
191202 int mi_col, BLOCK_SIZE bsize, int *min_e,
@@ -202,31 +213,35 @@ void vp9_get_sub_block_energy(VP9_COMP *cpi, MACROBLOCK *mb, int mi_row, · 10 unmodified lines
202213 *min_e = vp9_block_energy(cpi, mb, bsize);
203214 *max_e = *min_e;
204215 } else {
205− int energy;
206− *min_e = ENERGY_MAX;
207− *max_e = ENERGY_MIN;
216+ unsigned int var;
217+ // Because scale_block_energy is non-decreasing, we can find the min/max
218+ // block variance and scale afterwards. This avoids a costly scaling at
219+ // every iteration.
220+ unsigned int min_var = UINT_MAX;
221+ unsigned int max_var = 0;
208222
209223 for (y = 0; y < ymis; ++y) {
210224 for (x = 0; x < xmis; ++x) {
211225 vp9_setup_src_planes(mb, cpi->Source, mi_row + y, mi_col + x);
212− energy = vp9_block_energy(cpi, mb, BLOCK_8X8);
213− *min_e = VPXMIN(*min_e, energy);
214− *max_e = VPXMAX(*max_e, energy);
226+ vpx_clear_system_state();
227+ var = block_variance(cpi, mb, BLOCK_8X8);
228+ vpx_clear_system_state();
229+ min_var = VPXMIN(min_var, var);
230+ max_var = VPXMAX(max_var, var);
215231 }
216232 }
233+ *min_e = scale_block_energy(cpi, min_var);
234+ *max_e = scale_block_energy(cpi, max_var);
217235 }
218236
219237 // Re-instate source pointers back to what they should have been on entry.
220238 vp9_setup_src_planes(mb, cpi->Source, mi_row, mi_col);
221239 }
222240
223−#define DEFAULT_E_MIDPOINT 10.0
224241 int vp9_block_energy(VP9_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bs) {
225− double energy;
226− double energy_midpoint;
242+ unsigned int var;
227243 vpx_clear_system_state();
228− energy_midpoint =
229− (cpi->oxcf.pass == 2) ? cpi->twopass.mb_av_energy : DEFAULT_E_MIDPOINT;
230− energy = vp9_log_block_var(cpi, x, bs) - energy_midpoint;
231− return clamp((int)round(energy), ENERGY_MIN, ENERGY_MAX);
244+ var = block_variance(cpi, x, bs);
245+ vpx_clear_system_state();
246+ return scale_block_energy(cpi, var);
232247 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t