1 /*
2  * Copyright (C) 2017 The Android Open Source Project
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 EVS_VTS_FORMATCONVERT_H
18 #define EVS_VTS_FORMATCONVERT_H
19 
20 #include <queue>
21 #include <stdint.h>
22 
23 
24 // Given an image buffer in NV21 format (HAL_PIXEL_FORMAT_YCRCB_420_SP), output 32bit RGBx/BGRx
25 // values.  The NV21 format provides a Y array of 8bit values, followed by a 1/2 x 1/2 interleaved
26 // U/V array.  It assumes an even width and height for the overall image, and a horizontal
27 // stride that is an even multiple of 16 bytes for both the Y and UV arrays.
28 void copyNV21toRGB32(unsigned width, unsigned height,
29                      uint8_t* src,
30                      uint32_t* dst, unsigned dstStridePixels,
31                      bool bgrxFormat = false);
32 
33 void copyNV21toBGR32(unsigned width, unsigned height,
34                      uint8_t* src,
35                      uint32_t* dst, unsigned dstStridePixels);
36 
37 
38 // Given an image buffer in YV12 format (HAL_PIXEL_FORMAT_YV12), output 32bit RGBx/BGRx values.
39 // The YV12 format provides a Y array of 8bit values, followed by a 1/2 x 1/2 U array, followed
40 // by another 1/2 x 1/2 V array.  It assumes an even width and height for the overall image,
41 // and a horizontal stride that is an even multiple of 16 bytes for each of the Y, U,
42 // and V arrays.
43 void copyYV12toRGB32(unsigned width, unsigned height,
44                      uint8_t* src,
45                      uint32_t* dst, unsigned dstStridePixels,
46                      bool bgrxFormat = false);
47 
48 void copyYV12toBGR32(unsigned width, unsigned height,
49                      uint8_t* src,
50                      uint32_t* dst, unsigned dstStridePixels);
51 
52 // Given an image buffer in YUYV format (HAL_PIXEL_FORMAT_YCBCR_422_I), output 32bit RGBx/BGRx
53 // values.  The NV21 format provides a Y array of 8bit values, followed by a 1/2 x 1/2 interleaved
54 // U/V array.  It assumes an even width and height for the overall image, and a horizontal
55 // stride that is an even multiple of 16 bytes for both the Y and UV arrays.
56 void copyYUYVtoRGB32(unsigned width, unsigned height,
57                      uint8_t* src, unsigned srcStrideBytes,
58                      uint32_t* dst, unsigned dstStrideBytes,
59                      bool bgrxFormat = false);
60 
61 void copyYUYVtoBGR32(unsigned width, unsigned height,
62                      uint8_t* src, unsigned srcStrideBytes,
63                      uint32_t* dst, unsigned dstStrideBytes);
64 
65 
66 // Given an simple rectangular image buffer with an integer number of bytes per pixel,
67 // copy the pixel values into a new rectangular buffer (potentially with a different stride).
68 // This is typically used to copy RGBx data into an RGBx output buffer.
69 void copyMatchedInterleavedFormats(unsigned width, unsigned height,
70                                    void* src, unsigned srcStridePixels,
71                                    void* dst, unsigned dstStridePixels,
72                                    unsigned pixelSize);
73 
74 #endif // EVS_VTS_FORMATCONVERT_H
75