bump product version to 7.2.5.1
[LibreOffice.git] / vcl / source / bitmap / BitmapInfoAccess.cxx
blob50607e94dde345a62e64b8e767c11d3118bc953d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <vcl/BitmapInfoAccess.hxx>
22 #include <salbmp.hxx>
23 #include <svdata.hxx>
24 #include <salinst.hxx>
26 BitmapInfoAccess::BitmapInfoAccess(Bitmap& rBitmap, BitmapAccessMode nMode)
27 : mpBuffer(nullptr)
28 , mnAccessMode(nMode)
30 std::shared_ptr<SalBitmap> xImpBmp = rBitmap.ImplGetSalBitmap();
32 if (!xImpBmp)
33 return;
35 if (mnAccessMode == BitmapAccessMode::Write)
37 xImpBmp->DropScaledCache();
39 if (xImpBmp.use_count() > 2)
41 xImpBmp.reset();
42 rBitmap.ImplMakeUnique();
43 xImpBmp = rBitmap.ImplGetSalBitmap();
47 mpBuffer = xImpBmp->AcquireBuffer(mnAccessMode);
49 if (!mpBuffer)
51 std::shared_ptr<SalBitmap> xNewImpBmp(ImplGetSVData()->mpDefInst->CreateSalBitmap());
52 if (xNewImpBmp->Create(*xImpBmp, rBitmap.getPixelFormat()))
54 xImpBmp = xNewImpBmp;
55 rBitmap.ImplSetSalBitmap(xImpBmp);
56 mpBuffer = xImpBmp->AcquireBuffer(mnAccessMode);
60 maBitmap = rBitmap;
63 BitmapInfoAccess::~BitmapInfoAccess()
65 std::shared_ptr<SalBitmap> xImpBmp = maBitmap.ImplGetSalBitmap();
67 if (mpBuffer && xImpBmp)
69 xImpBmp->ReleaseBuffer(mpBuffer, mnAccessMode);
73 sal_uInt16 BitmapInfoAccess::GetBestPaletteIndex(const BitmapColor& rBitmapColor) const
75 const BitmapBuffer* pBuffer = mpBuffer;
77 return (HasPalette() ? pBuffer->maPalette.GetBestIndex(rBitmapColor) : 0);
80 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */