1 /*
2 * Copyright (C) 2004-2019 the xine project
3 *
4 * This file is part of xine, a free video player.
5 *
6 * xine is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * xine is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 *
20 * $Id:
21 *
22 */
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include <xine/xineutils.h>
29
_copy_plane(uint8_t * restrict dst,const uint8_t * restrict src,int dst_pitch,int src_pitch,int width,int height)30 static void _copy_plane(uint8_t *restrict dst, const uint8_t *restrict src,
31 int dst_pitch, int src_pitch,
32 int width, int height)
33 {
34 if (src_pitch == dst_pitch) {
35 xine_fast_memcpy(dst, src, src_pitch * height);
36 } else {
37 int y;
38
39 for (y = 0; y < height; y++) {
40 xine_fast_memcpy(dst, src, width);
41 src += src_pitch;
42 dst += dst_pitch;
43 }
44 }
45 }
46
yv12_to_yv12(const unsigned char * y_src,int y_src_pitch,unsigned char * y_dst,int y_dst_pitch,const unsigned char * u_src,int u_src_pitch,unsigned char * u_dst,int u_dst_pitch,const unsigned char * v_src,int v_src_pitch,unsigned char * v_dst,int v_dst_pitch,int width,int height)47 void yv12_to_yv12
48 (const unsigned char *y_src, int y_src_pitch, unsigned char *y_dst, int y_dst_pitch,
49 const unsigned char *u_src, int u_src_pitch, unsigned char *u_dst, int u_dst_pitch,
50 const unsigned char *v_src, int v_src_pitch, unsigned char *v_dst, int v_dst_pitch,
51 int width, int height) {
52
53 _copy_plane(y_dst, y_src, y_dst_pitch, y_src_pitch, width, height);
54 _copy_plane(u_dst, u_src, u_dst_pitch, u_src_pitch, width/2, height/2);
55 _copy_plane(v_dst, v_src, v_dst_pitch, v_src_pitch, width/2, height/2);
56 }
57
yuy2_to_yuy2(const unsigned char * src,int src_pitch,unsigned char * dst,int dst_pitch,int width,int height)58 void yuy2_to_yuy2
59 (const unsigned char *src, int src_pitch,
60 unsigned char *dst, int dst_pitch,
61 int width, int height) {
62
63 _copy_plane(dst, src, dst_pitch, src_pitch, width*2, height);
64 }
65
_x_nv12_to_yv12(const uint8_t * restrict y_src,int y_src_pitch,const uint8_t * restrict uv_src,int uv_src_pitch,uint8_t * restrict y_dst,int y_dst_pitch,uint8_t * restrict u_dst,int u_dst_pitch,uint8_t * restrict v_dst,int v_dst_pitch,int width,int height)66 void _x_nv12_to_yv12(const uint8_t *restrict y_src, int y_src_pitch,
67 const uint8_t *restrict uv_src, int uv_src_pitch,
68 uint8_t *restrict y_dst, int y_dst_pitch,
69 uint8_t *restrict u_dst, int u_dst_pitch,
70 uint8_t *restrict v_dst, int v_dst_pitch,
71 int width, int height) {
72
73 int y, x;
74
75 _copy_plane(y_dst, y_src, y_dst_pitch, y_src_pitch, width, height);
76
77 for (y = 0; y < height / 2; y++) {
78 for (x = 0; x < width / 2; x++) {
79 u_dst[x] = uv_src[2*x];
80 v_dst[x] = uv_src[2*x + 1];
81 }
82 uv_src += uv_src_pitch;
83 u_dst += u_dst_pitch;
84 v_dst += v_dst_pitch;
85 }
86 }
87
88