mirror of
https://github.com/ittiam-systems/libhevc.git
synced 2026-10-02 08:42:42 +07:00
Some checks are pending
CMake / build (cmake, aarch64-linux-gnu-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch64_toolchain.cmake, aarch64-linux-gnu-g++, ubuntu-latest-cross-aarch64-cmake, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, arm-linux-gnueabihf-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch32_toolchain.cmake, arm-linux-gnueabihf-g++, ubuntu-latest-cross-aarch32-cmake, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, clang, , clang++, macos-latest-clang-cmake, macos-latest) (push) Waiting to run
CMake / build (cmake, clang, , clang++, ubuntu-24.04-arm-clang-cmake, ubuntu-24.04-arm) (push) Waiting to run
CMake / build (cmake, clang, , clang++, ubuntu-latest-clang-cmake, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, clang, -DSANITIZE=fuzzer-no-link,address, clang++, ubuntu-latest-clang-cmake-asan-fuzzer, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, clang, -G Ninja, clang++, ubuntu-latest-clang-cmake-ninja, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, gcc, , g++, ubuntu-latest-gcc-cmake, ubuntu-latest) (push) Waiting to run
As the decoder doesn't support high-bit-depth profiles, 10-bit decoder tests are currently disabled. Also, updated the decoder tests to not silently ignore errors.
135 lines
3.5 KiB
C++
135 lines
3.5 KiB
C++
/******************************************************************************
|
|
*
|
|
* Copyright (C) 2026 Ittiam Systems Pvt Ltd, Bangalore
|
|
*
|
|
* 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.
|
|
*
|
|
******************************************************************************/
|
|
|
|
#include "RawBuf.h"
|
|
|
|
#include <stdexcept>
|
|
|
|
size_t RawBuf::numPlanes() const {
|
|
switch (mFormat) {
|
|
case libhevc::test::Format::yuv400p:
|
|
return 1;
|
|
case libhevc::test::Format::yuv420sp_uv:
|
|
case libhevc::test::Format::yuv420sp_vu:
|
|
return 2;
|
|
case libhevc::test::Format::yuv420p:
|
|
case libhevc::test::Format::yuv422p:
|
|
case libhevc::test::Format::yuv444p:
|
|
return 3;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
size_t RawBuf::planeWidth(size_t planeIdx) const {
|
|
if (planeIdx == 0) {
|
|
return mWidth;
|
|
}
|
|
if (planeIdx >= numPlanes()) {
|
|
return 0;
|
|
}
|
|
switch (mFormat) {
|
|
case libhevc::test::Format::yuv400p:
|
|
return 0;
|
|
case libhevc::test::Format::yuv420p:
|
|
case libhevc::test::Format::yuv422p:
|
|
return mWidth / 2;
|
|
case libhevc::test::Format::yuv420sp_uv:
|
|
case libhevc::test::Format::yuv420sp_vu:
|
|
return mWidth; // Interleaved UV has same byte-width as Y luma
|
|
case libhevc::test::Format::yuv444p:
|
|
return mWidth;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
size_t RawBuf::planeHeight(size_t planeIdx) const {
|
|
if (planeIdx == 0) {
|
|
return mHeight;
|
|
}
|
|
if (planeIdx >= numPlanes()) {
|
|
return 0;
|
|
}
|
|
switch (mFormat) {
|
|
case libhevc::test::Format::yuv400p:
|
|
return 0;
|
|
case libhevc::test::Format::yuv420p:
|
|
case libhevc::test::Format::yuv420sp_uv:
|
|
case libhevc::test::Format::yuv420sp_vu:
|
|
return mHeight / 2;
|
|
case libhevc::test::Format::yuv422p:
|
|
case libhevc::test::Format::yuv444p:
|
|
return mHeight;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
bool RawBuf::allocBuffer(size_t width, size_t height, size_t bitDepth,
|
|
libhevc::test::Format format, size_t alignment) {
|
|
mWidth = width;
|
|
mHeight = height;
|
|
mBitDepth = bitDepth ? bitDepth : 8;
|
|
mFormat = format;
|
|
|
|
size_t planesCount = numPlanes();
|
|
size_t totalSize = 0;
|
|
|
|
for (size_t i = 0; i < 3; ++i) {
|
|
mStrides[i] = 0;
|
|
mOffsets[i] = 0;
|
|
}
|
|
|
|
size_t pixelSize = (mBitDepth + 7) / 8;
|
|
for (size_t i = 0; i < planesCount; ++i) {
|
|
size_t w = planeWidth(i);
|
|
size_t h = planeHeight(i);
|
|
|
|
// Align stride to alignment boundary
|
|
size_t alignedStride = (w + alignment - 1) & ~(alignment - 1);
|
|
mStrides[i] = alignedStride;
|
|
mOffsets[i] = totalSize;
|
|
totalSize += alignedStride * h * pixelSize;
|
|
}
|
|
|
|
mStorage.resize(totalSize);
|
|
return true;
|
|
}
|
|
|
|
void RawBuf::freeBuffer() {
|
|
mStorage.clear();
|
|
mStorage.shrink_to_fit();
|
|
mWidth = 0;
|
|
mHeight = 0;
|
|
for (size_t i = 0; i < 3; ++i) {
|
|
mStrides[i] = 0;
|
|
mOffsets[i] = 0;
|
|
}
|
|
}
|
|
|
|
uint8_t* RawBuf::planeData(size_t planeIdx) {
|
|
if (planeIdx >= numPlanes() || mStorage.empty()) {
|
|
return nullptr;
|
|
}
|
|
return mStorage.data() + mOffsets[planeIdx];
|
|
}
|
|
|
|
const uint8_t* RawBuf::planeData(size_t planeIdx) const {
|
|
if (planeIdx >= numPlanes() || mStorage.empty()) {
|
|
return nullptr;
|
|
}
|
|
return mStorage.data() + mOffsets[planeIdx];
|
|
}
|