Skip to content

Commit

Permalink
camerad: IFE BLC/linearization (#33884)
Browse files Browse the repository at this point in the history
* simplify

* not all needed

* need to combine this

* there is none

* p0s

* cleanup

* lgtm

* lgtm2

* same

* 4

---------

Co-authored-by: Comma Device <device@comma.ai>
  • Loading branch information
ZwX1616 and Comma Device authored Oct 29, 2024
1 parent fcbdd39 commit 22a1b40
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 37 deletions.
40 changes: 6 additions & 34 deletions system/camerad/cameras/ife.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int build_update(uint8_t *dst, const SensorInfo *s, std::vector<uint32_t> &patch
});

dst += write_cont(dst, 0x40, {
0x00000c04, // (1<<8) to enable vignetting correction
0x00000c06, // (1<<8) to enable vignetting correction
});

dst += write_cont(dst, 0x48, {
Expand Down Expand Up @@ -67,7 +67,7 @@ int build_update(uint8_t *dst, const SensorInfo *s, std::vector<uint32_t> &patch

// black level scale + offset
dst += write_cont(dst, 0x6b0, {
(((uint32_t)(1 << s->bits_per_pixel) - 1) << 0xf) | (s->black_level << 0),
((uint32_t)(1 << 11) << 0xf) | (s->black_level << 0),
0x0,
0x0,
});
Expand Down Expand Up @@ -105,39 +105,11 @@ int build_initial_config(uint8_t *dst, const SensorInfo *s, std::vector<uint32_t
// linearization
dst += write_cont(dst, 0x4dc, {
0x00000000,
0x04050b84,
0x13031a82,
0x22022981,
0x3100387f,
0x04010b80,
0x13001a80,
0x2200297f,
0x30ff387f,
0x04050b84,
0x13031a82,
0x22022981,
0x3100387f,
0x04010b80,
0x13001a80,
0x2200297f,
0x30ff387f,
0x04050b84,
0x13031a82,
0x22022981,
0x3100387f,
0x04010b80,
0x13001a80,
0x2200297f,
0x30ff387f,
0x04050b84,
0x13031a82,
0x22022981,
0x3100387f,
0x04010b80,
0x13001a80,
0x2200297f,
0x30ff387f,
});
dst += write_cont(dst, 0x4e0, s->linearization_pts);
dst += write_cont(dst, 0x4f0, s->linearization_pts);
dst += write_cont(dst, 0x500, s->linearization_pts);
dst += write_cont(dst, 0x510, s->linearization_pts);
// TODO: this is DMI64 in the dump, does that matter?
dst += write_dmi(dst, &addr, 288, 0xc24, 9);
patches.push_back(addr - (uint64_t)start);
Expand Down
15 changes: 15 additions & 0 deletions system/camerad/sensors/ar0231.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,21 @@ AR0231::AR0231() {
((rk * (fx-mp) * (gamma_k*mp+gamma_b) * (1+1/(rk*mp)) / (1-rk*(fx-mp))) + gamma_k*mp + gamma_b);
gamma_lut_rgb.push_back((uint32_t)(fx*1023.0 + 0.5));
}
linearization_lut = {
0x02000000, 0x02000000, 0x02000000, 0x02000000,
0x020007ff, 0x020007ff, 0x020007ff, 0x020007ff,
0x02000bff, 0x02000bff, 0x02000bff, 0x02000bff,
0x020017ff, 0x020017ff, 0x020017ff, 0x020017ff,
0x020006ff, 0x020006ff, 0x020006ff, 0x020006ff,
0x02001bff, 0x02001bff, 0x02001bff, 0x02001bff,
0x020023ff, 0x020023ff, 0x020023ff, 0x020023ff,
0x00003fff, 0x00003fff, 0x00003fff, 0x00003fff,
0x00003fff, 0x00003fff, 0x00003fff, 0x00003fff,
};
for (int i = 0; i < 252; i++) {
linearization_lut.push_back(0x0);
}
linearization_pts = {0x07ff0bff, 0x17ff06ff, 0x1bff23ff, 0x3fff3fff};
}

void AR0231::processRegisters(uint8_t *cur_buf, cereal::FrameData::Builder &framed) const {
Expand Down
15 changes: 15 additions & 0 deletions system/camerad/sensors/os04c10.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ OS04C10::OS04C10() {
float fx = i / 63.0;
gamma_lut_rgb.push_back((uint32_t)(pow(fx, 0.7)*1023.0 + 0.5));
}
linearization_lut = {
0x02000000, 0x02000000, 0x02000000, 0x02000000,
0x020007ff, 0x020007ff, 0x020007ff, 0x020007ff,
0x02000bff, 0x02000bff, 0x02000bff, 0x02000bff,
0x020017ff, 0x020017ff, 0x020017ff, 0x020017ff,
0x020006ff, 0x020006ff, 0x020006ff, 0x020006ff,
0x02001bff, 0x02001bff, 0x02001bff, 0x02001bff,
0x020023ff, 0x020023ff, 0x020023ff, 0x020023ff,
0x00003fff, 0x00003fff, 0x00003fff, 0x00003fff,
0x00003fff, 0x00003fff, 0x00003fff, 0x00003fff,
};
for (int i = 0; i < 252; i++) {
linearization_lut.push_back(0x0);
}
linearization_pts = {0x07ff0bff, 0x17ff06ff, 0x1bff23ff, 0x3fff3fff};
}

std::vector<i2c_random_wr_payload> OS04C10::getExposureRegisters(int exposure_time, int new_exp_g, bool dc_gain_enabled) const {
Expand Down
18 changes: 15 additions & 3 deletions system/camerad/sensors/ox03c10.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ OX03C10::OX03C10() {
max_ev = exposure_time_max * dc_gain_factor * sensor_analog_gains[analog_gain_max_idx];
target_grey_factor = 0.01;

black_level = 64;
black_level = 0;
color_correct_matrix = {
0x000000b6, 0x00000ff1, 0x00000fda,
0x00000fcc, 0x000000b9, 0x00000ffb,
Expand All @@ -75,9 +75,21 @@ OX03C10::OX03C10() {
fx = -0.507089*exp(-12.54124638*fx) + 0.9655*pow(fx, 0.5) - 0.472597*fx + 0.507089;
gamma_lut_rgb.push_back((uint32_t)(fx*1023.0 + 0.5));
}
for (int i = 0; i < 288; i++) {
linearization_lut.push_back(0xff);
linearization_lut = {
0x00200000, 0x00200000, 0x00200000, 0x00200000,
0x00404080, 0x00404080, 0x00404080, 0x00404080,
0x00804100, 0x00804100, 0x00804100, 0x00804100,
0x006b8402, 0x006b8402, 0x006b8402, 0x006b8402,
0x00b8c070, 0x00b8c070, 0x00b8c070, 0x00b8c070,
0x06044804, 0x06044804, 0x06044804, 0x06044804,
0x100ba015, 0x100ba015, 0x100ba015, 0x100ba015,
0x00003fff, 0x00003fff, 0x00003fff, 0x00003fff,
0x00003fff, 0x00003fff, 0x00003fff, 0x00003fff,
};
for (int i = 0; i < 252; i++) {
linearization_lut.push_back(0x0);
}
linearization_pts = {0x07ff0bff, 0x17ff06ff, 0x1bff23ff, 0x27ff3fff};
for (int i = 0; i < 884*2; i++) {
vignetting_lut.push_back(0xff);
}
Expand Down
1 change: 1 addition & 0 deletions system/camerad/sensors/sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class SensorInfo {
std::vector<uint32_t> color_correct_matrix; // 3x3
std::vector<uint32_t> gamma_lut_rgb; // gamma LUTs are length 64 * sizeof(uint32_t); same for r/g/b here
std::vector<uint32_t> linearization_lut; // length 288
std::vector<uint32_t> linearization_pts; // length 4
std::vector<uint32_t> vignetting_lut; // 2x length 884
};

Expand Down

0 comments on commit 22a1b40

Please sign in to comment.