2010-10-14 08:27:31 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
re-base on ALv2 code. Includes (at least) relevant parts of:
linecap: Reintegrating finished LineCap feature
Patch contributed by Regina Henschel
http://svn.apache.org/viewvc?view=revision&revision=1232507
Patches contributed by Sven Jacobi
impress212: #i81610# fixed animation export
http://svn.apache.org/viewvc?view=revision&revision=1167620
impress212: drawinglayer gbuild environment changes
http://svn.apache.org/viewvc?view=revision&revision=1167627
http://svn.apache.org/viewvc?view=revision&revision=1167628
impress212: DffPropSet -> minor code improvements, removing table
http://svn.apache.org/viewvc?view=revision&revision=1167634
impress212: #158494# fixed excel import (text rotation)
http://svn.apache.org/viewvc?view=revision&revision=1167638
Patches contributed by Armin Le Grand
Svg: Reintegrated Svg replacement from /branches/alg/svgreplavement
http://svn.apache.org/viewvc?view=revision&revision=1220836
#118728# changed indentifying definitions for Svg file detection
http://svn.apache.org/viewvc?view=revision&revision=1229961
#118838# LineGeometry creation for complicated cases optimized to
create single Polygons
http://svn.apache.org/viewvc?view=revision&revision=1236232
#119176# corrected file type detection for SVG for svg files
without xml header
http://svn.apache.org/viewvc?view=revision&revision=1309445
#118728# Extended Svg file detection
http://svn.apache.org/viewvc?view=revision&revision=1230531
#118529# solve break converters and convert commands for OLEs and images
http://svn.apache.org/viewvc?view=revision&revision=1186168
svg: added WaE changes from branch svgreplacement to trunc
http://svn.apache.org/viewvc?view=revision&revision=1222974
svg: corrected missing member initialization
http://svn.apache.org/viewvc?view=revision&revision=1226134
fix for #118525#: Using primitives for chart sub-geometry visualisation
http://svn.apache.org/viewvc?view=revision&revision=1226879
#118898# Adapted ImpGraphic::ImplGetBitmap to correctly convert
metafiles to bitmapEx ...
http://svn.apache.org/viewvc?view=revision&revision=1293316
fix for #118525#: removed no longer used variable maOriginalMapMode, one
more exception eliminated
http://svn.apache.org/viewvc?view=revision&revision=1227097
#16758# Added buffering to the VDev usages of the VclProcessor2D derivates...
http://svn.apache.org/viewvc?view=revision&revision=1229521
#116758# Secured VDev buffer device to Vcl deinit
http://svn.apache.org/viewvc?view=revision&revision=1230574
#116758# added remembering allocated VDevs for VDevBuffer to be able to also
delete these when vcl goes down; it should never happen, but You never know
http://svn.apache.org/viewvc?view=revision&revision=1230927
#118730# Changed SvgClipPathNode to use MaskPrimitive2D for primitive
representation instead of TransparencePrimitive2D
http://svn.apache.org/viewvc?view=revision&revision=1231198
#118822# secured 3D geometry creation (slices) by subdividing the 2D
source polyPolygon early
http://svn.apache.org/viewvc?view=revision&revision=1234749
#118829# enhanced Svg gradient quality, obstacles avoided
http://svn.apache.org/viewvc?view=revision&revision=1235361
#118834# Unified usage of TextBreakupHelper as single tooling class
for i18n text primitive breakup
http://svn.apache.org/viewvc?view=revision&revision=1236110
#118853# added square pixel size limit to conversion of
TransparencePrimitive2D to Metafile action
http://svn.apache.org/viewvc?view=revision&revision=1237656
#118824# coreccted mirroring and boundrect when the graphicmanager
is used for bitmap output
http://svn.apache.org/viewvc?view=revision&revision=1240097
#115092# Corrected VclProcessor2D::RenderPolygonStrokePrimitive2D for
various optimization scenarios
http://svn.apache.org/viewvc?view=revision&revision=1241434
#118783# Corrected errors in ID strings, corrected Svg line/fill export,
corrected polygon close state
http://svn.apache.org/viewvc?view=revision&revision=1232006
#118796# corrected null-pointer usage in SVG text exporter
http://svn.apache.org/viewvc?view=revision&revision=1240262
#118729# Use GraphicStreamUrl and GraphicUrl to allow multi image
import with linked graphics, too
http://svn.apache.org/viewvc?view=revision&revision=1229962
#118898# corrected error in GDIMetaFile::GetBoundRect in handling
MetaFloatTransparentAction
http://svn.apache.org/viewvc?view=revision&revision=1293349
#118855# Corrected handling of possibly created empty clipRegions
after PolyPolygon clipping
http://svn.apache.org/viewvc?view=revision&revision=1237725
#115962# Better (but not yet optimal, see comments in task) handling
of MetaFloatTransparentAction in PDF export
http://svn.apache.org/viewvc?view=revision&revision=1241078
IP clearance: #118466# This patch removes librsvg, libcroco, libgsf, ...
http://svn.apache.org/viewvc?view=revision&revision=1200879
118779# Added svg content streaming in/out to ImpGraphic stream operators
http://svn.apache.org/viewvc?view=revision&revision=1231908
linecap: correctons for WaE and mac drawing
http://svn.apache.org/viewvc?view=revision&revision=1232793
svg: uses current system Dpi for Svg replacement image creation
http://svn.apache.org/viewvc?view=revision&revision=1233948
Patches contributed by Mathias Bauer (and others)
gnumake4 work variously
http://svn.apache.org/viewvc?view=revision&revision=1394326
http://svn.apache.org/viewvc?view=revision&revision=1396797
http://svn.apache.org/viewvc?view=revision&revision=1397315
http://svn.apache.org/viewvc?view=revision&revision=1394326
Remove duplicate header includes.
cws mba34issues01: #i117720#: convert assertion into warning
http://svn.apache.org/viewvc?view=revision&revision=1172352
118485 - Styles for OLEs are not saved. Submitted by Armin Le Grand.
http://svn.apache.org/viewvc?view=revision&revision=1182166
cws mba34issues01: #i117714#: remove assertion
http://svn.apache.org/viewvc?view=revision&revision=1172357
Patch contributed by Jurgen Schmidt
add some additional checks to ensure proper reading operations
http://svn.apache.org/viewvc?view=revision&revision=1209022
mostly prefer our stream / bounds checking work.
Patches contributed by Herbert Duerr
#i118816# add clarifying comment regarding Font::*Color*() methods
http://svn.apache.org/viewvc?view=revision&revision=1233833
extend macro->string handling for empty strings
http://svn.apache.org/viewvc?view=revision&revision=1175801
avoid magic constants for SALCOLOR_NONE
http://svn.apache.org/viewvc?view=revision&revision=1177543
initialize slant properly in ImplFontMetricData constructor (author=iorsh)
http://svn.apache.org/viewvc?view=revision&revision=1177551
#i118675# make check for extension updates more stable
http://svn.apache.org/viewvc?view=revision&revision=1214797
#a118617# remove VBasicEventListener.dll binary
There are no known users depending on its CLSID
http://svn.apache.org/viewvc?view=revision&revision=1203697
Patches contributed by Ariel Constenla-Haile
Fix build breaker on Linux/gcc
http://svn.apache.org/viewvc?view=revision&revision=1221104
Fix crash when trying to instantiate css.graphic.GraphicRasterizer_RSVG
http://svn.apache.org/viewvc?view=revision&revision=1215559
Patches contributed by Oliver-Rainer Wittmann
sw34bf06: #i117962# - method <SwFlyFrm::IsPaint(..)> - consider
instances of <SwFlyDrawObj>
http://svn.apache.org/viewvc?view=revision&revision=1172120
sw34bf06: #i117783# - Writer's implementation of XPagePrintable -
apply print settings to new printing routines
http://svn.apache.org/viewvc?view=revision&revision=1172115
gnumake4 work variously from Hans-Joachim Lankenau
http://svn.apache.org/viewvc?view=revision&revision=1397315
http://svn.apache.org/viewvc?view=revision&revision=1396797
http://svn.apache.org/viewvc?view=revision&revision=1396782
http://svn.apache.org/viewvc?view=revision&revision=1394707
plus some amount of re-splitting of legacy headers.
Patch contributed by Pavel Janik
WaE: Remove unused variables.
http://svn.apache.org/viewvc?view=revision&revision=1230697
Patches contributed by Takashi Ono
mingwport35: i#117795: MinGW port fix for vcl2gnumake
http://svn.apache.org/viewvc?view=revision&revision=1172091
mingwport35: i#117795: MinGW port fix for vcl2gnumake
http://svn.apache.org/viewvc?view=revision&revision=1172091
Patch contributed by Christian Lippka
impress212: #i98044# re enable Text menu for outline and title shapes
http://svn.apache.org/viewvc?view=revision&revision=1167639
Patch contributed by Andre Fischer
118674: Made category B code optional and disabled by default.
http://svn.apache.org/viewvc?view=revision&revision=1215131
118881: Ignore empty paragraphs after bullets.
http://svn.apache.org/viewvc?view=revision&revision=1296205
Patches contributed by Philipp Lohmann
ooo340fixes: #i117780# use rtl allocator
http://svn.apache.org/viewvc?view=revision&revision=1172087
ooo34gsl02: #i117807# fix an off by one error (index actually
inside the pfb section header)
http://svn.apache.org/viewvc?view=revision&revision=1167576
various cleanups, related compilation fixes, warning cleanups, re-working
of obsolete stl template pieces to use boost instead, changed string
classes, re-adapt KDE about data, about dialog, fixing warnings,
and other fixes & improvements.
Disable svg import / render for about/ branding code-paths for now.
Restore full icon theme set.
Remove OS/2 conditionals and sources.
Remove conflicting gtk/full-screen monitors support.
Retain existing svg rasterizer files - temporarily disabled.
Standardize stringificaiton and fixup dllpostfix issues.
Rename SvgGradientHelper::== to equalTo to avoid overloading issues.
Use the flat GdiPlus API for LineCaps calls.
2012-10-09 12:22:23 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2008-06-24 10:42:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
// bootstrap stuff
|
2013-10-09 20:02:19 +02:00
|
|
|
#include <test/bootstrapfixture.hxx>
|
|
|
|
|
2008-06-24 10:42:00 +00:00
|
|
|
#include <com/sun/star/util/Endianness.hpp>
|
|
|
|
#include <com/sun/star/rendering/ColorComponentTag.hpp>
|
|
|
|
#include <com/sun/star/rendering/ColorSpaceType.hpp>
|
|
|
|
#include <com/sun/star/rendering/RenderingIntent.hpp>
|
|
|
|
#include <com/sun/star/rendering/XIntegerReadOnlyBitmap.hpp>
|
|
|
|
#include <com/sun/star/rendering/XIntegerBitmapColorSpace.hpp>
|
|
|
|
#include <com/sun/star/rendering/XBitmapPalette.hpp>
|
|
|
|
|
|
|
|
#include <cppuhelper/compbase3.hxx>
|
|
|
|
#include <tools/diagnose_ex.h>
|
2013-10-09 20:02:19 +02:00
|
|
|
#include <rtl/ref.hxx>
|
2008-06-24 10:42:00 +00:00
|
|
|
|
|
|
|
#include "vcl/svapp.hxx"
|
|
|
|
#include "vcl/canvastools.hxx"
|
|
|
|
#include "vcl/dialog.hxx"
|
|
|
|
#include "vcl/outdev.hxx"
|
|
|
|
#include "vcl/bmpacc.hxx"
|
|
|
|
#include "vcl/virdev.hxx"
|
|
|
|
#include "vcl/bitmapex.hxx"
|
|
|
|
|
2013-10-09 20:02:19 +02:00
|
|
|
#include "canvasbitmap.hxx"
|
2008-06-24 10:42:00 +00:00
|
|
|
|
|
|
|
using namespace ::com::sun::star;
|
|
|
|
using namespace ::vcl::unotools;
|
|
|
|
|
2008-12-09 13:22:21 +00:00
|
|
|
|
2008-06-24 10:42:00 +00:00
|
|
|
namespace com { namespace sun { namespace star { namespace rendering
|
|
|
|
{
|
|
|
|
|
|
|
|
bool operator==( const RGBColor& rLHS, const ARGBColor& rRHS )
|
|
|
|
{
|
|
|
|
return rLHS.Red == rRHS.Red && rLHS.Green == rRHS.Green && rLHS.Blue == rRHS.Blue;
|
|
|
|
}
|
|
|
|
bool operator==( const ARGBColor& rLHS, const RGBColor& rRHS )
|
|
|
|
{
|
|
|
|
return rLHS.Red == rRHS.Red && rLHS.Green == rRHS.Green && rLHS.Blue == rRHS.Blue;
|
|
|
|
}
|
|
|
|
|
|
|
|
} } } }
|
|
|
|
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2013-10-09 20:02:19 +02:00
|
|
|
class CanvasBitmapTest : public test::BootstrapFixture
|
2008-06-24 10:42:00 +00:00
|
|
|
{
|
|
|
|
public:
|
2013-10-09 20:02:19 +02:00
|
|
|
CanvasBitmapTest() : BootstrapFixture(true, false) {}
|
2008-06-24 10:42:00 +00:00
|
|
|
|
2013-10-09 20:02:19 +02:00
|
|
|
void runTest();
|
2008-06-24 10:42:00 +00:00
|
|
|
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_TEST_SUITE(CanvasBitmapTest);
|
|
|
|
CPPUNIT_TEST(runTest);
|
|
|
|
CPPUNIT_TEST_SUITE_END();
|
2008-06-24 10:42:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
bool rangeCheck( const rendering::RGBColor& rColor )
|
|
|
|
{
|
|
|
|
return rColor.Red < 0.0 || rColor.Red > 1.0 ||
|
|
|
|
rColor.Green < 0.0 || rColor.Green > 1.0 ||
|
|
|
|
rColor.Blue < 0.0 || rColor.Blue > 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void checkCanvasBitmap( const rtl::Reference<VclCanvasBitmap>& xBmp,
|
|
|
|
const char* msg,
|
|
|
|
int nOriginalDepth )
|
|
|
|
{
|
|
|
|
OSL_TRACE("-------------------------");
|
|
|
|
OSL_TRACE("Testing %s, with depth %d", msg, nOriginalDepth);
|
|
|
|
|
|
|
|
BitmapEx aContainedBmpEx( xBmp->getBitmapEx() );
|
|
|
|
Bitmap aContainedBmp( aContainedBmpEx.GetBitmap() );
|
|
|
|
int nDepth = nOriginalDepth;
|
|
|
|
|
|
|
|
{
|
2011-05-17 10:03:46 +02:00
|
|
|
Bitmap::ScopedReadAccess pAcc( aContainedBmp );
|
2008-06-24 10:42:00 +00:00
|
|
|
nDepth = pAcc->GetBitCount();
|
|
|
|
}
|
|
|
|
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Original bitmap size not (200,200)",
|
|
|
|
aContainedBmp.GetSizePixel() == Size(200,200));
|
2008-06-24 10:42:00 +00:00
|
|
|
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Original bitmap size via API not (200,200)",
|
|
|
|
xBmp->getSize().Width == 200 && xBmp->getSize().Height == 200);
|
2008-06-24 10:42:00 +00:00
|
|
|
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE( "alpha state mismatch",
|
2014-02-21 12:53:51 +01:00
|
|
|
bool(xBmp->hasAlpha()) == aContainedBmpEx.IsTransparent());
|
2008-06-24 10:42:00 +00:00
|
|
|
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE( "getScaledBitmap() failed",
|
|
|
|
xBmp->getScaledBitmap( geometry::RealSize2D(500,500), sal_False ).is());
|
2008-06-24 10:42:00 +00:00
|
|
|
|
|
|
|
rendering::IntegerBitmapLayout aLayout;
|
|
|
|
uno::Sequence<sal_Int8> aPixelData = xBmp->getData(aLayout, geometry::IntegerRectangle2D(0,0,1,1));
|
|
|
|
|
|
|
|
const sal_Int32 nExpectedBitsPerPixel(
|
|
|
|
aContainedBmpEx.IsTransparent() ? std::max(8,nDepth)+8 : nDepth);
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE( "# scanlines not 1",
|
|
|
|
aLayout.ScanLines == 1);
|
|
|
|
CPPUNIT_ASSERT_MESSAGE( "# scanline bytes mismatch",
|
|
|
|
aLayout.ScanLineBytes == (nExpectedBitsPerPixel+7)/8);
|
|
|
|
CPPUNIT_ASSERT_MESSAGE( "# scanline stride mismatch",
|
|
|
|
aLayout.ScanLineStride == (nExpectedBitsPerPixel+7)/8 ||
|
|
|
|
aLayout.ScanLineStride == -(nExpectedBitsPerPixel+7)/8);
|
|
|
|
CPPUNIT_ASSERT_MESSAGE( "# plane stride not 0",
|
|
|
|
aLayout.PlaneStride == 0);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Color space not there",
|
|
|
|
aLayout.ColorSpace.is());
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Palette existance does not conform to bitmap",
|
|
|
|
aLayout.Palette.is() == (nDepth <= 8));
|
2008-06-24 10:42:00 +00:00
|
|
|
|
|
|
|
uno::Sequence<sal_Int8> aPixelData2 = xBmp->getPixel( aLayout, geometry::IntegerPoint2D(0,0) );
|
|
|
|
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE( "getData and getPixel did not return same amount of data",
|
|
|
|
aPixelData2.getLength() == aPixelData.getLength());
|
2008-06-24 10:42:00 +00:00
|
|
|
|
|
|
|
aPixelData = xBmp->getData(aLayout, geometry::IntegerRectangle2D(0,0,200,1));
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE( "# scanlines not 1 for getPixel",
|
|
|
|
aLayout.ScanLines == 1);
|
|
|
|
CPPUNIT_ASSERT_MESSAGE( "# scanline bytes mismatch for getPixel",
|
|
|
|
aLayout.ScanLineBytes == (200*nExpectedBitsPerPixel+7)/8);
|
|
|
|
CPPUNIT_ASSERT_MESSAGE( "# scanline stride mismatch for getPixel",
|
|
|
|
aLayout.ScanLineStride == (200*nExpectedBitsPerPixel+7)/8 ||
|
|
|
|
aLayout.ScanLineStride == -(200*nExpectedBitsPerPixel+7)/8);
|
2008-06-24 10:42:00 +00:00
|
|
|
|
|
|
|
uno::Sequence< rendering::RGBColor > aRGBColors = xBmp->convertIntegerToRGB( aPixelData );
|
|
|
|
uno::Sequence< rendering::ARGBColor > aARGBColors = xBmp->convertIntegerToARGB( aPixelData );
|
|
|
|
|
|
|
|
const rendering::RGBColor* pRGBStart ( aRGBColors.getConstArray() );
|
|
|
|
const rendering::RGBColor* pRGBEnd ( aRGBColors.getConstArray()+aRGBColors.getLength() );
|
|
|
|
const rendering::ARGBColor* pARGBStart( aARGBColors.getConstArray() );
|
|
|
|
std::pair<const rendering::RGBColor*,
|
|
|
|
const rendering::ARGBColor*> aRes = std::mismatch( pRGBStart, pRGBEnd, pARGBStart );
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE( "argb and rgb colors are not equal",
|
|
|
|
aRes.first == pRGBEnd);
|
2008-06-24 10:42:00 +00:00
|
|
|
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE( "rgb colors are not within [0,1] range",
|
|
|
|
std::find_if(pRGBStart,pRGBEnd,&rangeCheck) == pRGBEnd);
|
2008-06-24 10:42:00 +00:00
|
|
|
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE( "First pixel is not white",
|
|
|
|
pRGBStart[0].Red == 1.0 && pRGBStart[0].Green == 1.0 && pRGBStart[0].Blue == 1.0);
|
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Second pixel is not opaque",
|
|
|
|
pARGBStart[1].Alpha == 1.0);
|
2008-06-24 10:42:00 +00:00
|
|
|
if( aContainedBmpEx.IsTransparent() )
|
|
|
|
{
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE( "First pixel is not fully transparent",
|
|
|
|
pARGBStart[0].Alpha == 0.0);
|
2008-06-24 10:42:00 +00:00
|
|
|
}
|
|
|
|
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Second pixel is not black",
|
|
|
|
pRGBStart[1].Red == 0.0 && pRGBStart[1].Green == 0.0 && pRGBStart[1].Blue == 0.0);
|
2008-06-24 10:42:00 +00:00
|
|
|
|
|
|
|
if( nOriginalDepth > 8 )
|
|
|
|
{
|
|
|
|
const Color aCol(COL_GREEN);
|
2013-10-16 14:43:18 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE(
|
|
|
|
"Sixth pixel is not green (red component)",
|
|
|
|
vcl::unotools::toDoubleColor(aCol.GetRed()), pRGBStart[5].Red);
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE(
|
|
|
|
"Sixth pixel is not green (green component)",
|
|
|
|
vcl::unotools::toDoubleColor(aCol.GetGreen()), pRGBStart[5].Green);
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE(
|
|
|
|
"Sixth pixel is not green (blue component)",
|
|
|
|
vcl::unotools::toDoubleColor(aCol.GetBlue()), pRGBStart[5].Blue);
|
2008-06-24 10:42:00 +00:00
|
|
|
}
|
|
|
|
else if( nDepth <= 8 )
|
|
|
|
{
|
|
|
|
uno::Reference<rendering::XBitmapPalette> xPal = xBmp->getPalette();
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE( "8bit or less: missing palette",
|
|
|
|
xPal.is());
|
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Palette incorrect entry count",
|
|
|
|
xPal->getNumberOfEntries() == 1L << nOriginalDepth);
|
2008-06-24 10:42:00 +00:00
|
|
|
uno::Sequence<double> aIndex;
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Palette is not read-only",
|
|
|
|
xPal->setIndex(aIndex,sal_True,0) == sal_False);
|
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Palette entry 0 is not opaque",
|
|
|
|
xPal->getIndex(aIndex,0));
|
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Palette has no valid color space",
|
|
|
|
xPal->getColorSpace().is());
|
2008-06-24 10:42:00 +00:00
|
|
|
}
|
|
|
|
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE( "150th pixel is not white",
|
|
|
|
pRGBStart[150].Red == 1.0 &&
|
|
|
|
pRGBStart[150].Green == 1.0 &&
|
|
|
|
pRGBStart[150].Blue == 1.0);
|
2008-06-24 10:42:00 +00:00
|
|
|
|
|
|
|
if( nOriginalDepth > 8 )
|
|
|
|
{
|
2008-12-09 13:22:21 +00:00
|
|
|
uno::Sequence<rendering::ARGBColor> aARGBColor(1);
|
|
|
|
uno::Sequence<rendering::RGBColor> aRGBColor(1);
|
2008-06-24 10:42:00 +00:00
|
|
|
uno::Sequence<sal_Int8> aPixel3, aPixel4;
|
|
|
|
|
|
|
|
const Color aCol(COL_GREEN);
|
2008-12-09 13:22:21 +00:00
|
|
|
aARGBColor[0].Red = vcl::unotools::toDoubleColor(aCol.GetRed());
|
|
|
|
aARGBColor[0].Green = vcl::unotools::toDoubleColor(aCol.GetGreen());
|
|
|
|
aARGBColor[0].Blue = vcl::unotools::toDoubleColor(aCol.GetBlue());
|
|
|
|
aARGBColor[0].Alpha = 1.0;
|
2008-06-24 10:42:00 +00:00
|
|
|
|
2008-12-09 13:22:21 +00:00
|
|
|
aRGBColor[0].Red = vcl::unotools::toDoubleColor(aCol.GetRed());
|
|
|
|
aRGBColor[0].Green = vcl::unotools::toDoubleColor(aCol.GetGreen());
|
|
|
|
aRGBColor[0].Blue = vcl::unotools::toDoubleColor(aCol.GetBlue());
|
2008-06-24 10:42:00 +00:00
|
|
|
|
2008-12-09 13:22:21 +00:00
|
|
|
aPixel3 = xBmp->convertIntegerFromARGB( aARGBColor );
|
2008-06-24 10:42:00 +00:00
|
|
|
aPixel4 = xBmp->getPixel( aLayout, geometry::IntegerPoint2D(5,0) );
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Green pixel from bitmap mismatch with manually converted green pixel",
|
|
|
|
aPixel3 == aPixel4);
|
2008-06-24 10:42:00 +00:00
|
|
|
|
|
|
|
if( !aContainedBmpEx.IsTransparent() )
|
|
|
|
{
|
2008-12-09 13:22:21 +00:00
|
|
|
aPixel3 = xBmp->convertIntegerFromRGB( aRGBColor );
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Green pixel from bitmap mismatch with manually RGB-converted green pixel",
|
|
|
|
aPixel3 == aPixel4);
|
2008-06-24 10:42:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class TestBitmap : public cppu::WeakImplHelper3< rendering::XIntegerReadOnlyBitmap,
|
|
|
|
rendering::XBitmapPalette,
|
|
|
|
rendering::XIntegerBitmapColorSpace >
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
geometry::IntegerSize2D maSize;
|
|
|
|
uno::Sequence<sal_Int8> maComponentTags;
|
|
|
|
uno::Sequence<sal_Int32> maComponentBitCounts;
|
|
|
|
rendering::IntegerBitmapLayout maLayout;
|
|
|
|
const sal_Int32 mnBitsPerPixel;
|
|
|
|
|
|
|
|
// XBitmap
|
|
|
|
virtual geometry::IntegerSize2D SAL_CALL getSize() throw (uno::RuntimeException) { return maSize; }
|
|
|
|
virtual ::sal_Bool SAL_CALL hasAlpha( ) throw (uno::RuntimeException) { return mnBitsPerPixel != 8; }
|
|
|
|
virtual uno::Reference< rendering::XBitmap > SAL_CALL getScaledBitmap( const geometry::RealSize2D&,
|
|
|
|
sal_Bool ) throw (uno::RuntimeException) { return this; }
|
|
|
|
|
|
|
|
// XIntegerReadOnlyBitmap
|
|
|
|
virtual uno::Sequence< ::sal_Int8 > SAL_CALL getData( rendering::IntegerBitmapLayout& bitmapLayout,
|
2014-02-09 21:01:06 +00:00
|
|
|
const geometry::IntegerRectangle2D& rect )
|
|
|
|
throw (lang::IndexOutOfBoundsException,
|
|
|
|
rendering::VolatileContentDestroyedException,
|
|
|
|
uno::RuntimeException,
|
|
|
|
std::exception)
|
2008-06-24 10:42:00 +00:00
|
|
|
{
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE( "X1 out of bounds", rect.X1 >= 0 );
|
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Y1 out of bounds", rect.Y1 >= 0 );
|
|
|
|
CPPUNIT_ASSERT_MESSAGE( "X2 out of bounds", rect.X2 <= maSize.Width );
|
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Y2 out of bounds", rect.Y2 <= maSize.Height );
|
2008-06-24 10:42:00 +00:00
|
|
|
|
|
|
|
bitmapLayout = getMemoryLayout();
|
|
|
|
|
|
|
|
const sal_Int32 nWidth = rect.X2-rect.X1;
|
|
|
|
const sal_Int32 nHeight = rect.Y2-rect.Y1;
|
|
|
|
const sal_Int32 nScanlineLen = (nWidth * mnBitsPerPixel + 7)/8;
|
|
|
|
uno::Sequence<sal_Int8> aRes( nScanlineLen * nHeight );
|
|
|
|
sal_Int8* pOut = aRes.getArray();
|
|
|
|
|
|
|
|
bitmapLayout.ScanLines = nHeight;
|
|
|
|
bitmapLayout.ScanLineBytes =
|
|
|
|
bitmapLayout.ScanLineStride= nScanlineLen;
|
|
|
|
|
|
|
|
if( mnBitsPerPixel == 8 )
|
|
|
|
{
|
|
|
|
for( sal_Int32 y=0; y<nHeight; ++y )
|
|
|
|
{
|
|
|
|
for( sal_Int32 x=0; x<nWidth; ++x )
|
|
|
|
pOut[ y*nScanlineLen + x ] = sal_Int8(x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( sal_Int32 y=0; y<nHeight; ++y )
|
|
|
|
{
|
|
|
|
for( sal_Int32 x=0; x<nWidth; ++x )
|
|
|
|
{
|
|
|
|
pOut[ y*nScanlineLen + 4*x ] = sal_Int8(rect.X1);
|
|
|
|
pOut[ y*nScanlineLen + 4*x + 1 ] = sal_Int8(rect.Y2);
|
|
|
|
pOut[ y*nScanlineLen + 4*x + 2 ] = sal_Int8(x);
|
|
|
|
pOut[ y*nScanlineLen + 4*x + 3 ] = sal_Int8(rect.Y1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return aRes;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual uno::Sequence< ::sal_Int8 > SAL_CALL getPixel( rendering::IntegerBitmapLayout&,
|
2014-02-10 10:05:51 +00:00
|
|
|
const geometry::IntegerPoint2D& )
|
|
|
|
throw (lang::IndexOutOfBoundsException,
|
|
|
|
rendering::VolatileContentDestroyedException,
|
|
|
|
uno::RuntimeException,
|
|
|
|
std::exception)
|
2008-06-24 10:42:00 +00:00
|
|
|
{
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE("getPixel: method not implemented", false);
|
2008-06-24 10:42:00 +00:00
|
|
|
return uno::Sequence< sal_Int8 >();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual uno::Reference< rendering::XBitmapPalette > SAL_CALL getPalette( ) throw (uno::RuntimeException)
|
|
|
|
{
|
|
|
|
uno::Reference< XBitmapPalette > aRet;
|
|
|
|
if( mnBitsPerPixel == 8 )
|
|
|
|
aRet.set(this);
|
|
|
|
return aRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual rendering::IntegerBitmapLayout SAL_CALL getMemoryLayout( ) throw (uno::RuntimeException)
|
|
|
|
{
|
|
|
|
rendering::IntegerBitmapLayout aLayout( maLayout );
|
|
|
|
|
|
|
|
const sal_Int32 nScanlineLen = (maSize.Width * mnBitsPerPixel + 7)/8;
|
|
|
|
|
|
|
|
aLayout.ScanLines = maSize.Height;
|
|
|
|
aLayout.ScanLineBytes =
|
|
|
|
aLayout.ScanLineStride= nScanlineLen;
|
|
|
|
aLayout.Palette = getPalette();
|
|
|
|
aLayout.ColorSpace.set( this );
|
|
|
|
|
|
|
|
return aLayout;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XBitmapPalette
|
|
|
|
virtual sal_Int32 SAL_CALL getNumberOfEntries() throw (uno::RuntimeException)
|
|
|
|
{
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Got palette getNumberOfEntries interface call without handing out palette",
|
|
|
|
getPalette().is() );
|
2008-06-24 10:42:00 +00:00
|
|
|
|
|
|
|
return 255;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ::sal_Bool SAL_CALL getIndex( uno::Sequence< double >& entry,
|
2014-02-10 10:06:32 +00:00
|
|
|
::sal_Int32 nIndex )
|
|
|
|
throw (lang::IndexOutOfBoundsException,
|
|
|
|
uno::RuntimeException,
|
|
|
|
std::exception)
|
2008-06-24 10:42:00 +00:00
|
|
|
{
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Got palette getIndex interface call without handing out palette",
|
|
|
|
getPalette().is() );
|
|
|
|
CPPUNIT_ASSERT_MESSAGE( "getIndex: index out of range",
|
|
|
|
nIndex >= 0 && nIndex < 256 );
|
2008-06-24 10:42:00 +00:00
|
|
|
entry = colorToStdColorSpaceSequence(
|
2013-10-09 20:02:19 +02:00
|
|
|
Color(sal_uInt8(nIndex),
|
|
|
|
sal_uInt8(nIndex),
|
|
|
|
sal_uInt8(nIndex)) );
|
2008-06-24 10:42:00 +00:00
|
|
|
|
|
|
|
return sal_True; // no palette transparency here.
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ::sal_Bool SAL_CALL setIndex( const uno::Sequence< double >&,
|
|
|
|
::sal_Bool,
|
|
|
|
::sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException,
|
|
|
|
lang::IllegalArgumentException,
|
2014-02-09 20:57:03 +00:00
|
|
|
uno::RuntimeException,
|
|
|
|
std::exception)
|
2008-06-24 10:42:00 +00:00
|
|
|
{
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Got palette setIndex interface call without handing out palette",
|
|
|
|
getPalette().is());
|
|
|
|
CPPUNIT_ASSERT_MESSAGE( "setIndex: index out of range",
|
|
|
|
nIndex >= 0 && nIndex < 256);
|
2008-06-24 10:42:00 +00:00
|
|
|
return sal_False;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct PaletteColorSpaceHolder: public rtl::StaticWithInit<uno::Reference<rendering::XColorSpace>,
|
|
|
|
PaletteColorSpaceHolder>
|
|
|
|
{
|
|
|
|
uno::Reference<rendering::XColorSpace> operator()()
|
|
|
|
{
|
|
|
|
return vcl::unotools::createStandardColorSpace();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
virtual uno::Reference< rendering::XColorSpace > SAL_CALL getColorSpace( ) throw (uno::RuntimeException)
|
|
|
|
{
|
|
|
|
// this is the method from XBitmapPalette. Return palette color
|
|
|
|
// space here
|
|
|
|
return PaletteColorSpaceHolder::get();
|
|
|
|
}
|
|
|
|
|
|
|
|
// XIntegerBitmapColorSpace
|
|
|
|
virtual ::sal_Int8 SAL_CALL getType( ) throw (uno::RuntimeException)
|
|
|
|
{
|
|
|
|
return rendering::ColorSpaceType::RGB;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual uno::Sequence< sal_Int8 > SAL_CALL getComponentTags( ) throw (uno::RuntimeException)
|
|
|
|
{
|
|
|
|
return maComponentTags;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ::sal_Int8 SAL_CALL getRenderingIntent( ) throw (uno::RuntimeException)
|
|
|
|
{
|
|
|
|
return rendering::RenderingIntent::PERCEPTUAL;
|
|
|
|
}
|
|
|
|
|
2014-02-10 10:11:39 +00:00
|
|
|
virtual uno::Sequence< beans::PropertyValue > SAL_CALL getProperties()
|
|
|
|
throw (uno::RuntimeException,
|
|
|
|
std::exception)
|
2008-06-24 10:42:00 +00:00
|
|
|
{
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE("getProperties: method not implemented", false );
|
2008-06-24 10:42:00 +00:00
|
|
|
return uno::Sequence< ::beans::PropertyValue >();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual uno::Sequence< double > SAL_CALL convertColorSpace( const uno::Sequence< double >&,
|
2014-02-10 10:08:33 +00:00
|
|
|
const uno::Reference< rendering::XColorSpace >& )
|
|
|
|
throw (uno::RuntimeException,
|
|
|
|
std::exception)
|
2008-06-24 10:42:00 +00:00
|
|
|
{
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE("convertColorSpace: method not implemented", false);
|
2008-06-24 10:42:00 +00:00
|
|
|
return uno::Sequence< double >();
|
|
|
|
}
|
|
|
|
|
2014-02-10 10:12:43 +00:00
|
|
|
virtual uno::Sequence< rendering::RGBColor > SAL_CALL convertToRGB( const uno::Sequence< double >& )
|
|
|
|
throw (lang::IllegalArgumentException,
|
|
|
|
uno::RuntimeException,
|
|
|
|
std::exception)
|
2008-06-24 10:42:00 +00:00
|
|
|
{
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE("convertToRGB: method not implemented", false);
|
2008-06-24 10:42:00 +00:00
|
|
|
return uno::Sequence< rendering::RGBColor >();
|
|
|
|
}
|
|
|
|
|
2014-02-10 10:12:13 +00:00
|
|
|
virtual uno::Sequence< rendering::ARGBColor > SAL_CALL convertToARGB( const uno::Sequence< double >& )
|
|
|
|
throw (lang::IllegalArgumentException,
|
|
|
|
uno::RuntimeException,
|
|
|
|
std::exception)
|
2008-06-24 10:42:00 +00:00
|
|
|
{
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE("convertToARGB: method not implemented", false);
|
2008-06-24 10:42:00 +00:00
|
|
|
return uno::Sequence< rendering::ARGBColor >();
|
|
|
|
}
|
|
|
|
|
2014-02-10 10:10:33 +00:00
|
|
|
virtual uno::Sequence< rendering::ARGBColor > SAL_CALL convertToPARGB( const uno::Sequence< double >& )
|
|
|
|
throw (lang::IllegalArgumentException,
|
|
|
|
uno::RuntimeException,
|
|
|
|
std::exception)
|
2008-12-09 13:22:21 +00:00
|
|
|
{
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE("convertToPARGB: method not implemented", false);
|
2008-12-09 13:22:21 +00:00
|
|
|
return uno::Sequence< rendering::ARGBColor >();
|
|
|
|
}
|
|
|
|
|
2014-02-10 10:11:08 +00:00
|
|
|
virtual uno::Sequence< double > SAL_CALL convertFromRGB( const uno::Sequence< rendering::RGBColor >& )
|
|
|
|
throw (lang::IllegalArgumentException,
|
|
|
|
uno::RuntimeException,
|
|
|
|
std::exception)
|
2008-06-24 10:42:00 +00:00
|
|
|
{
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE("convertFromRGB: method not implemented", false);
|
2008-06-24 10:42:00 +00:00
|
|
|
return uno::Sequence< double >();
|
|
|
|
}
|
|
|
|
|
2014-02-10 10:09:52 +00:00
|
|
|
virtual uno::Sequence< double > SAL_CALL convertFromARGB( const uno::Sequence< rendering::ARGBColor >& )
|
|
|
|
throw (lang::IllegalArgumentException,
|
|
|
|
uno::RuntimeException,
|
|
|
|
std::exception)
|
2008-06-24 10:42:00 +00:00
|
|
|
{
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE("convertFromARGB: this method is not expected to be called!", false);
|
2008-06-24 10:42:00 +00:00
|
|
|
return uno::Sequence< double >();
|
|
|
|
}
|
|
|
|
|
2014-02-10 10:09:15 +00:00
|
|
|
virtual uno::Sequence< double > SAL_CALL convertFromPARGB( const uno::Sequence< rendering::ARGBColor >& )
|
|
|
|
throw (lang::IllegalArgumentException,
|
|
|
|
uno::RuntimeException,
|
|
|
|
std::exception)
|
2008-12-09 13:22:21 +00:00
|
|
|
{
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE("convertFromPARGB: this method is not expected to be called!", false);
|
2008-12-09 13:22:21 +00:00
|
|
|
return uno::Sequence< double >();
|
|
|
|
}
|
|
|
|
|
2008-06-24 10:42:00 +00:00
|
|
|
virtual ::sal_Int32 SAL_CALL getBitsPerPixel( ) throw (uno::RuntimeException)
|
|
|
|
{
|
|
|
|
return mnBitsPerPixel;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual uno::Sequence< ::sal_Int32 > SAL_CALL getComponentBitCounts( ) throw (uno::RuntimeException)
|
|
|
|
{
|
|
|
|
return maComponentBitCounts;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ::sal_Int8 SAL_CALL getEndianness( ) throw (uno::RuntimeException)
|
|
|
|
{
|
|
|
|
return util::Endianness::LITTLE;
|
|
|
|
}
|
|
|
|
|
2008-12-09 13:22:21 +00:00
|
|
|
virtual uno::Sequence< double > SAL_CALL convertFromIntegerColorSpace( const uno::Sequence< ::sal_Int8 >& ,
|
2014-02-09 21:02:11 +00:00
|
|
|
const uno::Reference< rendering::XColorSpace >& )
|
|
|
|
throw (lang::IllegalArgumentException,
|
|
|
|
uno::RuntimeException,
|
|
|
|
std::exception)
|
2008-12-09 13:22:21 +00:00
|
|
|
{
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE("convertFromIntegerColorSpace: method not implemented", false);
|
2008-12-09 13:22:21 +00:00
|
|
|
return uno::Sequence< double >();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual uno::Sequence< ::sal_Int8 > SAL_CALL convertToIntegerColorSpace( const uno::Sequence< ::sal_Int8 >& ,
|
2014-02-09 21:02:56 +00:00
|
|
|
const uno::Reference< rendering::XIntegerBitmapColorSpace >& )
|
|
|
|
throw (lang::IllegalArgumentException,
|
|
|
|
uno::RuntimeException,
|
|
|
|
std::exception)
|
2008-06-24 10:42:00 +00:00
|
|
|
{
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE("convertToIntegerColorSpace: method not implemented", false);
|
2008-06-24 10:42:00 +00:00
|
|
|
return uno::Sequence< sal_Int8 >();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual uno::Sequence< rendering::RGBColor > SAL_CALL convertIntegerToRGB( const uno::Sequence< ::sal_Int8 >& deviceColor ) throw (lang::IllegalArgumentException,
|
|
|
|
uno::RuntimeException)
|
|
|
|
{
|
|
|
|
const uno::Sequence< rendering::ARGBColor > aTemp( convertIntegerToARGB(deviceColor) );
|
|
|
|
const sal_Size nLen(aTemp.getLength());
|
|
|
|
uno::Sequence< rendering::RGBColor > aRes( nLen );
|
|
|
|
rendering::RGBColor* pOut = aRes.getArray();
|
|
|
|
for( sal_Size i=0; i<nLen; ++i )
|
|
|
|
{
|
|
|
|
*pOut++ = rendering::RGBColor(aTemp[i].Red,
|
|
|
|
aTemp[i].Green,
|
|
|
|
aTemp[i].Blue);
|
|
|
|
}
|
|
|
|
|
|
|
|
return aRes;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual uno::Sequence< rendering::ARGBColor > SAL_CALL convertIntegerToARGB( const uno::Sequence< ::sal_Int8 >& deviceColor ) throw (lang::IllegalArgumentException,
|
|
|
|
uno::RuntimeException)
|
|
|
|
{
|
|
|
|
const sal_Size nLen( deviceColor.getLength() );
|
|
|
|
const sal_Int32 nBytesPerPixel(mnBitsPerPixel == 8 ? 1 : 4);
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE("number of channels no multiple of pixel element count",
|
|
|
|
nLen%nBytesPerPixel==0);
|
2008-06-24 10:42:00 +00:00
|
|
|
|
|
|
|
uno::Sequence< rendering::ARGBColor > aRes( nLen / nBytesPerPixel );
|
|
|
|
rendering::ARGBColor* pOut( aRes.getArray() );
|
|
|
|
|
|
|
|
if( getPalette().is() )
|
|
|
|
{
|
|
|
|
for( sal_Size i=0; i<nLen; ++i )
|
|
|
|
{
|
|
|
|
*pOut++ = rendering::ARGBColor(
|
|
|
|
1.0,
|
|
|
|
vcl::unotools::toDoubleColor(deviceColor[i]),
|
|
|
|
vcl::unotools::toDoubleColor(deviceColor[i]),
|
|
|
|
vcl::unotools::toDoubleColor(deviceColor[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( sal_Size i=0; i<nLen; i+=4 )
|
|
|
|
{
|
|
|
|
*pOut++ = rendering::ARGBColor(
|
|
|
|
vcl::unotools::toDoubleColor(deviceColor[i+3]),
|
|
|
|
vcl::unotools::toDoubleColor(deviceColor[i+0]),
|
|
|
|
vcl::unotools::toDoubleColor(deviceColor[i+1]),
|
|
|
|
vcl::unotools::toDoubleColor(deviceColor[i+2]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return aRes;
|
|
|
|
}
|
|
|
|
|
2014-02-21 15:01:30 +00:00
|
|
|
virtual uno::Sequence< rendering::ARGBColor > SAL_CALL convertIntegerToPARGB(
|
|
|
|
const uno::Sequence< ::sal_Int8 >& deviceColor)
|
|
|
|
throw (lang::IllegalArgumentException,
|
|
|
|
uno::RuntimeException,
|
|
|
|
std::exception)
|
2008-12-09 13:22:21 +00:00
|
|
|
{
|
|
|
|
const sal_Size nLen( deviceColor.getLength() );
|
|
|
|
const sal_Int32 nBytesPerPixel(mnBitsPerPixel == 8 ? 1 : 4);
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE("number of channels no multiple of pixel element count",
|
|
|
|
nLen%nBytesPerPixel==0);
|
2008-12-09 13:22:21 +00:00
|
|
|
|
|
|
|
uno::Sequence< rendering::ARGBColor > aRes( nLen / nBytesPerPixel );
|
|
|
|
rendering::ARGBColor* pOut( aRes.getArray() );
|
|
|
|
|
|
|
|
if( getPalette().is() )
|
|
|
|
{
|
|
|
|
for( sal_Size i=0; i<nLen; ++i )
|
|
|
|
{
|
|
|
|
*pOut++ = rendering::ARGBColor(
|
|
|
|
1.0,
|
|
|
|
vcl::unotools::toDoubleColor(deviceColor[i]),
|
|
|
|
vcl::unotools::toDoubleColor(deviceColor[i]),
|
|
|
|
vcl::unotools::toDoubleColor(deviceColor[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( sal_Size i=0; i<nLen; i+=4 )
|
|
|
|
{
|
|
|
|
const double fAlpha=vcl::unotools::toDoubleColor(deviceColor[i+3]);
|
|
|
|
*pOut++ = rendering::ARGBColor(
|
|
|
|
fAlpha,
|
|
|
|
fAlpha*vcl::unotools::toDoubleColor(deviceColor[i+0]),
|
|
|
|
fAlpha*vcl::unotools::toDoubleColor(deviceColor[i+1]),
|
|
|
|
fAlpha*vcl::unotools::toDoubleColor(deviceColor[i+2]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return aRes;
|
|
|
|
}
|
|
|
|
|
2008-06-24 10:42:00 +00:00
|
|
|
virtual uno::Sequence< ::sal_Int8 > SAL_CALL convertIntegerFromRGB( const uno::Sequence< rendering::RGBColor >& ) throw (lang::IllegalArgumentException,
|
|
|
|
uno::RuntimeException)
|
|
|
|
{
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE("convertIntegerFromRGB: method not implemented", false);
|
2008-06-24 10:42:00 +00:00
|
|
|
return uno::Sequence< sal_Int8 >();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual uno::Sequence< ::sal_Int8 > SAL_CALL convertIntegerFromARGB( const uno::Sequence< rendering::ARGBColor >& ) throw (lang::IllegalArgumentException,
|
2014-02-09 21:04:50 +00:00
|
|
|
uno::RuntimeException,
|
|
|
|
std::exception)
|
2008-06-24 10:42:00 +00:00
|
|
|
{
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE("convertIntegerFromARGB: method not implemented", false);
|
2008-06-24 10:42:00 +00:00
|
|
|
return uno::Sequence< sal_Int8 >();
|
|
|
|
}
|
|
|
|
|
2014-02-09 21:04:12 +00:00
|
|
|
virtual uno::Sequence< ::sal_Int8 > SAL_CALL convertIntegerFromPARGB( const uno::Sequence< rendering::ARGBColor >& )
|
|
|
|
throw (lang::IllegalArgumentException,
|
|
|
|
uno::RuntimeException,
|
|
|
|
std::exception)
|
2008-12-09 13:22:21 +00:00
|
|
|
{
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE("convertIntegerFromPARGB: method not implemented", false);
|
2008-12-09 13:22:21 +00:00
|
|
|
return uno::Sequence< sal_Int8 >();
|
|
|
|
}
|
|
|
|
|
2008-06-24 10:42:00 +00:00
|
|
|
public:
|
|
|
|
TestBitmap( const geometry::IntegerSize2D& rSize, bool bPalette ) :
|
|
|
|
maSize(rSize),
|
|
|
|
maComponentTags(),
|
|
|
|
maComponentBitCounts(),
|
|
|
|
maLayout(),
|
|
|
|
mnBitsPerPixel( bPalette ? 8 : 32 )
|
|
|
|
{
|
|
|
|
if( bPalette )
|
|
|
|
{
|
|
|
|
maComponentTags.realloc(1);
|
|
|
|
maComponentTags[0] = rendering::ColorComponentTag::INDEX;
|
|
|
|
|
|
|
|
maComponentBitCounts.realloc(1);
|
|
|
|
maComponentBitCounts[0] = 8;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
maComponentTags.realloc(4);
|
|
|
|
sal_Int8* pTags = maComponentTags.getArray();
|
|
|
|
pTags[0] = rendering::ColorComponentTag::RGB_BLUE;
|
|
|
|
pTags[1] = rendering::ColorComponentTag::RGB_GREEN;
|
|
|
|
pTags[2] = rendering::ColorComponentTag::RGB_RED;
|
|
|
|
pTags[3] = rendering::ColorComponentTag::ALPHA;
|
|
|
|
|
|
|
|
maComponentBitCounts.realloc(4);
|
|
|
|
sal_Int32* pCounts = maComponentBitCounts.getArray();
|
|
|
|
pCounts[0] = 8;
|
|
|
|
pCounts[1] = 8;
|
|
|
|
pCounts[2] = 8;
|
|
|
|
pCounts[3] = 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
maLayout.ScanLines = 0;
|
|
|
|
maLayout.ScanLineBytes = 0;
|
|
|
|
maLayout.ScanLineStride = 0;
|
|
|
|
maLayout.PlaneStride = 0;
|
|
|
|
maLayout.ColorSpace.clear();
|
|
|
|
maLayout.Palette.clear();
|
|
|
|
maLayout.IsMsbFirst = sal_False;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-09 20:02:19 +02:00
|
|
|
void CanvasBitmapTest::runTest()
|
2008-06-24 10:42:00 +00:00
|
|
|
{
|
2013-06-29 01:00:09 +09:00
|
|
|
static const sal_Int8 lcl_depths[]={1,4,8,16,24};
|
2008-06-24 10:42:00 +00:00
|
|
|
|
2013-10-09 20:02:19 +02:00
|
|
|
// Testing VclCanvasBitmap wrapper
|
|
|
|
// ===============================
|
2008-06-24 10:42:00 +00:00
|
|
|
|
2013-10-09 20:02:19 +02:00
|
|
|
for( unsigned int i=0; i<SAL_N_ELEMENTS(lcl_depths); ++i )
|
|
|
|
{
|
|
|
|
const sal_Int8 nDepth( lcl_depths[i] );
|
|
|
|
Bitmap aBitmap(Size(200,200),nDepth);
|
|
|
|
aBitmap.Erase(COL_WHITE);
|
2008-06-24 10:42:00 +00:00
|
|
|
{
|
2013-10-09 20:02:19 +02:00
|
|
|
Bitmap::ScopedWriteAccess pAcc(aBitmap);
|
|
|
|
if( pAcc.get() )
|
2008-06-24 10:42:00 +00:00
|
|
|
{
|
2013-10-09 20:02:19 +02:00
|
|
|
BitmapColor aBlack(0);
|
|
|
|
BitmapColor aWhite(0);
|
|
|
|
if( pAcc->HasPalette() )
|
|
|
|
{
|
|
|
|
aBlack.SetIndex( sal::static_int_cast<sal_Int8>(pAcc->GetBestPaletteIndex(BitmapColor(0,0,0))) );
|
|
|
|
aWhite.SetIndex( sal::static_int_cast<sal_Int8>(pAcc->GetBestPaletteIndex(BitmapColor(255,255,255))) );
|
|
|
|
}
|
|
|
|
else
|
2008-06-24 10:42:00 +00:00
|
|
|
{
|
2013-10-09 20:02:19 +02:00
|
|
|
aBlack = Color(COL_BLACK);
|
|
|
|
aWhite = Color(COL_WHITE);
|
2008-06-24 10:42:00 +00:00
|
|
|
}
|
2013-10-09 20:02:19 +02:00
|
|
|
pAcc->SetFillColor(COL_GREEN);
|
|
|
|
pAcc->FillRect(Rectangle(0,0,100,100));
|
|
|
|
pAcc->SetPixel(0,0,aWhite);
|
|
|
|
pAcc->SetPixel(0,1,aBlack);
|
|
|
|
pAcc->SetPixel(0,2,aWhite);
|
2008-06-24 10:42:00 +00:00
|
|
|
}
|
2013-10-09 20:02:19 +02:00
|
|
|
}
|
2008-06-24 10:42:00 +00:00
|
|
|
|
2013-10-09 20:02:19 +02:00
|
|
|
rtl::Reference<VclCanvasBitmap> xBmp( new VclCanvasBitmap(aBitmap) );
|
2008-06-24 10:42:00 +00:00
|
|
|
|
2013-10-09 20:02:19 +02:00
|
|
|
checkCanvasBitmap( xBmp, "single bitmap", nDepth );
|
2008-06-24 10:42:00 +00:00
|
|
|
|
2013-10-09 20:02:19 +02:00
|
|
|
Bitmap aMask(Size(200,200),1);
|
|
|
|
aMask.Erase(COL_WHITE);
|
|
|
|
{
|
|
|
|
Bitmap::ScopedWriteAccess pAcc(aMask);
|
|
|
|
if( pAcc.get() )
|
2008-06-24 10:42:00 +00:00
|
|
|
{
|
2013-10-09 20:02:19 +02:00
|
|
|
pAcc->SetFillColor(COL_BLACK);
|
|
|
|
pAcc->FillRect(Rectangle(0,0,100,100));
|
|
|
|
pAcc->SetPixel(0,0,BitmapColor(1));
|
|
|
|
pAcc->SetPixel(0,1,BitmapColor(0));
|
|
|
|
pAcc->SetPixel(0,2,BitmapColor(1));
|
2008-06-24 10:42:00 +00:00
|
|
|
}
|
2013-10-09 20:02:19 +02:00
|
|
|
}
|
2008-06-24 10:42:00 +00:00
|
|
|
|
2013-10-09 20:02:19 +02:00
|
|
|
xBmp.set( new VclCanvasBitmap(BitmapEx(aBitmap,aMask)) );
|
2008-06-24 10:42:00 +00:00
|
|
|
|
2013-10-09 20:02:19 +02:00
|
|
|
checkCanvasBitmap( xBmp, "masked bitmap", nDepth );
|
2008-06-24 10:42:00 +00:00
|
|
|
|
2013-10-09 20:02:19 +02:00
|
|
|
AlphaMask aAlpha(Size(200,200));
|
|
|
|
aAlpha.Erase(255);
|
|
|
|
{
|
|
|
|
BitmapWriteAccess* pAcc = aAlpha.AcquireWriteAccess();
|
|
|
|
if( pAcc )
|
2008-06-24 10:42:00 +00:00
|
|
|
{
|
2013-10-09 20:02:19 +02:00
|
|
|
pAcc->SetFillColor(COL_BLACK);
|
|
|
|
pAcc->FillRect(Rectangle(0,0,100,100));
|
|
|
|
pAcc->SetPixel(0,0,BitmapColor(255));
|
|
|
|
pAcc->SetPixel(0,1,BitmapColor(0));
|
|
|
|
pAcc->SetPixel(0,2,BitmapColor(255));
|
|
|
|
aAlpha.ReleaseAccess(pAcc);
|
2008-06-24 10:42:00 +00:00
|
|
|
}
|
2013-10-09 20:02:19 +02:00
|
|
|
}
|
2008-06-24 10:42:00 +00:00
|
|
|
|
2013-10-09 20:02:19 +02:00
|
|
|
xBmp.set( new VclCanvasBitmap(BitmapEx(aBitmap,aAlpha)) );
|
2008-06-24 10:42:00 +00:00
|
|
|
|
2013-10-09 20:02:19 +02:00
|
|
|
checkCanvasBitmap( xBmp, "alpha bitmap", nDepth );
|
|
|
|
}
|
2008-06-24 10:42:00 +00:00
|
|
|
|
2013-10-09 20:02:19 +02:00
|
|
|
// Testing XBitmap import
|
|
|
|
// ======================
|
|
|
|
uno::Reference< rendering::XIntegerReadOnlyBitmap > xTestBmp(
|
|
|
|
new TestBitmap( geometry::IntegerSize2D(10,10), true ));
|
2008-06-24 10:42:00 +00:00
|
|
|
|
2013-10-09 20:02:19 +02:00
|
|
|
BitmapEx aBmp = vcl::unotools::bitmapExFromXBitmap(xTestBmp);
|
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Palette bitmap is transparent",
|
2014-01-22 11:28:14 +01:00
|
|
|
!aBmp.IsTransparent());
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Bitmap does not have size (10,10)",
|
|
|
|
aBmp.GetSizePixel() == Size(10,10));
|
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Bitmap does not have bitcount of 8",
|
|
|
|
aBmp.GetBitCount() == 8);
|
|
|
|
{
|
|
|
|
BitmapReadAccess* pBmpAcc = aBmp.GetBitmap().AcquireReadAccess();
|
2008-06-24 10:42:00 +00:00
|
|
|
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Bitmap has invalid BitmapReadAccess",
|
|
|
|
pBmpAcc );
|
2008-06-24 10:42:00 +00:00
|
|
|
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE("(0,0) incorrect content",
|
|
|
|
pBmpAcc->GetPixel(0,0) == BitmapColor(0));
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("(2,2) incorrect content",
|
|
|
|
pBmpAcc->GetPixel(2,2) == BitmapColor(2));
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("(9,2) incorrect content",
|
|
|
|
pBmpAcc->GetPixel(2,9) == BitmapColor(9));
|
2008-06-24 10:42:00 +00:00
|
|
|
|
2013-10-09 20:02:19 +02:00
|
|
|
aBmp.GetBitmap().ReleaseAccess(pBmpAcc);
|
2008-06-24 10:42:00 +00:00
|
|
|
}
|
2013-10-09 20:02:19 +02:00
|
|
|
|
|
|
|
xTestBmp.set( new TestBitmap( geometry::IntegerSize2D(10,10), false ));
|
|
|
|
|
|
|
|
aBmp = vcl::unotools::bitmapExFromXBitmap(xTestBmp);
|
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Palette bitmap is not transparent",
|
2013-10-09 21:51:41 +02:00
|
|
|
aBmp.IsTransparent());
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Palette bitmap has no alpha",
|
2013-10-09 21:51:41 +02:00
|
|
|
aBmp.IsAlpha());
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Bitmap does not have size (10,10)",
|
|
|
|
aBmp.GetSizePixel() == Size(10,10));
|
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Bitmap has bitcount of 24",
|
|
|
|
aBmp.GetBitCount() == 24);
|
2008-06-24 10:42:00 +00:00
|
|
|
{
|
2013-10-09 20:02:19 +02:00
|
|
|
BitmapReadAccess* pBmpAcc = aBmp.GetBitmap().AcquireReadAccess();
|
|
|
|
BitmapReadAccess* pAlphaAcc = aBmp.GetAlpha().AcquireReadAccess();
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Bitmap has invalid BitmapReadAccess",
|
|
|
|
pBmpAcc);
|
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Bitmap has invalid alpha BitmapReadAccess",
|
|
|
|
pAlphaAcc);
|
2008-06-24 10:42:00 +00:00
|
|
|
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE("(0,0) incorrect content",
|
|
|
|
pBmpAcc->GetPixel(0,0) == BitmapColor(0,1,0));
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("(0,0) incorrect alpha content",
|
|
|
|
pAlphaAcc->GetPixel(0,0) == BitmapColor(255));
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("(2,2) incorrect content",
|
|
|
|
pBmpAcc->GetPixel(2,2) == BitmapColor(0,3,2));
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("(2,2) incorrect alpha content",
|
|
|
|
pAlphaAcc->GetPixel(2,2) == BitmapColor(253));
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("(9,2) incorrect content",
|
|
|
|
pBmpAcc->GetPixel(2,9) == BitmapColor(0,3,9));
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("(9,2) correct alpha content",
|
|
|
|
pAlphaAcc->GetPixel(2,9) == BitmapColor(253));
|
|
|
|
|
|
|
|
aBmp.GetAlpha().ReleaseAccess(pAlphaAcc);
|
|
|
|
aBmp.GetBitmap().ReleaseAccess(pBmpAcc);
|
|
|
|
}
|
2008-06-24 10:42:00 +00:00
|
|
|
}
|
|
|
|
|
2008-12-09 13:22:21 +00:00
|
|
|
} // namespace
|
2008-06-24 10:42:00 +00:00
|
|
|
|
2013-10-09 20:02:19 +02:00
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(CanvasBitmapTest);
|
2008-06-24 10:42:00 +00:00
|
|
|
|
2010-10-14 08:27:31 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|