diff options
author | Patrick Roth <roth@stettbacher.ch> | 2019-10-04 11:51:48 +0200 |
---|---|---|
committer | Patrick Roth <roth@stettbacher.ch> | 2019-10-04 11:51:48 +0200 |
commit | a0f501fa5650d0b6062cc8f26b34bce11137643d (patch) | |
tree | 8e31c5ac3409d4ce48887d88d4530b88a02c2660 /alg_rgb_to_yuv.h | |
download | o3000-color-pipe-a0f501fa5650d0b6062cc8f26b34bce11137643d.tar.gz o3000-color-pipe-a0f501fa5650d0b6062cc8f26b34bce11137643d.zip |
initial commit
import from github
Diffstat (limited to 'alg_rgb_to_yuv.h')
-rw-r--r-- | alg_rgb_to_yuv.h | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/alg_rgb_to_yuv.h b/alg_rgb_to_yuv.h new file mode 100644 index 0000000..f75df6a --- /dev/null +++ b/alg_rgb_to_yuv.h @@ -0,0 +1,78 @@ +/** +* @file alg_rgb_to_yuv.h +* @brief color space conversion definitions +* @author Patrick Roth - roth@stettbacher.ch +* @version 1.0 +* @date 2015-08-20 +* @copyright 2012-2016 Stettbacher Signal Processing AG +* +* @remarks +* +* <PRE> +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* </PRE> +* +*/ + + +/* + * This code inplements a RGB to YUV color space conversion and is pixel size independent. Including this code at the + * C-Source file will define the pixel-bit-depth (see color.c). + */ +// static void rgb8_to_yuv(int32_t *img_yuv, const uint8_t *img_rgb, const int height, const int width) +// static void rgb16_to_yuv(int32_t *img_yuv, const uint16_t *img_rgb, const int height, const int width) +{ + + int x, y, index; + int blue, green, red; + int pixel_y, pixel_u, pixel_v; + const int scale_fact = 10; + + const int y_r = (int)roundf(RGB2YUV_COEFF_Y_RED*(1<<scale_fact)); + const int y_g = (int)roundf(RGB2YUV_COEFF_Y_GREEN*(1<<scale_fact)); + const int y_b = (int)roundf(RGB2YUV_COEFF_Y_BLUE*(1<<scale_fact)); + + const int u_r = (int)roundf(RGB2YUV_COEFF_U_RED*(1<<scale_fact)); + const int u_g = (int)roundf(RGB2YUV_COEFF_U_GREEN*(1<<scale_fact)); + const int u_b = (int)roundf(RGB2YUV_COEFF_U_BLUE*(1<<scale_fact)); + + const int v_r = (int)roundf(RGB2YUV_COEFF_V_RED*(1<<scale_fact)); + const int v_g = (int)roundf(RGB2YUV_COEFF_V_GREEN*(1<<scale_fact)); + const int v_b = (int)roundf(RGB2YUV_COEFF_V_BLUE*(1<<scale_fact)); + + + + index = 0; + for(y = 0; y < height; y++) { + for(x = 0; x < width; x++) { + + // put each RGB color on stack + red = img_rgb[index]; + green = img_rgb[index + 1]; + blue = img_rgb[index + 2]; + + // color space conversion from RGB to YUV + pixel_y = (y_r*red + y_g*green + y_b*blue) >> scale_fact; + pixel_u = (u_r*red + u_g*green + u_b*blue) >> scale_fact; + pixel_v = (v_r*red + v_g*green + v_b*blue) >> scale_fact; + + img_yuv[index] = pixel_y; + img_yuv[index+1] = pixel_u; + img_yuv[index+2] = pixel_v; + + index += 3; + } + } +} |