1 /* Copyright 2017 The Chromium OS Authors. All rights reserved.
2  * Use of this source code is governed by a BSD-style license that can be
3  * found in the LICENSE file.
4  */
5 
6 #ifndef HAL_USB_IMAGE_PROCESSOR_H_
7 #define HAL_USB_IMAGE_PROCESSOR_H_
8 
9 #include <camera/CameraMetadata.h>
10 // FourCC pixel formats (defined as V4L2_PIX_FMT_*).
11 #include <linux/videodev2.h>
12 // Declarations of HAL_PIXEL_FORMAT_XXX.
13 #include <system/graphics.h>
14 
15 #include "frame_buffer.h"
16 
17 namespace arc {
18 
19 // V4L2_PIX_FMT_YVU420(YV12) in ImageProcessor has alignment requirement.
20 // The stride of Y, U, and V planes should a multiple of 16 pixels.
21 struct ImageProcessor {
22   // Calculate the output buffer size when converting to the specified pixel
23   // format. |fourcc| is defined as V4L2_PIX_FMT_* in linux/videodev2.h.
24   // Return 0 on error.
25   static size_t GetConvertedSize(int fourcc, uint32_t width, uint32_t height);
26 
27   // Return whether this class supports the provided conversion.
28   static bool SupportsConversion(uint32_t from_fourcc, uint32_t to_fourcc);
29 
30   // Convert format from |in_frame.fourcc| to |out_frame->fourcc|. Caller should
31   // fill |data|, |buffer_size|, |width|, and |height| of |out_frame|. The
32   // function will fill |out_frame->data_size|. Return non-zero error code on
33   // failure; return 0 on success.
34   static int ConvertFormat(const android::CameraMetadata& metadata,
35                            const FrameBuffer& in_frame, FrameBuffer* out_frame);
36 
37   // Scale image size according to |in_frame| and |out_frame|. Only support
38   // V4L2_PIX_FMT_YUV420 format. Caller should fill |data|, |width|, |height|,
39   // and |buffer_size| of |out_frame|. The function will fill |data_size| and
40   // |fourcc| of |out_frame|.
41   static int Scale(const FrameBuffer& in_frame, FrameBuffer* out_frame);
42 };
43 
44 }  // namespace arc
45 
46 #endif  // HAL_USB_IMAGE_PROCESSOR_H_
47