Coverage Report

Created: 2026-10-28 07:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/Simd/src/Simd/SimdBaseBgraToGray.cpp
Line
Count
Source
1
/*
2
* Simd Library (http://ermig1979.github.io/Simd).
3
*
4
* Copyright (c) 2011-2021 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/SimdConversion.h"
25
26
namespace Simd
27
{
28
    namespace Base
29
    {
30
        void BgraToGray(const uint8_t * bgra, size_t width, size_t height, size_t bgraStride, uint8_t * gray, size_t grayStride)
31
5.80k
        {
32
13.8k
            for (size_t row = 0; row < height; ++row)
33
8.09k
            {
34
8.09k
                const uint8_t * pBgra = bgra + row*bgraStride;
35
8.09k
                uint8_t * pGray = gray + row*grayStride;
36
244k
                for (const uint8_t *pGrayEnd = pGray + width; pGray < pGrayEnd; pGray += 1, pBgra += 4)
37
236k
                {
38
236k
                    *pGray = BgrToGray(pBgra[0], pBgra[1], pBgra[2]);
39
236k
                }
40
8.09k
            }
41
5.80k
        }
42
43
        void RgbaToGray(const uint8_t* rgba, size_t width, size_t height, size_t rgbaStride, uint8_t* gray, size_t grayStride)
44
766
        {
45
3.75M
            for (size_t row = 0; row < height; ++row)
46
3.75M
            {
47
3.75M
                const uint8_t* pRgba = rgba + row * rgbaStride;
48
3.75M
                uint8_t* pGray = gray + row * grayStride;
49
311M
                for (const uint8_t* pGrayEnd = pGray + width; pGray < pGrayEnd; pGray += 1, pRgba += 4)
50
307M
                {
51
307M
                    *pGray = BgrToGray(pRgba[2], pRgba[1], pRgba[0]);
52
307M
                }
53
3.75M
            }
54
766
        }
55
    }
56
}