Vinay Kalia | 6c51b6e | 2012-10-15 15:18:04 -0700 | [diff] [blame] | 1 | #ifndef __MEDIA_INFO_H__ |
| 2 | #define __MEDIA_INFO_H__ |
| 3 | |
Vinay Kalia | c546ca5 | 2013-01-09 19:27:43 -0800 | [diff] [blame] | 4 | #ifndef MSM_MEDIA_ALIGN |
| 5 | #define MSM_MEDIA_ALIGN(__sz, __align) (((__sz) + (__align-1)) & (~(__align-1))) |
Vinay Kalia | 6c51b6e | 2012-10-15 15:18:04 -0700 | [diff] [blame] | 6 | #endif |
| 7 | |
| 8 | enum color_fmts { |
| 9 | COLOR_FMT_NV12, |
Deva Ramasubramanian | e370b39 | 2013-05-06 11:37:17 -0700 | [diff] [blame] | 10 | COLOR_FMT_NV21, |
Vinay Kalia | 6c51b6e | 2012-10-15 15:18:04 -0700 | [diff] [blame] | 11 | }; |
| 12 | |
| 13 | static 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 Ramasubramanian | e370b39 | 2013-05-06 11:37:17 -0700 | [diff] [blame] | 20 | case COLOR_FMT_NV21: |
Vinay Kalia | 6c51b6e | 2012-10-15 15:18:04 -0700 | [diff] [blame] | 21 | case COLOR_FMT_NV12: |
Ashray Kulkarni | 0eaa226 | 2012-11-02 11:57:55 -0700 | [diff] [blame] | 22 | alignment = 128; |
Vinay Kalia | c546ca5 | 2013-01-09 19:27:43 -0800 | [diff] [blame] | 23 | stride = MSM_MEDIA_ALIGN(width, alignment); |
Vinay Kalia | 6c51b6e | 2012-10-15 15:18:04 -0700 | [diff] [blame] | 24 | break; |
| 25 | default: |
| 26 | break; |
| 27 | } |
| 28 | invalid_input: |
| 29 | return stride; |
| 30 | } |
| 31 | |
| 32 | static 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 Ramasubramanian | e370b39 | 2013-05-06 11:37:17 -0700 | [diff] [blame] | 39 | case COLOR_FMT_NV21: |
Vinay Kalia | 6c51b6e | 2012-10-15 15:18:04 -0700 | [diff] [blame] | 40 | case COLOR_FMT_NV12: |
Ashray Kulkarni | 0eaa226 | 2012-11-02 11:57:55 -0700 | [diff] [blame] | 41 | alignment = 128; |
Vinay Kalia | c546ca5 | 2013-01-09 19:27:43 -0800 | [diff] [blame] | 42 | stride = MSM_MEDIA_ALIGN(width, alignment); |
Vinay Kalia | 6c51b6e | 2012-10-15 15:18:04 -0700 | [diff] [blame] | 43 | break; |
| 44 | default: |
| 45 | break; |
| 46 | } |
| 47 | invalid_input: |
| 48 | return stride; |
| 49 | } |
| 50 | |
| 51 | static 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 Ramasubramanian | e370b39 | 2013-05-06 11:37:17 -0700 | [diff] [blame] | 58 | case COLOR_FMT_NV21: |
Vinay Kalia | 6c51b6e | 2012-10-15 15:18:04 -0700 | [diff] [blame] | 59 | case COLOR_FMT_NV12: |
| 60 | alignment = 32; |
Vinay Kalia | c546ca5 | 2013-01-09 19:27:43 -0800 | [diff] [blame] | 61 | sclines = MSM_MEDIA_ALIGN(height, alignment); |
Vinay Kalia | 6c51b6e | 2012-10-15 15:18:04 -0700 | [diff] [blame] | 62 | break; |
| 63 | default: |
| 64 | break; |
| 65 | } |
| 66 | invalid_input: |
| 67 | return sclines; |
| 68 | } |
| 69 | |
| 70 | static 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 Ramasubramanian | e370b39 | 2013-05-06 11:37:17 -0700 | [diff] [blame] | 77 | case COLOR_FMT_NV21: |
Vinay Kalia | 6c51b6e | 2012-10-15 15:18:04 -0700 | [diff] [blame] | 78 | case COLOR_FMT_NV12: |
Ashray Kulkarni | 0eaa226 | 2012-11-02 11:57:55 -0700 | [diff] [blame] | 79 | alignment = 16; |
Vinay Kalia | c546ca5 | 2013-01-09 19:27:43 -0800 | [diff] [blame] | 80 | sclines = MSM_MEDIA_ALIGN(((height + 1) >> 1), alignment); |
Vinay Kalia | 6c51b6e | 2012-10-15 15:18:04 -0700 | [diff] [blame] | 81 | break; |
| 82 | default: |
| 83 | break; |
| 84 | } |
| 85 | invalid_input: |
| 86 | return sclines; |
| 87 | } |
| 88 | |
| 89 | static 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 Ramasubramanian | e370b39 | 2013-05-06 11:37:17 -0700 | [diff] [blame] | 104 | case COLOR_FMT_NV21: |
Vinay Kalia | 6c51b6e | 2012-10-15 15:18:04 -0700 | [diff] [blame] | 105 | case COLOR_FMT_NV12: |
Vinay Kalia | cc0505c | 2012-12-10 13:31:50 -0800 | [diff] [blame] | 106 | uv_alignment = 4096; |
Vinay Kalia | 6c51b6e | 2012-10-15 15:18:04 -0700 | [diff] [blame] | 107 | y_plane = y_stride * y_sclines; |
| 108 | uv_plane = uv_stride * uv_sclines + uv_alignment; |
| 109 | size = y_plane + uv_plane; |
Vinay Kalia | c546ca5 | 2013-01-09 19:27:43 -0800 | [diff] [blame] | 110 | size = MSM_MEDIA_ALIGN(size, 4096); |
Vinay Kalia | 6c51b6e | 2012-10-15 15:18:04 -0700 | [diff] [blame] | 111 | break; |
| 112 | default: |
| 113 | break; |
| 114 | } |
| 115 | invalid_input: |
| 116 | return size; |
| 117 | } |
| 118 | |
| 119 | #endif |