LCOV - code coverage report
Current view: top level - drawinglayer/source/tools - converters.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 32 37 86.5 %
Date: 2014-11-03 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             :                     const primitive2d::Primitive2DReference xRef(
     118             :                         new primitive2d::ModifiedColorPrimitive2D(
     119             :                             aSequence,
     120             :                             basegfx::BColorModifierSharedPtr(
     121             :                                 new basegfx::BColorModifier_replace(
     122         584 :                                     basegfx::BColor(0.0, 0.0, 0.0)))));
     123         584 :                     const primitive2d::Primitive2DSequence xSeq(&xRef, 1);
     124             : 
     125             :                     // render
     126         292 :                     pContentProcessor->process(xSeq);
     127         292 :                     delete pContentProcessor;
     128             : 
     129             :                     // get alpha cahannel from vdev
     130         292 :                     maContent.EnableMapMode(false);
     131         584 :                     const Bitmap aAlpha(maContent.GetBitmap(aEmptyPoint, aSizePixel));
     132             : #ifdef DBG_UTIL
     133             :                     if(bDoSaveForVisualControl)
     134             :                     {
     135             :                         SvFileStream aNew(OUString("c:\\test_alpha.png"), STREAM_WRITE|STREAM_TRUNC);
     136             :                         ::vcl::PNGWriter aPNGWriter(aAlpha);
     137             :                         aPNGWriter.Write(aNew);
     138             :                     }
     139             : #endif
     140             : 
     141             :                     // create BitmapEx result
     142         584 :                     aRetval = BitmapEx(aContent, AlphaMask(aAlpha));
     143             : #ifdef DBG_UTIL
     144             :                     if(bDoSaveForVisualControl)
     145             :                     {
     146             :                         SvFileStream aNew(OUString("c:\\test_combined.png"), STREAM_WRITE|STREAM_TRUNC);
     147             :                         ::vcl::PNGWriter aPNGWriter(aRetval);
     148             :                         aPNGWriter.Write(aNew);
     149             :                     }
     150             : #endif
     151         292 :                 }
     152             :             }
     153             : 
     154         292 :             return aRetval;
     155             :         }
     156             : 
     157             :     } // end of namespace tools
     158        1143 : } // end of namespace drawinglayer
     159             : 
     160             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10