1 // Copyright (c) 2012-2018 Intel Corporation
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in all
11 // copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 // SOFTWARE.
20
21 #include <cm/cm.h>
22
23 typedef unsigned char uint1; // unsigned byte
24 typedef char int1; // byte
25
26 extern "C" _GENX_MAIN_ void
MbCopyFieLd(SurfaceIndex InSurfIndex,SurfaceIndex OutSurfIndex,int fieldMask)27 MbCopyFieLd(SurfaceIndex InSurfIndex, SurfaceIndex OutSurfIndex, int fieldMask)
28 {
29 // Luma only
30 uint mbX = get_thread_origin_x();
31 uint mbY = get_thread_origin_y();
32 uint ix = mbX << 4; // 16x16
33 uint iy = mbY << 4;
34
35 if (fieldMask > 5) {
36 matrix<uint1,16,16> inMbY0;
37 matrix<uint1,16,16> inMbY1;
38 matrix<uint1,16,16> outMbY;
39 matrix<uint1,16,16> inMbUV;
40 matrix<uint1,8,16> outMbUV;
41
42 read_plane(InSurfIndex, GENX_SURFACE_Y_PLANE, ix, iy * 2, inMbY0);
43 read_plane(InSurfIndex, GENX_SURFACE_Y_PLANE, ix, iy * 2 + 16, inMbY1);
44 read_plane(InSurfIndex, GENX_SURFACE_UV_PLANE, ix, iy, inMbUV);
45
46 switch (fieldMask)
47 {
48 case 0x6: // TFF2FIELD
49 outMbY.select<8,1,16,1>(0,0) = inMbY0.select<8,2,16,1>(0,0);
50 outMbY.select<8,1,16,1>(8,0) = inMbY1.select<8,2,16,1>(0,0);
51 outMbUV.select<8,1,16,1>(0,0) = inMbUV.select<8,2,16,1>(0,0);
52 break;
53 case 0x7: // BFF2FIELD
54 outMbY.select<8,1,16,1>(0,0) = inMbY0.select<8,2,16,1>(1,0);
55 outMbY.select<8,1,16,1>(8,0) = inMbY1.select<8,2,16,1>(1,0);
56 outMbUV.select<8,1,16,1>(0,0) = inMbUV.select<8,2,16,1>(1,0);
57 break;
58 default:
59 return;
60 }
61
62 write_plane(OutSurfIndex, GENX_SURFACE_Y_PLANE, ix, iy, outMbY);
63 write_plane(OutSurfIndex, GENX_SURFACE_UV_PLANE, ix, iy / 2, outMbUV);
64 } else if (fieldMask > 3) {
65 matrix<uint1,16,16> inMbY;
66 matrix<uint1,16,16> outMbY0;
67 matrix<uint1,16,16> outMbY1;
68 matrix<uint1,8,16> inMbUV;
69 matrix<uint1,16,16> outMbUV;
70
71 read_plane(InSurfIndex, GENX_SURFACE_Y_PLANE, ix, iy, inMbY);
72 read_plane(OutSurfIndex, GENX_SURFACE_Y_PLANE, ix, iy * 2, outMbY0);
73 read_plane(OutSurfIndex, GENX_SURFACE_Y_PLANE, ix, iy * 2 + 16, outMbY1);
74 read_plane(InSurfIndex, GENX_SURFACE_UV_PLANE, ix, iy / 2, inMbUV);
75 read_plane(OutSurfIndex, GENX_SURFACE_UV_PLANE, ix, iy, outMbUV);
76
77 switch (fieldMask)
78 {
79 case 0x4: // FIELD2TFF
80 outMbY0.select<8,2,16,1>(0,0) = inMbY.select<8,1,16,1>(0,0);
81 outMbY1.select<8,2,16,1>(0,0) = inMbY.select<8,1,16,1>(8,0);
82 outMbUV.select<8,2,16,1>(0,0) = inMbUV.select<8,1,16,1>(0,0);
83 break;
84 case 0x5: // FIELD2BFF
85 outMbY0.select<8,2,16,1>(1,0) = inMbY.select<8,1,16,1>(0,0);
86 outMbY1.select<8,2,16,1>(1,0) = inMbY.select<8,1,16,1>(8,0);
87 outMbUV.select<8,2,16,1>(1,0) = inMbUV.select<8,1,16,1>(0,0);
88 break;
89 }
90
91 write_plane(OutSurfIndex, GENX_SURFACE_Y_PLANE, ix, iy * 2, outMbY0);
92 write_plane(OutSurfIndex, GENX_SURFACE_Y_PLANE, ix, iy * 2 + 16, outMbY1);
93 write_plane(OutSurfIndex, GENX_SURFACE_UV_PLANE, ix, iy, outMbUV);
94 } else {
95 matrix<uint1,16,16> inMbY;
96 matrix<uint1,16,16> outMbY;
97 matrix<uint1,8,16> inMbUV;
98 matrix<uint1,8,16> outMbUV;
99
100 read_plane(InSurfIndex, GENX_SURFACE_Y_PLANE, ix, iy, inMbY);
101 read_plane(OutSurfIndex, GENX_SURFACE_Y_PLANE, ix, iy, outMbY);
102 read_plane(InSurfIndex, GENX_SURFACE_UV_PLANE, ix, iy / 2, inMbUV);
103 read_plane(OutSurfIndex, GENX_SURFACE_UV_PLANE, ix, iy / 2, outMbUV);
104
105 switch (fieldMask)
106 {
107 case 0x0: // TFF2TFF
108 outMbY.select<8,2,16,1>(0,0) = inMbY.select<8,2,16,1>(0,0);
109 outMbUV.select<4,2,16,1>(0,0) = inMbUV.select<4,2,16,1>(0,0);
110 break;
111 case 0x1: // TFF2BFF
112 outMbY.select<8,2,16,1>(1,0) = inMbY.select<8,2,16,1>(0,0);
113 outMbUV.select<4,2,16,1>(1,0) = inMbUV.select<4,2,16,1>(0,0);
114 break;
115 case 0x2: // BFF2TFF
116 outMbY.select<8,2,16,1>(0,0) = inMbY.select<8,2,16,1>(1,0);
117 outMbUV.select<4,2,16,1>(0,0) = inMbUV.select<4,2,16,1>(1,0);
118 break;
119 case 0x3: // BTFF2BFF
120 outMbY.select<8,2,16,1>(1,0) = inMbY.select<8,2,16,1>(1,0);
121 outMbUV.select<4,2,16,1>(1,0) = inMbUV.select<4,2,16,1>(1,0);
122 break;
123 default:
124 return;
125 }
126
127 write_plane(OutSurfIndex, GENX_SURFACE_Y_PLANE, ix, iy, outMbY);
128 write_plane(OutSurfIndex, GENX_SURFACE_UV_PLANE, ix, iy / 2, outMbUV);
129 }
130 }
131