blob: 65831dbff767e086ee7a2a163cc98908648c6310 [file] [log] [blame]
Vinay Kalia6c51b6e2012-10-15 15:18:04 -07001#ifndef __MEDIA_INFO_H__
2#define __MEDIA_INFO_H__
3
Vinay Kaliac546ca52013-01-09 19:27:43 -08004#ifndef MSM_MEDIA_ALIGN
5#define MSM_MEDIA_ALIGN(__sz, __align) (((__sz) + (__align-1)) & (~(__align-1)))
Vinay Kalia6c51b6e2012-10-15 15:18:04 -07006#endif
7
8enum color_fmts {
9 COLOR_FMT_NV12,
Deva Ramasubramaniane370b392013-05-06 11:37:17 -070010 COLOR_FMT_NV21,
Vinay Kalia6c51b6e2012-10-15 15:18:04 -070011};
12
13static inline unsigned int VENUS_Y_STRIDE(int color_fmt, int width)
14{
15 unsigned int alignment, stride = 0;
16 if (!width)
17 goto invalid_input;
18
19 switch (color_fmt) {
Deva Ramasubramaniane370b392013-05-06 11:37:17 -070020 case COLOR_FMT_NV21:
Vinay Kalia6c51b6e2012-10-15 15:18:04 -070021 case COLOR_FMT_NV12:
Ashray Kulkarni0eaa2262012-11-02 11:57:55 -070022 alignment = 128;
Vinay Kaliac546ca52013-01-09 19:27:43 -080023 stride = MSM_MEDIA_ALIGN(width, alignment);
Vinay Kalia6c51b6e2012-10-15 15:18:04 -070024 break;
25 default:
26 break;
27 }
28invalid_input:
29 return stride;
30}
31
32static inline unsigned int VENUS_UV_STRIDE(int color_fmt, int width)
33{
34 unsigned int alignment, stride = 0;
35 if (!width)
36 goto invalid_input;
37
38 switch (color_fmt) {
Deva Ramasubramaniane370b392013-05-06 11:37:17 -070039 case COLOR_FMT_NV21:
Vinay Kalia6c51b6e2012-10-15 15:18:04 -070040 case COLOR_FMT_NV12:
Ashray Kulkarni0eaa2262012-11-02 11:57:55 -070041 alignment = 128;
Vinay Kaliac546ca52013-01-09 19:27:43 -080042 stride = MSM_MEDIA_ALIGN(width, alignment);
Vinay Kalia6c51b6e2012-10-15 15:18:04 -070043 break;
44 default:
45 break;
46 }
47invalid_input:
48 return stride;
49}
50
51static inline unsigned int VENUS_Y_SCANLINES(int color_fmt, int height)
52{
53 unsigned int alignment, sclines = 0;
54 if (!height)
55 goto invalid_input;
56
57 switch (color_fmt) {
Deva Ramasubramaniane370b392013-05-06 11:37:17 -070058 case COLOR_FMT_NV21:
Vinay Kalia6c51b6e2012-10-15 15:18:04 -070059 case COLOR_FMT_NV12:
60 alignment = 32;
Vinay Kaliac546ca52013-01-09 19:27:43 -080061 sclines = MSM_MEDIA_ALIGN(height, alignment);
Vinay Kalia6c51b6e2012-10-15 15:18:04 -070062 break;
63 default:
64 break;
65 }
66invalid_input:
67 return sclines;
68}
69
70static inline unsigned int VENUS_UV_SCANLINES(int color_fmt, int height)
71{
72 unsigned int alignment, sclines = 0;
73 if (!height)
74 goto invalid_input;
75
76 switch (color_fmt) {
Deva Ramasubramaniane370b392013-05-06 11:37:17 -070077 case COLOR_FMT_NV21:
Vinay Kalia6c51b6e2012-10-15 15:18:04 -070078 case COLOR_FMT_NV12:
Ashray Kulkarni0eaa2262012-11-02 11:57:55 -070079 alignment = 16;
Vinay Kaliac546ca52013-01-09 19:27:43 -080080 sclines = MSM_MEDIA_ALIGN(((height + 1) >> 1), alignment);
Vinay Kalia6c51b6e2012-10-15 15:18:04 -070081 break;
82 default:
83 break;
84 }
85invalid_input:
86 return sclines;
87}
88
89static inline unsigned int VENUS_BUFFER_SIZE(
90 int color_fmt, int width, int height)
91{
92 unsigned int uv_alignment;
93 unsigned int size = 0;
94 unsigned int y_plane, uv_plane, y_stride,
95 uv_stride, y_sclines, uv_sclines;
96 if (!width || !height)
97 goto invalid_input;
98
99 y_stride = VENUS_Y_STRIDE(color_fmt, width);
100 uv_stride = VENUS_UV_STRIDE(color_fmt, width);
101 y_sclines = VENUS_Y_SCANLINES(color_fmt, height);
102 uv_sclines = VENUS_UV_SCANLINES(color_fmt, height);
103 switch (color_fmt) {
Deva Ramasubramaniane370b392013-05-06 11:37:17 -0700104 case COLOR_FMT_NV21:
Vinay Kalia6c51b6e2012-10-15 15:18:04 -0700105 case COLOR_FMT_NV12:
Vinay Kaliacc0505c2012-12-10 13:31:50 -0800106 uv_alignment = 4096;
Vinay Kalia6c51b6e2012-10-15 15:18:04 -0700107 y_plane = y_stride * y_sclines;
108 uv_plane = uv_stride * uv_sclines + uv_alignment;
109 size = y_plane + uv_plane;
Vinay Kaliac546ca52013-01-09 19:27:43 -0800110 size = MSM_MEDIA_ALIGN(size, 4096);
Vinay Kalia6c51b6e2012-10-15 15:18:04 -0700111 break;
112 default:
113 break;
114 }
115invalid_input:
116 return size;
117}
118
119#endif