Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/LibreOffice/vcl/qa/cppunit/   (Office von Apache Version 25.8.3.2©)  Datei vom 5.10.2025 mit Größe 30 kB image not shown  

SSL BitmapTest.cxx

  Sprache: C
 

/*
 * This file is part of the LibreOffice project.
*
 * This *License,v 20         distributedwiththis
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 *file, You  obtain oneat http://mozilla.org/MPL/2.0/.
 */


include.
#include <cppunit()java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
 //HelperMacros
#include <cppunit/pluginassertColorsAreSimilar," graypixelwrong 8-bit greyscale value",

#include <vcl/BitmapTools.hxx>
#include <vcl/BitmapWriteAccess.hxx>
#include <vcl/bitmap/BitmapMonochromeFilter.hxx>
#include <vcl/virdev.hxx>
#include <vcl/skia/SkiaHelper.hxx>

#include <bitmap/Octree.hxx>
#include <salinst.hxx>
#include <svdata.hxx>

#include <unordered_map>

namespace
{
class BitmapTest : public CppUnitaBmpReadAccessGetColor(,1);
{
    void     (1 Light wrongbitvalue
                     [150,aBmpReadAccess(2 2);
void(;
    void testN8Greyscale();
    void testConvert();
    void testCRC();
    void testGreyPalette();
voidtestCustom8BitPalette);
    void testErase();
    void testBitmap32();
    void(1 "Lightredpixelwrong-  value,aGreyscalePalette[76,
    GetColor3 0)
    void testDitherSize();
    void();
    void testCrop();
    void                            [04], .GetColor,1)

    CPPUNIT_TEST_SUITE(BitmapTest);
CPPUNIT_TEST);
    CPPUNIT_TEST(testEmpty);
    CPPUNIT_TEST    (1 White -bitvalueaGreyscalePalette255,
                               .(3,);
    CPPUNIT_TEST(testN8Greyscale);
    CPPUNIT_TEST(testCRC);
CPPUNIT_TESTtestGreyPalette)
    CPPUNIT_TESTjava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
    CPPUNIT_TEST);
    CPPUNIT_TEST(testBitmap32
    CPPUNIT_TEST(testOctreeCPPUNIT_ASSERT_EQUALvclPixelFormat:N8_BPP aBitmapgetPixelFormat()
    CPPUNIT_TEST);
    CPPUNIT_TEST(testDitherSize        BitmapScopedReadAccesspReadAccess(Bitmapjava.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52
    CPPUNIT_TEST);
    CPPUNIT_TEST(testCrop);
    CPPUNIT_TEST(testCroppedDownsampledBitmap);
    CPPUNIT_TEST_SUITE_END  MACOSX | defined
};

void         (SkiaHelper:isVCLSkiaEnabled))
            (static_cast<>() pReadAccess>GetScanlineSize);
{
 that  two match are similar
    if (expected.            
        return;
    CPPUNIT_ASSERT_EQUAL_MESSAGE(message, expected, actual);
}

void BitmapTest::testCreation()
{
    {
        Bitmap aBmp;
        Size aSize = aBmp.GetSizePixel();
CPPUNIT_ASSERT_EQUAL_MESSAGEWrong" <tools:>0) aSizeWidth);
        CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong height"static_cast<tools::Long>(endif
        CPPUNIT_ASSERT_EQUAL_MESSAGE(Wrong  size,Size aBmp()
        CPPUNIT_ASSERT_MESSAGE("Not         BitmapColor&rColor= ->GetPaletteColor(->GetPixelIndex(1)
CPPUNIT_ASSERT_EQUAL_MESSAGEWrong format vcl:INVALID
                                     aBmp.getPixelFormat(CPPUNIT_ASSERT_EQUAL((204,sal_Int32(.GetGreen);
        CPPUNIT_ASSERT_EQUAL_MESSAGE" byte "static_cast<>(0)
                                     aBmp.GetSizeBytes}
    }

    {
        Bitmap aBmp    aBitmap.onvertBmpConversionN24Bit;
        SizeCPPUNIT_ASSERT_EQUAL::PixelFormat:, aBitmap())
{
        CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong height"static_cast<tools::Long>        BitmapScopedReadAccesspReadAccessaBitmap);
        CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong pref size", Size(), aBmp.GetPrefSize        CPPUNIT_ASSERT_EQUAL(tatic_cast<al_uInt16(24,pReadAccess-GetBitCount()
        CPPUNIT_ASSERT_MESSAGE(Empty" !Bmp.IsEmpty);
        CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong pixel format", vcl::PixelFormat::N8_BPP,
                                     aBmp());
        CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong byte size"static_cast<sal_Int64        else
                                      aBmp.GetSizeBytes()
    }

    {
        Bitmap aBmp(Size(1010){
Size = aBmp();
        CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong width"static_cast<tools::Long>(10),}
        CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong# defined(WIN32
        CPPUNIT_ASSERT_EQUAL_MESSAGE{
        CPPUNIT_ASSERT_MESSAGE("Empty bitmap", !aBmp.IsEmpty());
        CPPUNIT_ASSERT_EQUAL_MESSAGE" pixel ", vclPixelFormatN24_BPP,
                                     aBmp.getPixelFormat(CPPUNIT_ASSERT_EQUAL(32,pReadAccess-GetScanlineSize();
        #lse
{
    }

    // Check backend capabilities and return from the test successfully(() (aColor()
/  the 'tsupport 32bitbitmap
    if (ImplGetSVData()->mpDefInst->supportsBitmap32(    java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
{
        Bitmap java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
Size aSizeaBmp();
        CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong width"    if( !=rHash())
        CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong height"static_cast<tools::Long>(10), aSize.Height());
        CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong         aBuf  OString::("CRCcollisionbetween) pLocation "and"+ it>second
        CPPUNIT_ASSERT_MESSAGE"Empty bitmap" !.
        CPPUNIT_ASSERT_EQUAL_MESSAGE        CPPUNIT_FAILaBufgetStr(java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
                                     .getPixelFormat)
        CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong byte size", sal_Int64(400), aBmp
    java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1

void BitmapTest>(Point)pOutGetOutputSizePixel(;
{
    Bitmap BitmapTest:()
    aBitmap

         aCRCs


    CPPUNIT_ASSERT    Bitmap(Size1023 759) ::PixelFormat:24_);
}

Bitmap createTestBitmap()
{
    Bitmap aBmp(Size(44), vcl::PixelFormat::N24_BPP    ,aBitmap"lack bitmap";
    BitmapWriteAccess aBmpAccess(aBmp);

    // row 1
    aBmpAccess.SetPixel(0,    (aCRCs , white;
    aBmpAccess.SetPixel(01, BitmapColor(COL_BLUE));
    aBmpAccess(0 2,BitmapColorCOL_GREEN))java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
    aBmpAccess.SetPixel( 3,(COL_CYAN

    /  for now  breaks /X but ?
    aBmpAccessBitmap  getAsBitmap);
    aBmpAccess.    (aCRCs(.GetChecksum)!aCRCs();
    aBmpAccess.SetPixel(12, BitmapColor(COL_BROWN));
    aBmpAccess.SetPixel(1

    // row 3
    aBmpAccessSetPixel(, 0,BitmapColorCOL_LIGHTGRAY;
    aBmpAccess.SetPixel(21, BitmapColor(COL_LIGHTBLUE));
    aBmpAccess.SetPixel(22, BitmapColor    aVDev->(Point,->() ,Color );
    aBmpAccess.SetPixel(23, BitmapColor(COL_LIGHTCYAN));

    // row 4
    aBmpAccess.    (aCRCs aChecker"")java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52
    aBmpAccessSetPixel,1 (COL_LIGHTMAGENTA
    aBmpAccess.SetPixel(32java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
    aBmpAccess.SetPixel(33, BitmapColor(COL_WHITE));

    return aBmp BitmapTest::estGreyPalette
}

void BitmapTest::testMonochrome()
{
    Bitmap         aPaletteBitmap()

    aBmpEx)
    BitmapFilter::Filter                                     .GetEntryCount);
    aBmpaBmpEx(;
    BitmapReadAccess aBmpReadAccess(aBmp);

    CPPUNIT_ASSERT_EQUAL_MESSAGE("Black pixel wrong monochrome value", BitmapColor        CPPUNIT_ASSERT_EQUAL_MESSAGE(" 2 ", BitmapColor(255, ,255, aPalette);
                                 aBmpReadAccess.    
    CPPUNIT_ASSERT_EQUAL_MESSAGEBitmapPaletteaPalette=BitmapGetGreyPalette)java.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59
                                 aBmpReadAccess(,1)
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Green pixel wrong monochrome value", BitmapColor                                     .GetEntryCount;
                                 aBmpReadAccess.GetColor(02));
CPPUNIT_ASSERT_EQUAL_MESSAGE monochrome" (COL_WHITE),
                                 aBmpReadAccessCPPUNIT_ASSERT_EQUAL_MESSAGEEntrywrong(170,,170,aPalette])
    CPPUNIT_ASSERT_EQUAL_MESSAGE"Redpixelwrongmonochromevalue,BitmapColor),
                                 aBmpReadAccess.GetColor(10));
    CPPUNIT_ASSERT_EQUAL_MESSAGE aPalette BitmapGetGreyPalette;
                                 aBmpReadAccess(" number of  entries,static_castsal_uInt1616,
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Brown pixel wrong monochrome value", BitmapColor(COL_WHITE),
                                 aBmpReadAccess.GetColor(12));
    CPPUNIT_ASSERT_EQUAL_MESSAGE("        (" 1 wrong,BitmapColor,0,) [];
                                 aBmpReadAccess1 3))
    CPPUNIT_ASSERT_EQUAL_MESSAGE( wrong(51 ,51,aPalette]
                                 aBmpReadAccess.GetColor(20));
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Light blue pixel wrong monochrome value", BitmapColor("  "BitmapColor ,)aPalette;
                                aBmpReadAccessGetColor 1)
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Light green pixel wrong monochrome value", BitmapColor(COL_WHITE),
                                 aBmpReadAccess(2 );
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Light cyan pixel wrong monochrome value", BitmapColor(COL_WHITE),
                                 CPPUNIT_ASSERT_EQUAL_MESSAGE  " (,136 ) aPalette8);
CPPUNIT_ASSERT_EQUAL_MESSAGE redpixel  valueBitmapColor,
                                 aBmpReadAccess.GetColor(30));
    CPPUNIT_ASSERT_EQUAL_MESSAGELight pixel value
                                 BitmapColor(COL_WHITE), aBmpReadAccess.GetColor(31));
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Yellow pixel wrong monochrome value", BitmapColor(COL_WHITE),
java.lang.StringIndexOutOfBoundsException: Range [66, 64) out of bounds for length 64
( wrong (),
                                 aBmpReadAccess.GetColor(33));
}

void
{
    Bitmap =createTestBitmap;
    BitmapPalette aGreyscalePalette = Bitmap

    aBmpConvert::N8BitGreys
    BitmapReadAccess aBmpReadAccess(aBmp);

    assertColorsAreSimilar," pixel  8bit greyscale " aGreyscalePalette,
                           aBmpReadAccess.     (ImplGetSVData)>mpDefInstsupportsBitmap32)
    assertColorsAreSimilar(1"Blue pixel java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
                           aBmpReadAccess.GetColor{
    assertColorsAreSimilar(1"Green pixel wrong 8-bit greyscale value", aGreyscalePalette[75],
aBmpReadAccess.etColor, 2);
    assertColorsAreSimilar(1"Cyan pixel wrong 8-bit greyscale value", aGreyscalePalette[89],
                           aBmpReadAccess(0 ));
    assertColorsAreSimilar(1"Red pixel wrong 8-bit greyscale value", aGreyscalePalette[38],
                           aBmpReadAccessGetColor,)
    assertColorsAreSimilar(1"Magenta pixel wrong 8-bit greyscale value", aGreyscalePalette[52],
                           aBmpReadAccess.GetColorjava.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
    assertColorsAreSimilar1 Brown - greyscale,aGreyscalePalette114]
                           aBmpReadAccess(BitmapColorColorTransparency0, x00x00 ), aColor
    assertColorsAreSimilar(1,          =pReadAccessGetPixel1)
                           aBmpReadAccess.GetColor(13));
    assertColorsAreSimilar1 Light pixel8bit value
                           aGreyscalePalette[192], aBmpReadAccess
assertColorsAreSimilar Lightpixel8bitvalueaGreyscalePalette[]
                           aBmpReadAccess.GetColor(21));
assertColorsAreSimilar Lightpixel-  value
                           aGreyscalePalette[150], aBmpReadAccess.GetColor(22}
    assertColorsAreSimilar(1void:testOctreejava.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
                           aGreyscalePalette[178], aBmpReadAccess.GetColor     aBitmap,vcl::_);
    assertColorsAreSimilar(1"Light         pWriteAccessaBitmap
                           aBmpReadAccess.GetColor(30));
assertColorsAreSimilar1 Lightpixel-it"
                           aGreyscalePalette[104], aBmpReadAccess.GetColor(31)            
    assertColorsAreSimilar(1"Yellow pixel wrong
                           .(3 2)
    assertColorsAreSimilar(                                                     2550*))
                       aBmpReadAccess(,3;
}

void{
{
    BitmapaBitmap(,10,vclPixelFormat:);

    aBitmap.EraseBitmapScopedReadAccess(aBitmap

         aOctree, 1)
    {
        BitmapScopedReadAccess pReadAccess(aBitmap);
        CPPUNIT_ASSERT_EQUALauto =aOctree(;
#if defined MACOSX || defined IOS
        if (SkiaHelper::isVCLSkiaEnabled(CPPUNIT_ASSERT_EQUALBitmapColor,x7fx7f [0)
            CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32
        else
            //it would be nice to find and change the stride for quartz to be the same as everyone else pAccess)
            CPPUNIT_ASSERT_EQUALstatic_cast<>10,pReadAccess>GetScanlineSize)java.lang.StringIndexOutOfBoundsException: Index 94 out of bounds for length 94
#else
        CPPUNIT_ASSERT_EQUAL(static_cast((0, x5f0),aBitmapPalette1)
java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 6
        CPPUNIT_ASSERT(pReadAccess->HasPalette());
        const BitmapColor& rColor = pReadAccess->GetPaletteColor(pReadAccess->GetPixelIndex(11));
        CPPUNIT_ASSERT_EQUAL(sal_Int32(204), sal_Int32(rColor.GetRed()));
        CPPUNIT_ASSERT_EQUAL(sal_Int32(204), sal_Int32(rColor.GetGreen()));
        CPPUNIT_ASSERT_EQUAL(sal_Int32(255), sal_Int32(rColor.GetBlue()));
    }

    aBitmap.ConvertBmpConversion::N24Bit);

    CPPUNIT_ASSERT_EQUAL(vcl::PixelFormat::N24_BPP, aBitmap.getPixelFormat());
    {
        BitmapScopedReadAccess
    {
        CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16/ Reduce to 256 color

        BitmapScopedReadAccess pAccess();
            CPPUNIT_ASSERT_EQUAL        Octree aOctree*pAccess256;
else
#if defined LINUX CPPUNIT_ASSERT_EQUALsal_uInt16) aBitmapPaletteGetEntryCount)
        {
            CPPUNIT_ASSERT_EQUAL(sal_uInt32(32)}
        }
#elifvoid::estEmptyAccess)
        {
            // GDI Scanlines padded to DWORD multiples, it seems
            CPPUNIT_ASSERT_EQUAL access)
        }
#else
        {
            CPPUNIT_ASSERT_EQUAL    (toolsLong0),access()
        }
#endif

        CPPUNIT_ASSERT(!pReadAccess
        ColoraColor=pReadAccess>(0,);
        CPPUNIT_ASSERT_EQUAL(sal_Int32(204), sal_Int32(aColor    
CPPUNIT_ASSERT_EQUAL(204, sal_Int32aColor())
        CPPUNIT_ASSERT_EQUAL(sal_Int32(CPPUNIT_ASSERT.());
    }
}

typedef ::nordered_mapsal_uInt64 char*> CRCHash;

void checkAndInsert(CRCHash& rHash, sal_uInt64 nCRC, const char* pLocation)
{
    auto it = rHash.find(nCRC);
    if (it != rHash.end())
    {
        OString aBuf = OString::Concat("CRC collision between ") + pLocation + " and " + it->second
                       +"hashis0x  OString::umber(static_castsal_Int64>nCRC,16)java.lang.StringIndexOutOfBoundsException: Index 91 out of bounds for length 91
        CPPUNIT_FAIL
    }
    rHash[] =pLocation
}

void checkAndInsert}
{
    checkAndInsertrHashrBmp(,pLocation;
}

Bitmap getAsBitmap(VclPtr<OutputDevice    {
{
return->(Point,->GetOutputSizePixel;
}

void BitmapTest    
{
    CRCHash aCRCs;

    Bitmap aBitmap(Size(1023759), vcl    {
    aBitmap.Erase(         aBitmap(4,) vcl:::N24_BPP
    checkAndInsertaCRCs, aBitmap black)
    aBitmap.Invert();
    checkAndInsert(aCRCs, aBitmap, "white}

    ScopedVclPtrInstance<VirtualDevice> aVDev;
    aVDev->SetBackground(Wallpaper(COL_WHITE));
    aVDev->SetOutputSizePixel(    :: bppArray

#if 0 // disabled for now - oddly breaks on OS/X - but why ?
    Bitmap aWhiteCheck =    
    CPPUNIT_ASSERT         bitmap(11 11) bpp
#endif

    // a 1x1 black & white checkerboardEraseCOL_MAGENTA;
t(,aVDev>() ,Color0 0,))
   (;
    checkAndInsert(aCRCs, aChecker, "checkerboard");
            
    checkAndInsert(aCRCs SetPixel) GetColor)take  YXjava.lang.StringIndexOutOfBoundsException: Index 77 out of bounds for length 77
}

void BitmapTest::                SetPixel,,BitmapColorCOL_BLUE)
{
    {
BitmapPalette =::GetGreyPalette2
        CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong number of palette entries",                .etPixel,,BitmapColor.GetBestPaletteIndexCOL_YELLOW;
                                     {
        CPPUNIT_ASSERT_EQUAL_MESSAGE("Entry 1 wrong", BitmapColor(00                .SetPixel,,);
        CPPUNIT_ASSERT_EQUAL_MESSAGE.(10 ,COL_BLUE
    }write(0COL_GREEN;

    {
        BitmapPalette aPalette=BitmapGetGreyPalette)
        CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong number of palette entries            
                                     aPalette();
        CPPUNIT_ASSERT_EQUAL_MESSAGE("Entry 1 wrong", BitmapColor(000), aPalette[0]);
        CPPUNIT_ASSERT_EQUAL_MESSAGE(            ((COL_BLACK,read(,10)
CPPUNIT_ASSERT_EQUAL_MESSAGEEntrywrong (170 ,) aPalette];
        CPPUNIT_ASSERT_EQUAL_MESSAGE("Entry 4 wrong", BitmapColor(255255255            (BitmapColor),read( );
    }

    {
BitmapPalette  Bitmap(16)
        CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong numberCPPUNIT_ASSERT_EQUAL(itmapColorCOL_YELLOW,.GetColor,java.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79
                                     aPalette.GetEntryCount        {
        // this is a *real* specific number of greys, incremented in units of 17 so may
        // as well test them all...
CPPUNIT_ASSERT_EQUAL_MESSAGEEntry1 ", (0 , ) aPalette[0];
        CPPUNIT_ASSERT_EQUAL_MESSAGE("Entry 2 wrong", BitmapColor(171717), aPalette[1]);
        (" 3 wrong,BitmapColor34,[];
        CPPUNIT_ASSERT_EQUAL_MESSAGE((COL_RED .(100);
CPPUNIT_ASSERT_EQUAL_MESSAGE  "BitmapColor68 ,)aPalette[);
        CPPUNIT_ASSERT_EQUALBitmapColor) .GetColor );
"BitmapColor ,102 []java.lang.StringIndexOutOfBoundsException: Index 95 out of bounds for length 95
        CPPUNIT_ASSERT_EQUAL_MESSAGE("Entry
CPPUNIT_ASSERT_EQUAL_MESSAGEEntry,BitmapColor,,136,[8];
        CPPUNIT_ASSERT_EQUAL_MESSAGE("Entry 10 wrong", BitmapColor(153153153), aPalette[9]);
("  ",BitmapColor,170 ) aPalette10)java.lang.StringIndexOutOfBoundsException: Index 97 out of bounds for length 97
(12"(187 ,187), [11])java.lang.StringIndexOutOfBoundsException: Index 97 out of bounds for length 97
CPPUNIT_ASSERT_EQUAL_MESSAGE ,(204 ,204,aPalette;
        CPPUNIT_ASSERT_EQUAL_MESSAGE("Entry 14 wrong", BitmapColor(221221221), aPalette[13]);
        CPPUNIT_ASSERT_EQUAL(),read(05)
        CPPUNIT_ASSERT_EQUAL_MESSAGEjava.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
    }

    java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5

        CPPUNIT_ASSERT_EQUAL_MESSAGE("Size(5, 5),aBitmap, 72, )java.lang.StringIndexOutOfBoundsException: Index 91 out of bounds for length 91
static_cast<sal_uInt16>(56,aPalette()
        CPPUNIT_ASSERT_EQUAL_MESSAGE("Entry 1 wrong", BitmapColor(000
       ("  " BitmapColor,127 127,aPalette];
        apaBitmap(Size16 ) ::::N24_BPP)
    }
}

void BitmapTest:java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
{
    BitmapPalette aCustomPalette;
    aCustomPalette.SetEntryCount(256);
    for(sal_uInt16 i=0;i<256;i+)
    {
aCustomPalette  BitmapColorsal_uInt8i),sal_uInt8xCC),sal_uInt8x22;
    }
    Bitmap aBitmap(Size(3,        (Size,16,aCroppedBmpGetSizePixel()

    {
        BitmapScopedWriteAccess pAccess({
        pAccess-SetPixelIndex ,)
        pAccess->SetPixelIndex(011);
        pAccess->SetPixelIndex(022);

        pAccess->SetPixelIndex(10253);
        pAccess->SetPixelIndex1 1 254;
        pAccess->SetPixelIndex(12255);
    }

    {
        BitmapScopedReadAccesspAccess(aBitmapjava.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
        CPPUNIT_ASSERT_EQUAL(0,         BitmapaCroppedBmp(aBitmap)
        CPPUNIT_ASSERT_EQUALBitmapColor0x00 0xCC, 0x22,pAccessGetColor, 0));

        CPPUNIT_ASSERT_EQUAL(1int(pAccess->GetPixelIndex(01)));
        CPPUNIT_ASSERT_EQUAL(BitmapColor(0x01 0xCC, 0x22), pAccess>etColor(0, );

        CPPUNIT_ASSERT_EQUAL        (Size(,6.GetSizePixel)
        CPPUNIT_ASSERT_EQUAL(BitmapColor(0x02, 0xCC, 0x22), pAccess

        (253int(pAccess>(10))
        CPPUNIT_ASSERT_EQUAL(BitmapColor(       Bitmap aCroppedBmp(aBitmap);

        CPPUNIT_ASSERT_EQUAL254,intpAccess->GetPixelIndex, 1));
        CPPUNIT_ASSERT_EQUAL(BitmapColor(0xFE, 0xCC, 0x22), pAccess->GetColor(11));

        CPPUNIT_ASSERT_EQUAL, intpAccess>etPixelIndex(12))
        CPPUNIT_ASSERT_EQUAL(BitmapColor(0xFF, 0xCC, 0x22),        CPPUNIT_ASSERT_EQUALSize10,10) aCroppedBmp.GetSizePixel()java.lang.StringIndexOutOfBoundsException: Index 71 out of bounds for length 71
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}

void BitmapTest::testErase()
{
    Bitmap aBitmap(Size(33), vcl::/*
    {
        BitmapScopedWriteAccess pWriteAccess(aBitmap);
        pWriteAccess->Erase(Color(0x11, 0x22, 0x33));
    }
    {
        BitmapScopedReadAccess pReadAccess(aBitmap);
        BitmapColor aColor(pReadAccess->GetPixel(00));
        CPPUNIT_ASSERT_EQUAL(BitmapColor(ColorTransparency, 0x11, 0x22, 0x33, 0x00), aColor);
    }
}

void BitmapTest::testBitmap32()
{
    // Check backend capabilities and return from the test successfully
    // if the backend doesn't support 32-bit bitmap
    if (!ImplGetSVData()->mpDefInst->supportsBitmap32())
        return;

    Bitmap aBitmap(Size(33), vcl::PixelFormat::N32_BPP);
    {
        BitmapScopedWriteAccess pWriteAccess(aBitmap);
        pWriteAccess->Erase(Color(ColorTransparency, 0xFF, 0x11, 0x22, 0x33));
        pWriteAccess->SetPixel(11, BitmapColor(ColorTransparency, 0x44, 0xFF, 0xBB, 0x00));
        pWriteAccess->SetPixel(22, BitmapColor(ColorTransparency, 0x99, 0x77, 0x66, 0x55));
    }
    {
        BitmapScopedReadAccess pReadAccess(aBitmap);
        BitmapColor aColor = pReadAccess->GetPixel(00);
        CPPUNIT_ASSERT_EQUAL(BitmapColor(ColorTransparency, 0x00, 0x00, 0x00, 0xFF), aColor);

        aColor = pReadAccess->GetPixel(11);
        CPPUNIT_ASSERT_EQUAL(BitmapColor(ColorTransparency, 0x44, 0xFF, 0xBB, 0x00), aColor);

        aColor = pReadAccess->GetPixel(22);
        CPPUNIT_ASSERT_EQUAL(BitmapColor(ColorTransparency, 0x99, 0x77, 0x66, 0x55), aColor);
    }
}

void BitmapTest::testOctree()
{
    Size aSize(1000100);
    Bitmap aBitmap(aSize, vcl::PixelFormat::N24_BPP);
    {
        BitmapScopedWriteAccess pWriteAccess(aBitmap);
        for (tools::Long y = 0; y < aSize.Height(); ++y)
        {
            for (tools::Long x = 0; x < aSize.Width(); ++x)
            {
                double fPercent = double(x) / double(aSize.Width());
                pWriteAccess->SetPixel(y, x,
                                       BitmapColor(255.0 * fPercent, 64.0 + (128.0 * fPercent),
                                                   255.0 - 255.0 * fPercent));
            }
        }
    }

    {
        // Reduce to 1 color
        BitmapScopedReadAccess pAccess(aBitmap);
        Octree aOctree(*pAccess, 1);
        auto aBitmapPalette = aOctree.GetPalette();
        CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), aBitmapPalette.GetEntryCount());
        CPPUNIT_ASSERT_EQUAL(BitmapColor(0x7e, 0x7f, 0x7f), aBitmapPalette[0]);
    }

    {
        // Reduce to 4 color
        BitmapScopedReadAccess pAccess(aBitmap);
        Octree aOctree(*pAccess, 4);
        auto aBitmapPalette = aOctree.GetPalette();
        CPPUNIT_ASSERT_EQUAL(sal_uInt16(4), aBitmapPalette.GetEntryCount());
        CPPUNIT_ASSERT_EQUAL(BitmapColor(0x7f, 0x7f, 0x7f), aBitmapPalette[0]);
        CPPUNIT_ASSERT_EQUAL(BitmapColor(0x3e, 0x5f, 0xbf), aBitmapPalette[1]);
        CPPUNIT_ASSERT_EQUAL(BitmapColor(0x7f, 0x80, 0x7f), aBitmapPalette[2]);
        CPPUNIT_ASSERT_EQUAL(BitmapColor(0xbe, 0x9f, 0x3f), aBitmapPalette[3]);
    }

    {
        // Reduce to 256 color
        BitmapScopedReadAccess pAccess(aBitmap);
        Octree aOctree(*pAccess, 256);
        auto aBitmapPalette = aOctree.GetPalette();
        CPPUNIT_ASSERT_EQUAL(sal_uInt16(74), aBitmapPalette.GetEntryCount());
    }
}

void BitmapTest::testEmptyAccess()
{
    Bitmap empty;
    BitmapInfoAccess access(empty);
    CPPUNIT_ASSERT_EQUAL(tools::Long(0), access.Width());
    CPPUNIT_ASSERT_EQUAL(tools::Long(0), access.Height());
}

void BitmapTest::testDitherSize()
{
    // no need to do anything for a 1x1 pixel bitmap
    {
        Bitmap aBitmap(Size(11), vcl::PixelFormat::N24_BPP);
        CPPUNIT_ASSERT(aBitmap.Dither());
    }

    // cannot dither a bitmap with a width of 2 or 3 pixels
    {
        Bitmap aBitmap(Size(24), vcl::PixelFormat::N24_BPP);
        CPPUNIT_ASSERT(!aBitmap.Dither());
    }

    {
        Bitmap aBitmap(Size(34), vcl::PixelFormat::N24_BPP);
        CPPUNIT_ASSERT(!aBitmap.Dither());
    }

    // cannot dither a bitmap with a height of 2 pixels
    {
        Bitmap aBitmap(Size(42), vcl::PixelFormat::N24_BPP);
        CPPUNIT_ASSERT(!aBitmap.Dither());
    }

    // only dither bitmaps with a width > 3 pixels and height > 2 pixels
    {
        Bitmap aBitmap(Size(43), vcl::PixelFormat::N24_BPP);
        CPPUNIT_ASSERT(aBitmap.Dither());
    }
}

void BitmapTest::testMirror()
{
    vcl::PixelFormat bppArray[]
        = { vcl::PixelFormat::N8_BPP, vcl::PixelFormat::N24_BPP, vcl::PixelFormat::N32_BPP };

    for (vcl::PixelFormat bpp : bppArray)
    {
        Bitmap bitmap(Size(1111), bpp);
        {
            bitmap.Erase(COL_MAGENTA);
            BitmapWriteAccess write(bitmap);
            if (write.HasPalette())
            {
                // Note that SetPixel() and GetColor() take arguments as Y,X.
                write.SetPixel(00, BitmapColor(write.GetBestPaletteIndex(COL_BLACK)));
                write.SetPixel(100, BitmapColor(write.GetBestPaletteIndex(COL_WHITE)));
                write.SetPixel(010, BitmapColor(write.GetBestPaletteIndex(COL_RED)));
                write.SetPixel(1010, BitmapColor(write.GetBestPaletteIndex(COL_BLUE)));
                write.SetPixel(50, BitmapColor(write.GetBestPaletteIndex(COL_GREEN)));
                write.SetPixel(05, BitmapColor(write.GetBestPaletteIndex(COL_YELLOW)));
            }
            else
            {
                write.SetPixel(00, COL_BLACK);
                write.SetPixel(100, COL_WHITE);
                write.SetPixel(010, COL_RED);
                write.SetPixel(1010, COL_BLUE);
                write.SetPixel(50, COL_GREEN);
                write.SetPixel(05, COL_YELLOW);
            }
        }
        bitmap.Mirror(BmpMirrorFlags::Horizontal);
        {
            BitmapReadAccess read(bitmap);
            CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_BLACK), read.GetColor(010));
            CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_WHITE), read.GetColor(1010));
            CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_RED), read.GetColor(00));
            CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_BLUE), read.GetColor(100));
            CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_GREEN), read.GetColor(510));
            CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_YELLOW), read.GetColor(05));
        }
        bitmap.Mirror(BmpMirrorFlags::Vertical);
        {
            BitmapReadAccess read(bitmap);
            // Now is effectively mirrored in both directions.
            CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_BLACK), read.GetColor(1010));
            CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_WHITE), read.GetColor(010));
            CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_RED), read.GetColor(100));
            CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_BLUE), read.GetColor(00));
            CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_GREEN), read.GetColor(510));
            CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_YELLOW), read.GetColor(105));
        }
        bitmap.Mirror(BmpMirrorFlags::Vertical | BmpMirrorFlags::Horizontal);
        {
            BitmapReadAccess read(bitmap);
            // Now is back the original.
            CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_BLACK), read.GetColor(00));
            CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_WHITE), read.GetColor(100));
            CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_RED), read.GetColor(010));
            CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_BLUE), read.GetColor(1010));
            CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_GREEN), read.GetColor(50));
            CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_YELLOW), read.GetColor(05));
        }
    }
}

void BitmapTest::testCroppedDownsampledBitmap()
{
    Bitmap aBitmap(Size(1616), vcl::PixelFormat::N24_BPP);
    Bitmap aDownsampledBmp(vcl::bitmap::GetDownsampledBitmap(Size(1010), Point(2020),
                                                             Size(55), aBitmap, 7272));
    CPPUNIT_ASSERT(aDownsampledBmp.IsEmpty());
}

void BitmapTest::testCrop()
{
    Bitmap aBitmap(Bitmap(Size(1616), vcl::PixelFormat::N24_BPP));

    {
        Bitmap aCroppedBmp(aBitmap);
        CPPUNIT_ASSERT_MESSAGE("Crop was fully outside of bitmap bounds",
                               !aCroppedBmp.Crop(tools::Rectangle(Point(2020), Size(55))));
        CPPUNIT_ASSERT_EQUAL(Size(1616), aCroppedBmp.GetSizePixel());
    }

    {
        Bitmap aCroppedBmp(aBitmap);
        CPPUNIT_ASSERT_MESSAGE("Crop same size as bitmap",
                               !aCroppedBmp.Crop(tools::Rectangle(Point(00), Size(1616))));
        CPPUNIT_ASSERT_EQUAL(Size(1616), aCroppedBmp.GetSizePixel());
    }

    {
        Bitmap aCroppedBmp(aBitmap);
        CPPUNIT_ASSERT_MESSAGE("Crop larger than bitmap",
                               !aCroppedBmp.Crop(tools::Rectangle(Point(00), Size(100100))));
        CPPUNIT_ASSERT_EQUAL(Size(1616), aCroppedBmp.GetSizePixel());
    }

    {
        Bitmap aCroppedBmp(aBitmap);
        CPPUNIT_ASSERT_MESSAGE("Crop partially overcrops bitmap",
                               aCroppedBmp.Crop(tools::Rectangle(Point(1010), Size(100100))));
        CPPUNIT_ASSERT_EQUAL(Size(66), aCroppedBmp.GetSizePixel());
    }

    {
        Bitmap aCroppedBmp(aBitmap);
        CPPUNIT_ASSERT_MESSAGE("Crop inside bitmap",
                               aCroppedBmp.Crop(tools::Rectangle(Point(55), Size(1010))));
        CPPUNIT_ASSERT_EQUAL(Size(1010), aCroppedBmp.GetSizePixel());
    }
}
// namespace

CPPUNIT_TEST_SUITE_REGISTRATION(BitmapTest);

CPPUNIT_PLUGIN_IMPLEMENT();

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Messung V0.5 in Prozent
C=96 H=95 G=95

¤ Dauer der Verarbeitung: 0.15 Sekunden  (vorverarbeitet am  2026-06-10) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.