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 namespace android { 25 namespace hardware { 26 namespace automotive { 27 namespace evs { 28 namespace common { 29 30 class Utils { 31 public: 32 // Given an image buffer in NV21 format (HAL_PIXEL_FORMAT_YCRCB_420_SP), output 32bit RGBx/BGRx 33 // values. The NV21 format provides a Y array of 8bit values, followed by a 1/2 x 1/2 interleaved 34 // U/V array. It assumes an even width and height for the overall image, and a horizontal 35 // stride that is an even multiple of 16 bytes for both the Y and UV arrays. 36 static void copyNV21toRGB32(unsigned width, unsigned height, 37 uint8_t* src, 38 uint32_t* dst, unsigned dstStridePixels, 39 bool bgrxFormat = false); 40 41 static void copyNV21toBGR32(unsigned width, unsigned height, 42 uint8_t* src, 43 uint32_t* dst, unsigned dstStridePixels); 44 45 46 // Given an image buffer in YV12 format (HAL_PIXEL_FORMAT_YV12), output 32bit RGBx/BGRx values. 47 // The YV12 format provides a Y array of 8bit values, followed by a 1/2 x 1/2 U array, followed 48 // by another 1/2 x 1/2 V array. It assumes an even width and height for the overall image, 49 // and a horizontal stride that is an even multiple of 16 bytes for each of the Y, U, 50 // and V arrays. 51 static void copyYV12toRGB32(unsigned width, unsigned height, 52 uint8_t* src, 53 uint32_t* dst, unsigned dstStridePixels, 54 bool bgrxFormat = false); 55 56 static void copyYV12toBGR32(unsigned width, unsigned height, 57 uint8_t* src, 58 uint32_t* dst, unsigned dstStridePixels); 59 60 // Given an image buffer in YUYV format (HAL_PIXEL_FORMAT_YCBCR_422_I), output 32bit RGBx/BGRx 61 // values. The NV21 format provides a Y array of 8bit values, followed by a 1/2 x 1/2 interleaved 62 // U/V array. It assumes an even width and height for the overall image, and a horizontal 63 // stride that is an even multiple of 16 bytes for both the Y and UV arrays. 64 static void copyYUYVtoRGB32(unsigned width, unsigned height, 65 uint8_t* src, unsigned srcStrideBytes, 66 uint32_t* dst, unsigned dstStrideBytes, 67 bool bgrxFormat = false); 68 69 static void copyYUYVtoBGR32(unsigned width, unsigned height, 70 uint8_t* src, unsigned srcStrideBytes, 71 uint32_t* dst, unsigned dstStrideBytes); 72 73 74 // Given an simple rectangular image buffer with an integer number of bytes per pixel, 75 // copy the pixel values into a new rectangular buffer (potentially with a different stride). 76 // This is typically used to copy RGBx data into an RGBx output buffer. 77 static void copyMatchedInterleavedFormats(unsigned width, unsigned height, 78 void* src, unsigned srcStridePixels, 79 void* dst, unsigned dstStridePixels, 80 unsigned pixelSize); 81 82 private: 83 template<unsigned alignment> 84 static int align(int value); 85 86 static inline float clamp(float v, float min, float max); 87 static uint32_t yuvToRgbx(const unsigned char Y, 88 const unsigned char Uin, 89 const unsigned char Vin, 90 bool bgrxFormat = false); 91 }; 92 93 } // namespace common 94 } // namespace evs 95 } // namespace automotive 96 } // namespace hardware 97 } // namespace android 98 99 #endif // EVS_VTS_FORMATCONVERT_H 100