diff --git a/selfdrive/camerad/cameras/camera_qcom2.c b/selfdrive/camerad/cameras/camera_qcom2.c index a84926220a..979219360b 100644 --- a/selfdrive/camerad/cameras/camera_qcom2.c +++ b/selfdrive/camerad/cameras/camera_qcom2.c @@ -550,10 +550,6 @@ void enqueue_req_multi(struct CameraState *s, int start, int n) { // ******************* camera ******************* -static void camera_release_buffer(void* cookie, int i) { - return; -} - static void camera_init(CameraState *s, int camera_id, int camera_num, unsigned int fps) { LOGD("camera init %d", camera_num); @@ -564,7 +560,7 @@ static void camera_init(CameraState *s, int camera_id, int camera_num, unsigned s->camera_num = camera_num; s->frame_size = s->ci.frame_height * s->ci.frame_stride; - tbuffer_init2(&s->camera_tb, FRAME_BUF_COUNT, "frame", camera_release_buffer, s); + tbuffer_init2(&s->camera_tb, FRAME_BUF_COUNT, "frame", NULL, s); s->transform = (mat3){{ 1.0, 0.0, 0.0, @@ -1025,23 +1021,28 @@ void camera_autoexposure(CameraState *s, float grey_frac) { const int exposure_time_max = 1066; //1416; // no slower than 1/25 sec. calculated from 0x300C and clock freq float exposure_factor = pow(1.05, (target_grey - grey_frac) / 0.16 ); - if (s->analog_gain_frac > 1 && exposure_factor > 1 && !s->dc_gain_enabled && s->dc_opstate != 1) { // iso 800 + if (s->analog_gain_frac > 1 && exposure_factor > 0.98 && exposure_factor < 1.02) { // high analog gains are coarse + return; + } else if (s->analog_gain_frac > 1 && exposure_factor > 1 && !s->dc_gain_enabled && s->dc_opstate != 1) { // switch to HCG at iso 800 s->dc_gain_enabled = true; s->analog_gain_frac *= 0.5; s->dc_opstate = 1; - } else if (s->analog_gain_frac < 0.5 && exposure_factor < 1 && s->dc_gain_enabled && s->dc_opstate != 1) { // iso 400 + } else if (s->analog_gain_frac < 0.5 && exposure_factor < 1 && s->dc_gain_enabled && s->dc_opstate != 1) { // switch back to LCG at iso 400 s->dc_gain_enabled = false; - s->analog_gain_frac *= 2; + s->analog_gain_frac *= 2.0; s->dc_opstate = 1; - } else if (s->analog_gain_frac > 0.5 && exposure_factor < 0.9) { - s->analog_gain_frac *= sqrt(exposure_factor); - s->exposure_time = max(min(s->exposure_time * sqrt(exposure_factor), exposure_time_max),exposure_time_min); + } else if (s->analog_gain_frac > 1 && exposure_factor < 1) { // force gain down first + s->analog_gain_frac /= 2.0; + s->dc_opstate = 0; + } else if (s->analog_gain_frac > 0.5 && exposure_factor < 0.9) { // smoother transistion on large stepdowns + s->analog_gain_frac = max(min(s->analog_gain_frac * sqrt(exposure_factor), analog_gain_frac_max), analog_gain_frac_min); + s->exposure_time = max(min(s->exposure_time * sqrt(exposure_factor), exposure_time_max), exposure_time_min); s->dc_opstate = 0; - } else if ((s->exposure_time < exposure_time_max || exposure_factor < 1) && (s->exposure_time > exposure_time_min || exposure_factor > 1)) { - s->exposure_time = max(min(s->exposure_time * exposure_factor, exposure_time_max),exposure_time_min); + } else if ((s->exposure_time < exposure_time_max || exposure_factor < 1) && (s->exposure_time > exposure_time_min || exposure_factor > 1)) { // ramp up shutter time before gain + s->exposure_time = max(min(s->exposure_time * exposure_factor, exposure_time_max), exposure_time_min); s->dc_opstate = 0; } else { - s->analog_gain_frac = max(min(s->analog_gain_frac * exposure_factor, analog_gain_frac_max),analog_gain_frac_min); + s->analog_gain_frac = max(min(s->analog_gain_frac * exposure_factor, analog_gain_frac_max), analog_gain_frac_min); s->dc_opstate = 0; } // set up config @@ -1061,8 +1062,8 @@ void camera_autoexposure(CameraState *s, float grey_frac) { struct i2c_random_wr_payload exp_reg_array[] = {{0x3366, AG}, // analog gain {0x3362, s->dc_gain_enabled?0x1:0x0}, // DC_GAIN - {0x305A, 0x00C4}, // red gain - {0x3058, 0x00B1}, // blue gain + {0x305A, 0x00D1}, // red gain + {0x3058, 0x0118}, // blue gain {0x3056, 0x009A}, // g1 gain {0x305C, 0x009A}, // g2 gain {0x3012, s->exposure_time}}; // integ time @@ -1077,15 +1078,22 @@ void sendrgb(MultiCameraState *s, uint8_t* dat, int len, uint8_t cam_id) { int err, err2; int scale = 6; int old_width = FRAME_WIDTH; + // int old_height = FRAME_HEIGHT; int new_width = FRAME_WIDTH / scale; int new_height = FRAME_HEIGHT / scale; uint8_t resized_dat[new_width*new_height*3]; + // int goff, loff; + // goff = ((old_width*(scale-1)*old_height/scale)/2); memset(&resized_dat, cam_id, 3); for (uint32_t r=1;rrgb_sock), &resized_dat, new_width*new_height*3, 0); diff --git a/selfdrive/camerad/cameras/real_debayer.cl b/selfdrive/camerad/cameras/real_debayer.cl index eaea1ed12f..97631e52f9 100644 --- a/selfdrive/camerad/cameras/real_debayer.cl +++ b/selfdrive/camerad/cameras/real_debayer.cl @@ -1,8 +1,8 @@ const __constant float3 color_correction[3] = { // post wb CCM - (float3)(1.17898387, -0.19583185, -0.19881648), - (float3)(-0.03367879, 1.33692858, -0.02475203), - (float3)(-0.14530508, -0.14109673, 1.22356851), + (float3)(1.44602146, -0.24727126, -0.0403062), + (float3)(-0.37658179, 1.26329038, -0.45978396), + (float3)(-0.06943967, -0.01601912, 1.50009016), }; float3 color_correct(float r, float g, float b) { @@ -29,7 +29,7 @@ float to_normal(uint x) { const float black_level = 0; pv = max(0.0, pv - black_level); pv /= (1024.0f - black_level); - pv = 1.6*pv / (1.0f + 1.6*pv); // reinhard + pv = 5*pv / (1.0f + 5*pv); // reinhard return pv; } diff --git a/selfdrive/camerad/cameras/sensor2_i2c.h b/selfdrive/camerad/cameras/sensor2_i2c.h index 070ed43677..9a1cbcaed6 100644 --- a/selfdrive/camerad/cameras/sensor2_i2c.h +++ b/selfdrive/camerad/cameras/sensor2_i2c.h @@ -359,8 +359,8 @@ struct i2c_random_wr_payload init_array_ar0231[] = { {0x3022, 0x01}, // GROUPED_PARAMETER_HOLD_ {0x3366, 0x7777}, // ANALOG_GAIN {0x3060, 0xBBBB}, // ANALOG_COLOR_GAIN - {0x305A, 0x00C4}, // RED_GAIN - {0x3058, 0x00B1}, // BLUE_GAIN + {0x305A, 0x00D1}, // RED_GAIN + {0x3058, 0x0118}, // BLUE_GAIN {0x3056, 0x009A}, // GREEN1_GAIN {0x305C, 0x009A}, // GREEN2_GAIN {0x3022, 0x00}, // GROUPED_PARAMETER_HOLD_