libsstvenc
Asynchronous Analogue SSTV encoder
Loading...
Searching...
No Matches
RGB to YUV conversions (and vice versa).
Collaboration diagram for RGB to YUV conversions (and vice versa).:

Functions

uint8_t sstvenc_yuv_calc_y (uint8_t r, uint8_t g, uint8_t b)
 
uint8_t sstvenc_yuv_calc_u (uint8_t r, uint8_t g, uint8_t b)
 
uint8_t sstvenc_yuv_calc_v (uint8_t r, uint8_t g, uint8_t b)
 
uint8_t sstvenc_rgb_calc_r (uint8_t r, uint8_t g, uint8_t b)
 
uint8_t sstvenc_rgb_calc_g (uint8_t r, uint8_t g, uint8_t b)
 
uint8_t sstvenc_rgb_calc_b (uint8_t r, uint8_t g, uint8_t b)
 
void sstvenc_rgb_to_mono (uint8_t *dest, const uint8_t *src, uint16_t width, uint16_t height)
 
void sstvenc_rgb_to_yuv (uint8_t *dest, const uint8_t *src, uint16_t width, uint16_t height)
 
void sstvenc_yuv_to_rgb (uint8_t *dest, const uint8_t *src, uint16_t width, uint16_t height)
 
void sstvenc_yuv_to_mono (uint8_t *dest, const uint8_t *src, uint16_t width, uint16_t height)
 
void sstvenc_mono_to_rgb (uint8_t *dest, const uint8_t *src, uint16_t width, uint16_t height)
 
void sstvenc_mono_to_yuv (uint8_t *dest, const uint8_t *src, uint16_t width, uint16_t height)
 

Detailed Description

Functions for extracting the Y, U or V components of a RGB colour. The equations in this module came from JL Barber (N7CXI)'s presentation at the Dayton SSSTV forum, 2000-05-20.

http://www.barberdsp.com/downloads/Dayton%20Paper.pdf

Function Documentation

◆ sstvenc_mono_to_rgb()

void sstvenc_mono_to_rgb ( uint8_t * dest,
const uint8_t * src,
uint16_t width,
uint16_t height )

Convert the given mono framebuffer to RGB.

Parameters
[out]destDestination framebuffer, which is assumed to be triple the size of src. This can be the same location as src – so long as the buffer is sufficiently large.
[in]srcSource framebuffer, which is assumed to be mono
[in]widthWidth of the framebuffer in pixels
[in]heightHeight of the framebuffer in pixels

Definition at line 122 of file yuv.c.

123 {
124 size_t sz = (size_t)width * (size_t)height;
125 while (sz) {
126 /* Work backwards so we don't overwrite the source */
127 const uint8_t src_pos = sz - 1;
128 const uint8_t dest_pos = src_pos * 3;
129
130 dest[dest_pos + 0] = src[src_pos]; /* R */
131 dest[dest_pos + 1] = src[src_pos]; /* G */
132 dest[dest_pos + 2] = src[src_pos]; /* B */
133
134 sz--;
135 }
136}

◆ sstvenc_mono_to_yuv()

void sstvenc_mono_to_yuv ( uint8_t * dest,
const uint8_t * src,
uint16_t width,
uint16_t height )

Convert the given mono framebuffer to YUV.

Parameters
[out]destDestination framebuffer, which is assumed to be triple the size as src. This can be the same location as src if it is big enough.
[in]srcSource framebuffer, which is assumed to be RGB
[in]widthWidth of the framebuffer in pixels
[in]heightHeight of the framebuffer in pixels

Definition at line 138 of file yuv.c.

139 {
140 size_t sz = (size_t)width * (size_t)height;
141 while (sz) {
142 /* Work backwards so we don't overwrite the source */
143 const uint8_t src_pos = sz - 1;
144 const uint8_t dest_pos = src_pos * 3;
145
146 dest[dest_pos + 0] = src[src_pos]; /* Y */
147 dest[dest_pos + 1] = 0; /* U */
148 dest[dest_pos + 2] = 0; /* V */
149
150 sz--;
151 }
152}

◆ sstvenc_rgb_calc_b()

uint8_t sstvenc_rgb_calc_b ( uint8_t r,
uint8_t g,
uint8_t b )

Return the blue component of a YUV colour.

Parameters
[in]yY (monochrome) component in Q8 fixed-point
[in]uU (Y - R) component in Q8 fixed-point
[in]vV (Y - B) component in Q8 fixed-point
Returns
Blue component in Q8 fixed-point.

Definition at line 53 of file yuv.c.

53 {
54 return (0.003906
55 * ((298.082 * ((double)y - 16.0))
56 + (516.411 * ((double)v - 128.0))))
57 + 0.5;
58}

Referenced by sstvenc_yuv_to_rgb().

Here is the caller graph for this function:

◆ sstvenc_rgb_calc_g()

uint8_t sstvenc_rgb_calc_g ( uint8_t r,
uint8_t g,
uint8_t b )

Return the green component of a YUV colour.

Parameters
[in]yY (monochrome) component in Q8 fixed-point
[in]uU (Y - R) component in Q8 fixed-point
[in]vV (Y - B) component in Q8 fixed-point
Returns
Green component in Q8 fixed-point.

Definition at line 45 of file yuv.c.

45 {
46 return (0.003906
47 * ((298.082 * ((double)y - 16.0))
48 + (-100.291 * ((double)v - 128.0))
49 + (-208.12 * ((double)u - 128.0))))
50 + 0.5;
51}

Referenced by sstvenc_yuv_to_rgb().

Here is the caller graph for this function:

◆ sstvenc_rgb_calc_r()

uint8_t sstvenc_rgb_calc_r ( uint8_t r,
uint8_t g,
uint8_t b )

Return the red component of a YUV colour.

Parameters
[in]yY (monochrome) component in Q8 fixed-point
[in]uU (Y - R) component in Q8 fixed-point
[in]vV (Y - B) component in Q8 fixed-point
Returns
Red component in Q8 fixed-point.

Definition at line 38 of file yuv.c.

38 {
39 return (0.003906
40 * ((298.082 * ((double)y - 16.0))
41 + (408.583 * ((double)u - 128.0))))
42 + 0.5;
43}

Referenced by sstvenc_yuv_to_rgb().

Here is the caller graph for this function:

◆ sstvenc_rgb_to_mono()

void sstvenc_rgb_to_mono ( uint8_t * dest,
const uint8_t * src,
uint16_t width,
uint16_t height )

Convert the given RGB framebuffer to monochrome (Y component only).

Parameters
[out]destDestination framebuffer, which is assumed to be at least one third of the size of src. This can be the same location as src – after conversion the occupied size will be one third of the original buffer and may be realloc()'d to that size.
[in]srcSource framebuffer, which is assumed to be RGB
[in]widthWidth of the framebuffer in pixels
[in]heightHeight of the framebuffer in pixels

Definition at line 60 of file yuv.c.

61 {
62 size_t sz = (size_t)width * (size_t)height;
63 while (sz) {
64 /* Convert and write out YUV */
65 dest[0] = sstvenc_yuv_calc_y(src[0], src[1], src[2]);
66
67 dest += 1;
68 src += 3;
69 sz--;
70 }
71}
uint8_t sstvenc_yuv_calc_y(uint8_t r, uint8_t g, uint8_t b)
Definition yuv.c:14

References sstvenc_yuv_calc_y().

Here is the call graph for this function:

◆ sstvenc_rgb_to_yuv()

void sstvenc_rgb_to_yuv ( uint8_t * dest,
const uint8_t * src,
uint16_t width,
uint16_t height )

Convert the given RGB framebuffer to YUV.

Parameters
[out]destDestination framebuffer, which is assumed to be the same size as src. This can be the same location as src.
[in]srcSource framebuffer, which is assumed to be RGB
[in]widthWidth of the framebuffer in pixels
[in]heightHeight of the framebuffer in pixels

Definition at line 73 of file yuv.c.

74 {
75 size_t sz = (size_t)width * (size_t)height;
76 while (sz) {
77 /* Pull out RGB values */
78 const uint8_t r = src[0], g = src[1], b = src[2];
79
80 /* Convert and write out YUV */
81 dest[0] = sstvenc_yuv_calc_y(r, g, b); /* Y */
82 dest[1] = sstvenc_yuv_calc_u(r, g, b); /* U */
83 dest[2] = sstvenc_yuv_calc_v(r, g, b); /* V */
84
85 dest += 3;
86 src += 3;
87 sz--;
88 }
89}
uint8_t sstvenc_yuv_calc_v(uint8_t r, uint8_t g, uint8_t b)
Definition yuv.c:30
uint8_t sstvenc_yuv_calc_u(uint8_t r, uint8_t g, uint8_t b)
Definition yuv.c:22

References sstvenc_yuv_calc_u(), sstvenc_yuv_calc_v(), and sstvenc_yuv_calc_y().

Here is the call graph for this function:

◆ sstvenc_yuv_calc_u()

uint8_t sstvenc_yuv_calc_u ( uint8_t r,
uint8_t g,
uint8_t b )

Return the U (red - luminance) component of a RGB colour.

Parameters
[in]rRed component in Q8 fixed-point
[in]gGreen component in Q8 fixed-point
[in]bBlue component in Q8 fixed-point
Returns
U component in Q8 fixed-point.

Definition at line 22 of file yuv.c.

22 {
23 return (128.0
24 + (.003906
25 * ((112.439 * (double)r) + (-94.154 * (double)g)
26 + (-18.285 * (double)b))))
27 + 0.5;
28}

Referenced by main(), and sstvenc_rgb_to_yuv().

Here is the caller graph for this function:

◆ sstvenc_yuv_calc_v()

uint8_t sstvenc_yuv_calc_v ( uint8_t r,
uint8_t g,
uint8_t b )

Return the V (blue - luminance) component of a RGB colour.

Parameters
[in]rRed component in Q8 fixed-point
[in]gGreen component in Q8 fixed-point
[in]bBlue component in Q8 fixed-point
Returns
V component in Q8 fixed-point.

Definition at line 30 of file yuv.c.

30 {
31 return (128.0
32 + (.003906
33 * ((-37.945 * (double)r) + (-74.494 * (double)g)
34 + (112.439 * (double)b))))
35 + 0.5;
36}

Referenced by main(), and sstvenc_rgb_to_yuv().

Here is the caller graph for this function:

◆ sstvenc_yuv_calc_y()

uint8_t sstvenc_yuv_calc_y ( uint8_t r,
uint8_t g,
uint8_t b )

Return the Y (luminance) component of a RGB colour. This routine is useful for converting colour to monochrome as well as RGB to YUV.

Parameters
[in]rRed component in Q8 fixed-point
[in]gGreen component in Q8 fixed-point
[in]bBlue component in Q8 fixed-point
Returns
Y component in Q8 fixed-point.

Definition at line 14 of file yuv.c.

14 {
15 return (16.0
16 + (.003906
17 * ((65.738 * (double)r) + (129.057 * (double)g)
18 + (25.064 * (double)b))))
19 + 0.5;
20}

Referenced by main(), sstvenc_rgb_to_mono(), and sstvenc_rgb_to_yuv().

Here is the caller graph for this function:

◆ sstvenc_yuv_to_mono()

void sstvenc_yuv_to_mono ( uint8_t * dest,
const uint8_t * src,
uint16_t width,
uint16_t height )

Convert the given YUV framebuffer to monochrome (Y component only).

Parameters
[out]destDestination framebuffer, which is assumed to be at least one third of the size of src. This can be the same location as src – after conversion the occupied size will be one third of the original buffer and may be realloc()'d to that size.
[in]srcSource framebuffer, which is assumed to be YUV
[in]widthWidth of the framebuffer in pixels
[in]heightHeight of the framebuffer in pixels

Definition at line 109 of file yuv.c.

110 {
111 size_t sz = (size_t)width * (size_t)height;
112 while (sz) {
113 /* Extract Y out of YUV */
114 dest[0] = src[0];
115
116 dest += 1;
117 src += 3;
118 sz--;
119 }
120}

◆ sstvenc_yuv_to_rgb()

void sstvenc_yuv_to_rgb ( uint8_t * dest,
const uint8_t * src,
uint16_t width,
uint16_t height )

Convert the given YUV framebuffer to RGB.

Parameters
[out]destDestination framebuffer, which is assumed to be the same size as src. This can be the same location as src.
[in]srcSource framebuffer, which is assumed to be YUV
[in]widthWidth of the framebuffer in pixels
[in]heightHeight of the framebuffer in pixels

Definition at line 91 of file yuv.c.

92 {
93 size_t sz = (size_t)width * (size_t)height;
94 while (sz) {
95 /* Pull out YUV values */
96 const uint8_t y = src[0], u = src[1], v = src[2];
97
98 /* Convert and write out RGB */
99 dest[0] = sstvenc_rgb_calc_r(y, u, v); /* R */
100 dest[1] = sstvenc_rgb_calc_g(y, u, v); /* G */
101 dest[2] = sstvenc_rgb_calc_b(y, u, v); /* B */
102
103 dest += 3;
104 src += 3;
105 sz--;
106 }
107}
uint8_t sstvenc_rgb_calc_g(uint8_t r, uint8_t g, uint8_t b)
Definition yuv.c:45
uint8_t sstvenc_rgb_calc_b(uint8_t r, uint8_t g, uint8_t b)
Definition yuv.c:53
uint8_t sstvenc_rgb_calc_r(uint8_t r, uint8_t g, uint8_t b)
Definition yuv.c:38

References sstvenc_rgb_calc_b(), sstvenc_rgb_calc_g(), and sstvenc_rgb_calc_r().

Here is the call graph for this function: