@@ -79,6 +79,10 @@ static int map(int value, int fromLow, int fromHigh, int toLow, int toHigh) {
7979 return (int )((int32_t )(value - fromLow ) * (toHigh - toLow ) / (fromHigh - fromLow ) + toLow );
8080}
8181
82+ static int get_mapped_jpeg_quality (int8_t quality ) {
83+ return map (quality , 0 , 100 , 63 , 0 );
84+ }
85+
8286// Camera HAL Funcitons
8387void mp_camera_hal_construct (
8488 mp_camera_obj_t * self ,
@@ -153,7 +157,7 @@ void mp_camera_hal_init(mp_camera_obj_t *self) {
153157 camera_config_t temp_config = self -> camera_config ;
154158 temp_config .frame_size = FRAMESIZE_QVGA ; //use values supported by all cameras
155159 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 );
160+ temp_config .jpeg_quality = get_mapped_jpeg_quality ( self -> camera_config .jpeg_quality );
157161 esp_err_t err = esp_camera_init (& temp_config );
158162 if (err != ESP_OK ) {
159163 self -> initialized = false;
@@ -223,7 +227,7 @@ void mp_camera_hal_reconfigure(mp_camera_obj_t *self, mp_camera_framesize_t fram
223227
224228 // Correct the quality before it is passed to esp32 driver and then "undo" the correction in the camera_config
225229 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 );
230+ self -> camera_config .jpeg_quality = get_mapped_jpeg_quality ( api_jpeg_quality );
227231 esp_err_t err = esp_camera_init (& self -> camera_config );
228232 self -> camera_config .jpeg_quality = api_jpeg_quality ;
229233
@@ -433,7 +437,7 @@ void mp_camera_hal_set_quality(mp_camera_obj_t * self, int value) {
433437 if (!sensor -> set_quality ) {
434438 mp_raise_ValueError (MP_ERROR_TEXT ("No attribute quality" ));
435439 }
436- if (sensor -> set_quality (sensor , map (value , 0 , 100 , 63 , 0 )) < 0 ) {
440+ if (sensor -> set_quality (sensor , get_mapped_jpeg_quality (value )) < 0 ) {
437441 mp_raise_ValueError (MP_ERROR_TEXT ("Invalid setting for quality" ));
438442 } else {
439443 self -> camera_config .jpeg_quality = value ;
0 commit comments