@@ -100,7 +100,8 @@ void mp_camera_hal_construct(
100100 // configure camera based on arguments
101101 self -> camera_config .pixel_format = pixel_format ;
102102 self -> camera_config .frame_size = frame_size ;
103- self -> camera_config .jpeg_quality = (int8_t )map (jpeg_quality ,0 ,100 ,63 ,0 ); //0-63 lower number means higher quality.
103+ // self->camera_config.jpeg_quality = (int8_t)map(jpeg_quality,0,100,63,0); //0-63 lower number means higher quality.
104+ self -> camera_config .jpeg_quality = jpeg_quality ; //save value in here, but will be corrected (with map) before passing it to the esp32-driver
104105 self -> camera_config .pin_d0 = data_pins [0 ];
105106 self -> camera_config .pin_d1 = data_pins [1 ];
106107 self -> camera_config .pin_d2 = data_pins [2 ];
@@ -152,6 +153,7 @@ void mp_camera_hal_init(mp_camera_obj_t *self) {
152153 camera_config_t temp_config = self -> camera_config ;
153154 temp_config .frame_size = FRAMESIZE_QVGA ; //use values supported by all cameras
154155 temp_config .pixel_format = PIXFORMAT_RGB565 ; //use values supported by all cameras
156+ temp_config .jpeg_quality = (int8_t )map (self -> camera_config .jpeg_quality ,0 ,100 ,63 ,0 );
155157 esp_err_t err = esp_camera_init (& temp_config );
156158 if (err != ESP_OK ) {
157159 self -> initialized = false;
@@ -219,10 +221,12 @@ void mp_camera_hal_reconfigure(mp_camera_obj_t *self, mp_camera_framesize_t fram
219221
220222 raise_micropython_error_from_esp_err (esp_camera_deinit ());
221223
222- // sensor->set_pixformat(sensor, self->camera_config.pixel_format); //seems to be needed because of some bug?
223- // sensor->set_framesize(sensor, self->camera_config.frame_size); //seems to be needed because of some bug?
224-
224+ // Correct the quality before it is passed to esp32 driver and then "undo" the correction in the camera_config
225+ int8_t api_jpeg_quality = self -> camera_config .jpeg_quality ;
226+ self -> camera_config . jpeg_quality = ( int8_t ) map ( api_jpeg_quality , 0 , 100 , 63 , 0 );
225227 esp_err_t err = esp_camera_init (& self -> camera_config );
228+ self -> camera_config .jpeg_quality = api_jpeg_quality ;
229+
226230 if (err != ESP_OK ) {
227231 self -> initialized = false;
228232 raise_micropython_error_from_esp_err (err );
@@ -433,7 +437,7 @@ void mp_camera_hal_set_quality(mp_camera_obj_t * self, int value) {
433437 if (sensor -> set_quality (sensor , map (value ,0 ,100 ,63 ,0 )) < 0 ) {
434438 mp_raise_ValueError (MP_ERROR_TEXT ("Invalid setting for quality" ));
435439 } else {
436- self -> camera_config .jpeg_quality = map ( value , 0 , 100 , 63 , 0 ) ;
440+ self -> camera_config .jpeg_quality = value ;
437441 }
438442}
439443
0 commit comments