1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
|
/*
* Copyright@ Samsung Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __SAMSUNG_SYSLSI_SEC_COMMON_H__
#define __SAMSUNG_SYSLSI_SEC_COMMON_H__
//---------------------------------------------------------//
// Include
//---------------------------------------------------------//
#include <hardware/hardware.h>
#include "sec_format.h"
#ifdef __cplusplus
extern "C" {
#endif
#include <linux/videodev2.h>
#ifdef __cplusplus
}
#endif
//---------------------------------------------------------//
// Common structure //
//---------------------------------------------------------//
struct ADDRS {
unsigned int addr_y;
unsigned int addr_cbcr;
unsigned int buf_idx;
unsigned int reserved;
};
//---------------------------------------------------------//
// Common function //
//---------------------------------------------------------//
inline int HAL_PIXEL_FORMAT_2_V4L2_PIX(int HAL_PIXEL_FORMAT)
{
int V4L2_PIX = -1;
switch (HAL_PIXEL_FORMAT) {
case HAL_PIXEL_FORMAT_RGBA_8888:
case HAL_PIXEL_FORMAT_RGBX_8888:
V4L2_PIX = V4L2_PIX_FMT_RGB32;
break;
case HAL_PIXEL_FORMAT_RGB_888:
V4L2_PIX = V4L2_PIX_FMT_RGB24;
break;
case HAL_PIXEL_FORMAT_RGB_565:
V4L2_PIX = V4L2_PIX_FMT_RGB565;
break;
case HAL_PIXEL_FORMAT_BGRA_8888:
//V4L2_PIX = V4L2_PIX_FMT_BGR32; // this is not proper on fimc.
V4L2_PIX = V4L2_PIX_FMT_RGB32;
break;
case HAL_PIXEL_FORMAT_RGBA_5551:
V4L2_PIX = V4L2_PIX_FMT_RGB555X;
break;
case HAL_PIXEL_FORMAT_RGBA_4444:
V4L2_PIX = V4L2_PIX_FMT_RGB444;
break;
case HAL_PIXEL_FORMAT_YV12:
case SAMSUNG_HAL_PIXEL_FORMAT_YCbCr_420_P:
V4L2_PIX = V4L2_PIX_FMT_YUV420;
break;
case HAL_PIXEL_FORMAT_YCbCr_422_SP:
case SAMSUNG_HAL_PIXEL_FORMAT_CUSTOM_YCbCr_422_SP:
V4L2_PIX = V4L2_PIX_FMT_NV61;
break;
case SAMSUNG_HAL_PIXEL_FORMAT_YCbCr_420_SP:
case SAMSUNG_HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_SP:
V4L2_PIX = V4L2_PIX_FMT_NV12;
break;
case HAL_PIXEL_FORMAT_YCbCr_422_I:
case SAMSUNG_HAL_PIXEL_FORMAT_CUSTOM_YCbCr_422_I:
V4L2_PIX = V4L2_PIX_FMT_YUYV;
break;
case SAMSUNG_HAL_PIXEL_FORMAT_YCbCr_422_P:
V4L2_PIX = V4L2_PIX_FMT_YUV422P;
break;
case SAMSUNG_HAL_PIXEL_FORMAT_CbYCrY_422_I:
case SAMSUNG_HAL_PIXEL_FORMAT_CUSTOM_CbYCrY_422_I:
V4L2_PIX = V4L2_PIX_FMT_UYVY;
break;
case SAMSUNG_HAL_PIXEL_FORMAT_YCrCb_422_SP:
case SAMSUNG_HAL_PIXEL_FORMAT_CUSTOM_YCrCb_422_SP:
V4L2_PIX = V4L2_PIX_FMT_NV16;
break;
case HAL_PIXEL_FORMAT_YCrCb_420_SP:
case SAMSUNG_HAL_PIXEL_FORMAT_CUSTOM_YCrCb_420_SP:
V4L2_PIX = V4L2_PIX_FMT_NV21;
break;
case SAMSUNG_HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_SP_TILED:
V4L2_PIX = V4L2_PIX_FMT_NV12T;
break;
case SAMSUNG_HAL_PIXEL_FORMAT_CUSTOM_YCrCb_422_I:
V4L2_PIX = V4L2_PIX_FMT_YVYU;
break;
case SAMSUNG_HAL_PIXEL_FORMAT_CUSTOM_CrYCbY_422_I:
V4L2_PIX = V4L2_PIX_FMT_VYUY;
break;
default:
ALOGE("%s::unmatched HAL_PIXEL_FORMAT color_space(0x%x)\n",
__func__, HAL_PIXEL_FORMAT);
break;
}
return V4L2_PIX;
}
inline int V4L2_PIX_2_HAL_PIXEL_FORMAT(int V4L2_PIX)
{
int HAL_PIXEL_FORMAT = -1;
switch (V4L2_PIX) {
case V4L2_PIX_FMT_RGB32:
HAL_PIXEL_FORMAT = HAL_PIXEL_FORMAT_RGBA_8888;
//HAL_PIXEL_FORMAT = HAL_PIXEL_FORMAT_RGBX_8888;
break;
case V4L2_PIX_FMT_RGB24:
HAL_PIXEL_FORMAT = HAL_PIXEL_FORMAT_RGB_888;
break;
case V4L2_PIX_FMT_RGB565:
HAL_PIXEL_FORMAT = HAL_PIXEL_FORMAT_RGB_565;
break;
case V4L2_PIX_FMT_BGR32:
HAL_PIXEL_FORMAT = HAL_PIXEL_FORMAT_BGRA_8888;
break;
case V4L2_PIX_FMT_RGB555X:
HAL_PIXEL_FORMAT = HAL_PIXEL_FORMAT_RGBA_5551;
break;
case V4L2_PIX_FMT_RGB444:
HAL_PIXEL_FORMAT = HAL_PIXEL_FORMAT_RGBA_4444;
break;
case V4L2_PIX_FMT_YUV420:
//HAL_PIXEL_FORMAT = HAL_PIXEL_FORMAT_YV12;
HAL_PIXEL_FORMAT = SAMSUNG_HAL_PIXEL_FORMAT_YCbCr_420_P;
break;
case V4L2_PIX_FMT_NV16:
//HAL_PIXEL_FORMAT = SAMSUNG_HAL_PIXEL_FORMAT_YCrCb_422_SP;
HAL_PIXEL_FORMAT = SAMSUNG_HAL_PIXEL_FORMAT_CUSTOM_YCrCb_422_SP;
break;
case V4L2_PIX_FMT_NV12:
//HAL_PIXEL_FORMAT = HAL_PIXEL_FORMAT_YCrCb_420_SP;
HAL_PIXEL_FORMAT = SAMSUNG_HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_SP;
break;
case V4L2_PIX_FMT_YUYV:
//HAL_PIXEL_FORMAT = HAL_PIXEL_FORMAT_YCbCr_422_I;
HAL_PIXEL_FORMAT = SAMSUNG_HAL_PIXEL_FORMAT_CUSTOM_YCbCr_422_I;
break;
case V4L2_PIX_FMT_YUV422P:
HAL_PIXEL_FORMAT = SAMSUNG_HAL_PIXEL_FORMAT_YCbCr_422_P;
break;
case V4L2_PIX_FMT_UYVY:
//HAL_PIXEL_FORMAT = SAMSUNG_HAL_PIXEL_FORMAT_CbYCrY_422_I;
HAL_PIXEL_FORMAT = SAMSUNG_HAL_PIXEL_FORMAT_CUSTOM_CbYCrY_422_I;
break;
case V4L2_PIX_FMT_NV21:
//HAL_PIXEL_FORMAT = SAMSUNG_HAL_PIXEL_FORMAT_YCbCr_420_SP;
HAL_PIXEL_FORMAT = SAMSUNG_HAL_PIXEL_FORMAT_CUSTOM_YCrCb_420_SP;
break;
case V4L2_PIX_FMT_NV12T:
HAL_PIXEL_FORMAT = SAMSUNG_HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_SP_TILED;
break;
case V4L2_PIX_FMT_NV61:
HAL_PIXEL_FORMAT = SAMSUNG_HAL_PIXEL_FORMAT_CUSTOM_YCbCr_422_SP;
break;
case V4L2_PIX_FMT_YVYU:
HAL_PIXEL_FORMAT = SAMSUNG_HAL_PIXEL_FORMAT_CUSTOM_YCrCb_422_I;
break;
case V4L2_PIX_FMT_VYUY:
HAL_PIXEL_FORMAT = SAMSUNG_HAL_PIXEL_FORMAT_CUSTOM_CrYCbY_422_I;
break;
default:
ALOGE("%s::unmatched V4L2_PIX color_space(%d)\n",
__func__, V4L2_PIX);
break;
}
return HAL_PIXEL_FORMAT;
}
#define ALIGN_TO_32B(x) ((((x) + (1 << 5) - 1) >> 5) << 5)
#define ALIGN_TO_128B(x) ((((x) + (1 << 7) - 1) >> 7) << 7)
#define ALIGN_TO_8KB(x) ((((x) + (1 << 13) - 1) >> 13) << 13)
#define GET_32BPP_FRAME_SIZE(w, h) (((w) * (h)) << 2)
#define GET_24BPP_FRAME_SIZE(w, h) (((w) * (h)) * 3)
#define GET_16BPP_FRAME_SIZE(w, h) (((w) * (h)) << 1)
inline unsigned int FRAME_SIZE(int HAL_PIXEL_FORMAT, int w, int h)
{
unsigned int frame_size = 0;
unsigned int size = 0;
switch (HAL_PIXEL_FORMAT) {
// 16bpp
case HAL_PIXEL_FORMAT_RGB_565:
case HAL_PIXEL_FORMAT_RGBA_5551:
//case HAL_PIXEL_FORMAT_ARGB_1555:
//case HAL_PIXEL_FORMAT_BGRA_5551:
//case HAL_PIXEL_FORMAT_ABGR_1555:
//case HAL_PIXEL_FORMAT_RGBX_5551:
//case HAL_PIXEL_FORMAT_XRGB_1555:
//case HAL_PIXEL_FORMAT_BGRX_5551:
//case HAL_PIXEL_FORMAT_XBGR_1555:
case HAL_PIXEL_FORMAT_RGBA_4444:
//case HAL_PIXEL_FORMAT_ARGB_4444:
//case HAL_PIXEL_FORMAT_BGRA_4444:
//case HAL_PIXEL_FORMAT_ABGR_4444:
//case HAL_PIXEL_FORMAT_RGBX_4444:
//case HAL_PIXEL_FORMAT_XRGB_4444:
//case HAL_PIXEL_FORMAT_BGRX_4444:
//case HAL_PIXEL_FORMAT_XBGR_4444:
frame_size = GET_16BPP_FRAME_SIZE(w, h);
break;
// 24bpp
case HAL_PIXEL_FORMAT_RGB_888:
frame_size = GET_24BPP_FRAME_SIZE(w, h);
break;
// 32bpp
case HAL_PIXEL_FORMAT_RGBA_8888:
//case HAL_PIXEL_FORMAT_ARGB_8888:
case HAL_PIXEL_FORMAT_BGRA_8888:
//case HAL_PIXEL_FORMAT_ABGR_8888:
case HAL_PIXEL_FORMAT_RGBX_8888:
//case HAL_PIXEL_FORMAT_XRGB_8888:
//case HAL_PIXEL_FORMAT_BGRX_8888:
//case HAL_PIXEL_FORMAT_XBGR_8888:
frame_size = GET_32BPP_FRAME_SIZE(w, h);
break;
// 12bpp
case HAL_PIXEL_FORMAT_YV12:
case HAL_PIXEL_FORMAT_YCrCb_420_SP:
case SAMSUNG_HAL_PIXEL_FORMAT_YCbCr_420_P:
case SAMSUNG_HAL_PIXEL_FORMAT_YCbCr_420_I:
case SAMSUNG_HAL_PIXEL_FORMAT_CbYCrY_420_I:
case SAMSUNG_HAL_PIXEL_FORMAT_YCbCr_420_SP:
case SAMSUNG_HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_SP:
case SAMSUNG_HAL_PIXEL_FORMAT_CUSTOM_YCrCb_420_SP:
size = w * h;
// frame_size = width * height * 3 / 2;
// sw5771.park : very curious...
// frame_size = size + ((size / 4) * 2);
frame_size = size + ((size >> 2) << 1);
break;
case SAMSUNG_HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_SP_TILED:
frame_size = ALIGN_TO_8KB(ALIGN_TO_128B(w) * ALIGN_TO_32B(h))
+ ALIGN_TO_8KB(ALIGN_TO_128B(w) * ALIGN_TO_32B(h >> 1));
break;
// 16bpp
case HAL_PIXEL_FORMAT_YCbCr_422_SP:
case HAL_PIXEL_FORMAT_YCbCr_422_I:
case SAMSUNG_HAL_PIXEL_FORMAT_YCbCr_422_P:
case SAMSUNG_HAL_PIXEL_FORMAT_CbYCrY_422_I:
case SAMSUNG_HAL_PIXEL_FORMAT_YCrCb_422_SP:
case SAMSUNG_HAL_PIXEL_FORMAT_CUSTOM_YCbCr_422_SP:
case SAMSUNG_HAL_PIXEL_FORMAT_CUSTOM_YCrCb_422_SP:
case SAMSUNG_HAL_PIXEL_FORMAT_CUSTOM_YCbCr_422_I:
case SAMSUNG_HAL_PIXEL_FORMAT_CUSTOM_YCrCb_422_I:
case SAMSUNG_HAL_PIXEL_FORMAT_CUSTOM_CbYCrY_422_I:
case SAMSUNG_HAL_PIXEL_FORMAT_CUSTOM_CrYCbY_422_I:
frame_size = GET_16BPP_FRAME_SIZE(w, h);
break;
default:
ALOGD("%s::no matching source colorformat(0x%x), w(%d), h(%d) fail\n",
__func__, HAL_PIXEL_FORMAT, w, h);
break;
}
return frame_size;
}
#endif //__SAMSUNG_SYSLSI_SEC_COMMON_H__
|