mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Made histeg work for RGB565.
Added YUV to RGB565 conversion to make this happen.
This commit is contained in:
parent
90ac31c0ff
commit
fc605b0a80
@ -16,12 +16,13 @@
|
||||
#include "fb_alloc.h"
|
||||
#include "xalloc.h"
|
||||
#include "imlib.h"
|
||||
#include "mdefs.h"
|
||||
|
||||
// Gamma uncompress
|
||||
extern const float xyz_table[256];
|
||||
|
||||
// Grayscale to RGB565 conversion
|
||||
extern const uint16_t rainbow_table[256];
|
||||
// RGB565 to YUV conversion
|
||||
extern const int8_t yuv_table[196608];
|
||||
|
||||
// USE THE LUT FOR RGB->LAB CONVERSION - NOT THIS FUNCTION!
|
||||
void imlib_rgb_to_lab(simple_color_t *rgb, simple_color_t *lab)
|
||||
@ -90,6 +91,14 @@ void imlib_grayscale_to_rgb(simple_color_t *grayscale, simple_color_t *rgb)
|
||||
rgb->blue = grayscale->G;
|
||||
}
|
||||
|
||||
ALWAYS_INLINE uint16_t imlib_yuv_to_rgb(uint8_t y, int8_t u, int8_t v)
|
||||
{
|
||||
uint32_t r = IM_MAX(IM_MIN(y + ((91881*v)>>16), 255), 0);
|
||||
uint32_t g = IM_MAX(IM_MIN(y - (((22554*u)+(46802*v))>>16), 255), 0);
|
||||
uint32_t b = IM_MAX(IM_MIN(y + ((116130*u)>>16), 255), 0);
|
||||
return IM_RGB565(IM_R825(r), IM_G826(g), IM_B825(b));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static save_image_format_t imblib_parse_extension(image_t *img, const char *path)
|
||||
@ -797,10 +806,11 @@ void imlib_blend(image_t *img, const char *path, image_t *other, int alpha)
|
||||
|
||||
void imlib_histeq(image_t *img)
|
||||
{
|
||||
int a = img->w * img->h;
|
||||
float s = IM_MAX_GS / ((float)a);
|
||||
uint32_t *hist = fb_alloc0(IM_G_HIST_SIZE * sizeof(uint32_t));
|
||||
|
||||
if (IM_IS_GS(img)) {
|
||||
int a = img->w * img->h;
|
||||
float s = IM_MAX_GS / ((float)a);
|
||||
uint32_t *hist = fb_alloc0(IM_G_HIST_SIZE * sizeof(uint32_t));
|
||||
|
||||
/* compute image histogram */
|
||||
for (int i=0; i<a; i++) {
|
||||
@ -817,10 +827,31 @@ void imlib_histeq(image_t *img)
|
||||
img->pixels[i] = s * hist[img->pixels[i]];
|
||||
}
|
||||
|
||||
fb_free();
|
||||
} else {
|
||||
// do nothing for now
|
||||
|
||||
uint16_t *pixels = (uint16_t *) img->pixels;
|
||||
|
||||
/* compute image histogram */
|
||||
for (int i=0; i<a; i++) {
|
||||
hist[yuv_table[pixels[i]*3]+128] += 1;
|
||||
}
|
||||
|
||||
/* compute the CDF */
|
||||
for (int i=0, sum=0; i<IM_G_HIST_SIZE; i++) {
|
||||
sum += hist[i];
|
||||
hist[i] = sum;
|
||||
}
|
||||
|
||||
for (int i=0; i<a; i++) {
|
||||
uint8_t y = s * hist[yuv_table[pixels[i]*3]+128];
|
||||
int8_t u = yuv_table[(pixels[i]*3)+1];
|
||||
int8_t v = yuv_table[(pixels[i]*3)+2];
|
||||
pixels[i] = imlib_yuv_to_rgb(y, u, v);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fb_free();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -351,6 +351,7 @@ void imlib_rgb_to_lab(simple_color_t *rgb, simple_color_t *lab);
|
||||
void imlib_lab_to_rgb(simple_color_t *lab, simple_color_t *rgb);
|
||||
void imlib_rgb_to_grayscale(simple_color_t *rgb, simple_color_t *grayscale);
|
||||
void imlib_grayscale_to_rgb(simple_color_t *grayscale, simple_color_t *rgb);
|
||||
uint16_t imlib_yuv_to_rgb(uint8_t y, int8_t u, int8_t v);
|
||||
|
||||
/* Image file functions */
|
||||
void ppm_read_geometry(FIL *fp, image_t *img, const char *path, ppm_read_settings_t *rs);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user