Wind Yuan | 41c9378 | 2015-03-18 15:36:02 +0800 | [diff] [blame] | 1 | /* |
| 2 | * video_buffer.cpp - video buffer base |
| 3 | * |
| 4 | * Copyright (c) 2014-2015 Intel Corporation |
| 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | * |
| 18 | * Author: Wind Yuan <feng.yuan@intel.com> |
| 19 | */ |
| 20 | |
| 21 | #include "video_buffer.h" |
| 22 | #include <linux/videodev2.h> |
| 23 | |
| 24 | namespace XCam { |
| 25 | |
| 26 | VideoBufferInfo::VideoBufferInfo () |
| 27 | : format (0) |
| 28 | , color_bits (8) |
| 29 | , width (0) |
| 30 | , height (0) |
Wind Yuan | ada12e4 | 2015-03-25 17:26:56 +0800 | [diff] [blame] | 31 | , aligned_width (0) |
| 32 | , aligned_height (0) |
Wind Yuan | 41c9378 | 2015-03-18 15:36:02 +0800 | [diff] [blame] | 33 | , size (0) |
| 34 | , components (0) |
| 35 | { |
| 36 | xcam_mem_clear (strides); |
| 37 | xcam_mem_clear (offsets); |
| 38 | } |
| 39 | |
| 40 | bool |
| 41 | VideoBufferInfo::init ( |
| 42 | uint32_t format, |
| 43 | uint32_t width, uint32_t height, |
Wind Yuan | ada12e4 | 2015-03-25 17:26:56 +0800 | [diff] [blame] | 44 | uint32_t alignment_w, uint32_t alignment_h) |
Wind Yuan | 41c9378 | 2015-03-18 15:36:02 +0800 | [diff] [blame] | 45 | { |
Wind Yuan | ada12e4 | 2015-03-25 17:26:56 +0800 | [diff] [blame] | 46 | XCAM_ASSERT ((alignment_w & (alignment_w - 1)) == 0 && alignment_w != 0); |
| 47 | XCAM_ASSERT ((alignment_h & (alignment_h - 1)) == 0 && alignment_h != 0); |
Wind Yuan | 41c9378 | 2015-03-18 15:36:02 +0800 | [diff] [blame] | 48 | |
Wind Yuan | ada12e4 | 2015-03-25 17:26:56 +0800 | [diff] [blame] | 49 | uint32_t final_width = XCAM_ALIGN_UP (width, alignment_w); |
| 50 | uint32_t final_height = XCAM_ALIGN_UP (height, alignment_h); |
Wind Yuan | 41c9378 | 2015-03-18 15:36:02 +0800 | [diff] [blame] | 51 | |
| 52 | this->format = format; |
| 53 | this->width = width; |
| 54 | this->height = height; |
Wind Yuan | ada12e4 | 2015-03-25 17:26:56 +0800 | [diff] [blame] | 55 | this->aligned_width = final_width; |
| 56 | this->aligned_height = final_height; |
Wind Yuan | 41c9378 | 2015-03-18 15:36:02 +0800 | [diff] [blame] | 57 | |
| 58 | switch (format) { |
| 59 | case V4L2_PIX_FMT_NV12: |
| 60 | this->color_bits = 8; |
| 61 | this->components = 2; |
| 62 | this->strides [0] = final_width; |
| 63 | this->strides [1] = this->strides [0]; |
| 64 | this->offsets [0] = 0; |
| 65 | this->offsets [1] = this->offsets [0] + this->strides [0] * final_height; |
| 66 | this->size = this->strides [0] * final_height + this->strides [1] * final_height / 2; |
| 67 | break; |
| 68 | case V4L2_PIX_FMT_YUYV: |
| 69 | this->color_bits = 8; |
| 70 | this->components = 1; |
| 71 | this->strides [0] = final_width * 2; |
| 72 | this->offsets [0] = 0; |
| 73 | this->size = this->strides [0] * final_height; |
| 74 | break; |
Wind Yuan | 95e5b36 | 2015-03-27 15:17:50 +0800 | [diff] [blame] | 75 | case V4L2_PIX_FMT_RGB565: |
| 76 | this->color_bits = 16; |
| 77 | this->components = 1; |
| 78 | this->strides [0] = final_width * 2; |
| 79 | this->offsets [0] = 0; |
| 80 | this->size = this->strides [0] * final_height; |
| 81 | break; |
Wind Yuan | 41c9378 | 2015-03-18 15:36:02 +0800 | [diff] [blame] | 82 | case V4L2_PIX_FMT_RGB24: |
| 83 | this->color_bits = 8; |
| 84 | this->components = 1; |
| 85 | this->strides [0] = final_width * 3; |
| 86 | this->offsets [0] = 0; |
| 87 | this->size = this->strides [0] * final_height; |
| 88 | break; |
Wind Yuan | 95e5b36 | 2015-03-27 15:17:50 +0800 | [diff] [blame] | 89 | // memory order: BGRA |
| 90 | case V4L2_PIX_FMT_XBGR32: |
| 91 | case V4L2_PIX_FMT_ABGR32: |
| 92 | case V4L2_PIX_FMT_BGR32: |
| 93 | // memory order: ARGB |
Wind Yuan | 41c9378 | 2015-03-18 15:36:02 +0800 | [diff] [blame] | 94 | case V4L2_PIX_FMT_RGB32: |
Wind Yuan | 95e5b36 | 2015-03-27 15:17:50 +0800 | [diff] [blame] | 95 | case V4L2_PIX_FMT_ARGB32: |
| 96 | case V4L2_PIX_FMT_XRGB32: |
Wind Yuan | 41c9378 | 2015-03-18 15:36:02 +0800 | [diff] [blame] | 97 | this->color_bits = 8; |
| 98 | this->components = 1; |
| 99 | this->strides [0] = final_width * 4; |
| 100 | this->offsets [0] = 0; |
| 101 | this->size = this->strides [0] * final_height; |
| 102 | break; |
| 103 | case XCAM_PIX_FMT_RGB48: |
| 104 | this->color_bits = 16; |
| 105 | this->components = 1; |
| 106 | this->strides [0] = final_width * 3 * 2; |
| 107 | this->offsets [0] = 0; |
| 108 | this->size = this->strides [0] * final_height; |
| 109 | break; |
| 110 | case XCAM_PIX_FMT_RGBA64: |
| 111 | this->color_bits = 16; |
| 112 | this->components = 1; |
| 113 | this->strides [0] = final_width * 4 * 2; |
| 114 | this->offsets [0] = 0; |
| 115 | this->size = this->strides [0] * final_height; |
| 116 | break; |
| 117 | |
| 118 | case V4L2_PIX_FMT_SBGGR8: |
| 119 | case V4L2_PIX_FMT_SGBRG8: |
| 120 | case V4L2_PIX_FMT_SGRBG8: |
| 121 | case V4L2_PIX_FMT_SRGGB8: |
| 122 | this->color_bits = 8; |
| 123 | this->components = 1; |
| 124 | this->strides [0] = final_width; |
| 125 | this->offsets [0] = 0; |
| 126 | this->size = this->strides [0] * final_height; |
| 127 | break; |
| 128 | |
| 129 | case V4L2_PIX_FMT_SBGGR10: |
| 130 | case V4L2_PIX_FMT_SGBRG10: |
| 131 | case V4L2_PIX_FMT_SGRBG10: |
| 132 | case V4L2_PIX_FMT_SRGGB10: |
| 133 | this->color_bits = 10; |
| 134 | this->components = 1; |
| 135 | this->strides [0] = final_width * 2; |
| 136 | this->offsets [0] = 0; |
| 137 | this->size = this->strides [0] * final_height; |
| 138 | break; |
| 139 | |
| 140 | case V4L2_PIX_FMT_SBGGR12: |
| 141 | case V4L2_PIX_FMT_SGBRG12: |
| 142 | case V4L2_PIX_FMT_SGRBG12: |
| 143 | case V4L2_PIX_FMT_SRGGB12: |
| 144 | this->color_bits = 12; |
| 145 | this->components = 1; |
| 146 | this->strides [0] = final_width * 2; |
| 147 | this->offsets [0] = 0; |
| 148 | this->size = this->strides [0] * final_height; |
| 149 | break; |
| 150 | |
| 151 | case V4L2_PIX_FMT_SBGGR16: |
| 152 | case XCAM_PIX_FMT_SGRBG16: |
| 153 | this->color_bits = 16; |
| 154 | this->components = 1; |
| 155 | this->strides [0] = final_width * 2; |
| 156 | this->offsets [0] = 0; |
| 157 | this->size = this->strides [0] * final_height; |
| 158 | break; |
wangfei | 1a7d9f3 | 2015-03-26 18:30:00 +0800 | [diff] [blame] | 159 | |
| 160 | case XCAM_PIX_FMT_LAB: |
| 161 | this->color_bits = 32; |
| 162 | this->components = 1; |
| 163 | this->strides [0] = final_width * 3 * 4; |
| 164 | this->offsets [0] = 0; |
| 165 | this->size = this->strides [0] * final_height; |
| 166 | break; |
Wind Yuan | 41c9378 | 2015-03-18 15:36:02 +0800 | [diff] [blame] | 167 | default: |
| 168 | XCAM_LOG_WARNING ("VideoBufferInfo init failed, unsupported format:%s", xcam_fourcc_to_string (format)); |
| 169 | return false; |
| 170 | } |
| 171 | |
| 172 | return true; |
| 173 | } |
| 174 | |
| 175 | }; |