1 /*
2  * Copyright@ Samsung Electronics Co. LTD
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15 */
16 
17 #ifndef _EXYNOS_FORMAT_H_
18 #define _EXYNOS_FORMAT_H_
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 enum {
25                                                            /* HAL_PIXEL_FORMAT_YCbCr_422_P = 0x100, */
26     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_P_M       = 0x101,   /* HAL_PIXEL_FORMAT_YCbCr_420_P */
27                                                            /* HAL_PIXEL_FORMAT_YCbCr_420_I = 0x102, */
28     HAL_PIXEL_FORMAT_EXYNOS_CbYCrY_422_I        = 0x103,   /* HAL_PIXEL_FORMAT_CbYCrY_422_I */
29                                                            /* HAL_PIXEL_FORMAT_CbYCrY_420_I = 0x104, */
30     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M      = 0x105,   /* HAL_PIXEL_FORMAT_YCbCr_420_SP */
31     HAL_PIXEL_FORMAT_EXYNOS_YCrCb_422_SP        = 0x106,   /* HAL_PIXEL_FORMAT_YCrCb_422_SP */
32     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_TILED= 0x107,   /* HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED */
33     HAL_PIXEL_FORMAT_EXYNOS_ARGB_8888           = 0x108,   /* HAL_PIXEL_FORMAT_CUSTOM_ARGB_8888 */
34     // support custom format for zero copy
35                                                            /* HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_SP = 0x110 */
36                                                            /* HAL_PIXEL_FORMAT_CUSTOM_YCrCb_420_SP = 0x111, */
37                                                            /* HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_SP_TILED  = 0x112, */
38                                                            /* HAL_PIXEL_FORMAT_CUSTOM_YCbCr_422_SP = 0x113, */
39                                                            /* HAL_PIXEL_FORMAT_CUSTOM_YCrCb_422_SP = 0x114, */
40                                                            /* HAL_PIXEL_FORMAT_CUSTOM_YCbCr_422_I  = 0x115, */
41     HAL_PIXEL_FORMAT_EXYNOS_YCrCb_422_I         = 0x116,   /* HAL_PIXEL_FORMAT_CUSTOM_YCrCb_422_I */
42                                                            /* HAL_PIXEL_FORMAT_CUSTOM_CbYCrY_422_I = 0x117, */
43     HAL_PIXEL_FORMAT_EXYNOS_CrYCbY_422_I        = 0x118,   /* HAL_PIXEL_FORMAT_CUSTOM_CrYCbY_422_I */
44                                                            /* HAL_PIXEL_FORMAT_CUSTOM_CbYCr_422_I = 0x11B, */
45 
46     HAL_PIXEL_FORMAT_EXYNOS_YV12_M              = 0x11C,   /* HAL_PIXEL_FORMAT_EXYNOS_YV12 */
47     HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP_M      = 0x11D,   /* HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP */
48     HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP_M_FULL = 0x11E,   /* HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP_FULL */
49 
50     /* newly added formats */
51     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_P         = 0x11F,
52     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP        = 0x120,
53 
54     /* EXYNOS_YCbCr_420_SP_M w/ private data buffer */
55     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_PRIV = 0x121,
56 
57     /* contiguous(single fd) custom formats */
58     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_PN        = 0x122,
59     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN       = 0x123,
60     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_TILED = 0x124,
61 
62     /* 10-bit format (8bit + separated 2bit) w/ private data buffer */
63     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_S10B = 0x125,
64 
65     /* 10-bit contiguous(single fd, 8bit + separated 2bit) custom formats */
66     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_S10B  = 0x126,
67 
68     /* 10-bit format (2 fd, 10bit, 2x byte) custom formats */
69     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_P010_M        = 0x127,
70 
71     /* YUV 4:2:2 planar, Y/Cb/Cr */
72     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_422_P         = 0x128,
73 
74     /* SBWC format */
75     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_SBWC = 0x130,
76     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_SBWC  = 0x131,
77 
78     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_10B_SBWC = 0x132,
79     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_10B_SBWC  = 0x133,
80 
81     HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP_M_SBWC = 0x134,
82     HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP_M_10B_SBWC = 0x135,
83 
84 	/* SBWC Lossy formats */
85     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_SBWC_L50 = 0x140,
86     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_SBWC_L75 = 0x141,
87     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_SBWC_L50  = 0x150,
88     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_SBWC_L75  = 0x151,
89 
90     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_10B_SBWC_L40 = 0x160,
91     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_10B_SBWC_L60 = 0x161,
92     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_10B_SBWC_L80 = 0x162,
93     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_10B_SBWC_L40  = 0x170,
94     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_10B_SBWC_L60  = 0x171,
95     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_10B_SBWC_L80  = 0x172,
96 
97     HAL_PIXEL_FORMAT_EXYNOS_MAX,
98 };
99 
100 enum {
101     HAL_PIXEL_FORMAT_GOOGLE_NV12_SP = 0x301,
102     HAL_PIXEL_FORMAT_GOOGLE_NV12_SP_10B = 0x302,
103     HAL_PIXEL_FORMAT_GOOGLE_R_8 = 0x303,
104     HAL_PIXEL_FORMAT_GOOGLE_RG_88 = 0x304,
105     HAL_PIXEL_FORMAT_GOOGLE_MAX,
106 };
107 
is_sbwc_format(uint32_t format)108 static inline int is_sbwc_format(uint32_t format)
109 {
110     switch (format) {
111     default:
112         return 0;
113     case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_SBWC:
114     case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_SBWC:
115     case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_10B_SBWC:
116     case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_10B_SBWC:
117     case HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP_M_SBWC:
118     case HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP_M_10B_SBWC:
119     case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_SBWC_L50:
120     case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_SBWC_L75:
121     case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_SBWC_L50:
122     case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_SBWC_L75:
123     case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_10B_SBWC_L40:
124     case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_10B_SBWC_L60:
125     case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_10B_SBWC_L80:
126     case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_10B_SBWC_L40:
127     case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_10B_SBWC_L60:
128     case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_10B_SBWC_L80:
129         return 1;
130     }
131 }
132 
133 /* for backward compatibility */
134 #define HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_SP    HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M
135 #define HAL_PIXEL_FORMAT_CUSTOM_YCrCb_420_SP    HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP_M
136 
137 // Gamut (colorspace range)
138 enum {
139     HAL_PIXEL_GAMUT_DEFAULT = 0,
140     // Values range 0-255
141     HAL_PIXEL_GAMUT_WIDE_8,
142     // Values range 16-235
143     HAL_PIXEL_GAMUT_NARROW_8
144 };
145 
146 // Chromaticities (colorspace parameters)
147 enum {
148     HAL_PIXEL_CHROMA_DEFAULT = 0,
149     // BT.601 "Standard Definition" color space
150     HAL_PIXEL_CHROMA_BT601_8,
151     // BT.709 "High Definition" color space
152     HAL_PIXEL_CHROMA_BT709_8
153 };
154 
155 struct ADDRS {
156     unsigned int addr_y;
157     unsigned int addr_cbcr;
158     unsigned int buf_idx;
159     unsigned int reserved;
160 };
161 
162 /* 12  Y/CbCr 4:2:0 64x32 macroblocks */
163 #define V4L2_PIX_FMT_NV12T    v4l2_fourcc('T', 'V', '1', '2')
164 
165 #define ALIGN_UP(x, a)    (((x) + (a) - 1) & ~((a) - 1))
166 #define ALIGN_DOWN(x, a)  ((x) - (x % a))
167 #ifndef ALIGN
168 #define ALIGN(x, a)       ALIGN_UP(x, a)
169 #endif
170 #ifndef ALIGN_TO_32B
171 #define ALIGN_TO_32B(x)   ((((x) + (1 <<  5) - 1) >>  5) <<  5)
172 #endif
173 #ifndef ALIGN_TO_128B
174 #define ALIGN_TO_128B(x)  ((((x) + (1 <<  7) - 1) >>  7) <<  7)
175 #endif
176 #ifndef ALIGN_TO_8KB
177 #define ALIGN_TO_8KB(x)   ((((x) + (1 << 13) - 1) >> 13) << 13)
178 #endif
179 
180 #define GET_32BPP_FRAME_SIZE(w, h)  (((w) * (h)) << 2)
181 #define GET_24BPP_FRAME_SIZE(w, h)  (((w) * (h)) * 3)
182 #define GET_16BPP_FRAME_SIZE(w, h)  (((w) * (h)) << 1)
183 
184 /*
185  * Convert hal_pixel_format to v4l2_pixel_format.
186  *
187  * @param hal_pixel_format
188  *   hal_pixel_format[in]
189  *
190  * @return
191  *   v4l2_pixel_format
192  */
193 int HAL_PIXEL_FORMAT_2_V4L2_PIX(
194     int hal_pixel_format);
195 
196 /*
197  * Convert v4l2_pixel_format to hal_pixel_format.
198  *
199  * @param v4l2_pixel_format
200  *   v4l2_pixel_format[in]
201  *
202  * @return
203  *   hal_pixel_format
204  */
205 int V4L2_PIX_2_HAL_PIXEL_FORMAT(
206     int v4l2_pixel_format);
207 
208 /*
209  * Get frame_size of hal_pixel_format.
210  *
211  * @param hal_pixel_format
212  *   hal_pixel_format[in]
213  *
214  * @param width
215  *   width[in]
216  *
217  * @param height
218  *   height[in]
219  *
220  * @return
221  *   frame_size
222  */
223 unsigned int FRAME_SIZE(
224     int hal_pixel_format,
225     int width,
226     int height);
227 
228 int PLANAR_FRAME_SIZE(
229     int hal_pixel_format,
230     int width,
231     int height,
232     unsigned int *luma_size,
233     unsigned int *chroma_size);
234 
235 int NUM_PLANES(int hal_pixel_format);
236 
237 
238 /*
239  * Get bpp and plane of v4l2_pixel_format.
240  *
241  * @param v4l2_pixel_format
242  *   v4l2_pixel_format[in]
243  *
244  * @param bpp
245  *   address of bpp[out]
246  *
247  * @param planes
248  *   address of planes[out]
249  *
250  * @return
251  *   error code
252  */
253 int V4L2_PIX_2_YUV_INFO(
254     unsigned int  v4l2_pixel_format,
255     unsigned int *bpp,
256     unsigned int *planes);
257 
258 /*
259  * Get bpp of v4l2_pixel_format.
260  *
261  * @param v4l2_pixel_format
262  *   v4l2_pixel_format[in]
263  *
264  * @return
265  *   bpp
266  */
267 int get_yuv_bpp(
268     unsigned int v4l2_pixel_format);
269 
270 /*
271  * Get plane of v4l2_pixel_format.
272  *
273  * @param v4l2_pixel_format
274  *   v4l2_pixel_format[in]
275  *
276  * @return
277  *   num of plane
278  */
279 int get_yuv_planes(
280     unsigned int v4l2_pixel_format);
281 
282 #ifdef __cplusplus
283 }
284 #endif
285 
286 #endif
287