I am implementing C++ code to do the color space conversion. The need is to convert YVU to HSV. What I did is to convert YVU to RGB, and then to HSV. When converting back, I converted HSV to RGB and then YVU.
I feel it's not very convenient to convert via RGB. How can I convert YVU to HSV and then convert back in C++?
Below is part of my code to the conversion, which is not very efficient...Thank you!
void yvu2hsv(uint8_t* in_y, uint8_t* in_vu, uint8_t* unet_in, uint8_t* out_y, uint8_t* out_vu, int size)
{
for(int i = 0; i < size; i++)
{
size_t i_2 = i * 2;
float yuv_y = (float) in_y[i] / 255.f;
float yuv_v = (float) in_vu[i_2] / 255.f - 0.5;
float yuv_u = (float) in_vu[i_2 + 1] / 255.f - 0.5;
rgb rgb_in;
rgb_in.r = yuv_y + 1.5748 * yuv_v;
rgb_in.g = yuv_y - 0.1873 * yuv_u - 0.4681 * yuv_v;
rgb_in.b = yuv_y + 1.8556 * yuv_u;
float unet_in_x = (float)unet_in[i] / 255.f;
hsv hsv_out = rgb2hsv(rgb_in);
// SOME PROCESSING ON HSV COLOR SPACE HERE
rgb rgb_out = hsv2rgb(hsv_out);
out_y[i] = (uint8_t)(( std::max(std::min(1.0, 0.2126 * rgb_out.r + 0.7152 * rgb_out.g + 0.0722 * rgb_out.b) ,0.0) ) * 255);
out_vu[i_2 + 1] = (uint8_t)(( std::max(std::min(1.0, -0.1146 * rgb_out.r - 0.3854 * rgb_out.g + 0.5 * rgb_out.b + 0.5) ,0.0) ) * 255);
out_vu[i_2]= (uint8_t)(( std::max(std::min(1.0, 0.5 * rgb_out.r - 0.4542 * rgb_out.g - 0.0458 * rgb_out.b + 0.5) ,0.0) ) * 255);
}
}