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

Generated by: LCOV version 1.10