21 #include "../SDL_internal.h" 29 #define SDL_YUV_SD_THRESHOLD 576 95 int pitches[3] = { 0, 0, 0 };
100 pitches[0] = yuv_pitch;
101 pitches[1] = (pitches[0] + 1) / 2;
102 pitches[2] = (pitches[0] + 1) / 2;
103 planes[0] = (
const Uint8 *)yuv;
104 planes[1] = planes[0] + pitches[0] *
height;
105 planes[2] = planes[1] + pitches[1] * ((height + 1) / 2);
110 pitches[0] = yuv_pitch;
111 planes[0] = (
const Uint8 *)yuv;
115 pitches[0] = yuv_pitch;
116 pitches[1] = 2 * ((pitches[0] + 1) / 2);
117 planes[0] = (
const Uint8 *)yuv;
118 planes[1] = planes[0] + pitches[0] *
height;
127 *y_stride = pitches[0];
130 *uv_stride = pitches[1];
134 *y_stride = pitches[0];
137 *uv_stride = pitches[1];
141 *y_stride = pitches[0];
144 *uv_stride = pitches[0];
148 *y_stride = pitches[0];
151 *uv_stride = pitches[0];
155 *y_stride = pitches[0];
158 *uv_stride = pitches[0];
162 *y_stride = pitches[0];
165 *uv_stride = pitches[1];
169 *y_stride = pitches[0];
172 *uv_stride = pitches[1];
196 switch (dst_format) {
198 yuv420_rgb565_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
201 yuv420_rgb24_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
205 yuv420_rgba_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
209 yuv420_bgra_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
213 yuv420_argb_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
217 yuv420_abgr_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
228 switch (dst_format) {
230 yuv422_rgb565_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
233 yuv422_rgb24_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
237 yuv422_rgba_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
241 yuv422_bgra_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
245 yuv422_argb_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
249 yuv422_abgr_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
259 switch (dst_format) {
261 yuvnv12_rgb565_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
264 yuvnv12_rgb24_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
268 yuvnv12_rgba_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
272 yuvnv12_bgra_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
276 yuvnv12_argb_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
280 yuvnv12_abgr_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
300 switch (dst_format) {
302 yuv420_rgb565_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
305 yuv420_rgb24_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
309 yuv420_rgba_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
313 yuv420_bgra_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
317 yuv420_argb_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
321 yuv420_abgr_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
332 switch (dst_format) {
334 yuv422_rgb565_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
337 yuv422_rgb24_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
341 yuv422_rgba_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
345 yuv422_bgra_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
349 yuv422_argb_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
353 yuv422_abgr_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
363 switch (dst_format) {
365 yuvnv12_rgb565_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
368 yuvnv12_rgb24_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
372 yuvnv12_rgba_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
376 yuvnv12_bgra_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
380 yuvnv12_argb_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
384 yuvnv12_abgr_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
395 Uint32 src_format,
const void *
src,
int src_pitch,
396 Uint32 dst_format,
void *
dst,
int dst_pitch)
405 if (
GetYUVPlanes(width, height, src_format, src, src_pitch, &y, &u, &v, &y_stride, &uv_stride) < 0) {
413 if (
yuv_rgb_sse(src_format, dst_format, width, height, y, u, v, y_stride, uv_stride, (
Uint8*)dst, dst_pitch, yuv_type)) {
417 if (
yuv_rgb_std(src_format, dst_format, width, height, y, u, v, y_stride, uv_stride, (
Uint8*)dst, dst_pitch, yuv_type)) {
425 int tmp_pitch = (width *
sizeof(
Uint32));
459 const int src_pitch_x_2 = src_pitch * 2;
460 const int height_half = height / 2;
461 const int height_remainder = (height & 0x1);
462 const int width_half = width / 2;
463 const int width_remainder = (width & 0x1);
466 static struct RGB2YUVFactors RGB2YUVFactorTables[SDL_YUV_CONVERSION_BT709 + 1] =
471 { 0.2990f, 0.5870f, 0.1140f },
472 { -0.1687f, -0.3313f, 0.5000f },
473 { 0.5000f, -0.4187f, -0.0813f },
478 { 0.2568f, 0.5041f, 0.0979f },
479 { -0.1482f, -0.2910f, 0.4392f },
480 { 0.4392f, -0.3678f, -0.0714f },
485 { 0.1826f, 0.6142f, 0.0620f },
486 {-0.1006f, -0.3386f, 0.4392f },
487 { 0.4392f, -0.3989f, -0.0403f },
492 #define MAKE_Y(r, g, b) (Uint8)((int)(cvt->y[0] * (r) + cvt->y[1] * (g) + cvt->y[2] * (b) + 0.5f) + cvt->y_offset) 493 #define MAKE_U(r, g, b) (Uint8)((int)(cvt->u[0] * (r) + cvt->u[1] * (g) + cvt->u[2] * (b) + 0.5f) + 128) 494 #define MAKE_V(r, g, b) (Uint8)((int)(cvt->v[0] * (r) + cvt->v[1] * (g) + cvt->v[2] * (b) + 0.5f) + 128) 496 #define READ_2x2_PIXELS \ 497 const Uint32 p1 = ((const Uint32 *)curr_row)[2 * i]; \ 498 const Uint32 p2 = ((const Uint32 *)curr_row)[2 * i + 1]; \ 499 const Uint32 p3 = ((const Uint32 *)next_row)[2 * i]; \ 500 const Uint32 p4 = ((const Uint32 *)next_row)[2 * i + 1]; \ 501 const Uint32 r = ((p1 & 0x00ff0000) + (p2 & 0x00ff0000) + (p3 & 0x00ff0000) + (p4 & 0x00ff0000)) >> 18; \ 502 const Uint32 g = ((p1 & 0x0000ff00) + (p2 & 0x0000ff00) + (p3 & 0x0000ff00) + (p4 & 0x0000ff00)) >> 10; \ 503 const Uint32 b = ((p1 & 0x000000ff) + (p2 & 0x000000ff) + (p3 & 0x000000ff) + (p4 & 0x000000ff)) >> 2; \ 505 #define READ_2x1_PIXELS \ 506 const Uint32 p1 = ((const Uint32 *)curr_row)[2 * i]; \ 507 const Uint32 p2 = ((const Uint32 *)next_row)[2 * i]; \ 508 const Uint32 r = ((p1 & 0x00ff0000) + (p2 & 0x00ff0000)) >> 17; \ 509 const Uint32 g = ((p1 & 0x0000ff00) + (p2 & 0x0000ff00)) >> 9; \ 510 const Uint32 b = ((p1 & 0x000000ff) + (p2 & 0x000000ff)) >> 1; \ 512 #define READ_1x2_PIXELS \ 513 const Uint32 p1 = ((const Uint32 *)curr_row)[2 * i]; \ 514 const Uint32 p2 = ((const Uint32 *)curr_row)[2 * i + 1]; \ 515 const Uint32 r = ((p1 & 0x00ff0000) + (p2 & 0x00ff0000)) >> 17; \ 516 const Uint32 g = ((p1 & 0x0000ff00) + (p2 & 0x0000ff00)) >> 9; \ 517 const Uint32 b = ((p1 & 0x000000ff) + (p2 & 0x000000ff)) >> 1; \ 519 #define READ_1x1_PIXEL \ 520 const Uint32 p = ((const Uint32 *)curr_row)[2 * i]; \ 521 const Uint32 r = (p & 0x00ff0000) >> 16; \ 522 const Uint32 g = (p & 0x0000ff00) >> 8; \ 523 const Uint32 b = (p & 0x000000ff); \ 525 #define READ_TWO_RGB_PIXELS \ 526 const Uint32 p = ((const Uint32 *)curr_row)[2 * i]; \ 527 const Uint32 r = (p & 0x00ff0000) >> 16; \ 528 const Uint32 g = (p & 0x0000ff00) >> 8; \ 529 const Uint32 b = (p & 0x000000ff); \ 530 const Uint32 p1 = ((const Uint32 *)curr_row)[2 * i + 1]; \ 531 const Uint32 r1 = (p1 & 0x00ff0000) >> 16; \ 532 const Uint32 g1 = (p1 & 0x0000ff00) >> 8; \ 533 const Uint32 b1 = (p1 & 0x000000ff); \ 534 const Uint32 R = (r + r1)/2; \ 535 const Uint32 G = (g + g1)/2; \ 536 const Uint32 B = (b + b1)/2; \ 538 #define READ_ONE_RGB_PIXEL READ_1x1_PIXEL 547 const Uint8 *curr_row, *next_row;
552 Uint8 *plane_interleaved_uv;
553 Uint32 y_stride, uv_stride, y_skip, uv_skip;
556 (
const Uint8 **)&plane_y, (
const Uint8 **)&plane_u, (
const Uint8 **)&plane_v,
557 &y_stride, &uv_stride);
558 plane_interleaved_uv = (plane_y + height * y_stride);
559 y_skip = (y_stride -
width);
561 curr_row = (
const Uint8*)src;
564 for (j = 0; j <
height; j++) {
565 for (i = 0; i <
width; i++) {
567 const Uint32 r = (p1 & 0x00ff0000) >> 16;
568 const Uint32 g = (p1 & 0x0000ff00) >> 8;
569 const Uint32 b = (p1 & 0x000000ff);
570 *plane_y++ =
MAKE_Y(r, g, b);
573 curr_row += src_pitch;
576 curr_row = (
const Uint8*)src;
577 next_row = (
const Uint8*)src;
578 next_row += src_pitch;
583 uv_skip = (uv_stride - (width + 1)/2);
584 for (j = 0; j < height_half; j++) {
585 for (i = 0; i < width_half; i++) {
590 if (width_remainder) {
597 curr_row += src_pitch_x_2;
598 next_row += src_pitch_x_2;
600 if (height_remainder) {
601 for (i = 0; i < width_half; i++) {
606 if (width_remainder) {
617 uv_skip = (uv_stride - ((width + 1)/2)*2);
618 for (j = 0; j < height_half; j++) {
619 for (i = 0; i < width_half; i++) {
621 *plane_interleaved_uv++ =
MAKE_U(
r,
g,
b);
622 *plane_interleaved_uv++ =
MAKE_V(
r,
g,
b);
624 if (width_remainder) {
626 *plane_interleaved_uv++ =
MAKE_U(
r,
g,
b);
627 *plane_interleaved_uv++ =
MAKE_V(
r,
g,
b);
629 plane_interleaved_uv += uv_skip;
630 curr_row += src_pitch_x_2;
631 next_row += src_pitch_x_2;
633 if (height_remainder) {
634 for (i = 0; i < width_half; i++) {
636 *plane_interleaved_uv++ =
MAKE_U(
r,
g,
b);
637 *plane_interleaved_uv++ =
MAKE_V(
r,
g,
b);
639 if (width_remainder) {
641 *plane_interleaved_uv++ =
MAKE_U(
r,
g,
b);
642 *plane_interleaved_uv++ =
MAKE_V(
r,
g,
b);
648 uv_skip = (uv_stride - ((width + 1)/2)*2);
649 for (j = 0; j < height_half; j++) {
650 for (i = 0; i < width_half; i++) {
652 *plane_interleaved_uv++ =
MAKE_V(
r,
g,
b);
653 *plane_interleaved_uv++ =
MAKE_U(
r,
g,
b);
655 if (width_remainder) {
657 *plane_interleaved_uv++ =
MAKE_V(
r,
g,
b);
658 *plane_interleaved_uv++ =
MAKE_U(
r,
g,
b);
660 plane_interleaved_uv += uv_skip;
661 curr_row += src_pitch_x_2;
662 next_row += src_pitch_x_2;
664 if (height_remainder) {
665 for (i = 0; i < width_half; i++) {
667 *plane_interleaved_uv++ =
MAKE_V(
r,
g,
b);
668 *plane_interleaved_uv++ =
MAKE_U(
r,
g,
b);
670 if (width_remainder) {
672 *plane_interleaved_uv++ =
MAKE_V(
r,
g,
b);
673 *plane_interleaved_uv++ =
MAKE_U(
r,
g,
b);
686 const int row_size = (4 * ((width + 1) / 2));
689 if (dst_pitch < row_size) {
690 return SDL_SetError(
"Destination pitch is too small, expected at least %d\n", row_size);
692 plane_skip = (dst_pitch - row_size);
697 for (j = 0; j <
height; j++) {
698 for (i = 0; i < width_half; i++) {
703 *plane++ =
MAKE_Y(r1, g1, b1);
706 if (width_remainder) {
715 curr_row += src_pitch;
720 for (j = 0; j <
height; j++) {
721 for (i = 0; i < width_half; i++) {
727 *plane++ =
MAKE_Y(r1, g1, b1);
729 if (width_remainder) {
738 curr_row += src_pitch;
743 for (j = 0; j <
height; j++) {
744 for (i = 0; i < width_half; i++) {
749 *plane++ =
MAKE_Y(r1, g1, b1);
752 if (width_remainder) {
761 curr_row += src_pitch;
773 #undef READ_2x2_PIXELS 774 #undef READ_2x1_PIXELS 775 #undef READ_1x2_PIXELS 776 #undef READ_1x1_PIXEL 777 #undef READ_TWO_RGB_PIXELS 778 #undef READ_ONE_RGB_PIXEL 784 Uint32 src_format,
const void *
src,
int src_pitch,
785 Uint32 dst_format,
void *
dst,
int dst_pitch)
797 if (
GetYUVPlanes(width, height, dst_format, dst, dst_pitch, (
const Uint8 **)&y, (
const Uint8 **)&u, (
const Uint8 **)&v, &y_stride, &uv_stride) < 0) {
805 rgb24_yuv420_std(width, height, src, src_pitch, y, u, v, y_stride, uv_stride, yuv_type);
819 int tmp_pitch = (width *
sizeof(
Uint32));
842 const void *
src,
int src_pitch,
void *
dst,
int dst_pitch)
848 for (i = height; i--;) {
850 src = (
const Uint8*)src + src_pitch;
851 dst = (
Uint8*)dst + dst_pitch;
856 width = (width + 1) / 2;
857 height = (height + 1) / 2;
858 src_pitch = (src_pitch + 1) / 2;
859 dst_pitch = (dst_pitch + 1) / 2;
860 for (i = height * 2; i--;) {
862 src = (
const Uint8*)src + src_pitch;
863 dst = (
Uint8*)dst + dst_pitch;
867 height = (height + 1) / 2;
868 width = ((width + 1) / 2)*2;
869 src_pitch = ((src_pitch + 1) / 2)*2;
870 dst_pitch = ((dst_pitch + 1) / 2)*2;
871 for (i = height; i--;) {
873 src = (
const Uint8*)src + src_pitch;
874 dst = (
Uint8*)dst + dst_pitch;
882 width = 4 * ((width + 1) / 2);
883 for (i = height; i--;) {
885 src = (
const Uint8*)src + src_pitch;
886 dst = (
Uint8*)dst + dst_pitch;
898 const int UVwidth = (width + 1)/2;
899 const int UVheight = (height + 1)/2;
902 src = (
const Uint8 *)src + height * src_pitch;
903 dst = (
Uint8 *)dst + height * dst_pitch;
906 int UVpitch = (dst_pitch + 1)/2;
909 Uint8 *row2 = (
Uint8 *)dst + UVheight * UVpitch;
916 for (y = 0; y < UVheight; ++
y) {
927 int srcUVPitch = ((src_pitch + 1)/2);
928 int dstUVPitch = ((dst_pitch + 1)/2);
931 srcUV = (
const Uint8 *)src;
932 dstUV = (
Uint8 *)dst + UVheight * dstUVPitch;
933 for (y = 0; y < UVheight; ++
y) {
940 dstUV = (
Uint8 *)dst;
941 for (y = 0; y < UVheight; ++
y) {
954 const int UVwidth = (width + 1)/2;
955 const int UVheight = (height + 1)/2;
956 const int srcUVPitch = ((src_pitch + 1)/2);
957 const int srcUVPitchLeft = srcUVPitch - UVwidth;
958 const int dstUVPitch = ((dst_pitch + 1)/2)*2;
959 const int dstUVPitchLeft = dstUVPitch - UVwidth*2;
960 const Uint8 *src1, *src2;
968 src = (
const Uint8 *)src + height * src_pitch;
969 dst = (
Uint8 *)dst + height * dst_pitch;
982 src2 = (
const Uint8 *)src;
983 src1 = src2 + UVheight * srcUVPitch;
985 src1 = (
const Uint8 *)src;
986 src2 = src1 + UVheight * srcUVPitch;
988 dstUV = (
Uint8 *)dst;
996 __m128i
u = _mm_loadu_si128((__m128i *)src1);
997 __m128i
v = _mm_loadu_si128((__m128i *)src2);
998 __m128i uv1 = _mm_unpacklo_epi8(u, v);
999 __m128i uv2 = _mm_unpackhi_epi8(u, v);
1000 _mm_storeu_si128((__m128i*)dstUV, uv1);
1001 _mm_storeu_si128((__m128i*)(dstUV + 16), uv2);
1013 src1 += srcUVPitchLeft;
1014 src2 += srcUVPitchLeft;
1015 dstUV += dstUVPitchLeft;
1028 const int UVwidth = (width + 1)/2;
1029 const int UVheight = (height + 1)/2;
1030 const int srcUVPitch = ((src_pitch + 1)/2)*2;
1031 const int srcUVPitchLeft = srcUVPitch - UVwidth*2;
1032 const int dstUVPitch = ((dst_pitch + 1)/2);
1033 const int dstUVPitchLeft = dstUVPitch - UVwidth;
1042 src = (
const Uint8 *)src + height * src_pitch;
1043 dst = (
Uint8 *)dst + height * dst_pitch;
1056 dst2 = (
Uint8 *)dst;
1057 dst1 = dst2 + UVheight * dstUVPitch;
1059 dst1 = (
Uint8 *)dst;
1060 dst2 = dst1 + UVheight * dstUVPitch;
1062 srcUV = (
const Uint8 *)src;
1069 __m128i
mask = _mm_set1_epi16(0x00FF);
1071 __m128i uv1 = _mm_loadu_si128((__m128i*)srcUV);
1072 __m128i uv2 = _mm_loadu_si128((__m128i*)(srcUV+16));
1073 __m128i
u1 = _mm_and_si128(uv1, mask);
1074 __m128i
u2 = _mm_and_si128(uv2, mask);
1075 __m128i
u = _mm_packus_epi16(u1, u2);
1076 __m128i
v1 = _mm_srli_epi16(uv1, 8);
1077 __m128i
v2 = _mm_srli_epi16(uv2, 8);
1078 __m128i
v = _mm_packus_epi16(v1, v2);
1079 _mm_storeu_si128((__m128i*)dst1, u);
1080 _mm_storeu_si128((__m128i*)dst2, v);
1092 srcUV += srcUVPitchLeft;
1093 dst1 += dstUVPitchLeft;
1094 dst2 += dstUVPitchLeft;
1107 const int UVwidth = (width + 1)/2;
1108 const int UVheight = (height + 1)/2;
1109 const int srcUVPitch = ((src_pitch + 1)/2)*2;
1110 const int srcUVPitchLeft = (srcUVPitch - UVwidth*2)/
sizeof(
Uint16);
1111 const int dstUVPitch = ((dst_pitch + 1)/2)*2;
1112 const int dstUVPitchLeft = (dstUVPitch - UVwidth*2)/
sizeof(
Uint16);
1120 src = (
const Uint8 *)src + height * src_pitch;
1121 dst = (
Uint8 *)dst + height * dst_pitch;
1123 srcUV = (
const Uint16 *)src;
1131 __m128i uv = _mm_loadu_si128((__m128i*)srcUV);
1132 __m128i
v = _mm_slli_epi16(uv, 8);
1133 __m128i
u = _mm_srli_epi16(uv, 8);
1134 __m128i vu = _mm_or_si128(v, u);
1135 _mm_storeu_si128((__m128i*)dstUV, vu);
1145 srcUV += srcUVPitchLeft;
1146 dstUV += dstUVPitchLeft;
1153 Uint32 src_format,
const void *
src,
int src_pitch,
1154 Uint32 dst_format,
void *
dst,
int dst_pitch)
1161 for (i = height; i--; ) {
1168 switch (src_format) {
1170 switch (dst_format) {
1182 switch (dst_format) {
1194 switch (dst_format) {
1206 switch (dst_format) {
1223 #define PACKED4_TO_PACKED4_ROW_SSE2(shuffle) \ 1225 __m128i yuv = _mm_loadu_si128((__m128i*)srcYUV); \ 1226 __m128i lo = _mm_unpacklo_epi8(yuv, _mm_setzero_si128()); \ 1227 __m128i hi = _mm_unpackhi_epi8(yuv, _mm_setzero_si128()); \ 1228 lo = _mm_shufflelo_epi16(lo, shuffle); \ 1229 lo = _mm_shufflehi_epi16(lo, shuffle); \ 1230 hi = _mm_shufflelo_epi16(hi, shuffle); \ 1231 hi = _mm_shufflehi_epi16(hi, shuffle); \ 1232 yuv = _mm_packus_epi16(lo, hi); \ 1233 _mm_storeu_si128((__m128i*)dstYUV, yuv); \ 1243 const int YUVwidth = (width + 1)/2;
1244 const int srcYUVPitchLeft = (src_pitch - YUVwidth*4);
1245 const int dstYUVPitchLeft = (dst_pitch - YUVwidth*4);
1275 srcYUV += srcYUVPitchLeft;
1276 dstYUV += dstYUVPitchLeft;
1285 const int YUVwidth = (width + 1)/2;
1286 const int srcYUVPitchLeft = (src_pitch - YUVwidth*4);
1287 const int dstYUVPitchLeft = (dst_pitch - YUVwidth*4);
1317 srcYUV += srcYUVPitchLeft;
1318 dstYUV += dstYUVPitchLeft;
1327 const int YUVwidth = (width + 1)/2;
1328 const int srcYUVPitchLeft = (src_pitch - YUVwidth*4);
1329 const int dstYUVPitchLeft = (dst_pitch - YUVwidth*4);
1359 srcYUV += srcYUVPitchLeft;
1360 dstYUV += dstYUVPitchLeft;
1369 const int YUVwidth = (width + 1)/2;
1370 const int srcYUVPitchLeft = (src_pitch - YUVwidth*4);
1371 const int dstYUVPitchLeft = (dst_pitch - YUVwidth*4);
1401 srcYUV += srcYUVPitchLeft;
1402 dstYUV += dstYUVPitchLeft;
1411 const int YUVwidth = (width + 1)/2;
1412 const int srcYUVPitchLeft = (src_pitch - YUVwidth*4);
1413 const int dstYUVPitchLeft = (dst_pitch - YUVwidth*4);
1443 srcYUV += srcYUVPitchLeft;
1444 dstYUV += dstYUVPitchLeft;
1453 const int YUVwidth = (width + 1)/2;
1454 const int srcYUVPitchLeft = (src_pitch - YUVwidth*4);
1455 const int dstYUVPitchLeft = (dst_pitch - YUVwidth*4);
1485 srcYUV += srcYUVPitchLeft;
1486 dstYUV += dstYUVPitchLeft;
1493 Uint32 src_format,
const void *
src,
int src_pitch,
1494 Uint32 dst_format,
void *
dst,
int dst_pitch)
1496 switch (src_format) {
1498 switch (dst_format) {
1508 switch (dst_format) {
1518 switch (dst_format) {
1535 Uint32 src_format,
const void *
src,
int src_pitch,
1536 Uint32 dst_format,
void *
dst,
int dst_pitch)
1540 Uint32 srcY_pitch, srcUV_pitch;
1541 Uint32 srcY_pitch_left, srcUV_pitch_left, srcUV_pixel_stride;
1542 Uint8 *
dstY1, *dstY2, *dstU1, *dstU2, *dstV1, *dstV2;
1543 Uint32 dstY_pitch, dstUV_pitch;
1547 return SDL_SetError(
"Can't change YUV plane types in-place");
1550 if (
GetYUVPlanes(width, height, src_format, src, src_pitch,
1551 &srcY1, &srcU, &srcV, &srcY_pitch, &srcUV_pitch) < 0) {
1554 srcY2 = srcY1 + srcY_pitch;
1555 srcY_pitch_left = (srcY_pitch -
width);
1558 srcUV_pixel_stride = 2;
1559 srcUV_pitch_left = (srcUV_pitch - 2*((width + 1)/2));
1561 srcUV_pixel_stride = 1;
1562 srcUV_pitch_left = (srcUV_pitch - ((width + 1)/2));
1565 if (
GetYUVPlanes(width, height, dst_format, dst, dst_pitch,
1567 &dstY_pitch, &dstUV_pitch) < 0) {
1570 dstY2 = dstY1 + dstY_pitch;
1571 dstU2 = dstU1 + dstUV_pitch;
1572 dstV2 = dstV1 + dstUV_pitch;
1573 dst_pitch_left = (dstY_pitch - 4*((width + 1)/2));
1576 for (y = 0; y < (height - 1); y += 2) {
1577 for (x = 0; x < (width - 1); x += 2) {
1594 srcU += srcUV_pixel_stride;
1595 srcV += srcUV_pixel_stride;
1603 if (x == (width - 1)) {
1620 srcU += srcUV_pixel_stride;
1621 srcV += srcUV_pixel_stride;
1628 srcY1 += srcY_pitch_left + srcY_pitch;
1629 srcY2 += srcY_pitch_left + srcY_pitch;
1630 srcU += srcUV_pitch_left;
1631 srcV += srcUV_pitch_left;
1632 dstY1 += dst_pitch_left + dstY_pitch;
1633 dstY2 += dst_pitch_left + dstY_pitch;
1634 dstU1 += dst_pitch_left + dstUV_pitch;
1635 dstU2 += dst_pitch_left + dstUV_pitch;
1636 dstV1 += dst_pitch_left + dstUV_pitch;
1637 dstV2 += dst_pitch_left + dstUV_pitch;
1641 if (y == (height - 1)) {
1642 for (x = 0; x < (width - 1); x += 2) {
1651 srcU += srcUV_pixel_stride;
1652 srcV += srcUV_pixel_stride;
1658 if (x == (width - 1)) {
1667 srcU += srcUV_pixel_stride;
1668 srcV += srcUV_pixel_stride;
1678 Uint32 src_format,
const void *
src,
int src_pitch,
1679 Uint32 dst_format,
void *
dst,
int dst_pitch)
1682 const Uint8 *
srcY1, *srcY2, *srcU1, *srcU2, *srcV1, *srcV2;
1683 Uint32 srcY_pitch, srcUV_pitch;
1686 Uint32 dstY_pitch, dstUV_pitch;
1687 Uint32 dstY_pitch_left, dstUV_pitch_left, dstUV_pixel_stride;
1690 return SDL_SetError(
"Can't change YUV plane types in-place");
1693 if (
GetYUVPlanes(width, height, src_format, src, src_pitch,
1694 &srcY1, &srcU1, &srcV1, &srcY_pitch, &srcUV_pitch) < 0) {
1697 srcY2 = srcY1 + srcY_pitch;
1698 srcU2 = srcU1 + srcUV_pitch;
1699 srcV2 = srcV1 + srcUV_pitch;
1700 src_pitch_left = (srcY_pitch - 4*((width + 1)/2));
1702 if (
GetYUVPlanes(width, height, dst_format, dst, dst_pitch,
1704 &dstY_pitch, &dstUV_pitch) < 0) {
1707 dstY2 = dstY1 + dstY_pitch;
1708 dstY_pitch_left = (dstY_pitch -
width);
1711 dstUV_pixel_stride = 2;
1712 dstUV_pitch_left = (dstUV_pitch - 2*((width + 1)/2));
1714 dstUV_pixel_stride = 1;
1715 dstUV_pitch_left = (dstUV_pitch - ((width + 1)/2));
1719 for (y = 0; y < (height - 1); y += 2) {
1720 for (x = 0; x < (width - 1); x += 2) {
1740 dstU += dstUV_pixel_stride;
1741 dstV += dstUV_pixel_stride;
1745 if (x == (width - 1)) {
1765 dstU += dstUV_pixel_stride;
1766 dstV += dstUV_pixel_stride;
1769 srcY1 += src_pitch_left + srcY_pitch;
1770 srcY2 += src_pitch_left + srcY_pitch;
1771 srcU1 += src_pitch_left + srcUV_pitch;
1772 srcU2 += src_pitch_left + srcUV_pitch;
1773 srcV1 += src_pitch_left + srcUV_pitch;
1774 srcV2 += src_pitch_left + srcUV_pitch;
1775 dstY1 += dstY_pitch_left + dstY_pitch;
1776 dstY2 += dstY_pitch_left + dstY_pitch;
1777 dstU += dstUV_pitch_left;
1778 dstV += dstUV_pitch_left;
1782 if (y == (height - 1)) {
1783 for (x = 0; x < (width - 1); x += 2) {
1794 dstU += dstUV_pixel_stride;
1795 dstV += dstUV_pixel_stride;
1799 if (x == (width - 1)) {
1810 Uint32 src_format,
const void *
src,
int src_pitch,
1811 Uint32 dst_format,
void *
dst,
int dst_pitch)
1813 if (src_format == dst_format) {
void SDL_SetYUVConversionMode(SDL_YUV_CONVERSION_MODE mode)
Set the YUV conversion mode.
void yuv420_rgb565_sseu(uint32_t width, uint32_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type)
int SDL_ConvertPixels_YUV_to_YUV(int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch)
void yuvnv12_rgb565_std(uint32_t width, uint32_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type)
void yuv422_rgb565_sseu(uint32_t width, uint32_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type)
GLdouble GLdouble GLdouble r
void yuv422_rgb24_std(uint32_t width, uint32_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type)
SDL_YUV_CONVERSION_MODE SDL_GetYUVConversionModeForResolution(int width, int height)
Get the YUV conversion mode, returning the correct mode for the resolution when the current conversio...
static int SDL_ConvertPixels_YUY2_to_YVYU(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
static int SDL_ConvertPixels_Planar2x2_to_Packed4(int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch)
static int SDL_ConvertPixels_SwapNV(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
static SDL_bool IsPacked4Format(Uint32 format)
SDL_YUV_CONVERSION_MODE
The formula used for converting between YUV and RGB.
static int SDL_ConvertPixels_Packed4_to_Planar2x2(int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch)
GLint GLint GLint GLint GLint x
GLenum GLint GLint GLint GLint GLuint GLenum GLint GLint GLint dstY
static int SDL_ConvertPixels_YUY2_to_UYVY(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
void yuv420_rgb24_sseu(uint32_t width, uint32_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type)
static int SDL_ConvertPixels_SplitNV_to_UVPlanes(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch, SDL_bool reverseUV)
void yuvnv12_bgra_sseu(uint32_t width, uint32_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type)
static SDL_bool yuv_rgb_std(Uint32 src_format, Uint32 dst_format, Uint32 width, Uint32 height, const Uint8 *y, const Uint8 *u, const Uint8 *v, Uint32 y_stride, Uint32 uv_stride, Uint8 *rgb, Uint32 rgb_stride, YCbCrType yuv_type)
void yuv420_argb_sseu(uint32_t width, uint32_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type)
void yuv422_abgr_std(uint32_t width, uint32_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type)
void rgb24_yuv420_std(uint32_t width, uint32_t height, const uint8_t *RGB, uint32_t RGB_stride, uint8_t *Y, uint8_t *U, uint8_t *V, uint32_t Y_stride, uint32_t UV_stride, YCbCrType yuv_type)
void yuv420_rgba_sseu(uint32_t width, uint32_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type)
static int GetYUVPlanes(int width, int height, Uint32 format, const void *yuv, int yuv_pitch, const Uint8 **y, const Uint8 **u, const Uint8 **v, Uint32 *y_stride, Uint32 *uv_stride)
void yuvnv12_abgr_sseu(uint32_t width, uint32_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type)
void yuv422_argb_sseu(uint32_t width, uint32_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type)
int SDL_ConvertPixels_YUV_to_RGB(int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch)
GLint GLint GLsizei width
void yuv422_rgb24_sseu(uint32_t width, uint32_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type)
static int SDL_ConvertPixels_YVYU_to_YUY2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
GLenum GLint GLint GLint srcY
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
void yuvnv12_rgba_sseu(uint32_t width, uint32_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type)
#define PACKED4_TO_PACKED4_ROW_SSE2(shuffle)
GLfloat GLfloat GLfloat v2
static int SDL_ConvertPixels_ARGB8888_to_YUV(int width, int height, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch)
void yuv422_argb_std(uint32_t width, uint32_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type)
void yuv420_rgba_std(uint32_t width, uint32_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type)
static int SDL_ConvertPixels_SwapUVPlanes(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
void yuvnv12_argb_std(uint32_t width, uint32_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type)
void yuv422_rgb565_std(uint32_t width, uint32_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type)
static int GetYUVConversionType(int width, int height, YCbCrType *yuv_type)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int int in j)
void yuv420_abgr_std(uint32_t width, uint32_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type)
SDL_FORCE_INLINE Uint16 SDL_Swap16(Uint16 x)
static SDL_bool yuv_rgb_sse(Uint32 src_format, Uint32 dst_format, Uint32 width, Uint32 height, const Uint8 *y, const Uint8 *u, const Uint8 *v, Uint32 y_stride, Uint32 uv_stride, Uint8 *rgb, Uint32 rgb_stride, YCbCrType yuv_type)
void yuvnv12_rgb24_std(uint32_t width, uint32_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type)
void yuv420_abgr_sseu(uint32_t width, uint32_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type)
static SDL_bool IsPlanar2x2Format(Uint32 format)
void yuv420_rgb24_std(uint32_t width, uint32_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type)
GLint GLint GLint GLint GLint GLint y
#define READ_TWO_RGB_PIXELS
void yuv420_argb_std(uint32_t width, uint32_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type)
void yuv422_rgba_sseu(uint32_t width, uint32_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type)
void yuvnv12_bgra_std(uint32_t width, uint32_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type)
static SDL_YUV_CONVERSION_MODE SDL_YUV_ConversionMode
static int SDL_ConvertPixels_UYVY_to_YUY2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
void yuvnv12_argb_sseu(uint32_t width, uint32_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type)
#define SDL_OutOfMemory()
#define READ_ONE_RGB_PIXEL
void yuv420_bgra_std(uint32_t width, uint32_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type)
void yuvnv12_rgb565_sseu(uint32_t width, uint32_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type)
void yuv422_bgra_sseu(uint32_t width, uint32_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type)
GLint GLint GLsizei GLsizei height
#define SDL_YUV_SD_THRESHOLD
static int SDL_ConvertPixels_Packed4_to_Packed4(int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch)
void yuvnv12_abgr_std(uint32_t width, uint32_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type)
static int SDL_ConvertPixels_UYVY_to_YVYU(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
void yuv420_bgra_sseu(uint32_t width, uint32_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type)
void yuv422_rgba_std(uint32_t width, uint32_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type)
static int SDL_ConvertPixels_PackUVPlanes_to_NV(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch, SDL_bool reverseUV)
void yuv420_rgb565_std(uint32_t width, uint32_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type)
#define SDL_ConvertPixels
void yuv422_abgr_sseu(uint32_t width, uint32_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type)
static int SDL_ConvertPixels_YVYU_to_UYVY(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
int SDL_ConvertPixels_RGB_to_YUV(int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch)
static int SDL_ConvertPixels_Planar2x2_to_Planar2x2(int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch)
SDL_YUV_CONVERSION_MODE SDL_GetYUVConversionMode()
Get the YUV conversion mode.
void yuvnv12_rgba_std(uint32_t width, uint32_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type)
GLboolean GLboolean GLboolean b
void yuvnv12_rgb24_sseu(uint32_t width, uint32_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type)
static int SDL_ConvertPixels_YUV_to_YUV_Copy(int width, int height, Uint32 format, const void *src, int src_pitch, void *dst, int dst_pitch)
void yuv422_bgra_std(uint32_t width, uint32_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type)
GLint GLint GLint GLint GLint GLint GLint dstY1
#define SDL_GetPixelFormatName