Skip to content

Commit 95e9d94

Browse files
committed
frontend: Fix stats config params for stats decimation.
Decimate the stats config params in the buffer provided by FrontEnd::Prepare(). With this change, we use the undecimated coordinate space for all the config structures within the Frontend class. Signed-off-by: Naushir Patuck <[email protected]>
1 parent f381e67 commit 95e9d94

File tree

1 file changed

+64
-10
lines changed

1 file changed

+64
-10
lines changed

src/libpisp/frontend/frontend.cpp

Lines changed: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "frontend.hpp"
99

1010
#include <cstddef>
11+
#include <type_traits>
1112

1213
#include "common/logging.hpp"
1314
#include "common/utils.hpp"
@@ -142,6 +143,61 @@ void finalise_compression(pisp_fe_config const &fe_config, int i)
142143
PISP_LOG(fatal, "FrontEnd::finalise: compressed output is not 8 bit");
143144
}
144145

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 &region = 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+
145201
} // namespace
146202

147203
FrontEnd::FrontEnd(bool streaming, PiSPVariant const &variant, int align) : variant_(variant), align_(align)
@@ -373,19 +429,13 @@ void FrontEnd::Prepare(pisp_fe_config *config)
373429
height = fe_config_.stats_crop.height;
374430
}
375431

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)
383433
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)
385435
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)
387437
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)
389439
finalise_cdaf(fe_config_.cdaf_stats, width, height);
390440

391441
width = fe_config_.input.format.width, height = fe_config_.input.format.height;
@@ -416,6 +466,10 @@ void FrontEnd::Prepare(pisp_fe_config *config)
416466

417467
*config = fe_config_;
418468

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+
419473
fe_config_.dirty_flags = fe_config_.dirty_flags_extra = 0;
420474
}
421475

0 commit comments

Comments
 (0)