Coverage Report

Created: 2026-09-28 10:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/source/bitmap/BlendFrameCache.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
#include <tools/color.hxx>
21
22
#include <vcl/BitmapColor.hxx>
23
#include <vcl/BitmapWriteAccess.hxx>
24
25
#include <bitmap/BlendFrameCache.hxx>
26
27
BlendFrameCache::BlendFrameCache(Size const& rSize, sal_uInt8 nAlpha, Color const& rColorTopLeft,
28
                                 Color const& rColorTopRight, Color const& rColorBottomRight,
29
                                 Color const& rColorBottomLeft)
30
0
    : m_aLastSize(rSize)
31
0
    , m_nLastAlpha(nAlpha)
32
0
    , m_aLastColorTopLeft(rColorTopLeft)
33
0
    , m_aLastColorTopRight(rColorTopRight)
34
0
    , m_aLastColorBottomRight(rColorBottomRight)
35
0
    , m_aLastColorBottomLeft(rColorBottomLeft)
36
0
{
37
0
    if (rSize.Width() <= 1 || rSize.Height() <= 1)
38
0
        return;
39
40
0
    Bitmap aContent(rSize, vcl::PixelFormat::N32_BPP);
41
0
    aContent.Erase(COL_TRANSPARENT);
42
43
0
    {
44
0
        BitmapScopedWriteAccess pContent(aContent);
45
0
        assert(pContent);
46
0
        if (!pContent)
47
0
            return;
48
49
0
        Scanline pScanContent = pContent->GetScanline(0);
50
51
        // x == 0, y == 0, top-left corner
52
0
        Color aCol(rColorTopLeft);
53
0
        aCol.SetAlpha(nAlpha);
54
0
        pContent->SetPixelOnData(pScanContent, 0, aCol);
55
56
0
        tools::Long x;
57
0
        const tools::Long nW(rSize.Width());
58
59
        // y == 0, top line left to right
60
0
        for (x = 1; x < nW - 1; x++)
61
0
        {
62
0
            Color aMix(rColorTopLeft);
63
64
0
            aMix.Merge(rColorTopRight, 255 - sal_uInt8((x * 255) / nW));
65
0
            aMix.SetAlpha(nAlpha);
66
0
            pContent->SetPixelOnData(pScanContent, x, aMix);
67
0
        }
68
69
        // x == nW - 1, y == 0, top-right corner
70
        // #i123690# Caution! When nW is 1, x == nW is possible (!)
71
0
        if (x < nW)
72
0
        {
73
0
            aCol = rColorTopRight;
74
0
            aCol.SetAlpha(nAlpha);
75
0
            pContent->SetPixelOnData(pScanContent, x, aCol);
76
0
        }
77
78
0
        tools::Long y;
79
0
        const tools::Long nH(rSize.Height());
80
81
        // x == 0 and nW - 1, left and right line top-down
82
0
        for (y = 1; y < nH - 1; y++)
83
0
        {
84
0
            pScanContent = pContent->GetScanline(y);
85
0
            Color aMixA(rColorTopLeft);
86
87
0
            aMixA.Merge(rColorBottomLeft, 255 - sal_uInt8((y * 255) / nH));
88
0
            aMixA.SetAlpha(nAlpha);
89
0
            pContent->SetPixelOnData(pScanContent, 0, aMixA);
90
91
            // #i123690# Caution! When nW is 1, x == nW is possible (!)
92
0
            if (x < nW)
93
0
            {
94
0
                Color aMixB(rColorTopRight);
95
96
0
                aMixB.Merge(rColorBottomRight, 255 - sal_uInt8((y * 255) / nH));
97
0
                aMixB.SetAlpha(nAlpha);
98
0
                pContent->SetPixelOnData(pScanContent, x, aMixB);
99
0
            }
100
0
        }
101
102
        // #i123690# Caution! When nH is 1, y == nH is possible (!)
103
0
        if (y < nH)
104
0
        {
105
            // x == 0, y == nH - 1, bottom-left corner
106
0
            aCol = rColorBottomLeft;
107
0
            aCol.SetAlpha(nAlpha);
108
0
            pContent->SetPixelOnData(pScanContent, 0, aCol);
109
110
            // y == nH - 1, bottom line left to right
111
0
            for (x = 1; x < nW - 1; x++)
112
0
            {
113
0
                Color aMix(rColorBottomLeft);
114
115
0
                aMix.Merge(rColorBottomRight, 255 - sal_uInt8(((x - 0) * 255) / nW));
116
0
                aMix.SetAlpha(nAlpha);
117
0
                pContent->SetPixelOnData(pScanContent, x, aMix);
118
0
            }
119
120
            // x == nW - 1, y == nH - 1, bottom-right corner
121
            // #i123690# Caution! When nW is 1, x == nW is possible (!)
122
0
            if (x < nW)
123
0
            {
124
0
                aCol = rColorBottomRight;
125
0
                aCol.SetAlpha(nAlpha);
126
0
                pContent->SetPixelOnData(pScanContent, x, aCol);
127
0
            }
128
0
        }
129
0
    }
130
131
0
    m_aLastResult = std::move(aContent);
132
0
}
133
134
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */