LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/drawinglayer/source/tools - converters.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 32 37 86.5 %
Date: 2013-07-09 Functions: 3 3 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 <drawinglayer/tools/converters.hxx>
      21             : #include <drawinglayer/geometry/viewinformation2d.hxx>
      22             : #include <drawinglayer/primitive2d/modifiedcolorprimitive2d.hxx>
      23             : #include <basegfx/matrix/b2dhommatrixtools.hxx>
      24             : #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
      25             : #include <drawinglayer/processor2d/processor2dtools.hxx>
      26             : #include <vcl/virdev.hxx>
      27             : 
      28             : #ifdef DBG_UTIL
      29             : #include <tools/stream.hxx>
      30             : #include <vcl/pngwrite.hxx>
      31             : #endif
      32             : 
      33             : //////////////////////////////////////////////////////////////////////////////
      34             : 
      35             : namespace drawinglayer
      36             : {
      37             :     namespace tools
      38             :     {
      39         292 :         BitmapEx convertToBitmapEx(
      40             :             const drawinglayer::primitive2d::Primitive2DSequence& rSeq,
      41             :             const geometry::ViewInformation2D& rViewInformation2D,
      42             :             sal_uInt32 nDiscreteWidth,
      43             :             sal_uInt32 nDiscreteHeight,
      44             :             sal_uInt32 nMaxQuadratPixels)
      45             :         {
      46         292 :             BitmapEx aRetval;
      47             : #ifdef DBG_UTIL
      48             :             static bool bDoSaveForVisualControl(false);
      49             : #endif
      50             : 
      51         292 :             if(rSeq.hasElements() && nDiscreteWidth && nDiscreteHeight)
      52             :             {
      53             :                 // get destination size in pixels
      54         292 :                 const MapMode aMapModePixel(MAP_PIXEL);
      55         292 :                 const sal_uInt32 nViewVisibleArea(nDiscreteWidth * nDiscreteHeight);
      56         584 :                 drawinglayer::primitive2d::Primitive2DSequence aSequence(rSeq);
      57             : 
      58         292 :                 if(nViewVisibleArea > nMaxQuadratPixels)
      59             :                 {
      60             :                     // reduce render size
      61           0 :                     double fReduceFactor = sqrt((double)nMaxQuadratPixels / (double)nViewVisibleArea);
      62           0 :                     nDiscreteWidth = basegfx::fround((double)nDiscreteWidth * fReduceFactor);
      63           0 :                     nDiscreteHeight = basegfx::fround((double)nDiscreteHeight * fReduceFactor);
      64             : 
      65             :                     const drawinglayer::primitive2d::Primitive2DReference aEmbed(
      66             :                         new drawinglayer::primitive2d::TransformPrimitive2D(
      67             :                             basegfx::tools::createScaleB2DHomMatrix(fReduceFactor, fReduceFactor),
      68           0 :                             rSeq));
      69             : 
      70           0 :                     aSequence = drawinglayer::primitive2d::Primitive2DSequence(&aEmbed, 1);
      71             :                 }
      72             : 
      73         292 :                 const Point aEmptyPoint;
      74         292 :                 const Size aSizePixel(nDiscreteWidth, nDiscreteHeight);
      75         584 :                 geometry::ViewInformation2D aViewInformation2D(rViewInformation2D);
      76         584 :                 VirtualDevice maContent;
      77             : 
      78             :                 // prepare vdev
      79         292 :                 maContent.SetOutputSizePixel(aSizePixel, false);
      80         292 :                 maContent.SetMapMode(aMapModePixel);
      81             : 
      82             :                 // set to all white
      83         292 :                 maContent.SetBackground(Wallpaper(Color(COL_WHITE)));
      84         292 :                 maContent.Erase();
      85             : 
      86             :                 // create pixel processor, also already takes care of AAing and
      87             :                 // checking the getOptionsDrawinglayer().IsAntiAliasing() switch. If
      88             :                 // not wanted, change after this call as needed
      89             :                 processor2d::BaseProcessor2D* pContentProcessor = processor2d::createPixelProcessor2DFromOutputDevice(
      90             :                     maContent,
      91         292 :                     aViewInformation2D);
      92             : 
      93         292 :                 if(pContentProcessor)
      94             :                 {
      95             :                     // render content
      96         292 :                     pContentProcessor->process(aSequence);
      97             : 
      98             :                     // get content
      99         292 :                     maContent.EnableMapMode(false);
     100         292 :                     const Bitmap aContent(maContent.GetBitmap(aEmptyPoint, aSizePixel));
     101             : 
     102             : #ifdef DBG_UTIL
     103             :                     if(bDoSaveForVisualControl)
     104             :                     {
     105             :                         SvFileStream aNew(OUString("c:\\test_content.png"), STREAM_WRITE|STREAM_TRUNC);
     106             :                         ::vcl::PNGWriter aPNGWriter(aContent);
     107             :                         aPNGWriter.Write(aNew);
     108             :                     }
     109             : #endif
     110             :                     // prepare for mask creation
     111         292 :                     maContent.SetMapMode(aMapModePixel);
     112             : 
     113             :                     // set alpha to all white (fully transparent)
     114         292 :                     maContent.Erase();
     115             : 
     116             :                     // embed primitives to paint them black
     117             :                     static basegfx::BColorModifyMode aMode = basegfx::BCOLORMODIFYMODE_REPLACE;
     118             :                     const primitive2d::Primitive2DReference xRef(
     119             :                         new primitive2d::ModifiedColorPrimitive2D(
     120             :                             aSequence,
     121             :                             basegfx::BColorModifier(
     122             :                                 basegfx::BColor(0.0, 0.0, 0.0),
     123             :                                 0.5,
     124         584 :                                 aMode)));
     125         584 :                     const primitive2d::Primitive2DSequence xSeq(&xRef, 1);
     126             : 
     127             :                     // render
     128         292 :                     pContentProcessor->process(xSeq);
     129         292 :                     delete pContentProcessor;
     130             : 
     131             :                     // get alpha cahannel from vdev
     132         292 :                     maContent.EnableMapMode(false);
     133         584 :                     const Bitmap aAlpha(maContent.GetBitmap(aEmptyPoint, aSizePixel));
     134             : #ifdef DBG_UTIL
     135             :                     if(bDoSaveForVisualControl)
     136             :                     {
     137             :                         SvFileStream aNew(OUString("c:\\test_alpha.png"), STREAM_WRITE|STREAM_TRUNC);
     138             :                         ::vcl::PNGWriter aPNGWriter(aAlpha);
     139             :                         aPNGWriter.Write(aNew);
     140             :                     }
     141             : #endif
     142             : 
     143             :                     // create BitmapEx result
     144         584 :                     aRetval = BitmapEx(aContent, AlphaMask(aAlpha));
     145             : #ifdef DBG_UTIL
     146             :                     if(bDoSaveForVisualControl)
     147             :                     {
     148             :                         SvFileStream aNew(OUString("c:\\test_combined.png"), STREAM_WRITE|STREAM_TRUNC);
     149             :                         ::vcl::PNGWriter aPNGWriter(aRetval);
     150             :                         aPNGWriter.Write(aNew);
     151             :                     }
     152             : #endif
     153         292 :                 }
     154             :             }
     155             : 
     156         292 :             return aRetval;
     157             :         }
     158             : 
     159             :     } // end of namespace tools
     160         408 : } // end of namespace drawinglayer
     161             : 
     162             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10