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
21extern "C" {
22#endif
23
24enum {
25    HAL_PIXEL_FORMAT_YCbCr_422_P                = 0x100,
26    HAL_PIXEL_FORMAT_YCbCr_420_P                = 0x101,
27    HAL_PIXEL_FORMAT_YCbCr_420_I                = 0x102,
28    HAL_PIXEL_FORMAT_CbYCrY_422_I               = 0x103,
29    HAL_PIXEL_FORMAT_CbYCrY_420_I               = 0x104,
30    HAL_PIXEL_FORMAT_YCbCr_420_SP               = 0x105,
31    HAL_PIXEL_FORMAT_YCrCb_422_SP               = 0x106,
32    HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED         = 0x107,
33    HAL_PIXEL_FORMAT_CUSTOM_ARGB_8888           = 0x108,
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_CUSTOM_YCrCb_422_I         = 0x116,
42    HAL_PIXEL_FORMAT_CUSTOM_CbYCrY_422_I        = 0x117,
43    HAL_PIXEL_FORMAT_CUSTOM_CrYCbY_422_I        = 0x118,
44    HAL_PIXEL_FORMAT_CUSTOM_CbYCr_422_I         = 0x11B,
45
46    HAL_PIXEL_FORMAT_EXYNOS_YV12                = 0x11C,
47    HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP        = 0x11D,
48    HAL_PIXEL_FORMAT_CUSTOM_MAX
49};
50
51// Gamut (colorspace range)
52enum {
53    HAL_PIXEL_GAMUT_DEFAULT = 0,
54    // Values range 0-255
55    HAL_PIXEL_GAMUT_WIDE_8,
56    // Values range 16-235
57    HAL_PIXEL_GAMUT_NARROW_8
58};
59
60// Chromaticities (colorspace parameters)
61enum {
62    HAL_PIXEL_CHROMA_DEFAULT = 0,
63    // BT.601 "Standard Definition" color space
64    HAL_PIXEL_CHROMA_BT601_8,
65    // BT.709 "High Definition" color space
66    HAL_PIXEL_CHROMA_BT709_8
67};
68
69struct ADDRS {
70    unsigned int addr_y;
71    unsigned int addr_cbcr;
72    unsigned int buf_idx;
73    unsigned int reserved;
74};
75
76/* 12  Y/CbCr 4:2:0 64x32 macroblocks */
77#define V4L2_PIX_FMT_NV12T    v4l2_fourcc('T', 'V', '1', '2')
78
79#define ALIGN(x, a)       (((x) + (a) - 1) & ~((a) - 1))
80#define ALIGN_TO_32B(x)   ((((x) + (1 <<  5) - 1) >>  5) <<  5)
81#define ALIGN_TO_128B(x)  ((((x) + (1 <<  7) - 1) >>  7) <<  7)
82#define ALIGN_TO_8KB(x)   ((((x) + (1 << 13) - 1) >> 13) << 13)
83
84#define GET_32BPP_FRAME_SIZE(w, h)  (((w) * (h)) << 2)
85#define GET_24BPP_FRAME_SIZE(w, h)  (((w) * (h)) * 3)
86#define GET_16BPP_FRAME_SIZE(w, h)  (((w) * (h)) << 1)
87
88/*
89 * Convert hal_pixel_format to v4l2_pixel_format.
90 *
91 * @param hal_pixel_format
92 *   hal_pixel_format[in]
93 *
94 * @return
95 *   v4l2_pixel_format
96 */
97int HAL_PIXEL_FORMAT_2_V4L2_PIX(
98    int hal_pixel_format);
99
100/*
101 * Convert v4l2_pixel_format to hal_pixel_format.
102 *
103 * @param v4l2_pixel_format
104 *   v4l2_pixel_format[in]
105 *
106 * @return
107 *   hal_pixel_format
108 */
109int V4L2_PIX_2_HAL_PIXEL_FORMAT(
110    int v4l2_pixel_format);
111
112/*
113 * Get frame_size of hal_pixel_format.
114 *
115 * @param hal_pixel_format
116 *   hal_pixel_format[in]
117 *
118 * @param width
119 *   width[in]
120 *
121 * @param height
122 *   height[in]
123 *
124 * @return
125 *   frame_size
126 */
127unsigned int FRAME_SIZE(
128    int hal_pixel_format,
129    int width,
130    int height);
131
132int PLANAR_FRAME_SIZE(
133    int hal_pixel_format,
134    int width,
135    int height,
136    unsigned int *luma_size,
137    unsigned int *chroma_size);
138
139int NUM_PLANES(int hal_pixel_format);
140
141
142/*
143 * Get bpp and plane of v4l2_pixel_format.
144 *
145 * @param v4l2_pixel_format
146 *   v4l2_pixel_format[in]
147 *
148 * @param bpp
149 *   address of bpp[out]
150 *
151 * @param planes
152 *   address of planes[out]
153 *
154 * @return
155 *   error code
156 */
157int V4L2_PIX_2_YUV_INFO(
158    unsigned int  v4l2_pixel_format,
159    unsigned int *bpp,
160    unsigned int *planes);
161
162/*
163 * Get bpp of v4l2_pixel_format.
164 *
165 * @param v4l2_pixel_format
166 *   v4l2_pixel_format[in]
167 *
168 * @return
169 *   bpp
170 */
171unsigned int get_yuv_bpp(
172    unsigned int v4l2_pixel_format);
173
174/*
175 * Get plane of v4l2_pixel_format.
176 *
177 * @param v4l2_pixel_format
178 *   v4l2_pixel_format[in]
179 *
180 * @return
181 *   num of plane
182 */
183unsigned int get_yuv_planes(
184    unsigned int v4l2_pixel_format);
185
186#ifdef __cplusplus
187}
188#endif
189
190#endif
191