Merge pull request #1830 from kwagyeman/kwabena/isp_updates

imlib: Update gamma_corr to support bayer and yuv images.
This commit is contained in:
Ibrahim Abdelkader 2023-05-07 14:30:00 +03:00 committed by GitHub
commit 564b023020
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 17 deletions

View File

@ -1078,7 +1078,9 @@ void imlib_gamma(image_t *img, float gamma, float contrast, float brightness)
fb_free(); fb_free();
break; break;
} }
case PIXFORMAT_GRAYSCALE: { case PIXFORMAT_GRAYSCALE:
case PIXFORMAT_BAYER_ANY:
case PIXFORMAT_YUV_ANY: {
float pScale = COLOR_GRAYSCALE_MAX - COLOR_GRAYSCALE_MIN; float pScale = COLOR_GRAYSCALE_MAX - COLOR_GRAYSCALE_MIN;
float pDiv = 1 / pScale; float pDiv = 1 / pScale;
int *p_lut = fb_alloc((COLOR_GRAYSCALE_MAX - COLOR_GRAYSCALE_MIN + 1) * sizeof(int), FB_ALLOC_NO_HINT); int *p_lut = fb_alloc((COLOR_GRAYSCALE_MAX - COLOR_GRAYSCALE_MIN + 1) * sizeof(int), FB_ALLOC_NO_HINT);
@ -1088,12 +1090,16 @@ void imlib_gamma(image_t *img, float gamma, float contrast, float brightness)
p_lut[i] = IM_MIN(IM_MAX(p , COLOR_GRAYSCALE_MIN), COLOR_GRAYSCALE_MAX); p_lut[i] = IM_MIN(IM_MAX(p , COLOR_GRAYSCALE_MIN), COLOR_GRAYSCALE_MAX);
} }
for (int y = 0, yy = img->h; y < yy; y++) { uint8_t *ptr = (uint8_t *) img->data;
uint8_t *data = IMAGE_COMPUTE_GRAYSCALE_PIXEL_ROW_PTR(img, y); int n = img->w * img->h;
for (int x = 0, xx = img->w; x < xx; x++) {
int dataPixel = IMAGE_GET_GRAYSCALE_PIXEL_FAST(data, x); if (img->bpp == 2) {
int p = p_lut[dataPixel]; for (; n > 0; n--, ptr += 2) {
IMAGE_PUT_GRAYSCALE_PIXEL_FAST(data, x, p); *ptr = p_lut[*ptr];
}
} else {
for (; n > 0; n--, ptr += 1) {
*ptr = p_lut[*ptr];
} }
} }
@ -1126,15 +1132,15 @@ void imlib_gamma(image_t *img, float gamma, float contrast, float brightness)
b_lut[i] = IM_MIN(IM_MAX(b , COLOR_B5_MIN), COLOR_B5_MAX); b_lut[i] = IM_MIN(IM_MAX(b , COLOR_B5_MIN), COLOR_B5_MAX);
} }
for (int y = 0, yy = img->h; y < yy; y++) { uint16_t *ptr = (uint16_t *) img->data;
uint16_t *data = IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR(img, y); int n = img->w * img->h;
for (int x = 0, xx = img->w; x < xx; x++) {
int dataPixel = IMAGE_GET_RGB565_PIXEL_FAST(data, x); for (; n > 0; n--) {
int r = r_lut[COLOR_RGB565_TO_R5(dataPixel)]; int dataPixel = *ptr;
int g = g_lut[COLOR_RGB565_TO_G6(dataPixel)]; int r = r_lut[COLOR_RGB565_TO_R5(dataPixel)];
int b = b_lut[COLOR_RGB565_TO_B5(dataPixel)]; int g = g_lut[COLOR_RGB565_TO_G6(dataPixel)];
IMAGE_PUT_RGB565_PIXEL_FAST(data, x, COLOR_R5_G6_B5_TO_RGB565(r, g, b)); int b = b_lut[COLOR_RGB565_TO_B5(dataPixel)];
} *ptr++ = COLOR_R5_G6_B5_TO_RGB565(r, g, b);
} }
fb_free(); fb_free();

View File

@ -1854,7 +1854,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(py_ccm_obj, py_ccm);
STATIC mp_obj_t py_image_gamma(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) STATIC mp_obj_t py_image_gamma(uint n_args, const mp_obj_t *args, mp_map_t *kw_args)
{ {
image_t *arg_img = image_t *arg_img =
py_helper_arg_to_image_mutable(args[0]); py_helper_arg_to_image_not_compressed(args[0]);
float arg_gamma = float arg_gamma =
py_helper_keyword_float(n_args, args, 1, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_gamma), 1.0f); py_helper_keyword_float(n_args, args, 1, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_gamma), 1.0f);
float arg_contrast = float arg_contrast =