Skip to content

Commit

Permalink
Added flipping, bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
awxkee committed Apr 18, 2024
1 parent b5a72a5 commit 8fc8feb
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ set(SPARKYUV_SOURCES
src/YDbDr.cpp
src/YCbCr400.cpp
src/YCbCr411.cpp
src/Flip.cpp)
src/Flip.cpp
src/Transpose.cpp)

set(HWY_SOURCES
highway/hwy/aligned_allocator.cc highway/hwy/targets.cc highway/hwy/targets.cc
Expand Down
6 changes: 2 additions & 4 deletions src/Flip-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ FlipVerticalImpl(const T *SPARKYUV_RESTRICT src, const uint32_t srcStride,
auto mDestinationPtr = reinterpret_cast<uint8_t *>(dst);

for (uint32_t y = 0; y < height; ++y) {

uint32_t x = 0;

T *mDestination = reinterpret_cast<T *>(mDestinationPtr);
Expand Down Expand Up @@ -138,8 +137,8 @@ FlipHorizontalImpl(const T *SPARKYUV_RESTRICT src, const uint32_t srcStride,
const T *mSource = reinterpret_cast<const T *>(mFlippedSourcePtr);

if (x - lanes >= 0) {
mDestination = reinterpret_cast<T *>(mDestinationPtr + width*channels);
while (x - lanes >= 0) {
mDestination += channels;
for (;x - lanes >= 0; x -= lanes) {
mDestination -= lanes * channels;
if (Surface == sparkyuv::SURFACE_CHANNEL) {
const auto v = LoadU(d, mSource);
Expand All @@ -156,7 +155,6 @@ FlipHorizontalImpl(const T *SPARKYUV_RESTRICT src, const uint32_t srcStride,
StoreInterleaved4(Reverse(d, i1), Reverse(d, i2), Reverse(d, i3), Reverse(d, i4), d, mDestination);
}
mSource += lanes * channels;
x -= lanes;
}
}

Expand Down
35 changes: 35 additions & 0 deletions src/Transpose-inl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (C) 2024 Radzivon Bartoshyk
//
// This file belongs to sparkyuv 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.

#if defined(SPARKYUV_TRANSPOSE_INL_H) == defined(HWY_TARGET_TOGGLE)
#ifdef SPARKYUV_TRANSPOSE_INL_H
#undef SPARKYUV_TRANSPOSE_INL_H
#else
#define SPARKYUV_TRANSPOSE_INL_H
#endif

#include "hwy/highway.h"
#include "yuv-inl.h"
#include "sparkyuv-internal.h"
#include <algorithm>

HWY_BEFORE_NAMESPACE();
namespace sparkyuv::HWY_NAMESPACE {

}
HWY_AFTER_NAMESPACE();

#endif
30 changes: 30 additions & 0 deletions src/Transpose.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (C) 2024 Radzivon Bartoshyk
//
// This file belongs to sparkyuv 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.

#undef HWY_TARGET_INCLUDE
#define HWY_TARGET_INCLUDE "src/Transpose.cpp"

#include "hwy/foreach_target.h"
#include "hwy/highway.h"
#include "sparkyuv.h"
#include "yuv-inl.h"
#include "Transpose-inl.h"

#if HWY_ONCE
namespace sparkyuv {

}
#endif
11 changes: 5 additions & 6 deletions tools/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ int main() {
// sparkyuv::YCbCr400ToRGBA(rgbaData.data(), rgbaStride, width, height,
// yPlane.data(), yPlaneStride,0.299f, 0.114f, sparkyuv::YUV_RANGE_PC);
});
std::vector<uint8_t > flipped(rgbaData.size());
std::vector<uint8_t> flipped(rgbaData.size());

bench(1, ANSI_COLOR_GREEN, "Flip Vertical", [&]() {
// libyuv::I420ToABGR(yPlane.data(), yPlaneStride,
Expand All @@ -184,21 +184,20 @@ int main() {
// yPlane.data(), yPlaneStride,0.299f, 0.114f, sparkyuv::YUV_RANGE_PC);
});

std::vector<uint8_t > flipped2(rgbaData.size());
std::vector<uint8_t> flipped2(rgbaData.size());

bench(15, ANSI_COLOR_GREEN, "Flip Horizontal", [&]() {
bench(1, ANSI_COLOR_GREEN, "Flip Horizontal", [&]() {
// libyuv::I420ToABGR(yPlane.data(), yPlaneStride,
// uPlane.data(), uvPlaneStride,
// vPlane.data(), uvPlaneStride, rgbaData.data(), rgbaStride, width, height);
sparkyuv::FlipHorizontalRGBA(rgbaData.data(), rgbaStride, flipped2.data(), rgbaStride, width, height);
rgbaData = flipped2;
sparkyuv::FlipHorizontalRGBA(rgbaData.data(), rgbaStride, flipped2.data(), rgbaStride, width, height);
rgbaData = flipped2;
// sparkyuv::YCbCr400ToRGBA(rgbaData.data(), rgbaStride, width, height,
// yPlane.data(), yPlaneStride,0.299f, 0.114f, sparkyuv::YUV_RANGE_PC);
});




// RGBToRGBA(inSrcData.data(), inWidth * sizeof(uint8_t)* 3, rgbaData.data(), inWidth*4* sizeof(uint8_t), width, height);

// for (int i = 0; i < 5; ++i) {
Expand Down

0 comments on commit 8fc8feb

Please sign in to comment.