LCOV - code coverage report
Current view: top level - vcl/source/gdi - bmpacc3.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 73 120 60.8 %
Date: 2014-11-03 Functions: 9 9 100.0 %
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             : #include <tools/poly.hxx>
      21             : 
      22             : #include <vcl/salbtype.hxx>
      23             : #include <vcl/bitmap.hxx>
      24             : #include <vcl/region.hxx>
      25             : #include <vcl/bmpacc.hxx>
      26             : 
      27             : #include <bmpfast.hxx>
      28             : 
      29        8206 : void BitmapWriteAccess::SetLineColor( const Color& rColor )
      30             : {
      31        8206 :     delete mpLineColor;
      32             : 
      33        8206 :     if( rColor.GetTransparency() == 255 )
      34           0 :         mpLineColor = NULL;
      35             :     else
      36        8206 :         mpLineColor = ( HasPalette() ? new BitmapColor(  (sal_uInt8) GetBestPaletteIndex( rColor ) ) : new BitmapColor( rColor ) );
      37        8206 : }
      38             : 
      39         738 : void BitmapWriteAccess::SetFillColor()
      40             : {
      41         738 :     delete mpFillColor;
      42         738 :     mpFillColor = NULL;
      43         738 : }
      44             : 
      45       14394 : void BitmapWriteAccess::SetFillColor( const Color& rColor )
      46             : {
      47       14394 :     delete mpFillColor;
      48             : 
      49       14394 :     if( rColor.GetTransparency() == 255 )
      50           0 :         mpFillColor = NULL;
      51             :     else
      52       14394 :         mpFillColor = ( HasPalette() ? new BitmapColor(  (sal_uInt8) GetBestPaletteIndex( rColor ) ) : new BitmapColor( rColor ) );
      53       14394 : }
      54             : 
      55        6116 : void BitmapWriteAccess::Erase( const Color& rColor )
      56             : {
      57             :     // convert the color format from RGB to palette index if needed
      58             :     // TODO: provide and use Erase( BitmapColor& method)
      59        6116 :     BitmapColor aColor = rColor;
      60        6116 :     if( HasPalette() )
      61        5464 :         aColor = BitmapColor( (sal_uInt8)GetBestPaletteIndex( rColor) );
      62             :     // try fast bitmap method first
      63        6116 :     if( ImplFastEraseBitmap( *mpBuffer, aColor ) )
      64       12068 :         return;
      65             : 
      66             :     // use the canonical method to clear the bitmap
      67         164 :     BitmapColor*    pOldFillColor = mpFillColor ? new BitmapColor( *mpFillColor ) : NULL;
      68         164 :     const Point     aPoint;
      69         164 :     const Rectangle aRect( aPoint, maBitmap.GetSizePixel() );
      70             : 
      71         164 :     SetFillColor( rColor );
      72         164 :     FillRect( aRect );
      73         164 :     delete mpFillColor;
      74         164 :     mpFillColor = pOldFillColor;
      75             : }
      76             : 
      77        8856 : void BitmapWriteAccess::DrawLine( const Point& rStart, const Point& rEnd )
      78             : {
      79        8856 :     if( mpLineColor )
      80             :     {
      81        8856 :         const BitmapColor&  rLineColor = *mpLineColor;
      82             :         long                nX, nY;
      83             : 
      84        8856 :         if ( rStart.X() == rEnd.X() )
      85             :         {
      86             :             // Vertical Line
      87        4428 :             const long nEndY = rEnd.Y();
      88             : 
      89        4428 :             nX = rStart.X();
      90        4428 :             nY = rStart.Y();
      91             : 
      92        4428 :             if ( nEndY > nY )
      93             :             {
      94       28782 :                 for (; nY <= nEndY; nY++ )
      95       26568 :                     SetPixel( nY, nX, rLineColor );
      96             :             }
      97             :             else
      98             :             {
      99       28782 :                 for (; nY >= nEndY; nY-- )
     100       26568 :                     SetPixel( nY, nX, rLineColor );
     101             :             }
     102             :         }
     103        4428 :         else if ( rStart.Y() == rEnd.Y() )
     104             :         {
     105             :             // Horizontal Line
     106        4428 :             const long nEndX = rEnd.X();
     107             : 
     108        4428 :             nX = rStart.X();
     109        4428 :             nY = rStart.Y();
     110             : 
     111        4428 :             if ( nEndX > nX )
     112             :             {
     113      150552 :                 for (; nX <= nEndX; nX++ )
     114      148338 :                     SetPixel( nY, nX, rLineColor );
     115             :             }
     116             :             else
     117             :             {
     118      150552 :                 for (; nX >= nEndX; nX-- )
     119      148338 :                     SetPixel( nY, nX, rLineColor );
     120             :             }
     121             :         }
     122             :         else
     123             :         {
     124           0 :             const long  nDX = labs( rEnd.X() - rStart.X() );
     125           0 :             const long  nDY = labs( rEnd.Y() - rStart.Y() );
     126             :             long        nX1;
     127             :             long        nY1;
     128             :             long        nX2;
     129             :             long        nY2;
     130             : 
     131           0 :             if ( nDX >= nDY )
     132             :             {
     133           0 :                 if ( rStart.X() < rEnd.X() )
     134             :                 {
     135           0 :                     nX1 = rStart.X();
     136           0 :                     nY1 = rStart.Y();
     137           0 :                     nX2 = rEnd.X();
     138           0 :                     nY2 = rEnd.Y();
     139             :                 }
     140             :                 else
     141             :                 {
     142           0 :                     nX1 = rEnd.X();
     143           0 :                     nY1 = rEnd.Y();
     144           0 :                     nX2 = rStart.X();
     145           0 :                     nY2 = rStart.Y();
     146             :                 }
     147             : 
     148           0 :                 const long  nDYX = ( nDY - nDX ) << 1;
     149           0 :                 const long  nDY2 = nDY << 1;
     150           0 :                 long        nD = nDY2 - nDX;
     151           0 :                 bool        bPos = nY1 < nY2;
     152             : 
     153           0 :                 for ( nX = nX1, nY = nY1; nX <= nX2; nX++ )
     154             :                 {
     155           0 :                     SetPixel( nY, nX, rLineColor );
     156             : 
     157           0 :                     if ( nD < 0 )
     158           0 :                         nD += nDY2;
     159             :                     else
     160             :                     {
     161           0 :                         nD += nDYX;
     162             : 
     163           0 :                         if ( bPos )
     164           0 :                             nY++;
     165             :                         else
     166           0 :                             nY--;
     167             :                     }
     168             :                 }
     169             :             }
     170             :             else
     171             :             {
     172           0 :                 if ( rStart.Y() < rEnd.Y() )
     173             :                 {
     174           0 :                     nX1 = rStart.X();
     175           0 :                     nY1 = rStart.Y();
     176           0 :                     nX2 = rEnd.X();
     177           0 :                     nY2 = rEnd.Y();
     178             :                 }
     179             :                 else
     180             :                 {
     181           0 :                     nX1 = rEnd.X();
     182           0 :                     nY1 = rEnd.Y();
     183           0 :                     nX2 = rStart.X();
     184           0 :                     nY2 = rStart.Y();
     185             :                 }
     186             : 
     187           0 :                 const long  nDYX = ( nDX - nDY ) << 1;
     188           0 :                 const long  nDY2 = nDX << 1;
     189           0 :                 long        nD = nDY2 - nDY;
     190           0 :                 bool        bPos = nX1 < nX2;
     191             : 
     192           0 :                 for ( nX = nX1, nY = nY1; nY <= nY2; nY++ )
     193             :                 {
     194           0 :                     SetPixel( nY, nX, rLineColor );
     195             : 
     196           0 :                     if ( nD < 0 )
     197           0 :                         nD += nDY2;
     198             :                     else
     199             :                     {
     200           0 :                         nD += nDYX;
     201             : 
     202           0 :                         if ( bPos )
     203           0 :                             nX++;
     204             :                         else
     205           0 :                             nX--;
     206             :                     }
     207             :                 }
     208             :             }
     209             :         }
     210             :     }
     211        8856 : }
     212             : 
     213       14394 : void BitmapWriteAccess::FillRect( const Rectangle& rRect )
     214             : {
     215       14394 :     if( mpFillColor )
     216             :     {
     217       14394 :         const BitmapColor&  rFillColor = *mpFillColor;
     218       14394 :         Point               aPoint;
     219       14394 :         Rectangle           aRect( aPoint, maBitmap.GetSizePixel() );
     220             : 
     221       14394 :         aRect.Intersection( rRect );
     222             : 
     223       14394 :         if( !aRect.IsEmpty() )
     224             :         {
     225       14394 :             const long  nStartX = rRect.Left();
     226       14394 :             const long  nStartY = rRect.Top();
     227       14394 :             const long  nEndX = rRect.Right();
     228       14394 :             const long  nEndY = rRect.Bottom();
     229             : 
     230       94952 :             for( long nY = nStartY; nY <= nEndY; nY++ )
     231     3055604 :                 for( long nX = nStartX; nX <= nEndX; nX++ )
     232     2975046 :                     SetPixel( nY, nX, rFillColor );
     233             :         }
     234             :     }
     235       14394 : }
     236             : 
     237       14936 : void BitmapWriteAccess::DrawRect( const Rectangle& rRect )
     238             : {
     239       14936 :     if( mpFillColor )
     240       14198 :         FillRect( rRect );
     241             : 
     242       14936 :     if( mpLineColor && ( !mpFillColor || ( *mpFillColor != *mpLineColor ) ) )
     243             :     {
     244        2214 :         DrawLine( rRect.TopLeft(), rRect.TopRight() );
     245        2214 :         DrawLine( rRect.TopRight(), rRect.BottomRight() );
     246        2214 :         DrawLine( rRect.BottomRight(), rRect.BottomLeft() );
     247        2214 :         DrawLine( rRect.BottomLeft(), rRect.TopLeft() );
     248             :     }
     249       16169 : }
     250             : 
     251             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10