Kaydet (Commit) 632edfab authored tarafından Tor Lillqvist's avatar Tor Lillqvist

<drawinglayer/tools/converters.hxx> can be internal to drawinglayer

And while moving it, get rid of the 'drawinglyer::tools' subnamespace.
Less potential confusion with the global 'tools' namespace.

Change-Id: Iab3c25be0cec7f3d182228d122837e9f2ac9a529
Reviewed-on: https://gerrit.libreoffice.org/42619Reviewed-by: 's avatarTor Lillqvist <tml@collabora.com>
Tested-by: 's avatarTor Lillqvist <tml@collabora.com>
üst 442df6cf
...@@ -17,31 +17,27 @@ ...@@ -17,31 +17,27 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#ifndef INCLUDED_DRAWINGLAYER_TOOLS_CONVERTERS_HXX #ifndef INCLUDED_DRAWINGLAYER_INC_CONVERTERS_HXX
#define INCLUDED_DRAWINGLAYER_TOOLS_CONVERTERS_HXX #define INCLUDED_DRAWINGLAYER_INC_CONVERTERS_HXX
#include <drawinglayer/drawinglayerdllapi.h> #include <drawinglayer/drawinglayerdllapi.h>
#include <vcl/bitmapex.hxx> #include <vcl/bitmapex.hxx>
#include <drawinglayer/primitive2d/baseprimitive2d.hxx> #include <drawinglayer/primitive2d/baseprimitive2d.hxx>
namespace drawinglayer namespace drawinglayer
{ {
namespace tools
{
BitmapEx DRAWINGLAYER_DLLPUBLIC convertToBitmapEx(
const drawinglayer::primitive2d::Primitive2DContainer& rSeq,
const geometry::ViewInformation2D& rViewInformation2D,
sal_uInt32 nDiscreteWidth,
sal_uInt32 nDiscreteHeight,
sal_uInt32 nMaxQuadratPixels);
double DRAWINGLAYER_DLLPUBLIC getRandomColorRange();
} // end of namespace tools
} // end of namespace drawinglayer
BitmapEx convertToBitmapEx(
const drawinglayer::primitive2d::Primitive2DContainer& rSeq,
const geometry::ViewInformation2D& rViewInformation2D,
sal_uInt32 nDiscreteWidth,
sal_uInt32 nDiscreteHeight,
sal_uInt32 nMaxQuadratPixels);
double getRandomColorRange();
} // end of namespace drawinglayer
#endif // INCLUDED_DRAWINGLAYER_TOOLS_CONVERTERS_HXX #endif // INCLUDED_DRAWINGLAYER_INC_CONVERTERS_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -31,12 +31,13 @@ ...@@ -31,12 +31,13 @@
#include <drawinglayer/geometry/viewinformation2d.hxx> #include <drawinglayer/geometry/viewinformation2d.hxx>
#include <basegfx/numeric/ftools.hxx> #include <basegfx/numeric/ftools.hxx>
#include <vcl/bitmapex.hxx> #include <vcl/bitmapex.hxx>
#include <drawinglayer/tools/converters.hxx>
#include <vcl/canvastools.hxx> #include <vcl/canvastools.hxx>
#include <com/sun/star/geometry/RealRectangle2D.hpp> #include <com/sun/star/geometry/RealRectangle2D.hpp>
#include <basegfx/matrix/b2dhommatrixtools.hxx> #include <basegfx/matrix/b2dhommatrixtools.hxx>
#include <drawinglayer/primitive2d/transformprimitive2d.hxx> #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
#include "converters.hxx"
#include <xprimitive2drenderer.hxx> #include <xprimitive2drenderer.hxx>
using namespace ::com::sun::star; using namespace ::com::sun::star;
...@@ -160,7 +161,7 @@ namespace drawinglayer ...@@ -160,7 +161,7 @@ namespace drawinglayer
const primitive2d::Primitive2DContainer xEmbedSeq { xEmbedRef }; const primitive2d::Primitive2DContainer xEmbedSeq { xEmbedRef };
BitmapEx aBitmapEx( BitmapEx aBitmapEx(
tools::convertToBitmapEx( convertToBitmapEx(
xEmbedSeq, xEmbedSeq,
aViewInformation2D, aViewInformation2D,
nDiscreteWidth, nDiscreteWidth,
......
...@@ -26,9 +26,10 @@ ...@@ -26,9 +26,10 @@
#include <basegfx/matrix/b2dhommatrixtools.hxx> #include <basegfx/matrix/b2dhommatrixtools.hxx>
#include <drawinglayer/texture/texture.hxx> #include <drawinglayer/texture/texture.hxx>
#include <drawinglayer/primitive2d/maskprimitive2d.hxx> #include <drawinglayer/primitive2d/maskprimitive2d.hxx>
#include <drawinglayer/tools/converters.hxx>
#include <drawinglayer/geometry/viewinformation2d.hxx> #include <drawinglayer/geometry/viewinformation2d.hxx>
#include "converters.hxx"
using namespace com::sun::star; using namespace com::sun::star;
#define MAXIMUM_SQUARE_LENGTH (186.0) #define MAXIMUM_SQUARE_LENGTH (186.0)
...@@ -109,7 +110,7 @@ namespace drawinglayer ...@@ -109,7 +110,7 @@ namespace drawinglayer
const primitive2d::Primitive2DContainer xEmbedSeq { xEmbedRef }; const primitive2d::Primitive2DContainer xEmbedSeq { xEmbedRef };
const BitmapEx aBitmapEx( const BitmapEx aBitmapEx(
tools::convertToBitmapEx( convertToBitmapEx(
xEmbedSeq, xEmbedSeq,
aViewInformation2D, aViewInformation2D,
mnDiscreteWidth, mnDiscreteWidth,
......
...@@ -206,12 +206,9 @@ namespace drawinglayer ...@@ -206,12 +206,9 @@ namespace drawinglayer
namespace drawinglayer namespace drawinglayer
{ {
namespace tools double getRandomColorRange()
{ {
double getRandomColorRange() return comphelper::rng::uniform_real_distribution(0.0, nextafter(1.0, DBL_MAX));
{
return comphelper::rng::uniform_real_distribution(0.0, nextafter(1.0, DBL_MAX));
}
} }
namespace primitive2d namespace primitive2d
...@@ -270,7 +267,7 @@ namespace drawinglayer ...@@ -270,7 +267,7 @@ namespace drawinglayer
const basegfx::B2DPolyPolygon aNewPolyPolygon(aAreaPolyPolygon.getB2DPolygon(b)); const basegfx::B2DPolyPolygon aNewPolyPolygon(aAreaPolyPolygon.getB2DPolygon(b));
static bool bTestByUsingRandomColor(false); static bool bTestByUsingRandomColor(false);
const basegfx::BColor aColor(bTestByUsingRandomColor const basegfx::BColor aColor(bTestByUsingRandomColor
? basegfx::BColor(tools::getRandomColorRange(), tools::getRandomColorRange(), tools::getRandomColorRange()) ? basegfx::BColor(getRandomColorRange(), getRandomColorRange(), getRandomColorRange())
: getLineAttribute().getColor()); : getLineAttribute().getColor());
rContainer.push_back(new PolyPolygonColorPrimitive2D(aNewPolyPolygon, aColor)); rContainer.push_back(new PolyPolygonColorPrimitive2D(aNewPolyPolygon, aColor));
} }
......
...@@ -18,11 +18,12 @@ ...@@ -18,11 +18,12 @@
*/ */
#include <drawinglayer/texture/texture.hxx> #include <drawinglayer/texture/texture.hxx>
#include <drawinglayer/tools/converters.hxx>
#include <basegfx/numeric/ftools.hxx> #include <basegfx/numeric/ftools.hxx>
#include <basegfx/tools/gradienttools.hxx> #include <basegfx/tools/gradienttools.hxx>
#include <basegfx/matrix/b2dhommatrixtools.hxx> #include <basegfx/matrix/b2dhommatrixtools.hxx>
#include "converters.hxx"
namespace drawinglayer namespace drawinglayer
{ {
namespace texture namespace texture
...@@ -44,9 +45,9 @@ namespace drawinglayer ...@@ -44,9 +45,9 @@ namespace drawinglayer
void GeoTexSvx::modifyBColor(const basegfx::B2DPoint& /*rUV*/, basegfx::BColor& rBColor, double& /*rfOpacity*/) const void GeoTexSvx::modifyBColor(const basegfx::B2DPoint& /*rUV*/, basegfx::BColor& rBColor, double& /*rfOpacity*/) const
{ {
// base implementation creates random color (for testing only, may also be pure virtual) // base implementation creates random color (for testing only, may also be pure virtual)
rBColor.setRed(tools::getRandomColorRange()); rBColor.setRed(getRandomColorRange());
rBColor.setGreen(tools::getRandomColorRange()); rBColor.setGreen(getRandomColorRange());
rBColor.setBlue(tools::getRandomColorRange()); rBColor.setBlue(getRandomColorRange());
} }
void GeoTexSvx::modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const void GeoTexSvx::modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#include <drawinglayer/tools/converters.hxx>
#include <drawinglayer/geometry/viewinformation2d.hxx> #include <drawinglayer/geometry/viewinformation2d.hxx>
#include <drawinglayer/primitive2d/modifiedcolorprimitive2d.hxx> #include <drawinglayer/primitive2d/modifiedcolorprimitive2d.hxx>
#include <basegfx/matrix/b2dhommatrixtools.hxx> #include <basegfx/matrix/b2dhommatrixtools.hxx>
...@@ -25,134 +24,133 @@ ...@@ -25,134 +24,133 @@
#include <drawinglayer/processor2d/processor2dtools.hxx> #include <drawinglayer/processor2d/processor2dtools.hxx>
#include <vcl/virdev.hxx> #include <vcl/virdev.hxx>
#include "converters.hxx"
#ifdef DBG_UTIL #ifdef DBG_UTIL
#include <tools/stream.hxx> #include <tools/stream.hxx>
#include <vcl/pngwrite.hxx> #include <vcl/pngwrite.hxx>
#endif #endif
namespace drawinglayer namespace drawinglayer
{ {
namespace tools
BitmapEx convertToBitmapEx(
const drawinglayer::primitive2d::Primitive2DContainer& rSeq,
const geometry::ViewInformation2D& rViewInformation2D,
sal_uInt32 nDiscreteWidth,
sal_uInt32 nDiscreteHeight,
sal_uInt32 nMaxQuadratPixels)
{ {
BitmapEx convertToBitmapEx( BitmapEx aRetval;
const drawinglayer::primitive2d::Primitive2DContainer& rSeq,
const geometry::ViewInformation2D& rViewInformation2D,
sal_uInt32 nDiscreteWidth,
sal_uInt32 nDiscreteHeight,
sal_uInt32 nMaxQuadratPixels)
{
BitmapEx aRetval;
#ifdef DBG_UTIL #ifdef DBG_UTIL
static bool bDoSaveForVisualControl(false); static bool bDoSaveForVisualControl(false);
#endif #endif
if(!rSeq.empty() && nDiscreteWidth && nDiscreteHeight) if(!rSeq.empty() && nDiscreteWidth && nDiscreteHeight)
{ {
// get destination size in pixels // get destination size in pixels
const MapMode aMapModePixel(MapUnit::MapPixel); const MapMode aMapModePixel(MapUnit::MapPixel);
const sal_uInt32 nViewVisibleArea(nDiscreteWidth * nDiscreteHeight); const sal_uInt32 nViewVisibleArea(nDiscreteWidth * nDiscreteHeight);
drawinglayer::primitive2d::Primitive2DContainer aSequence(rSeq); drawinglayer::primitive2d::Primitive2DContainer aSequence(rSeq);
if(nViewVisibleArea > nMaxQuadratPixels) if(nViewVisibleArea > nMaxQuadratPixels)
{ {
// reduce render size // reduce render size
double fReduceFactor = sqrt((double)nMaxQuadratPixels / (double)nViewVisibleArea); double fReduceFactor = sqrt((double)nMaxQuadratPixels / (double)nViewVisibleArea);
nDiscreteWidth = basegfx::fround((double)nDiscreteWidth * fReduceFactor); nDiscreteWidth = basegfx::fround((double)nDiscreteWidth * fReduceFactor);
nDiscreteHeight = basegfx::fround((double)nDiscreteHeight * fReduceFactor); nDiscreteHeight = basegfx::fround((double)nDiscreteHeight * fReduceFactor);
const drawinglayer::primitive2d::Primitive2DReference aEmbed( const drawinglayer::primitive2d::Primitive2DReference aEmbed(
new drawinglayer::primitive2d::TransformPrimitive2D( new drawinglayer::primitive2d::TransformPrimitive2D(
basegfx::tools::createScaleB2DHomMatrix(fReduceFactor, fReduceFactor), basegfx::tools::createScaleB2DHomMatrix(fReduceFactor, fReduceFactor),
rSeq)); rSeq));
aSequence = drawinglayer::primitive2d::Primitive2DContainer { aEmbed }; aSequence = drawinglayer::primitive2d::Primitive2DContainer { aEmbed };
} }
const Point aEmptyPoint; const Point aEmptyPoint;
const Size aSizePixel(nDiscreteWidth, nDiscreteHeight); const Size aSizePixel(nDiscreteWidth, nDiscreteHeight);
ScopedVclPtrInstance< VirtualDevice > pContent; ScopedVclPtrInstance< VirtualDevice > pContent;
// prepare vdev // prepare vdev
pContent->SetOutputSizePixel(aSizePixel, false); pContent->SetOutputSizePixel(aSizePixel, false);
pContent->SetMapMode(aMapModePixel); pContent->SetMapMode(aMapModePixel);
// set to all white // set to all white
pContent->SetBackground(Wallpaper(Color(COL_WHITE))); pContent->SetBackground(Wallpaper(Color(COL_WHITE)));
pContent->Erase(); pContent->Erase();
// create pixel processor, also already takes care of AAing and // create pixel processor, also already takes care of AAing and
// checking the getOptionsDrawinglayer().IsAntiAliasing() switch. If // checking the getOptionsDrawinglayer().IsAntiAliasing() switch. If
// not wanted, change after this call as needed // not wanted, change after this call as needed
processor2d::BaseProcessor2D* pContentProcessor = processor2d::createPixelProcessor2DFromOutputDevice( processor2d::BaseProcessor2D* pContentProcessor = processor2d::createPixelProcessor2DFromOutputDevice(
*pContent.get(), *pContent.get(),
rViewInformation2D); rViewInformation2D);
if(pContentProcessor) if(pContentProcessor)
{ {
// render content // render content
pContentProcessor->process(aSequence); pContentProcessor->process(aSequence);
// get content // get content
pContent->EnableMapMode(false); pContent->EnableMapMode(false);
const Bitmap aContent(pContent->GetBitmap(aEmptyPoint, aSizePixel)); const Bitmap aContent(pContent->GetBitmap(aEmptyPoint, aSizePixel));
#ifdef DBG_UTIL #ifdef DBG_UTIL
if(bDoSaveForVisualControl) if(bDoSaveForVisualControl)
{ {
SvFileStream aNew("c:\\test_content.png", StreamMode::WRITE|StreamMode::TRUNC); SvFileStream aNew("c:\\test_content.png", StreamMode::WRITE|StreamMode::TRUNC);
vcl::PNGWriter aPNGWriter(aContent); vcl::PNGWriter aPNGWriter(aContent);
aPNGWriter.Write(aNew); aPNGWriter.Write(aNew);
} }
#endif #endif
// prepare for mask creation // prepare for mask creation
pContent->SetMapMode(aMapModePixel); pContent->SetMapMode(aMapModePixel);
// set alpha to all white (fully transparent) // set alpha to all white (fully transparent)
pContent->Erase(); pContent->Erase();
// embed primitives to paint them black // embed primitives to paint them black
const primitive2d::Primitive2DReference xRef( const primitive2d::Primitive2DReference xRef(
new primitive2d::ModifiedColorPrimitive2D( new primitive2d::ModifiedColorPrimitive2D(
aSequence, aSequence,
basegfx::BColorModifierSharedPtr( basegfx::BColorModifierSharedPtr(
new basegfx::BColorModifier_replace( new basegfx::BColorModifier_replace(
basegfx::BColor(0.0, 0.0, 0.0))))); basegfx::BColor(0.0, 0.0, 0.0)))));
const primitive2d::Primitive2DContainer xSeq { xRef }; const primitive2d::Primitive2DContainer xSeq { xRef };
// render // render
pContentProcessor->process(xSeq); pContentProcessor->process(xSeq);
delete pContentProcessor; delete pContentProcessor;
// get alpha channel from vdev // get alpha channel from vdev
pContent->EnableMapMode(false); pContent->EnableMapMode(false);
const Bitmap aAlpha(pContent->GetBitmap(aEmptyPoint, aSizePixel)); const Bitmap aAlpha(pContent->GetBitmap(aEmptyPoint, aSizePixel));
#ifdef DBG_UTIL #ifdef DBG_UTIL
if(bDoSaveForVisualControl) if(bDoSaveForVisualControl)
{ {
SvFileStream aNew("c:\\test_alpha.png", StreamMode::WRITE|StreamMode::TRUNC); SvFileStream aNew("c:\\test_alpha.png", StreamMode::WRITE|StreamMode::TRUNC);
vcl::PNGWriter aPNGWriter(aAlpha); vcl::PNGWriter aPNGWriter(aAlpha);
aPNGWriter.Write(aNew); aPNGWriter.Write(aNew);
} }
#endif #endif
// create BitmapEx result // create BitmapEx result
aRetval = BitmapEx(aContent, AlphaMask(aAlpha)); aRetval = BitmapEx(aContent, AlphaMask(aAlpha));
#ifdef DBG_UTIL #ifdef DBG_UTIL
if(bDoSaveForVisualControl) if(bDoSaveForVisualControl)
{ {
SvFileStream aNew("c:\\test_combined.png", StreamMode::WRITE|StreamMode::TRUNC); SvFileStream aNew("c:\\test_combined.png", StreamMode::WRITE|StreamMode::TRUNC);
vcl::PNGWriter aPNGWriter(aRetval); vcl::PNGWriter aPNGWriter(aRetval);
aPNGWriter.Write(aNew); aPNGWriter.Write(aNew);
}
#endif
} }
#endif
} }
return aRetval;
} }
} // end of namespace tools return aRetval;
}
} // end of namespace drawinglayer } // end of namespace drawinglayer
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment