Branch libreoffice-5-0-4
[LibreOffice.git] / vcl / inc / octree.hxx
blobad2968121e493f13cce6562007cbb5f018a8d6b7
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 typedef NODE* PNODE;
43 typedef PNODE* PPNODE;
45 class ImpNodeCache;
46 class BitmapReadAccess;
48 class VCL_PLUGIN_PUBLIC Octree
50 private:
52 BitmapPalette aPal;
53 sal_uLong nMax;
54 sal_uLong nLeafCount;
55 sal_uLong nLevel;
56 PNODE pTree;
57 PNODE pReduce[ OCTREE_BITS + 1 ];
58 BitmapColor* pColor;
59 ImpNodeCache* pNodeCache;
60 const BitmapReadAccess* pAcc;
61 sal_uInt16 nPalIndex;
63 Octree() {}
65 void CreatePalette( PNODE pNode );
66 void GetPalIndex( PNODE pNode );
68 SAL_DLLPRIVATE void ImplCreateOctree();
69 SAL_DLLPRIVATE void ImplDeleteOctree( PPNODE ppNode );
70 SAL_DLLPRIVATE void ImplAdd( PPNODE ppNode );
71 SAL_DLLPRIVATE void ImplReduce();
73 public:
75 Octree( const BitmapReadAccess& rReadAcc, sal_uLong nColors );
76 ~Octree();
78 inline const BitmapPalette& GetPalette();
79 inline sal_uInt16 GetBestPaletteIndex( const BitmapColor& rColor );
82 inline const BitmapPalette& Octree::GetPalette()
84 aPal.SetEntryCount( (sal_uInt16) nLeafCount );
85 nPalIndex = 0;
86 CreatePalette( pTree );
87 return aPal;
90 inline sal_uInt16 Octree::GetBestPaletteIndex( const BitmapColor& rColor )
92 pColor = &(BitmapColor&) rColor;
93 nPalIndex = 65535;
94 nLevel = 0L;
95 GetPalIndex( pTree );
96 return nPalIndex;
99 class VCL_PLUGIN_PUBLIC InverseColorMap
101 private:
103 sal_uInt8* pBuffer;
104 sal_uInt8* pMap;
105 const sal_uLong nBits;
107 SAL_DLLPRIVATE void ImplCreateBuffers( const sal_uLong nMax );
109 public:
111 explicit InverseColorMap( const BitmapPalette& rPal );
112 ~InverseColorMap();
114 inline sal_uInt16 GetBestPaletteIndex( const BitmapColor& rColor );
117 inline sal_uInt16 InverseColorMap::GetBestPaletteIndex( const BitmapColor& rColor )
119 return pMap[ ( ( (sal_uLong) rColor.GetRed() >> nBits ) << OCTREE_BITS_1 ) |
120 ( ( (sal_uLong) rColor.GetGreen() >> nBits ) << OCTREE_BITS ) |
121 ( (sal_uLong) rColor.GetBlue() >> nBits ) ];
124 #endif // INCLUDED_VCL_INC_OCTREE_HXX
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */