LCOV - code coverage report
Current view: top level - vcl/qa/cppunit - canvasbitmaptest.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 330 404 81.7 %
Date: 2014-11-03 Functions: 29 49 59.2 %
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             : // bootstrap stuff
      21             : #include <test/bootstrapfixture.hxx>
      22             : 
      23             : #include <com/sun/star/util/Endianness.hpp>
      24             : #include <com/sun/star/rendering/ColorComponentTag.hpp>
      25             : #include <com/sun/star/rendering/ColorSpaceType.hpp>
      26             : #include <com/sun/star/rendering/RenderingIntent.hpp>
      27             : #include <com/sun/star/rendering/XIntegerReadOnlyBitmap.hpp>
      28             : #include <com/sun/star/rendering/XIntegerBitmapColorSpace.hpp>
      29             : #include <com/sun/star/rendering/XBitmapPalette.hpp>
      30             : 
      31             : #include <cppuhelper/compbase3.hxx>
      32             : #include <tools/diagnose_ex.h>
      33             : #include <rtl/ref.hxx>
      34             : 
      35             : #include "vcl/svapp.hxx"
      36             : #include "vcl/canvastools.hxx"
      37             : #include "vcl/dialog.hxx"
      38             : #include "vcl/outdev.hxx"
      39             : #include "vcl/bmpacc.hxx"
      40             : #include "vcl/virdev.hxx"
      41             : #include "vcl/bitmapex.hxx"
      42             : 
      43             : #include "canvasbitmap.hxx"
      44             : 
      45             : using namespace ::com::sun::star;
      46             : using namespace ::vcl::unotools;
      47             : 
      48             : namespace com { namespace sun { namespace star { namespace rendering
      49             : {
      50             : 
      51        6000 : bool operator==( const RGBColor& rLHS, const ARGBColor& rRHS )
      52             : {
      53        6000 :     return rLHS.Red == rRHS.Red && rLHS.Green == rRHS.Green && rLHS.Blue == rRHS.Blue;
      54             : }
      55             : 
      56             : } } } }
      57             : 
      58             : namespace
      59             : {
      60             : 
      61           4 : class CanvasBitmapTest : public test::BootstrapFixture
      62             : {
      63             : public:
      64           2 :     CanvasBitmapTest() : BootstrapFixture(true, false) {}
      65             : 
      66             :     void runTest();
      67             : 
      68           4 :     CPPUNIT_TEST_SUITE(CanvasBitmapTest);
      69           2 :     CPPUNIT_TEST(runTest);
      70           4 :     CPPUNIT_TEST_SUITE_END();
      71             : };
      72             : 
      73        6000 : bool rangeCheck( const rendering::RGBColor& rColor )
      74             : {
      75       18000 :     return rColor.Red < 0.0 || rColor.Red > 1.0 ||
      76       18000 :         rColor.Green < 0.0 || rColor.Green > 1.0 ||
      77       18000 :         rColor.Blue < 0.0 || rColor.Blue > 1.0;
      78             : }
      79             : 
      80          30 : void checkCanvasBitmap( const rtl::Reference<VclCanvasBitmap>& xBmp,
      81             :                         const char*                            msg,
      82             :                         int                                    nOriginalDepth )
      83             : {
      84             :     OSL_TRACE("-------------------------");
      85             :     OSL_TRACE("Testing %s, with depth %d", msg, nOriginalDepth);
      86             : 
      87          30 :     BitmapEx aContainedBmpEx( xBmp->getBitmapEx() );
      88          60 :     Bitmap   aContainedBmp( aContainedBmpEx.GetBitmap() );
      89          30 :     int      nDepth = nOriginalDepth;
      90             : 
      91             :     {
      92          30 :         Bitmap::ScopedReadAccess pAcc( aContainedBmp );
      93          30 :         nDepth = pAcc->GetBitCount();
      94             :     }
      95             : 
      96          60 :     CPPUNIT_ASSERT_MESSAGE( "Original bitmap size not (200,200)",
      97          30 :                             aContainedBmp.GetSizePixel() == Size(200,200));
      98             : 
      99          60 :     CPPUNIT_ASSERT_MESSAGE( "Original bitmap size via API not (200,200)",
     100          30 :                             xBmp->getSize().Width == 200 && xBmp->getSize().Height == 200);
     101             : 
     102          60 :     CPPUNIT_ASSERT_MESSAGE( "alpha state mismatch",
     103          30 :                             bool(xBmp->hasAlpha()) == aContainedBmpEx.IsTransparent());
     104             : 
     105          60 :     CPPUNIT_ASSERT_MESSAGE( "getScaledBitmap() failed",
     106          30 :                             xBmp->getScaledBitmap( geometry::RealSize2D(500,500), false ).is());
     107             : 
     108          60 :     rendering::IntegerBitmapLayout aLayout;
     109          60 :     uno::Sequence<sal_Int8> aPixelData = xBmp->getData(aLayout, geometry::IntegerRectangle2D(0,0,1,1));
     110             : 
     111             :     const sal_Int32 nExpectedBitsPerPixel(
     112          30 :         aContainedBmpEx.IsTransparent() ? std::max(8,nDepth)+8 : nDepth);
     113          60 :     CPPUNIT_ASSERT_MESSAGE( "# scanlines not 1",
     114          30 :                             aLayout.ScanLines == 1);
     115          60 :     CPPUNIT_ASSERT_MESSAGE( "# scanline bytes mismatch",
     116          30 :                             aLayout.ScanLineBytes == (nExpectedBitsPerPixel+7)/8);
     117          60 :     CPPUNIT_ASSERT_MESSAGE( "# scanline stride mismatch",
     118             :                             aLayout.ScanLineStride == (nExpectedBitsPerPixel+7)/8 ||
     119          30 :                             aLayout.ScanLineStride == -(nExpectedBitsPerPixel+7)/8);
     120          60 :     CPPUNIT_ASSERT_MESSAGE( "# plane stride not 0",
     121          30 :                             aLayout.PlaneStride == 0);
     122             : 
     123          60 :     CPPUNIT_ASSERT_MESSAGE( "Color space not there",
     124          30 :                             aLayout.ColorSpace.is());
     125             : 
     126          60 :     CPPUNIT_ASSERT_MESSAGE( "Palette existence does not conform to bitmap",
     127          30 :                             aLayout.Palette.is() == (nDepth <= 8));
     128             : 
     129          60 :     uno::Sequence<sal_Int8> aPixelData2 = xBmp->getPixel( aLayout, geometry::IntegerPoint2D(0,0) );
     130             : 
     131          60 :     CPPUNIT_ASSERT_MESSAGE( "getData and getPixel did not return same amount of data",
     132          30 :                             aPixelData2.getLength() == aPixelData.getLength());
     133             : 
     134          30 :     aPixelData = xBmp->getData(aLayout, geometry::IntegerRectangle2D(0,0,200,1));
     135          60 :     CPPUNIT_ASSERT_MESSAGE( "# scanlines not 1 for getPixel",
     136          30 :                             aLayout.ScanLines == 1);
     137          60 :     CPPUNIT_ASSERT_MESSAGE( "# scanline bytes mismatch for getPixel",
     138          30 :                             aLayout.ScanLineBytes == (200*nExpectedBitsPerPixel+7)/8);
     139          60 :     CPPUNIT_ASSERT_MESSAGE( "# scanline stride mismatch for getPixel",
     140             :                             aLayout.ScanLineStride == (200*nExpectedBitsPerPixel+7)/8 ||
     141          30 :                             aLayout.ScanLineStride == -(200*nExpectedBitsPerPixel+7)/8);
     142             : 
     143          60 :     uno::Sequence< rendering::RGBColor >  aRGBColors  = xBmp->convertIntegerToRGB( aPixelData );
     144          60 :     uno::Sequence< rendering::ARGBColor > aARGBColors = xBmp->convertIntegerToARGB( aPixelData );
     145             : 
     146          30 :     const rendering::RGBColor*  pRGBStart ( aRGBColors.getConstArray() );
     147          30 :     const rendering::RGBColor*  pRGBEnd   ( aRGBColors.getConstArray()+aRGBColors.getLength() );
     148          30 :     const rendering::ARGBColor* pARGBStart( aARGBColors.getConstArray() );
     149             :     std::pair<const rendering::RGBColor*,
     150          30 :         const rendering::ARGBColor*> aRes = std::mismatch( pRGBStart, pRGBEnd, pARGBStart );
     151          60 :     CPPUNIT_ASSERT_MESSAGE( "argb and rgb colors are not equal",
     152          30 :                             aRes.first == pRGBEnd);
     153             : 
     154          60 :     CPPUNIT_ASSERT_MESSAGE( "rgb colors are not within [0,1] range",
     155          30 :                             std::find_if(pRGBStart,pRGBEnd,&rangeCheck) == pRGBEnd);
     156             : 
     157          60 :     CPPUNIT_ASSERT_MESSAGE( "First pixel is not white",
     158          30 :                             pRGBStart[0].Red == 1.0 && pRGBStart[0].Green == 1.0 && pRGBStart[0].Blue == 1.0);
     159          60 :     CPPUNIT_ASSERT_MESSAGE( "Second pixel is not opaque",
     160          30 :                             pARGBStart[1].Alpha == 1.0);
     161          30 :     if( aContainedBmpEx.IsTransparent() )
     162             :     {
     163          40 :         CPPUNIT_ASSERT_MESSAGE( "First pixel is not fully transparent",
     164          20 :                                 pARGBStart[0].Alpha == 0.0);
     165             :     }
     166             : 
     167          60 :     CPPUNIT_ASSERT_MESSAGE( "Second pixel is not black",
     168          30 :                             pRGBStart[1].Red == 0.0 && pRGBStart[1].Green == 0.0 && pRGBStart[1].Blue == 0.0);
     169             : 
     170          30 :     if( nOriginalDepth > 8 )
     171             :     {
     172          12 :         const Color aCol(COL_GREEN);
     173          24 :         CPPUNIT_ASSERT_EQUAL_MESSAGE(
     174             :             "Sixth pixel is not green (red component)",
     175          12 :             vcl::unotools::toDoubleColor(aCol.GetRed()), pRGBStart[5].Red);
     176          24 :         CPPUNIT_ASSERT_EQUAL_MESSAGE(
     177             :             "Sixth pixel is not green (green component)",
     178          12 :             vcl::unotools::toDoubleColor(aCol.GetGreen()), pRGBStart[5].Green);
     179          24 :         CPPUNIT_ASSERT_EQUAL_MESSAGE(
     180             :             "Sixth pixel is not green (blue component)",
     181          12 :             vcl::unotools::toDoubleColor(aCol.GetBlue()), pRGBStart[5].Blue);
     182             :     }
     183          18 :     else if( nDepth <= 8 )
     184             :     {
     185          14 :         uno::Reference<rendering::XBitmapPalette> xPal = xBmp->getPalette();
     186          28 :         CPPUNIT_ASSERT_MESSAGE( "8bit or less: missing palette",
     187          14 :                                 xPal.is());
     188          28 :         CPPUNIT_ASSERT_MESSAGE( "Palette incorrect entry count",
     189          14 :                                 xPal->getNumberOfEntries() == 1L << nOriginalDepth);
     190          28 :         uno::Sequence<double> aIndex;
     191          28 :         CPPUNIT_ASSERT_MESSAGE( "Palette is not read-only",
     192          14 :                                 !xPal->setIndex(aIndex,true,0));
     193          28 :         CPPUNIT_ASSERT_MESSAGE( "Palette entry 0 is not opaque",
     194          14 :                                 xPal->getIndex(aIndex,0));
     195          28 :         CPPUNIT_ASSERT_MESSAGE( "Palette has no valid color space",
     196          28 :                                 xPal->getColorSpace().is());
     197             :     }
     198             : 
     199          60 :     CPPUNIT_ASSERT_MESSAGE( "150th pixel is not white",
     200             :                             pRGBStart[150].Red == 1.0 &&
     201             :                             pRGBStart[150].Green == 1.0 &&
     202          30 :                             pRGBStart[150].Blue == 1.0);
     203             : 
     204          30 :     if( nOriginalDepth > 8 )
     205             :     {
     206          12 :         uno::Sequence<rendering::ARGBColor> aARGBColor(1);
     207          24 :         uno::Sequence<rendering::RGBColor>  aRGBColor(1);
     208          24 :         uno::Sequence<sal_Int8> aPixel3, aPixel4;
     209             : 
     210          12 :         const Color aCol(COL_GREEN);
     211          12 :         aARGBColor[0].Red   = vcl::unotools::toDoubleColor(aCol.GetRed());
     212          12 :         aARGBColor[0].Green = vcl::unotools::toDoubleColor(aCol.GetGreen());
     213          12 :         aARGBColor[0].Blue  = vcl::unotools::toDoubleColor(aCol.GetBlue());
     214          12 :         aARGBColor[0].Alpha = 1.0;
     215             : 
     216          12 :         aRGBColor[0].Red   = vcl::unotools::toDoubleColor(aCol.GetRed());
     217          12 :         aRGBColor[0].Green = vcl::unotools::toDoubleColor(aCol.GetGreen());
     218          12 :         aRGBColor[0].Blue  = vcl::unotools::toDoubleColor(aCol.GetBlue());
     219             : 
     220          12 :         aPixel3 = xBmp->convertIntegerFromARGB( aARGBColor );
     221          12 :         aPixel4 = xBmp->getPixel( aLayout, geometry::IntegerPoint2D(5,0) );
     222          24 :         CPPUNIT_ASSERT_MESSAGE( "Green pixel from bitmap mismatch with manually converted green pixel",
     223          12 :                                 aPixel3 == aPixel4);
     224             : 
     225          12 :         if( !aContainedBmpEx.IsTransparent() )
     226             :         {
     227           4 :             aPixel3 = xBmp->convertIntegerFromRGB( aRGBColor );
     228           8 :             CPPUNIT_ASSERT_MESSAGE( "Green pixel from bitmap mismatch with manually RGB-converted green pixel",
     229           4 :                                     aPixel3 == aPixel4);
     230          12 :         }
     231          30 :     }
     232          30 : }
     233             : 
     234           8 : class TestBitmap : public cppu::WeakImplHelper3< rendering::XIntegerReadOnlyBitmap,
     235             :                                                  rendering::XBitmapPalette,
     236             :                                                  rendering::XIntegerBitmapColorSpace >
     237             : {
     238             : private:
     239             :     geometry::IntegerSize2D        maSize;
     240             :     uno::Sequence<sal_Int8>        maComponentTags;
     241             :     uno::Sequence<sal_Int32>       maComponentBitCounts;
     242             :     rendering::IntegerBitmapLayout maLayout;
     243             :     const sal_Int32                mnBitsPerPixel;
     244             : 
     245             :     // XBitmap
     246           4 :     virtual geometry::IntegerSize2D SAL_CALL getSize() throw (uno::RuntimeException, std::exception) SAL_OVERRIDE { return maSize; }
     247           4 :     virtual sal_Bool SAL_CALL hasAlpha(  ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE { return mnBitsPerPixel != 8; }
     248           0 :     virtual uno::Reference< rendering::XBitmap > SAL_CALL getScaledBitmap( const geometry::RealSize2D&,
     249           0 :                                                                            sal_Bool ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE { return this; }
     250             : 
     251             :     // XIntegerReadOnlyBitmap
     252          40 :     virtual uno::Sequence< ::sal_Int8 > SAL_CALL getData( rendering::IntegerBitmapLayout&     bitmapLayout,
     253             :                                                           const geometry::IntegerRectangle2D& rect )
     254             :         throw (lang::IndexOutOfBoundsException,
     255             :                rendering::VolatileContentDestroyedException,
     256             :                uno::RuntimeException,
     257             :                std::exception) SAL_OVERRIDE
     258             :     {
     259          40 :         CPPUNIT_ASSERT_MESSAGE( "X1 out of bounds", rect.X1 >= 0 );
     260          40 :         CPPUNIT_ASSERT_MESSAGE( "Y1 out of bounds", rect.Y1 >= 0 );
     261          40 :         CPPUNIT_ASSERT_MESSAGE( "X2 out of bounds", rect.X2 <= maSize.Width );
     262          40 :         CPPUNIT_ASSERT_MESSAGE( "Y2 out of bounds", rect.Y2 <= maSize.Height );
     263             : 
     264          40 :         bitmapLayout = getMemoryLayout();
     265             : 
     266          40 :         const sal_Int32 nWidth  = rect.X2-rect.X1;
     267          40 :         const sal_Int32 nHeight = rect.Y2-rect.Y1;
     268          40 :         const sal_Int32 nScanlineLen = (nWidth * mnBitsPerPixel + 7)/8;
     269          40 :         uno::Sequence<sal_Int8> aRes( nScanlineLen * nHeight );
     270          40 :         sal_Int8* pOut = aRes.getArray();
     271             : 
     272          40 :         bitmapLayout.ScanLines     = nHeight;
     273             :         bitmapLayout.ScanLineBytes =
     274          40 :         bitmapLayout.ScanLineStride= nScanlineLen;
     275             : 
     276          40 :         if( mnBitsPerPixel == 8 )
     277             :         {
     278          40 :             for( sal_Int32 y=0; y<nHeight; ++y )
     279             :             {
     280         220 :                 for( sal_Int32 x=0; x<nWidth; ++x )
     281         200 :                     pOut[ y*nScanlineLen + x ] = sal_Int8(x);
     282             :             }
     283             :         }
     284             :         else
     285             :         {
     286          40 :             for( sal_Int32 y=0; y<nHeight; ++y )
     287             :             {
     288         220 :                 for( sal_Int32 x=0; x<nWidth; ++x )
     289             :                 {
     290         200 :                     pOut[ y*nScanlineLen + 4*x     ] = sal_Int8(rect.X1);
     291         200 :                     pOut[ y*nScanlineLen + 4*x + 1 ] = sal_Int8(rect.Y2);
     292         200 :                     pOut[ y*nScanlineLen + 4*x + 2 ] = sal_Int8(x);
     293         200 :                     pOut[ y*nScanlineLen + 4*x + 3 ] = sal_Int8(rect.Y1);
     294             :                 }
     295             :             }
     296             :         }
     297             : 
     298          40 :         return aRes;
     299             :     }
     300             : 
     301           0 :     virtual uno::Sequence< ::sal_Int8 > SAL_CALL getPixel( rendering::IntegerBitmapLayout&,
     302             :                                                            const geometry::IntegerPoint2D&  )
     303             :         throw (lang::IndexOutOfBoundsException,
     304             :                rendering::VolatileContentDestroyedException,
     305             :                uno::RuntimeException,
     306             :                std::exception) SAL_OVERRIDE
     307             :     {
     308           0 :         CPPUNIT_ASSERT_MESSAGE("getPixel: method not implemented", false);
     309           0 :         return uno::Sequence< sal_Int8 >();
     310             :     }
     311             : 
     312         596 :     virtual uno::Reference< rendering::XBitmapPalette > SAL_CALL getPalette(  ) throw (uno::RuntimeException)
     313             :     {
     314         596 :         uno::Reference< XBitmapPalette > aRet;
     315         596 :         if( mnBitsPerPixel == 8 )
     316         554 :             aRet.set(this);
     317         596 :         return aRet;
     318             :     }
     319             : 
     320          44 :     virtual rendering::IntegerBitmapLayout SAL_CALL getMemoryLayout(  ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
     321             :     {
     322          44 :         rendering::IntegerBitmapLayout aLayout( maLayout );
     323             : 
     324          44 :         const sal_Int32 nScanlineLen = (maSize.Width * mnBitsPerPixel + 7)/8;
     325             : 
     326          44 :         aLayout.ScanLines     = maSize.Height;
     327             :         aLayout.ScanLineBytes =
     328          44 :         aLayout.ScanLineStride= nScanlineLen;
     329          44 :         aLayout.Palette = getPalette();
     330          44 :         aLayout.ColorSpace.set( this );
     331             : 
     332          44 :         return aLayout;
     333             :     }
     334             : 
     335             :     // XBitmapPalette
     336           2 :     virtual sal_Int32 SAL_CALL getNumberOfEntries() throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
     337             :     {
     338           4 :         CPPUNIT_ASSERT_MESSAGE( "Got palette getNumberOfEntries interface call without handing out palette",
     339           2 :                                 getPalette().is() );
     340             : 
     341           2 :         return 255;
     342             :     }
     343             : 
     344         510 :     virtual sal_Bool SAL_CALL getIndex( uno::Sequence< double >& entry,
     345             :                                           ::sal_Int32 nIndex )
     346             :         throw (lang::IndexOutOfBoundsException,
     347             :                uno::RuntimeException,
     348             :                std::exception) SAL_OVERRIDE
     349             :     {
     350        1020 :         CPPUNIT_ASSERT_MESSAGE( "Got palette getIndex interface call without handing out palette",
     351         510 :                                 getPalette().is() );
     352        1020 :         CPPUNIT_ASSERT_MESSAGE( "getIndex: index out of range",
     353         510 :                                 nIndex >= 0 && nIndex < 256 );
     354        1020 :         entry = colorToStdColorSpaceSequence(
     355             :             Color(sal_uInt8(nIndex),
     356             :                   sal_uInt8(nIndex),
     357         510 :                   sal_uInt8(nIndex)) );
     358             : 
     359         510 :         return true; // no palette transparency here.
     360             :     }
     361             : 
     362           0 :     virtual sal_Bool SAL_CALL setIndex( const uno::Sequence< double >&,
     363             :                                           sal_Bool,
     364             :                                           ::sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException,
     365             :                                                                       lang::IllegalArgumentException,
     366             :                                                                       uno::RuntimeException,
     367             :                                                                       std::exception) SAL_OVERRIDE
     368             :     {
     369           0 :         CPPUNIT_ASSERT_MESSAGE( "Got palette setIndex interface call without handing out palette",
     370           0 :                                 getPalette().is());
     371           0 :         CPPUNIT_ASSERT_MESSAGE( "setIndex: index out of range",
     372           0 :                                 nIndex >= 0 && nIndex < 256);
     373           0 :         return false;
     374             :     }
     375             : 
     376             :     struct PaletteColorSpaceHolder: public rtl::StaticWithInit<uno::Reference<rendering::XColorSpace>,
     377             :                                                                PaletteColorSpaceHolder>
     378             :     {
     379           2 :         uno::Reference<rendering::XColorSpace> operator()()
     380             :         {
     381           2 :             return vcl::unotools::createStandardColorSpace();
     382             :         }
     383             :     };
     384             : 
     385           4 :     virtual uno::Reference< rendering::XColorSpace > SAL_CALL getColorSpace(  ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
     386             :     {
     387             :         // this is the method from XBitmapPalette. Return palette color
     388             :         // space here
     389           4 :         return PaletteColorSpaceHolder::get();
     390             :     }
     391             : 
     392             :     // XIntegerBitmapColorSpace
     393           0 :     virtual ::sal_Int8 SAL_CALL getType(  ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
     394             :     {
     395           0 :         return rendering::ColorSpaceType::RGB;
     396             :     }
     397             : 
     398           2 :     virtual uno::Sequence< sal_Int8 > SAL_CALL getComponentTags(  ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
     399             :     {
     400           2 :         return maComponentTags;
     401             :     }
     402             : 
     403           0 :     virtual ::sal_Int8 SAL_CALL getRenderingIntent(  ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
     404             :     {
     405           0 :         return rendering::RenderingIntent::PERCEPTUAL;
     406             :     }
     407             : 
     408           0 :     virtual uno::Sequence< beans::PropertyValue > SAL_CALL getProperties()
     409             :         throw (uno::RuntimeException,
     410             :                std::exception) SAL_OVERRIDE
     411             :     {
     412           0 :         CPPUNIT_ASSERT_MESSAGE("getProperties: method not implemented", false );
     413           0 :         return uno::Sequence< ::beans::PropertyValue >();
     414             :     }
     415             : 
     416           0 :     virtual uno::Sequence< double > SAL_CALL convertColorSpace( const uno::Sequence< double >&,
     417             :                                                                 const uno::Reference< rendering::XColorSpace >& )
     418             :         throw (uno::RuntimeException,
     419             :                std::exception) SAL_OVERRIDE
     420             :     {
     421           0 :         CPPUNIT_ASSERT_MESSAGE("convertColorSpace: method not implemented", false);
     422           0 :         return uno::Sequence< double >();
     423             :     }
     424             : 
     425           0 :     virtual uno::Sequence< rendering::RGBColor > SAL_CALL convertToRGB( const uno::Sequence< double >& )
     426             :         throw (lang::IllegalArgumentException,
     427             :                uno::RuntimeException,
     428             :                std::exception) SAL_OVERRIDE
     429             :     {
     430           0 :         CPPUNIT_ASSERT_MESSAGE("convertToRGB: method not implemented", false);
     431           0 :         return uno::Sequence< rendering::RGBColor >();
     432             :     }
     433             : 
     434           0 :     virtual uno::Sequence< rendering::ARGBColor > SAL_CALL convertToARGB( const uno::Sequence< double >& )
     435             :         throw (lang::IllegalArgumentException,
     436             :                uno::RuntimeException,
     437             :                std::exception) SAL_OVERRIDE
     438             :     {
     439           0 :         CPPUNIT_ASSERT_MESSAGE("convertToARGB: method not implemented", false);
     440           0 :         return uno::Sequence< rendering::ARGBColor >();
     441             :     }
     442             : 
     443           0 :     virtual uno::Sequence< rendering::ARGBColor > SAL_CALL convertToPARGB( const uno::Sequence< double >& )
     444             :         throw (lang::IllegalArgumentException,
     445             :                uno::RuntimeException,
     446             :                std::exception) SAL_OVERRIDE
     447             :     {
     448           0 :         CPPUNIT_ASSERT_MESSAGE("convertToPARGB: method not implemented", false);
     449           0 :         return uno::Sequence< rendering::ARGBColor >();
     450             :     }
     451             : 
     452           0 :     virtual uno::Sequence< double > SAL_CALL convertFromRGB( const uno::Sequence< rendering::RGBColor >& )
     453             :         throw (lang::IllegalArgumentException,
     454             :                uno::RuntimeException,
     455             :                std::exception) SAL_OVERRIDE
     456             :     {
     457           0 :         CPPUNIT_ASSERT_MESSAGE("convertFromRGB: method not implemented", false);
     458           0 :         return uno::Sequence< double >();
     459             :     }
     460             : 
     461           0 :     virtual uno::Sequence< double > SAL_CALL convertFromARGB( const uno::Sequence< rendering::ARGBColor >& )
     462             :         throw (lang::IllegalArgumentException,
     463             :                uno::RuntimeException,
     464             :                std::exception) SAL_OVERRIDE
     465             :     {
     466           0 :         CPPUNIT_ASSERT_MESSAGE("convertFromARGB: this method is not expected to be called!", false);
     467           0 :         return uno::Sequence< double >();
     468             :     }
     469             : 
     470           0 :     virtual uno::Sequence< double > SAL_CALL convertFromPARGB( const uno::Sequence< rendering::ARGBColor >& )
     471             :         throw (lang::IllegalArgumentException,
     472             :                uno::RuntimeException,
     473             :                std::exception) SAL_OVERRIDE
     474             :     {
     475           0 :         CPPUNIT_ASSERT_MESSAGE("convertFromPARGB: this method is not expected to be called!", false);
     476           0 :         return uno::Sequence< double >();
     477             :     }
     478             : 
     479           4 :     virtual ::sal_Int32 SAL_CALL getBitsPerPixel(  ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
     480             :     {
     481           4 :         return mnBitsPerPixel;
     482             :     }
     483             : 
     484           2 :     virtual uno::Sequence< ::sal_Int32 > SAL_CALL getComponentBitCounts(  ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
     485             :     {
     486           2 :         return maComponentBitCounts;
     487             :     }
     488             : 
     489           0 :     virtual ::sal_Int8 SAL_CALL getEndianness(  ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
     490             :     {
     491           0 :         return util::Endianness::LITTLE;
     492             :     }
     493             : 
     494           0 :     virtual uno::Sequence< double > SAL_CALL convertFromIntegerColorSpace( const uno::Sequence< ::sal_Int8 >& ,
     495             :                                                                            const uno::Reference< rendering::XColorSpace >& )
     496             :         throw (lang::IllegalArgumentException,
     497             :                uno::RuntimeException,
     498             :                std::exception) SAL_OVERRIDE
     499             :     {
     500           0 :         CPPUNIT_ASSERT_MESSAGE("convertFromIntegerColorSpace: method not implemented", false);
     501           0 :         return uno::Sequence< double >();
     502             :     }
     503             : 
     504           0 :     virtual uno::Sequence< ::sal_Int8 > SAL_CALL convertToIntegerColorSpace( const uno::Sequence< ::sal_Int8 >& ,
     505             :                                                                              const uno::Reference< rendering::XIntegerBitmapColorSpace >& )
     506             :         throw (lang::IllegalArgumentException,
     507             :                uno::RuntimeException,
     508             :                std::exception) SAL_OVERRIDE
     509             :     {
     510           0 :         CPPUNIT_ASSERT_MESSAGE("convertToIntegerColorSpace: method not implemented", false);
     511           0 :         return uno::Sequence< sal_Int8 >();
     512             :     }
     513             : 
     514          20 :     virtual uno::Sequence< rendering::RGBColor > SAL_CALL convertIntegerToRGB( const uno::Sequence< ::sal_Int8 >& deviceColor ) throw (lang::IllegalArgumentException,
     515             :                                                                                                                                        uno::RuntimeException, std::exception) SAL_OVERRIDE
     516             :     {
     517          20 :         const uno::Sequence< rendering::ARGBColor > aTemp( convertIntegerToARGB(deviceColor) );
     518          20 :         const sal_Size nLen(aTemp.getLength());
     519          20 :         uno::Sequence< rendering::RGBColor > aRes( nLen );
     520          20 :         rendering::RGBColor* pOut = aRes.getArray();
     521         220 :         for( sal_Size i=0; i<nLen; ++i )
     522             :         {
     523         200 :             *pOut++ = rendering::RGBColor(aTemp[i].Red,
     524         200 :                                           aTemp[i].Green,
     525         600 :                                           aTemp[i].Blue);
     526             :         }
     527             : 
     528          20 :         return aRes;
     529             :     }
     530             : 
     531          40 :     virtual uno::Sequence< rendering::ARGBColor > SAL_CALL convertIntegerToARGB( const uno::Sequence< ::sal_Int8 >& deviceColor ) throw (lang::IllegalArgumentException,
     532             :                                                                                                                                          uno::RuntimeException, std::exception) SAL_OVERRIDE
     533             :     {
     534          40 :         const sal_Size  nLen( deviceColor.getLength() );
     535          40 :         const sal_Int32 nBytesPerPixel(mnBitsPerPixel == 8 ? 1 : 4);
     536          80 :         CPPUNIT_ASSERT_MESSAGE("number of channels no multiple of pixel element count",
     537          40 :                                nLen%nBytesPerPixel==0);
     538             : 
     539          40 :         uno::Sequence< rendering::ARGBColor > aRes( nLen / nBytesPerPixel );
     540          40 :         rendering::ARGBColor* pOut( aRes.getArray() );
     541             : 
     542          40 :         if( getPalette().is() )
     543             :         {
     544         220 :             for( sal_Size i=0; i<nLen; ++i )
     545             :             {
     546             :                 *pOut++ = rendering::ARGBColor(
     547             :                     1.0,
     548         200 :                     vcl::unotools::toDoubleColor(deviceColor[i]),
     549         200 :                     vcl::unotools::toDoubleColor(deviceColor[i]),
     550         600 :                     vcl::unotools::toDoubleColor(deviceColor[i]));
     551             :             }
     552             :         }
     553             :         else
     554             :         {
     555         220 :             for( sal_Size i=0; i<nLen; i+=4 )
     556             :             {
     557             :                 *pOut++ = rendering::ARGBColor(
     558         200 :                     vcl::unotools::toDoubleColor(deviceColor[i+3]),
     559         200 :                     vcl::unotools::toDoubleColor(deviceColor[i+0]),
     560         200 :                     vcl::unotools::toDoubleColor(deviceColor[i+1]),
     561         800 :                     vcl::unotools::toDoubleColor(deviceColor[i+2]));
     562             :             }
     563             :         }
     564             : 
     565          40 :         return aRes;
     566             :     }
     567             : 
     568           0 :     virtual uno::Sequence< rendering::ARGBColor > SAL_CALL convertIntegerToPARGB(
     569             :         const uno::Sequence< ::sal_Int8 >& deviceColor)
     570             :             throw (lang::IllegalArgumentException,
     571             :                    uno::RuntimeException,
     572             :                    std::exception) SAL_OVERRIDE
     573             :     {
     574           0 :         const sal_Size  nLen( deviceColor.getLength() );
     575           0 :         const sal_Int32 nBytesPerPixel(mnBitsPerPixel == 8 ? 1 : 4);
     576           0 :         CPPUNIT_ASSERT_MESSAGE("number of channels no multiple of pixel element count",
     577           0 :                                nLen%nBytesPerPixel==0);
     578             : 
     579           0 :         uno::Sequence< rendering::ARGBColor > aRes( nLen / nBytesPerPixel );
     580           0 :         rendering::ARGBColor* pOut( aRes.getArray() );
     581             : 
     582           0 :         if( getPalette().is() )
     583             :         {
     584           0 :             for( sal_Size i=0; i<nLen; ++i )
     585             :             {
     586             :                 *pOut++ = rendering::ARGBColor(
     587             :                     1.0,
     588           0 :                     vcl::unotools::toDoubleColor(deviceColor[i]),
     589           0 :                     vcl::unotools::toDoubleColor(deviceColor[i]),
     590           0 :                     vcl::unotools::toDoubleColor(deviceColor[i]));
     591             :             }
     592             :         }
     593             :         else
     594             :         {
     595           0 :             for( sal_Size i=0; i<nLen; i+=4 )
     596             :             {
     597           0 :                 const double fAlpha=vcl::unotools::toDoubleColor(deviceColor[i+3]);
     598             :                 *pOut++ = rendering::ARGBColor(
     599             :                     fAlpha,
     600           0 :                     fAlpha*vcl::unotools::toDoubleColor(deviceColor[i+0]),
     601           0 :                     fAlpha*vcl::unotools::toDoubleColor(deviceColor[i+1]),
     602           0 :                     fAlpha*vcl::unotools::toDoubleColor(deviceColor[i+2]));
     603             :             }
     604             :         }
     605             : 
     606           0 :         return aRes;
     607             :     }
     608             : 
     609           0 :     virtual uno::Sequence< ::sal_Int8 > SAL_CALL convertIntegerFromRGB(
     610             :         const uno::Sequence< rendering::RGBColor >&)
     611             :             throw (lang::IllegalArgumentException,
     612             :                    uno::RuntimeException,
     613             :                    std::exception) SAL_OVERRIDE
     614             :     {
     615           0 :         CPPUNIT_ASSERT_MESSAGE("convertIntegerFromRGB: method not implemented", false);
     616           0 :         return uno::Sequence< sal_Int8 >();
     617             :     }
     618             : 
     619           0 :     virtual uno::Sequence< ::sal_Int8 > SAL_CALL convertIntegerFromARGB( const uno::Sequence< rendering::ARGBColor >& ) throw (lang::IllegalArgumentException,
     620             :                                                                                                                                uno::RuntimeException,
     621             :                                   std::exception) SAL_OVERRIDE
     622             :     {
     623           0 :         CPPUNIT_ASSERT_MESSAGE("convertIntegerFromARGB: method not implemented", false);
     624           0 :         return uno::Sequence< sal_Int8 >();
     625             :     }
     626             : 
     627           0 :     virtual uno::Sequence< ::sal_Int8 > SAL_CALL convertIntegerFromPARGB( const uno::Sequence< rendering::ARGBColor >& )
     628             :         throw (lang::IllegalArgumentException,
     629             :         uno::RuntimeException,
     630             :         std::exception) SAL_OVERRIDE
     631             :     {
     632           0 :         CPPUNIT_ASSERT_MESSAGE("convertIntegerFromPARGB: method not implemented", false);
     633           0 :         return uno::Sequence< sal_Int8 >();
     634             :     }
     635             : 
     636             : public:
     637           4 :     TestBitmap( const geometry::IntegerSize2D& rSize, bool bPalette ) :
     638             :         maSize(rSize),
     639             :         maComponentTags(),
     640             :         maComponentBitCounts(),
     641             :         maLayout(),
     642           4 :         mnBitsPerPixel( bPalette ? 8 : 32 )
     643             :     {
     644           4 :         if( bPalette )
     645             :         {
     646           2 :             maComponentTags.realloc(1);
     647           2 :             maComponentTags[0] = rendering::ColorComponentTag::INDEX;
     648             : 
     649           2 :             maComponentBitCounts.realloc(1);
     650           2 :             maComponentBitCounts[0] = 8;
     651             :         }
     652             :         else
     653             :         {
     654           2 :             maComponentTags.realloc(4);
     655           2 :             sal_Int8* pTags = maComponentTags.getArray();
     656           2 :             pTags[0]        = rendering::ColorComponentTag::RGB_BLUE;
     657           2 :             pTags[1]        = rendering::ColorComponentTag::RGB_GREEN;
     658           2 :             pTags[2]        = rendering::ColorComponentTag::RGB_RED;
     659           2 :             pTags[3]        = rendering::ColorComponentTag::ALPHA;
     660             : 
     661           2 :             maComponentBitCounts.realloc(4);
     662           2 :             sal_Int32* pCounts = maComponentBitCounts.getArray();
     663           2 :             pCounts[0]         = 8;
     664           2 :             pCounts[1]         = 8;
     665           2 :             pCounts[2]         = 8;
     666           2 :             pCounts[3]         = 8;
     667             :         }
     668             : 
     669           4 :         maLayout.ScanLines      = 0;
     670           4 :         maLayout.ScanLineBytes  = 0;
     671           4 :         maLayout.ScanLineStride = 0;
     672           4 :         maLayout.PlaneStride    = 0;
     673           4 :         maLayout.ColorSpace.clear();
     674           4 :         maLayout.Palette.clear();
     675           4 :         maLayout.IsMsbFirst     = false;
     676           4 :     }
     677             : };
     678             : 
     679           2 : void CanvasBitmapTest::runTest()
     680             : {
     681             :     static const sal_Int8 lcl_depths[]={1,4,8,16,24};
     682             : 
     683             :     // Testing VclCanvasBitmap wrapper
     684             : 
     685          12 :     for( unsigned int i=0; i<SAL_N_ELEMENTS(lcl_depths); ++i )
     686             :     {
     687          10 :         const sal_Int8 nDepth( lcl_depths[i] );
     688          10 :         Bitmap aBitmap(Size(200,200),nDepth);
     689          10 :         aBitmap.Erase(COL_WHITE);
     690             :         {
     691          10 :             Bitmap::ScopedWriteAccess pAcc(aBitmap);
     692          10 :             if( pAcc.get() )
     693             :             {
     694          10 :                 BitmapColor aBlack(0);
     695          20 :                 BitmapColor aWhite(0);
     696          10 :                 if( pAcc->HasPalette() )
     697             :                 {
     698           6 :                     aBlack.SetIndex( sal::static_int_cast<sal_Int8>(pAcc->GetBestPaletteIndex(BitmapColor(0,0,0))) );
     699           6 :                     aWhite.SetIndex( sal::static_int_cast<sal_Int8>(pAcc->GetBestPaletteIndex(BitmapColor(255,255,255))) );
     700             :                 }
     701             :                 else
     702             :                 {
     703           4 :                     aBlack = Color(COL_BLACK);
     704           4 :                     aWhite = Color(COL_WHITE);
     705             :                 }
     706          10 :                 pAcc->SetFillColor(COL_GREEN);
     707          10 :                 pAcc->FillRect(Rectangle(0,0,100,100));
     708          10 :                 pAcc->SetPixel(0,0,aWhite);
     709          10 :                 pAcc->SetPixel(0,1,aBlack);
     710          20 :                 pAcc->SetPixel(0,2,aWhite);
     711          10 :             }
     712             :         }
     713             : 
     714          20 :         rtl::Reference<VclCanvasBitmap> xBmp( new VclCanvasBitmap(aBitmap) );
     715             : 
     716          10 :         checkCanvasBitmap( xBmp, "single bitmap", nDepth );
     717             : 
     718          20 :         Bitmap aMask(Size(200,200),1);
     719          10 :         aMask.Erase(COL_WHITE);
     720             :         {
     721          10 :             Bitmap::ScopedWriteAccess pAcc(aMask);
     722          10 :             if( pAcc.get() )
     723             :             {
     724          10 :                 pAcc->SetFillColor(COL_BLACK);
     725          10 :                 pAcc->FillRect(Rectangle(0,0,100,100));
     726          10 :                 pAcc->SetPixel(0,0,BitmapColor(1));
     727          10 :                 pAcc->SetPixel(0,1,BitmapColor(0));
     728          10 :                 pAcc->SetPixel(0,2,BitmapColor(1));
     729          10 :             }
     730             :         }
     731             : 
     732          10 :         xBmp.set( new VclCanvasBitmap(BitmapEx(aBitmap,aMask)) );
     733             : 
     734          10 :         checkCanvasBitmap( xBmp, "masked bitmap", nDepth );
     735             : 
     736          20 :         AlphaMask aAlpha(Size(200,200));
     737          10 :         aAlpha.Erase(255);
     738             :         {
     739          10 :             BitmapWriteAccess* pAcc = aAlpha.AcquireWriteAccess();
     740          10 :             if( pAcc )
     741             :             {
     742          10 :                 pAcc->SetFillColor(COL_BLACK);
     743          10 :                 pAcc->FillRect(Rectangle(0,0,100,100));
     744          10 :                 pAcc->SetPixel(0,0,BitmapColor(255));
     745          10 :                 pAcc->SetPixel(0,1,BitmapColor(0));
     746          10 :                 pAcc->SetPixel(0,2,BitmapColor(255));
     747          10 :                 aAlpha.ReleaseAccess(pAcc);
     748             :             }
     749             :         }
     750             : 
     751          10 :         xBmp.set( new VclCanvasBitmap(BitmapEx(aBitmap,aAlpha)) );
     752             : 
     753          10 :         checkCanvasBitmap( xBmp, "alpha bitmap", nDepth );
     754          10 :     }
     755             : 
     756             :     // Testing XBitmap import
     757             : 
     758             :     uno::Reference< rendering::XIntegerReadOnlyBitmap > xTestBmp(
     759           2 :         new TestBitmap( geometry::IntegerSize2D(10,10), true ));
     760             : 
     761           4 :     BitmapEx aBmp = vcl::unotools::bitmapExFromXBitmap(xTestBmp);
     762           4 :     CPPUNIT_ASSERT_MESSAGE( "Palette bitmap is transparent",
     763           2 :                             !aBmp.IsTransparent());
     764           4 :     CPPUNIT_ASSERT_MESSAGE( "Bitmap does not have size (10,10)",
     765           2 :                             aBmp.GetSizePixel() == Size(10,10));
     766           4 :     CPPUNIT_ASSERT_MESSAGE( "Bitmap does not have bitcount of 8",
     767           2 :                             aBmp.GetBitCount() == 8);
     768             :     {
     769           2 :         BitmapReadAccess* pBmpAcc   = aBmp.GetBitmap().AcquireReadAccess();
     770             : 
     771           4 :         CPPUNIT_ASSERT_MESSAGE( "Bitmap has invalid BitmapReadAccess",
     772           2 :                                 pBmpAcc );
     773             : 
     774           4 :         CPPUNIT_ASSERT_MESSAGE("(0,0) incorrect content",
     775           2 :                                pBmpAcc->GetPixel(0,0) == BitmapColor(0));
     776           4 :         CPPUNIT_ASSERT_MESSAGE("(2,2) incorrect content",
     777           2 :                                pBmpAcc->GetPixel(2,2) == BitmapColor(2));
     778           4 :         CPPUNIT_ASSERT_MESSAGE("(9,2) incorrect content",
     779           2 :                                pBmpAcc->GetPixel(2,9) == BitmapColor(9));
     780             : 
     781           2 :         aBmp.GetBitmap().ReleaseAccess(pBmpAcc);
     782             :     }
     783             : 
     784           2 :     xTestBmp.set( new TestBitmap( geometry::IntegerSize2D(10,10), false ));
     785             : 
     786           2 :     aBmp = vcl::unotools::bitmapExFromXBitmap(xTestBmp);
     787           4 :     CPPUNIT_ASSERT_MESSAGE( "Palette bitmap is not transparent",
     788           2 :                             aBmp.IsTransparent());
     789           4 :     CPPUNIT_ASSERT_MESSAGE( "Palette bitmap has no alpha",
     790           2 :                             aBmp.IsAlpha());
     791           4 :     CPPUNIT_ASSERT_MESSAGE( "Bitmap does not have size (10,10)",
     792           2 :                             aBmp.GetSizePixel() == Size(10,10));
     793           4 :     CPPUNIT_ASSERT_MESSAGE( "Bitmap has bitcount of 24",
     794           2 :                             aBmp.GetBitCount() == 24);
     795             :     {
     796           2 :         BitmapReadAccess* pBmpAcc   = aBmp.GetBitmap().AcquireReadAccess();
     797           2 :         BitmapReadAccess* pAlphaAcc = aBmp.GetAlpha().AcquireReadAccess();
     798             : 
     799           4 :         CPPUNIT_ASSERT_MESSAGE( "Bitmap has invalid BitmapReadAccess",
     800           2 :                                 pBmpAcc);
     801           4 :         CPPUNIT_ASSERT_MESSAGE( "Bitmap has invalid alpha BitmapReadAccess",
     802           2 :                                 pAlphaAcc);
     803             : 
     804           4 :         CPPUNIT_ASSERT_MESSAGE("(0,0) incorrect content",
     805           2 :                                pBmpAcc->GetPixel(0,0) == BitmapColor(0,1,0));
     806           4 :         CPPUNIT_ASSERT_MESSAGE("(0,0) incorrect alpha content",
     807           2 :                                pAlphaAcc->GetPixel(0,0) == BitmapColor(255));
     808           4 :         CPPUNIT_ASSERT_MESSAGE("(2,2) incorrect content",
     809           2 :                                pBmpAcc->GetPixel(2,2) == BitmapColor(0,3,2));
     810           4 :         CPPUNIT_ASSERT_MESSAGE("(2,2) incorrect alpha content",
     811           2 :                                pAlphaAcc->GetPixel(2,2) == BitmapColor(253));
     812           4 :         CPPUNIT_ASSERT_MESSAGE("(9,2) incorrect content",
     813           2 :                                pBmpAcc->GetPixel(2,9) == BitmapColor(0,3,9));
     814           4 :         CPPUNIT_ASSERT_MESSAGE("(9,2) correct alpha content",
     815           2 :                                pAlphaAcc->GetPixel(2,9) == BitmapColor(253));
     816             : 
     817           2 :         aBmp.GetAlpha().ReleaseAccess(pAlphaAcc);
     818           2 :         aBmp.GetBitmap().ReleaseAccess(pBmpAcc);
     819           2 :     }
     820           2 : }
     821             : 
     822             : } // namespace
     823             : 
     824           6 : CPPUNIT_TEST_SUITE_REGISTRATION(CanvasBitmapTest);
     825             : 
     826             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10