From b97d1bda337ab44236f3894cc947ea1ff8d56036 Mon Sep 17 00:00:00 2001 From: Ahmet Inan Date: Thu, 8 Sep 2011 14:31:11 +0200 Subject: [PATCH] moved yuv into seperate files --- Makefile | 2 +- decode.c | 16 +--------------- yuv.c | 24 ++++++++++++++++++++++++ yuv.h | 9 +++++++++ 4 files changed, 35 insertions(+), 16 deletions(-) create mode 100644 yuv.c create mode 100644 yuv.h diff --git a/Makefile b/Makefile index bb87775..427b63b 100644 --- a/Makefile +++ b/Makefile @@ -22,5 +22,5 @@ clean: encode: encode.o mmap_file.o -decode: decode.o mmap_file.o pcm.o wav.o alsa.o window.o ddc.o delay.o +decode: decode.o mmap_file.o pcm.o wav.o alsa.o window.o ddc.o delay.o yuv.c diff --git a/decode.c b/decode.c index d841b7a..73a9b16 100644 --- a/decode.c +++ b/decode.c @@ -10,6 +10,7 @@ #include "pcm.h" #include "ddc.h" #include "delay.h" +#include "yuv.h" float lerp(float a, float b, float x) { @@ -40,21 +41,6 @@ char *string_time(char *fmt) return s; } -uint8_t R_YUV(uint8_t Y, uint8_t U, uint8_t V) -{ - (void)U; - return limit(0.0, 255.0, 0.003906 * ((298.082 * (Y - 16.0)) + (408.583 * (V - 128)))); -} -uint8_t G_YUV(uint8_t Y, uint8_t U, uint8_t V) -{ - return limit(0.0, 255.0, 0.003906 * ((298.082 * (Y - 16.0)) + (-100.291 * (U - 128)) + (-208.12 * (V - 128)))); -} -uint8_t B_YUV(uint8_t Y, uint8_t U, uint8_t V) -{ - (void)V; - return limit(0.0, 255.0, 0.003906 * ((298.082 * (Y - 16.0)) + (516.411 * (U - 128)))); -} - void process_line(uint8_t *pixel, uint8_t *y_pixel, uint8_t *uv_pixel, int y_width, int uv_width, int width, int height, int n) { // we only process after 2 full lines: on odd lines diff --git a/yuv.c b/yuv.c new file mode 100644 index 0000000..cb8934e --- /dev/null +++ b/yuv.c @@ -0,0 +1,24 @@ + +#include "yuv.h" + +uint8_t yuv_limit(float x) +{ + float tmp = x < 0.0 ? 0.0 : x; + return tmp > 255.0 ? 255.0 : tmp; +} + +uint8_t R_YUV(uint8_t Y, uint8_t U, uint8_t V) +{ + (void)U; + return yuv_limit(0.003906 * ((298.082 * (Y - 16.0)) + (408.583 * (V - 128)))); +} +uint8_t G_YUV(uint8_t Y, uint8_t U, uint8_t V) +{ + return yuv_limit(0.003906 * ((298.082 * (Y - 16.0)) + (-100.291 * (U - 128)) + (-208.12 * (V - 128)))); +} +uint8_t B_YUV(uint8_t Y, uint8_t U, uint8_t V) +{ + (void)V; + return yuv_limit(0.003906 * ((298.082 * (Y - 16.0)) + (516.411 * (U - 128)))); +} + diff --git a/yuv.h b/yuv.h new file mode 100644 index 0000000..53c0629 --- /dev/null +++ b/yuv.h @@ -0,0 +1,9 @@ + +#ifndef YUV_H +#define YUV_H +#include + +uint8_t R_YUV(uint8_t, uint8_t, uint8_t); +uint8_t G_YUV(uint8_t, uint8_t, uint8_t); +uint8_t B_YUV(uint8_t, uint8_t, uint8_t); +#endif