Coverage Report

Created: 2026-11-06 11:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/source/bitmap/BitmapInfoAccess.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <vcl/alpha.hxx>
21
#include <vcl/BitmapInfoAccess.hxx>
22
23
#include <salbmp.hxx>
24
#include <svdata.hxx>
25
#include <salinst.hxx>
26
27
BitmapInfoAccess::BitmapInfoAccess(const AlphaMask& rBitmap, BitmapAccessMode nMode)
28
0
    : BitmapInfoAccess(rBitmap.GetBitmap(), nMode)
29
0
{
30
0
}
31
32
BitmapInfoAccess::BitmapInfoAccess(const Bitmap& rBitmap, BitmapAccessMode nMode)
33
1.14M
    : mpBuffer(nullptr)
34
1.14M
    , mnAccessMode(nMode)
35
1.14M
{
36
1.14M
    std::shared_ptr<SalBitmap> xImpBmp = rBitmap.ImplGetSalBitmap();
37
38
1.14M
    if (!xImpBmp)
39
5.30k
        return;
40
41
1.14M
    if (mnAccessMode == BitmapAccessMode::Write)
42
936k
    {
43
936k
        xImpBmp->DropScaledCache();
44
45
936k
        if (xImpBmp.use_count() > 2)
46
9.36k
        {
47
9.36k
            xImpBmp.reset();
48
9.36k
            const_cast<Bitmap&>(rBitmap).ImplMakeUnique();
49
9.36k
            xImpBmp = rBitmap.ImplGetSalBitmap();
50
9.36k
        }
51
936k
    }
52
53
1.14M
    mpBuffer = xImpBmp->AcquireBuffer(mnAccessMode);
54
55
1.14M
    if (!mpBuffer)
56
140
    {
57
140
        std::shared_ptr<SalBitmap> xNewImpBmp(GetSalInstance()->CreateSalBitmap());
58
140
        if (xNewImpBmp->Create(*xImpBmp))
59
140
        {
60
140
            xImpBmp = std::move(xNewImpBmp);
61
140
            const_cast<Bitmap&>(rBitmap).ImplSetSalBitmap(xImpBmp);
62
140
            mpBuffer = xImpBmp->AcquireBuffer(mnAccessMode);
63
140
        }
64
140
    }
65
66
1.14M
    maBitmap = rBitmap;
67
1.14M
}
68
69
BitmapInfoAccess::~BitmapInfoAccess()
70
1.14M
{
71
1.14M
    std::shared_ptr<SalBitmap> xImpBmp = maBitmap.ImplGetSalBitmap();
72
73
1.14M
    if (mpBuffer && xImpBmp)
74
1.14M
    {
75
1.14M
        xImpBmp->ReleaseBuffer(mpBuffer, mnAccessMode);
76
1.14M
    }
77
1.14M
}
78
79
sal_uInt16 BitmapInfoAccess::GetBestPaletteIndex(const BitmapColor& rBitmapColor) const
80
148k
{
81
148k
    const BitmapBuffer* pBuffer = mpBuffer;
82
83
148k
    return (HasPalette() ? pBuffer->maPalette.GetBestIndex(rBitmapColor) : 0);
84
148k
}
85
86
sal_uInt16 BitmapInfoAccess::GetMatchingPaletteIndex(const BitmapColor& rBitmapColor) const
87
0
{
88
    assert(HasPalette());
89
0
    return mpBuffer->maPalette.GetMatchingIndex(rBitmapColor);
90
0
}
91
92
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */