LCOV - code coverage report
Current view: top level - drawinglayer/source/tools - converters.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 36 0.0 %
Date: 2014-04-14 Functions: 0 1 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 <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           0 :         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           0 :             BitmapEx aRetval;
      47             : #ifdef DBG_UTIL
      48             :             static bool bDoSaveForVisualControl(false);
      49             : #endif
      50             : 
      51           0 :             if(rSeq.hasElements() && nDiscreteWidth && nDiscreteHeight)
      52             :             {
      53             :                 // get destination size in pixels
      54           0 :                 const MapMode aMapModePixel(MAP_PIXEL);
      55           0 :                 const sal_uInt32 nViewVisibleArea(nDiscreteWidth * nDiscreteHeight);
      56           0 :                 drawinglayer::primitive2d::Primitive2DSequence aSequence(rSeq);
      57             : 
      58           0 :                 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           0 :                 const Point aEmptyPoint;
      74           0 :                 const Size aSizePixel(nDiscreteWidth, nDiscreteHeight);
      75           0 :                 geometry::ViewInformation2D aViewInformation2D(rViewInformation2D);
      76           0 :                 VirtualDevice maContent;
      77             : 
      78             :                 // prepare vdev
      79           0 :                 maContent.SetOutputSizePixel(aSizePixel, false);
      80           0 :                 maContent.SetMapMode(aMapModePixel);
      81             : 
      82             :                 // set to all white
      83           0 :                 maContent.SetBackground(Wallpaper(Color(COL_WHITE)));
      84           0 :                 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           0 :                     aViewInformation2D);
      92             : 
      93           0 :                 if(pContentProcessor)
      94             :                 {
      95             :                     // render content
      96           0 :                     pContentProcessor->process(aSequence);
      97             : 
      98             :                     // get content
      99           0 :                     maContent.EnableMapMode(false);
     100           0 :                     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           0 :                     maContent.SetMapMode(aMapModePixel);
     112             : 
     113             :                     // set alpha to all white (fully transparent)
     114           0 :                     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           0 :                                     basegfx::BColor(0.0, 0.0, 0.0)))));
     123           0 :                     const primitive2d::Primitive2DSequence xSeq(&xRef, 1);
     124             : 
     125             :                     // render
     126           0 :                     pContentProcessor->process(xSeq);
     127           0 :                     delete pContentProcessor;
     128             : 
     129             :                     // get alpha cahannel from vdev
     130           0 :                     maContent.EnableMapMode(false);
     131           0 :                     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           0 :                     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           0 :                 }
     152             :             }
     153             : 
     154           0 :             return aRetval;
     155             :         }
     156             : 
     157             :     } // end of namespace tools
     158             : } // end of namespace drawinglayer
     159             : 
     160             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10