blob: 73f7f4638da6cdc478a09711c6cb8d5647942440 [file] [log] [blame]
#include "samples/risp4ml/common/utils.h"
#include "samples/risp4ml/isp_stages/dg.h"
static const uint16_t kDgFractional = kRawPipelineFraction;
static const uint16_t kDgUnityGain = 1 << kDgFractional;
static DgParams dg_params = {
.enable = true,
.gains = {kDgUnityGain, kDgUnityGain, kDgUnityGain, kDgUnityGain}};
void set_dg_params(DgParams* params) { dg_params = *params; }
void dg_process(Image* input, Image* output) {
if (!dg_params.enable) {
*output = *input;
return;
}
uint16_t height = input->height;
uint16_t width = input->width;
for (uint16_t y = 0; y < height; ++y) {
const pixel_type_t* in_line = image_row(input, 0, y);
pixel_type_t* out_line = image_row(output, 0, y);
for (uint16_t x = 0; x < width; ++x) {
BayerIndex bayer_index = GetBayerIndex(kBayerType, x, y);
uint16_t input_val = in_line[x];
// + (1 << (kDgFractional -1)) adds 0.5 for more accurate rounding
uint32_t scaled_pixel =
input_val * dg_params.gains[bayer_index] + (1 << (kDgFractional - 1));
out_line[x] = (pixel_type_t)Clamp(scaled_pixel >> kDgFractional, 0,
kRawPipelineMaxVal);
}
}
}