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 #ifndef INCLUDED_VCL_BITMAPINFOACCESS_HXX 21 #define INCLUDED_VCL_BITMAPINFOACCESS_HXX 22 23 #include <vcl/dllapi.h> 24 #include <vcl/bitmap.hxx> 25 #include <vcl/Scanline.hxx> 26 #include <vcl/BitmapBuffer.hxx> 27 #include <vcl/BitmapColor.hxx> 28 #include <vcl/BitmapAccessMode.hxx> 29 30 bool Bitmap32IsPreMultipled(); 31 32 typedef BitmapColor (*FncGetPixel)(ConstScanline pScanline, tools::Long nX, const ColorMask& rMask); 33 typedef void (*FncSetPixel)(Scanline pScanline, tools::Long nX, const BitmapColor& rBitmapColor, 34 const ColorMask& rMask); 35 36 class VCL_DLLPUBLIC BitmapInfoAccess 37 { 38 friend class BitmapReadAccess; 39 40 public: 41 BitmapInfoAccess(Bitmap& rBitmap, BitmapAccessMode nMode = BitmapAccessMode::Info); 42 virtual ~BitmapInfoAccess(); 43 operator !() const44 bool operator!() const { return mpBuffer == nullptr; } 45 Width() const46 tools::Long Width() const { return mpBuffer ? mpBuffer->mnWidth : 0L; } 47 Height() const48 tools::Long Height() const { return mpBuffer ? mpBuffer->mnHeight : 0L; } 49 IsTopDown() const50 bool IsTopDown() const 51 { 52 assert(mpBuffer && "Access is not valid!"); 53 54 return mpBuffer && (mpBuffer->mnFormat & ScanlineFormat::TopDown); 55 } 56 IsBottomUp() const57 bool IsBottomUp() const { return !IsTopDown(); } 58 GetScanlineFormat() const59 ScanlineFormat GetScanlineFormat() const 60 { 61 assert(mpBuffer && "Access is not valid!"); 62 63 return mpBuffer ? RemoveScanline(mpBuffer->mnFormat) : ScanlineFormat::NONE; 64 } 65 GetScanlineSize() const66 sal_uInt32 GetScanlineSize() const 67 { 68 assert(mpBuffer && "Access is not valid!"); 69 70 return mpBuffer ? mpBuffer->mnScanlineSize : 0; 71 } 72 GetBitCount() const73 sal_uInt16 GetBitCount() const 74 { 75 assert(mpBuffer && "Access is not valid!"); 76 77 return mpBuffer ? mpBuffer->mnBitCount : 0; 78 } 79 GetBestMatchingColor(const BitmapColor & rBitmapColor)80 BitmapColor GetBestMatchingColor(const BitmapColor& rBitmapColor) 81 { 82 if (HasPalette()) 83 return BitmapColor(static_cast<sal_uInt8>(GetBestPaletteIndex(rBitmapColor))); 84 else 85 return rBitmapColor; 86 } 87 HasPalette() const88 bool HasPalette() const 89 { 90 const BitmapBuffer* pBuffer = mpBuffer; 91 92 assert(pBuffer && "Access is not valid!"); 93 94 return pBuffer && !!pBuffer->maPalette; 95 } 96 GetPalette() const97 const BitmapPalette& GetPalette() const 98 { 99 const BitmapBuffer* pBuffer = mpBuffer; 100 101 assert(pBuffer && "Access is not valid!"); 102 103 return pBuffer->maPalette; 104 } 105 GetPaletteEntryCount() const106 sal_uInt16 GetPaletteEntryCount() const 107 { 108 const BitmapBuffer* pBuffer = mpBuffer; 109 110 assert(HasPalette() && "Bitmap has no palette!"); 111 112 return HasPalette() ? pBuffer->maPalette.GetEntryCount() : 0; 113 } 114 GetPaletteColor(sal_uInt16 nColor) const115 const BitmapColor& GetPaletteColor(sal_uInt16 nColor) const 116 { 117 const BitmapBuffer* pBuffer = mpBuffer; 118 assert(pBuffer && "Access is not valid!"); 119 assert(HasPalette() && "Bitmap has no palette!"); 120 121 return pBuffer->maPalette[nColor]; 122 } 123 124 sal_uInt16 GetBestPaletteIndex(const BitmapColor& rBitmapColor) const; 125 GetColorMask() const126 const ColorMask& GetColorMask() const 127 { 128 const BitmapBuffer* pBuffer = mpBuffer; 129 130 assert(pBuffer && "Access is not valid!"); 131 132 return pBuffer->maColorMask; 133 } 134 135 private: 136 BitmapInfoAccess(const BitmapInfoAccess&) = delete; 137 BitmapInfoAccess& operator=(const BitmapInfoAccess&) = delete; 138 139 protected: 140 Bitmap maBitmap; 141 BitmapBuffer* mpBuffer; 142 ColorMask maColorMask; 143 BitmapAccessMode mnAccessMode; 144 }; 145 146 #endif // INCLUDED_VCL_BITMAPINFOACCESS_HXX 147 148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 149