LCOV - code coverage report
Current view: top level - vcl/inc - octree.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 9 15 60.0 %
Date: 2014-11-03 Functions: 2 3 66.7 %
Legend: Lines: hit not hit

          Line data    Source code
       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_INC_OCTREE_HXX
      21             : #define INCLUDED_VCL_INC_OCTREE_HXX
      22             : 
      23             : #include <vcl/salbtype.hxx>
      24             : #include <vcl/dllapi.h>
      25             : 
      26             : #define OCTREE_BITS     5
      27             : #define OCTREE_BITS_1   10
      28             : 
      29             : typedef struct OctreeNode
      30             : {
      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;
      41             : 
      42             : typedef NODE*       PNODE;
      43             : typedef PNODE*      PPNODE;
      44             : 
      45             : class ImpNodeCache;
      46             : class BitmapReadAccess;
      47             : 
      48             : class VCL_PLUGIN_PUBLIC Octree
      49             : {
      50             : private:
      51             : 
      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;
      62             : 
      63             :                                 Octree() {}
      64             : 
      65             :     void                        CreatePalette( PNODE pNode );
      66             :     void                        GetPalIndex( PNODE pNode );
      67             : 
      68             :     SAL_DLLPRIVATE void         ImplCreateOctree();
      69             :     SAL_DLLPRIVATE void         ImplDeleteOctree( PPNODE ppNode );
      70             :     SAL_DLLPRIVATE void         ImplAdd( PPNODE ppNode );
      71             :     SAL_DLLPRIVATE void         ImplReduce();
      72             : 
      73             : public:
      74             : 
      75             :                                 Octree( const BitmapReadAccess& rReadAcc, sal_uLong nColors );
      76             :                                 ~Octree();
      77             : 
      78             :     inline const BitmapPalette& GetPalette();
      79             :     inline sal_uInt16               GetBestPaletteIndex( const BitmapColor& rColor );
      80             : };
      81             : 
      82         554 : inline const BitmapPalette& Octree::GetPalette()
      83             : {
      84         554 :     aPal.SetEntryCount( (sal_uInt16) nLeafCount );
      85         554 :     nPalIndex = 0;
      86         554 :     CreatePalette( pTree );
      87         554 :     return aPal;
      88             : }
      89             : 
      90           0 : inline sal_uInt16 Octree::GetBestPaletteIndex( const BitmapColor& rColor )
      91             : {
      92           0 :     pColor = &(BitmapColor&) rColor;
      93           0 :     nPalIndex = 65535;
      94           0 :     nLevel = 0L;
      95           0 :     GetPalIndex( pTree );
      96           0 :     return nPalIndex;
      97             : }
      98             : 
      99             : class VCL_PLUGIN_PUBLIC InverseColorMap
     100             : {
     101             : private:
     102             : 
     103             :     sal_uInt8*              pBuffer;
     104             :     sal_uInt8*              pMap;
     105             :     const sal_uLong         nBits;
     106             : 
     107             :     SAL_DLLPRIVATE void ImplCreateBuffers( const sal_uLong nMax );
     108             : 
     109             : public:
     110             : 
     111             :     explicit            InverseColorMap( const BitmapPalette& rPal );
     112             :                         ~InverseColorMap();
     113             : 
     114             :     inline sal_uInt16       GetBestPaletteIndex( const BitmapColor& rColor );
     115             : };
     116             : 
     117     8216364 : inline sal_uInt16 InverseColorMap::GetBestPaletteIndex( const BitmapColor& rColor )
     118             : {
     119    16432728 :     return pMap[ ( ( (sal_uLong) rColor.GetRed() >> nBits ) << OCTREE_BITS_1 ) |
     120    16432728 :                  ( ( (sal_uLong) rColor.GetGreen() >> nBits ) << OCTREE_BITS ) |
     121    24649092 :                  ( (sal_uLong) rColor.GetBlue() >> nBits ) ];
     122             : }
     123             : 
     124             : #endif // INCLUDED_VCL_INC_OCTREE_HXX
     125             : 
     126             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10