Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e472971e authored by Changyeon Jo's avatar Changyeon Jo
Browse files

Move utility functions to a common library



This change creates a library that contains utility functions commonly
used in different EVS versions.

Bug: 13542573
Test: VTS
Change-Id: Ica8f5e6228d7d4b1426d8cc9cd2c570d6b584897
Signed-off-by: default avatarChangyeon Jo <changyeon@google.com>
parent 1d0f024b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -2,3 +2,4 @@ service vendor.evs-hal-mock /vendor/bin/hw/android.hardware.automotive.evs@1.0-s
    class hal
    user automotive_evs
    group automotive_evs
    disabled # do not start automatically
+4 −2
Original line number Diff line number Diff line
@@ -19,13 +19,15 @@ cc_test {
    srcs: [
        "VtsHalEvsV1_0TargetTest.cpp",
        "FrameHandler.cpp",
        "FormatConvert.cpp"
    ],
    defaults: ["VtsHalTargetTestDefaults"],
    shared_libs: [
        "libui",
    ],
    static_libs: ["android.hardware.automotive.evs@1.0"],
    static_libs: [
        "android.hardware.automotive.evs@1.0",
        "android.hardware.automotive.evs@common-default-lib",
    ],
    test_suites: ["general-tests"],
    cflags: [
        "-O0",
+0 −74
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef EVS_VTS_FORMATCONVERT_H
#define EVS_VTS_FORMATCONVERT_H

#include <queue>
#include <stdint.h>


// Given an image buffer in NV21 format (HAL_PIXEL_FORMAT_YCRCB_420_SP), output 32bit RGBx/BGRx
// values.  The NV21 format provides a Y array of 8bit values, followed by a 1/2 x 1/2 interleaved
// U/V array.  It assumes an even width and height for the overall image, and a horizontal
// stride that is an even multiple of 16 bytes for both the Y and UV arrays.
void copyNV21toRGB32(unsigned width, unsigned height,
                     uint8_t* src,
                     uint32_t* dst, unsigned dstStridePixels,
                     bool bgrxFormat = false);

void copyNV21toBGR32(unsigned width, unsigned height,
                     uint8_t* src,
                     uint32_t* dst, unsigned dstStridePixels);


// Given an image buffer in YV12 format (HAL_PIXEL_FORMAT_YV12), output 32bit RGBx/BGRx values.
// The YV12 format provides a Y array of 8bit values, followed by a 1/2 x 1/2 U array, followed
// by another 1/2 x 1/2 V array.  It assumes an even width and height for the overall image,
// and a horizontal stride that is an even multiple of 16 bytes for each of the Y, U,
// and V arrays.
void copyYV12toRGB32(unsigned width, unsigned height,
                     uint8_t* src,
                     uint32_t* dst, unsigned dstStridePixels,
                     bool bgrxFormat = false);

void copyYV12toBGR32(unsigned width, unsigned height,
                     uint8_t* src,
                     uint32_t* dst, unsigned dstStridePixels);

// Given an image buffer in YUYV format (HAL_PIXEL_FORMAT_YCBCR_422_I), output 32bit RGBx/BGRx
// values.  The NV21 format provides a Y array of 8bit values, followed by a 1/2 x 1/2 interleaved
// U/V array.  It assumes an even width and height for the overall image, and a horizontal
// stride that is an even multiple of 16 bytes for both the Y and UV arrays.
void copyYUYVtoRGB32(unsigned width, unsigned height,
                     uint8_t* src, unsigned srcStrideBytes,
                     uint32_t* dst, unsigned dstStrideBytes,
                     bool bgrxFormat = false);

void copyYUYVtoBGR32(unsigned width, unsigned height,
                     uint8_t* src, unsigned srcStrideBytes,
                     uint32_t* dst, unsigned dstStrideBytes);


// Given an simple rectangular image buffer with an integer number of bytes per pixel,
// copy the pixel values into a new rectangular buffer (potentially with a different stride).
// This is typically used to copy RGBx data into an RGBx output buffer.
void copyMatchedInterleavedFormats(unsigned width, unsigned height,
                                   void* src, unsigned srcStridePixels,
                                   void* dst, unsigned dstStridePixels,
                                   unsigned pixelSize);

#endif // EVS_VTS_FORMATCONVERT_H
+27 −26
Original line number Diff line number Diff line
@@ -240,21 +240,22 @@ bool FrameHandler::copyBufferContents(const BufferDesc& tgtBuffer,
    tgt->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&tgtPixels);

    if (srcPixels && tgtPixels) {
        using namespace ::android::hardware::automotive::evs::common;
        if (tgtBuffer.format == HAL_PIXEL_FORMAT_RGBA_8888) {
            if (srcBuffer.format == HAL_PIXEL_FORMAT_YCRCB_420_SP) {   // 420SP == NV21
                copyNV21toRGB32(width, height,
                Utils::copyNV21toRGB32(width, height,
                                       srcPixels,
                                       tgtPixels, tgtBuffer.stride);
            } else if (srcBuffer.format == HAL_PIXEL_FORMAT_YV12) { // YUV_420P == YV12
                copyYV12toRGB32(width, height,
                Utils::copyYV12toRGB32(width, height,
                                       srcPixels,
                                       tgtPixels, tgtBuffer.stride);
            } else if (srcBuffer.format == HAL_PIXEL_FORMAT_YCBCR_422_I) { // YUYV
                copyYUYVtoRGB32(width, height,
                Utils::copyYUYVtoRGB32(width, height,
                                       srcPixels, srcBuffer.stride,
                                       tgtPixels, tgtBuffer.stride);
            } else if (srcBuffer.format == tgtBuffer.format) {  // 32bit RGBA
                copyMatchedInterleavedFormats(width, height,
                Utils::copyMatchedInterleavedFormats(width, height,
                                                     srcPixels, srcBuffer.stride,
                                                     tgtPixels, tgtBuffer.stride,
                                                     tgtBuffer.pixelSize);
@@ -264,19 +265,19 @@ bool FrameHandler::copyBufferContents(const BufferDesc& tgtBuffer,
            }
        } else if (tgtBuffer.format == HAL_PIXEL_FORMAT_BGRA_8888) {
            if (srcBuffer.format == HAL_PIXEL_FORMAT_YCRCB_420_SP) {   // 420SP == NV21
                copyNV21toBGR32(width, height,
                Utils::copyNV21toBGR32(width, height,
                                       srcPixels,
                                       tgtPixels, tgtBuffer.stride);
            } else if (srcBuffer.format == HAL_PIXEL_FORMAT_YV12) { // YUV_420P == YV12
                copyYV12toBGR32(width, height,
                Utils::copyYV12toBGR32(width, height,
                                       srcPixels,
                                       tgtPixels, tgtBuffer.stride);
            } else if (srcBuffer.format == HAL_PIXEL_FORMAT_YCBCR_422_I) { // YUYV
                copyYUYVtoBGR32(width, height,
                Utils::copyYUYVtoBGR32(width, height,
                                       srcPixels, srcBuffer.stride,
                                       tgtPixels, tgtBuffer.stride);
            } else if (srcBuffer.format == tgtBuffer.format) {  // 32bit RGBA
                copyMatchedInterleavedFormats(width, height,
                Utils::copyMatchedInterleavedFormats(width, height,
                                                     srcPixels, srcBuffer.stride,
                                                     tgtPixels, tgtBuffer.stride,
                                                     tgtBuffer.pixelSize);
+31 −0
Original line number Diff line number Diff line
//
// Copyright (C) 2019 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

cc_library_static {
    name: "android.hardware.automotive.evs@common-default-lib",
    vendor_available: true,
    relative_install_path: "hw",
    cflags: [
        "-O0",
        "-g",
    ],
    srcs: [
        "FormatConvert.cpp"
    ],
    export_include_dirs: ["include"],
    shared_libs: [
    ],
}
Loading