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