Coverage Report

Created: 2026-04-01 07:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/Simd/src/Simd/SimdAvx2BayerToBgr.cpp
Line
Count
Source
1
/*
2
* Simd Library (http://ermig1979.github.io/Simd).
3
*
4
* Copyright (c) 2011-2022 Yermalayeu Ihar.
5
*
6
* Permission is hereby granted, free of charge, to any person obtaining a copy
7
* of this software and associated documentation files (the "Software"), to deal
8
* in the Software without restriction, including without limitation the rights
9
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
* copies of the Software, and to permit persons to whom the Software is
11
* furnished to do so, subject to the following conditions:
12
*
13
* The above copyright notice and this permission notice shall be included in
14
* all copies or substantial portions of the Software.
15
*
16
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
* SOFTWARE.
23
*/
24
#include "Simd/SimdStore.h"
25
#include "Simd/SimdMemory.h"
26
#include "Simd/SimdBayer.h"
27
#include "Simd/SimdConversion.h"
28
#include "Simd/SimdInterleave.h"
29
30
namespace Simd
31
{
32
#ifdef SIMD_AVX2_ENABLE    
33
    namespace Avx2
34
    {
35
        template <bool align> SIMD_INLINE void SaveBgr(const __m256i src[3], uint8_t * dst)
36
0
        {
37
0
            Store<align>((__m256i*)dst + 0, InterleaveBgr<0>(src[0], src[1], src[2]));
38
0
            Store<align>((__m256i*)dst + 1, InterleaveBgr<1>(src[0], src[1], src[2]));
39
0
            Store<align>((__m256i*)dst + 2, InterleaveBgr<2>(src[0], src[1], src[2]));
40
0
        }
Unexecuted instantiation: void Simd::Avx2::SaveBgr<true>(long long __vector(4) const*, unsigned char*)
Unexecuted instantiation: void Simd::Avx2::SaveBgr<false>(long long __vector(4) const*, unsigned char*)
41
42
        template <bool align, SimdPixelFormatType bayerFormat> void BayerToBgr(const __m256i src[12], uint8_t * bgr, size_t stride)
43
0
        {
44
0
            __m256i _bgr[6];
45
0
            BayerToBgr<bayerFormat>(src, _bgr);
46
0
            SaveBgr<align>(_bgr + 0, bgr);
47
0
            SaveBgr<align>(_bgr + 3, bgr + stride);
48
0
        }
Unexecuted instantiation: void Simd::Avx2::BayerToBgr<true, (SimdPixelFormatType)10>(long long __vector(4) const*, unsigned char*, unsigned long)
Unexecuted instantiation: void Simd::Avx2::BayerToBgr<false, (SimdPixelFormatType)10>(long long __vector(4) const*, unsigned char*, unsigned long)
Unexecuted instantiation: void Simd::Avx2::BayerToBgr<true, (SimdPixelFormatType)11>(long long __vector(4) const*, unsigned char*, unsigned long)
Unexecuted instantiation: void Simd::Avx2::BayerToBgr<false, (SimdPixelFormatType)11>(long long __vector(4) const*, unsigned char*, unsigned long)
Unexecuted instantiation: void Simd::Avx2::BayerToBgr<true, (SimdPixelFormatType)12>(long long __vector(4) const*, unsigned char*, unsigned long)
Unexecuted instantiation: void Simd::Avx2::BayerToBgr<false, (SimdPixelFormatType)12>(long long __vector(4) const*, unsigned char*, unsigned long)
Unexecuted instantiation: void Simd::Avx2::BayerToBgr<true, (SimdPixelFormatType)13>(long long __vector(4) const*, unsigned char*, unsigned long)
Unexecuted instantiation: void Simd::Avx2::BayerToBgr<false, (SimdPixelFormatType)13>(long long __vector(4) const*, unsigned char*, unsigned long)
49
50
        template <bool align, SimdPixelFormatType bayerFormat> void BayerToBgr(const uint8_t * bayer, size_t width, size_t height, size_t bayerStride, uint8_t * bgr, size_t bgrStride)
51
0
        {
52
0
            const uint8_t * src[3];
53
0
            __m256i _src[12];
54
0
            size_t body = AlignHi(width - 2, A) - A;
55
0
            for (size_t row = 0; row < height; row += 2)
56
0
            {
57
0
                src[0] = (row == 0 ? bayer : bayer - 2 * bayerStride);
58
0
                src[1] = bayer;
59
0
                src[2] = (row == height - 2 ? bayer : bayer + 2 * bayerStride);
60
61
0
                LoadBayerNose<align>(src, 0, bayerStride, _src);
62
0
                BayerToBgr<align, bayerFormat>(_src, bgr, bgrStride);
63
0
                for (size_t col = A; col < body; col += A)
64
0
                {
65
0
                    LoadBayerBody<align>(src, col, bayerStride, _src);
66
0
                    BayerToBgr<align, bayerFormat>(_src, bgr + 3 * col, bgrStride);
67
0
                }
68
0
                LoadBayerTail<false>(src, width - A, bayerStride, _src);
69
0
                BayerToBgr<false, bayerFormat>(_src, bgr + 3 * (width - A), bgrStride);
70
71
0
                bayer += 2 * bayerStride;
72
0
                bgr += 2 * bgrStride;
73
0
            }
74
0
        }
Unexecuted instantiation: void Simd::Avx2::BayerToBgr<true, (SimdPixelFormatType)10>(unsigned char const*, unsigned long, unsigned long, unsigned long, unsigned char*, unsigned long)
Unexecuted instantiation: void Simd::Avx2::BayerToBgr<true, (SimdPixelFormatType)11>(unsigned char const*, unsigned long, unsigned long, unsigned long, unsigned char*, unsigned long)
Unexecuted instantiation: void Simd::Avx2::BayerToBgr<true, (SimdPixelFormatType)12>(unsigned char const*, unsigned long, unsigned long, unsigned long, unsigned char*, unsigned long)
Unexecuted instantiation: void Simd::Avx2::BayerToBgr<true, (SimdPixelFormatType)13>(unsigned char const*, unsigned long, unsigned long, unsigned long, unsigned char*, unsigned long)
Unexecuted instantiation: void Simd::Avx2::BayerToBgr<false, (SimdPixelFormatType)10>(unsigned char const*, unsigned long, unsigned long, unsigned long, unsigned char*, unsigned long)
Unexecuted instantiation: void Simd::Avx2::BayerToBgr<false, (SimdPixelFormatType)11>(unsigned char const*, unsigned long, unsigned long, unsigned long, unsigned char*, unsigned long)
Unexecuted instantiation: void Simd::Avx2::BayerToBgr<false, (SimdPixelFormatType)12>(unsigned char const*, unsigned long, unsigned long, unsigned long, unsigned char*, unsigned long)
Unexecuted instantiation: void Simd::Avx2::BayerToBgr<false, (SimdPixelFormatType)13>(unsigned char const*, unsigned long, unsigned long, unsigned long, unsigned char*, unsigned long)
75
76
        template <bool align> void BayerToBgr(const uint8_t * bayer, size_t width, size_t height, size_t bayerStride, SimdPixelFormatType bayerFormat, uint8_t * bgr, size_t bgrStride)
77
0
        {
78
0
            switch (bayerFormat)
79
0
            {
80
0
            case SimdPixelFormatBayerGrbg:
81
0
                BayerToBgr<align, SimdPixelFormatBayerGrbg>(bayer, width, height, bayerStride, bgr, bgrStride);
82
0
                break;
83
0
            case SimdPixelFormatBayerGbrg:
84
0
                BayerToBgr<align, SimdPixelFormatBayerGbrg>(bayer, width, height, bayerStride, bgr, bgrStride);
85
0
                break;
86
0
            case SimdPixelFormatBayerRggb:
87
0
                BayerToBgr<align, SimdPixelFormatBayerRggb>(bayer, width, height, bayerStride, bgr, bgrStride);
88
0
                break;
89
0
            case SimdPixelFormatBayerBggr:
90
0
                BayerToBgr<align, SimdPixelFormatBayerBggr>(bayer, width, height, bayerStride, bgr, bgrStride);
91
0
                break;
92
0
            default:
93
0
                assert(0);
94
0
            }
95
0
        }
Unexecuted instantiation: void Simd::Avx2::BayerToBgr<true>(unsigned char const*, unsigned long, unsigned long, unsigned long, SimdPixelFormatType, unsigned char*, unsigned long)
Unexecuted instantiation: void Simd::Avx2::BayerToBgr<false>(unsigned char const*, unsigned long, unsigned long, unsigned long, SimdPixelFormatType, unsigned char*, unsigned long)
96
97
        void BayerToBgr(const uint8_t * bayer, size_t width, size_t height, size_t bayerStride, SimdPixelFormatType bayerFormat, uint8_t * bgr, size_t bgrStride)
98
0
        {
99
0
            assert((width % 2 == 0) && (height % 2 == 0));
100
101
0
            if (Aligned(bayer) && Aligned(bgr) && Aligned(bayerStride) && Aligned(bgrStride))
102
0
                BayerToBgr<true>(bayer, width, height, bayerStride, bayerFormat, bgr, bgrStride);
103
0
            else
104
0
                BayerToBgr<false>(bayer, width, height, bayerStride, bayerFormat, bgr, bgrStride);
105
0
        }
106
    }
107
#endif// SIMD_AVX2_ENABLE
108
}