LibreOffice Module vcl (master) 1
BitmapInfoAccess.cxx
Go to the documentation of this file.
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
21
22#include <salbmp.hxx>
23#include <svdata.hxx>
24#include <salinst.hxx>
25
27 : mpBuffer(nullptr)
28 , mnAccessMode(nMode)
29{
30 std::shared_ptr<SalBitmap> xImpBmp = rBitmap.ImplGetSalBitmap();
31
32 if (!xImpBmp)
33 return;
34
36 {
37 xImpBmp->DropScaledCache();
38
39 if (xImpBmp.use_count() > 2)
40 {
41 xImpBmp.reset();
42 rBitmap.ImplMakeUnique();
43 xImpBmp = rBitmap.ImplGetSalBitmap();
44 }
45 }
46
47 mpBuffer = xImpBmp->AcquireBuffer(mnAccessMode);
48
49 if (!mpBuffer)
50 {
51 std::shared_ptr<SalBitmap> xNewImpBmp(ImplGetSVData()->mpDefInst->CreateSalBitmap());
52 if (xNewImpBmp->Create(*xImpBmp, rBitmap.getPixelFormat()))
53 {
54 xImpBmp = xNewImpBmp;
55 rBitmap.ImplSetSalBitmap(xImpBmp);
56 mpBuffer = xImpBmp->AcquireBuffer(mnAccessMode);
57 }
58 }
59
60 maBitmap = rBitmap;
61}
62
64{
65 std::shared_ptr<SalBitmap> xImpBmp = maBitmap.ImplGetSalBitmap();
66
67 if (mpBuffer && xImpBmp)
68 {
69 xImpBmp->ReleaseBuffer(mpBuffer, mnAccessMode);
70 }
71}
72
73sal_uInt16 BitmapInfoAccess::GetBestPaletteIndex(const BitmapColor& rBitmapColor) const
74{
75 const BitmapBuffer* pBuffer = mpBuffer;
76
77 return (HasPalette() ? pBuffer->maPalette.GetBestIndex(rBitmapColor) : 0);
78}
79
80/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
BitmapAccessMode
sal_uInt16 GetBestPaletteIndex(const BitmapColor &rBitmapColor) const
bool HasPalette() const
BitmapInfoAccess(Bitmap &rBitmap, BitmapAccessMode nMode=BitmapAccessMode::Info)
BitmapAccessMode mnAccessMode
BitmapBuffer * mpBuffer
virtual ~BitmapInfoAccess()
sal_uInt16 GetBestIndex(const BitmapColor &rCol) const
const std::shared_ptr< SalBitmap > & ImplGetSalBitmap() const
SAL_DLLPRIVATE void ImplSetSalBitmap(const std::shared_ptr< SalBitmap > &xImpBmp)
SAL_DLLPRIVATE void ImplMakeUnique()
vcl::PixelFormat getPixelFormat() const
BitmapPalette maPalette
ImplSVData * ImplGetSVData()
Definition: svdata.cxx:77