Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / vcl / inc / octree.hxx
blob44a4c5e0a77f7125208eef5217ab4865cd943021
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 #ifndef INCLUDED_VCL_INC_OCTREE_HXX
21 #define INCLUDED_VCL_INC_OCTREE_HXX
23 #include <vcl/salbtype.hxx>
24 #include <vcl/dllapi.h>
26 #define OCTREE_BITS 5
27 #define OCTREE_BITS_1 10
29 typedef struct OctreeNode
31 sal_uLong nCount;
32 sal_uLong nRed;
33 sal_uLong nGreen;
34 sal_uLong nBlue;
35 OctreeNode* pChild[ 8 ];
36 OctreeNode* pNext;
37 OctreeNode* pNextInCache;
38 sal_uInt16 nPalIndex;
39 bool bLeaf;
40 } NODE;
42 class ImpNodeCache;
43 class BitmapReadAccess;
45 class VCL_PLUGIN_PUBLIC Octree
47 private:
48 void CreatePalette( NODE* pNode );
49 void GetPalIndex( NODE* pNode );
51 SAL_DLLPRIVATE void ImplDeleteOctree( NODE** ppNode );
52 SAL_DLLPRIVATE void ImplAdd( NODE** ppNode );
53 SAL_DLLPRIVATE void ImplReduce();
56 BitmapPalette aPal;
57 sal_uLong nMax;
58 sal_uLong nLeafCount;
59 sal_uLong nLevel;
60 NODE* pTree;
61 NODE* pReduce[ OCTREE_BITS + 1 ];
62 BitmapColor* pColor;
63 ImpNodeCache* pNodeCache;
64 const BitmapReadAccess* pAcc;
65 sal_uInt16 nPalIndex;
67 public:
69 Octree( const BitmapReadAccess& rReadAcc, sal_uLong nColors );
70 ~Octree();
72 inline const BitmapPalette& GetPalette();
73 inline sal_uInt16 GetBestPaletteIndex( const BitmapColor& rColor );
76 inline const BitmapPalette& Octree::GetPalette()
78 aPal.SetEntryCount( (sal_uInt16) nLeafCount );
79 nPalIndex = 0;
80 CreatePalette( pTree );
81 return aPal;
84 inline sal_uInt16 Octree::GetBestPaletteIndex( const BitmapColor& rColor )
86 pColor = &(BitmapColor&) rColor;
87 nPalIndex = 65535;
88 nLevel = 0L;
89 GetPalIndex( pTree );
90 return nPalIndex;
93 class VCL_PLUGIN_PUBLIC InverseColorMap
95 private:
97 sal_uInt8* pBuffer;
98 sal_uInt8* pMap;
99 const sal_uLong nBits;
101 SAL_DLLPRIVATE void ImplCreateBuffers( const sal_uLong nMax );
103 public:
105 explicit InverseColorMap( const BitmapPalette& rPal );
106 ~InverseColorMap();
108 inline sal_uInt16 GetBestPaletteIndex( const BitmapColor& rColor );
111 inline sal_uInt16 InverseColorMap::GetBestPaletteIndex( const BitmapColor& rColor )
113 return pMap[ ( ( (sal_uLong) rColor.GetRed() >> nBits ) << OCTREE_BITS_1 ) |
114 ( ( (sal_uLong) rColor.GetGreen() >> nBits ) << OCTREE_BITS ) |
115 ( (sal_uLong) rColor.GetBlue() >> nBits ) ];
118 #endif // INCLUDED_VCL_INC_OCTREE_HXX
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */