20 return ((z < x) ? x : ((z > y) ? y : z));
27 yuv[0] = (int)(0.299 * rgb[0] + 0.587 * rgb[1] + 0.114 * rgb[2]);
28 yuv[1] = (int)((rgb[2] - yuv[0]) * 0.565 + 128);
29 yuv[2] = (int)((rgb[0] - yuv[0]) * 0.713 + 128);
37 float S, Z, R,
G, B, L, Kr, Kb, Y, U,
V;
54 L = Kr * R + Kb * B + (1 - Kr - Kb) * G;
69 if (luminance != 100) {
70 yuv[0] = yuv[0] * luminance / 100;
82 int rgb_row_advance = (pitch - w*3) + pitch;
93 U = V + ((h + 1)/2)*((w + 1)/2);
98 V = U + ((h + 1)/2)*((w + 1)/2);
116 for (y = 0; y < (h - 1); y += 2) {
117 for (x = 0; x < (w - 1); x += 2) {
118 RGBtoYUV(rgb1, yuv[0], mode, monochrome, luminance);
120 *Y1++ = (
Uint8)yuv[0][0];
122 RGBtoYUV(rgb1, yuv[1], mode, monochrome, luminance);
124 *Y1++ = (
Uint8)yuv[1][0];
126 RGBtoYUV(rgb2, yuv[2], mode, monochrome, luminance);
128 *Y2++ = (
Uint8)yuv[2][0];
130 RGBtoYUV(rgb2, yuv[3], mode, monochrome, luminance);
132 *Y2++ = (
Uint8)yuv[3][0];
134 *U = (
Uint8)
SDL_floorf((yuv[0][1] + yuv[1][1] + yuv[2][1] + yuv[3][1])/4.0f + 0.5f);
137 *V = (
Uint8)
SDL_floorf((yuv[0][2] + yuv[1][2] + yuv[2][2] + yuv[3][2])/4.0f + 0.5f);
142 RGBtoYUV(rgb1, yuv[0], mode, monochrome, luminance);
144 *Y1++ = (
Uint8)yuv[0][0];
146 RGBtoYUV(rgb2, yuv[2], mode, monochrome, luminance);
148 *Y2++ = (
Uint8)yuv[2][0];
158 rgb1 += rgb_row_advance;
159 rgb2 += rgb_row_advance;
163 for (x = 0; x < (w - 1); x += 2) {
164 RGBtoYUV(rgb1, yuv[0], mode, monochrome, luminance);
166 *Y1++ = (
Uint8)yuv[0][0];
168 RGBtoYUV(rgb1, yuv[1], mode, monochrome, luminance);
170 *Y1++ = (
Uint8)yuv[1][0];
180 RGBtoYUV(rgb1, yuv[0], mode, monochrome, luminance);
181 *Y1++ = (
Uint8)yuv[0][0];
183 *U = (
Uint8)yuv[0][1];
186 *V = (
Uint8)yuv[0][2];
198 int rgb_row_advance = (pitch - w*3);
226 for (y = 0; y <
h; ++
y) {
227 for (x = 0; x < (w - 1); x += 2) {
228 RGBtoYUV(rgb, yuv[0], mode, monochrome, luminance);
230 *Y1 = (
Uint8)yuv[0][0];
233 RGBtoYUV(rgb, yuv[1], mode, monochrome, luminance);
235 *Y2 = (
Uint8)yuv[1][0];
246 RGBtoYUV(rgb, yuv[0], mode, monochrome, luminance);
248 *Y2 = *Y1 = (
Uint8)yuv[0][0];
252 *U = (
Uint8)yuv[0][1];
255 *V = (
Uint8)yuv[0][2];
258 rgb += rgb_row_advance;
294 return 4*((width + 1)/2);
static void ConvertRGBtoPacked4(Uint32 format, Uint8 *src, int pitch, Uint8 *out, int w, int h, SDL_YUV_CONVERSION_MODE mode, int monochrome, int luminance)
SDL_YUV_CONVERSION_MODE
The formula used for converting between YUV and RGB.
GLint GLint GLint GLint GLint x
GLfloat GLfloat GLfloat GLfloat h
static void RGBtoYUV(Uint8 *rgb, int *yuv, SDL_YUV_CONVERSION_MODE mode, int monochrome, int luminance)
static void ConvertRGBtoPlanar2x2(Uint32 format, Uint8 *src, int pitch, Uint8 *out, int w, int h, SDL_YUV_CONVERSION_MODE mode, int monochrome, int luminance)
GLint GLint GLsizei width
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
GLubyte GLubyte GLubyte GLubyte w
GLint GLint GLint GLint GLint GLint y
int CalculateYUVPitch(Uint32 format, int width)
#define SDL_assert(condition)
static float clip3(float x, float y, float z)
SDL_bool ConvertRGBtoYUV(Uint32 format, Uint8 *src, int pitch, Uint8 *out, int w, int h, SDL_YUV_CONVERSION_MODE mode, int monochrome, int luminance)