|
8 | 8 | #include "frontend.hpp" |
9 | 9 |
|
10 | 10 | #include <cstddef> |
| 11 | +#include <type_traits> |
11 | 12 |
|
12 | 13 | #include "common/logging.hpp" |
13 | 14 | #include "common/utils.hpp" |
@@ -142,6 +143,61 @@ void finalise_compression(pisp_fe_config const &fe_config, int i) |
142 | 143 | PISP_LOG(fatal, "FrontEnd::finalise: compressed output is not 8 bit"); |
143 | 144 | } |
144 | 145 |
|
| 146 | +template <typename T> |
| 147 | +std::enable_if_t<std::is_integral_v<T>> inline div2_round_e(T &val) |
| 148 | +{ |
| 149 | + // Divide by 2 and round to the next even number. |
| 150 | + val = ((val + 2) & ~3) >> 1; |
| 151 | +} |
| 152 | + |
| 153 | +void decimate_config(pisp_fe_config &fe_config) |
| 154 | +{ |
| 155 | + if (fe_config.global.enables & PISP_FE_ENABLE_LSC) |
| 156 | + { |
| 157 | + div2_round_e(fe_config.lsc.centre_x); |
| 158 | + div2_round_e(fe_config.lsc.centre_y); |
| 159 | + } |
| 160 | + |
| 161 | + if (fe_config.global.enables & PISP_FE_ENABLE_CDAF_STATS) |
| 162 | + { |
| 163 | + div2_round_e(fe_config.cdaf_stats.offset_x); |
| 164 | + div2_round_e(fe_config.cdaf_stats.offset_y); |
| 165 | + div2_round_e(fe_config.cdaf_stats.size_x); |
| 166 | + div2_round_e(fe_config.cdaf_stats.size_y); |
| 167 | + div2_round_e(fe_config.cdaf_stats.skip_x); |
| 168 | + div2_round_e(fe_config.cdaf_stats.skip_y); |
| 169 | + } |
| 170 | + |
| 171 | + if (fe_config.global.enables & PISP_FE_ENABLE_AWB_STATS) |
| 172 | + { |
| 173 | + div2_round_e(fe_config.awb_stats.offset_x); |
| 174 | + div2_round_e(fe_config.awb_stats.offset_y); |
| 175 | + div2_round_e(fe_config.awb_stats.size_x); |
| 176 | + div2_round_e(fe_config.awb_stats.size_y); |
| 177 | + } |
| 178 | + |
| 179 | + if (fe_config.global.enables & PISP_FE_ENABLE_AGC_STATS) |
| 180 | + { |
| 181 | + div2_round_e(fe_config.agc_stats.offset_x); |
| 182 | + div2_round_e(fe_config.agc_stats.offset_y); |
| 183 | + div2_round_e(fe_config.agc_stats.size_x); |
| 184 | + div2_round_e(fe_config.agc_stats.size_y); |
| 185 | + div2_round_e(fe_config.agc_stats.row_offset_x); |
| 186 | + div2_round_e(fe_config.agc_stats.row_offset_y); |
| 187 | + div2_round_e(fe_config.agc_stats.row_size_x); |
| 188 | + div2_round_e(fe_config.agc_stats.row_size_y); |
| 189 | + } |
| 190 | + |
| 191 | + for (unsigned int i = 0; i < PISP_FLOATING_STATS_NUM_ZONES; i++) |
| 192 | + { |
| 193 | + pisp_fe_floating_stats_region ®ion = fe_config.floating_stats.regions[i]; |
| 194 | + div2_round_e(region.offset_x); |
| 195 | + div2_round_e(region.offset_y); |
| 196 | + div2_round_e(region.size_x); |
| 197 | + div2_round_e(region.size_y); |
| 198 | + } |
| 199 | +} |
| 200 | + |
145 | 201 | } // namespace |
146 | 202 |
|
147 | 203 | FrontEnd::FrontEnd(bool streaming, PiSPVariant const &variant, int align) : variant_(variant), align_(align) |
@@ -373,19 +429,13 @@ void FrontEnd::Prepare(pisp_fe_config *config) |
373 | 429 | height = fe_config_.stats_crop.height; |
374 | 430 | } |
375 | 431 |
|
376 | | - if (fe_config_.global.enables & PISP_FE_ENABLE_DECIMATE) |
377 | | - { |
378 | | - width = ((width + 2) & ~3) >> 1; |
379 | | - height = 2 * (height >> 2) + ((height & 3) ? 1 : 0); |
380 | | - } |
381 | | - |
382 | | - if (dirty_flags & (PISP_FE_ENABLE_LSC | PISP_FE_ENABLE_DECIMATE)) |
| 432 | + if (dirty_flags & PISP_FE_ENABLE_LSC) |
383 | 433 | finalise_lsc(fe_config_.lsc, width, height); |
384 | | - if (dirty_flags & (PISP_FE_ENABLE_AGC_STATS | PISP_FE_ENABLE_DECIMATE)) |
| 434 | + if (dirty_flags & PISP_FE_ENABLE_AGC_STATS) |
385 | 435 | finalise_agc(fe_config_.agc_stats, width, height); |
386 | | - if (dirty_flags & (PISP_FE_ENABLE_AWB_STATS | PISP_FE_ENABLE_DECIMATE)) |
| 436 | + if (dirty_flags & PISP_FE_ENABLE_AWB_STATS) |
387 | 437 | finalise_awb(fe_config_.awb_stats, width, height); |
388 | | - if (dirty_flags & (PISP_FE_ENABLE_CDAF_STATS | PISP_FE_ENABLE_DECIMATE)) |
| 438 | + if (dirty_flags & PISP_FE_ENABLE_CDAF_STATS) |
389 | 439 | finalise_cdaf(fe_config_.cdaf_stats, width, height); |
390 | 440 |
|
391 | 441 | width = fe_config_.input.format.width, height = fe_config_.input.format.height; |
@@ -416,6 +466,10 @@ void FrontEnd::Prepare(pisp_fe_config *config) |
416 | 466 |
|
417 | 467 | *config = fe_config_; |
418 | 468 |
|
| 469 | + // Fixup any grid offsets/sizes if stats decimation is enabled. |
| 470 | + if (config->global.enables & PISP_FE_ENABLE_DECIMATE) |
| 471 | + decimate_config(*config); |
| 472 | + |
419 | 473 | fe_config_.dirty_flags = fe_config_.dirty_flags_extra = 0; |
420 | 474 | } |
421 | 475 |
|
|
0 commit comments