aboutsummaryrefslogtreecommitdiffstats
path: root/alg_yuv_to_rgb.h
diff options
context:
space:
mode:
authorPatrick Roth <roth@stettbacher.ch>2019-10-04 11:51:48 +0200
committerPatrick Roth <roth@stettbacher.ch>2019-10-04 11:51:48 +0200
commita0f501fa5650d0b6062cc8f26b34bce11137643d (patch)
tree8e31c5ac3409d4ce48887d88d4530b88a02c2660 /alg_yuv_to_rgb.h
downloado3000-color-pipe-a0f501fa5650d0b6062cc8f26b34bce11137643d.tar.gz
o3000-color-pipe-a0f501fa5650d0b6062cc8f26b34bce11137643d.zip
initial commit
import from github
Diffstat (limited to 'alg_yuv_to_rgb.h')
-rw-r--r--alg_yuv_to_rgb.h79
1 files changed, 79 insertions, 0 deletions
diff --git a/alg_yuv_to_rgb.h b/alg_yuv_to_rgb.h
new file mode 100644
index 0000000..c608a6d
--- /dev/null
+++ b/alg_yuv_to_rgb.h
@@ -0,0 +1,79 @@
+/**
+* @file alg_yuv_to_rgb.h
+* @brief color space conversion definitions
+* @author Patrick Roth - roth@stettbacher.ch
+* @version 1.0
+* @date 2015-08-27
+* @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 yuv_to_rgb8(uint8_t *img_rgb, const int32_t *img_yuv, const int height, const int width, const int pix_max)
+// static void yuv_to_rgb16(uint16_t *img_rgb, const int32_t *img_yuv, const int height, const int width, const int pix_max)
+{
+ int x, y, index;
+ int blue, green, red;
+ int val_y, val_u, val_v;
+ const int scale_fact = 10;
+
+
+ const int green_y = (int)roundf(1.0*(1<<scale_fact));
+ const int green_u = (int)roundf(-0.1942*(1<<scale_fact));
+ const int green_v = (int)roundf(-0.5094*(1<<scale_fact));
+
+ index = 0;
+ for(y = 0; y < height; y++) {
+ for(x = 0; x < width; x++) {
+
+ // save YUV values on stack
+ val_y = img_yuv[index];
+ val_u = img_yuv[index+1];
+ val_v = img_yuv[index+2];
+
+ red = val_y + val_v;
+ green = (green_y*val_y + green_u*val_u + green_v*val_v) >> scale_fact;
+ blue = val_y + val_u;
+
+ // range check red
+ if(red < 0) red = 0;
+ else if(red > pix_max) red = pix_max;
+
+ // range check green
+ if(green < 0) green = 0;
+ else if(green > pix_max) green = pix_max;
+
+ // range check blue
+ if(blue < 0) blue = 0;
+ else if(blue > pix_max) blue = pix_max;
+
+ img_rgb[index] = red;
+ img_rgb[index+1] = green;
+ img_rgb[index+2] = blue;
+
+ index += 3;
+ }
+ }
+}