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

Generated by: LCOV version 1.10