1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
24 #include <salinst.hxx>
26 BitmapInfoAccess::BitmapInfoAccess(Bitmap
& rBitmap
, BitmapAccessMode nMode
)
30 std::shared_ptr
<SalBitmap
> xImpBmp
= rBitmap
.ImplGetSalBitmap();
35 if (mnAccessMode
== BitmapAccessMode::Write
)
37 xImpBmp
->DropScaledCache();
39 if (xImpBmp
.use_count() > 2)
42 rBitmap
.ImplMakeUnique();
43 xImpBmp
= rBitmap
.ImplGetSalBitmap();
47 mpBuffer
= xImpBmp
->AcquireBuffer(mnAccessMode
);
51 std::shared_ptr
<SalBitmap
> xNewImpBmp(ImplGetSVData()->mpDefInst
->CreateSalBitmap());
52 if (xNewImpBmp
->Create(*xImpBmp
, rBitmap
.getPixelFormat()))
55 rBitmap
.ImplSetSalBitmap(xImpBmp
);
56 mpBuffer
= xImpBmp
->AcquireBuffer(mnAccessMode
);
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: */