/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.86M | : mpBuffer(nullptr) |
34 | 1.86M | , mnAccessMode(nMode) |
35 | 1.86M | { |
36 | 1.86M | std::shared_ptr<SalBitmap> xImpBmp = rBitmap.ImplGetSalBitmap(); |
37 | | |
38 | 1.86M | if (!xImpBmp) |
39 | 5.35k | return; |
40 | | |
41 | 1.86M | if (mnAccessMode == BitmapAccessMode::Write) |
42 | 1.61M | { |
43 | 1.61M | xImpBmp->DropScaledCache(); |
44 | | |
45 | 1.61M | if (xImpBmp.use_count() > 2) |
46 | 12.1k | { |
47 | 12.1k | xImpBmp.reset(); |
48 | 12.1k | const_cast<Bitmap&>(rBitmap).ImplMakeUnique(); |
49 | 12.1k | xImpBmp = rBitmap.ImplGetSalBitmap(); |
50 | 12.1k | } |
51 | 1.61M | } |
52 | | |
53 | 1.86M | mpBuffer = xImpBmp->AcquireBuffer(mnAccessMode); |
54 | | |
55 | 1.86M | if (!mpBuffer) |
56 | 167 | { |
57 | 167 | std::shared_ptr<SalBitmap> xNewImpBmp(GetSalInstance()->CreateSalBitmap()); |
58 | 167 | if (xNewImpBmp->Create(*xImpBmp)) |
59 | 167 | { |
60 | 167 | xImpBmp = std::move(xNewImpBmp); |
61 | 167 | const_cast<Bitmap&>(rBitmap).ImplSetSalBitmap(xImpBmp); |
62 | 167 | mpBuffer = xImpBmp->AcquireBuffer(mnAccessMode); |
63 | 167 | } |
64 | 167 | } |
65 | | |
66 | 1.86M | maBitmap = rBitmap; |
67 | 1.86M | } |
68 | | |
69 | | BitmapInfoAccess::~BitmapInfoAccess() |
70 | 1.86M | { |
71 | 1.86M | std::shared_ptr<SalBitmap> xImpBmp = maBitmap.ImplGetSalBitmap(); |
72 | | |
73 | 1.86M | if (mpBuffer && xImpBmp) |
74 | 1.86M | { |
75 | 1.86M | xImpBmp->ReleaseBuffer(mpBuffer, mnAccessMode); |
76 | 1.86M | } |
77 | 1.86M | } |
78 | | |
79 | | sal_uInt16 BitmapInfoAccess::GetBestPaletteIndex(const BitmapColor& rBitmapColor) const |
80 | 143k | { |
81 | 143k | const BitmapBuffer* pBuffer = mpBuffer; |
82 | | |
83 | 143k | return (HasPalette() ? pBuffer->maPalette.GetBestIndex(rBitmapColor) : 0); |
84 | 143k | } |
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: */ |