diff -r 000000000000 -r bde4ae8d615e os/graphics/graphicstest/graphicstestharness/src/graphicsimagecomparison.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/os/graphics/graphicstest/graphicstestharness/src/graphicsimagecomparison.cpp Fri Jun 15 03:10:57 2012 +0200 @@ -0,0 +1,272 @@ +// Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// + +/** + @file + @test +*/ + +#include "graphicsimagecomparison.h" + +/** +Compares the contents of a rectangular region of one bitmap with a similarly sized +rectangular region of another bitmap. + +@param aCompareSize, a const reference to a TSize object denoting the size of the +rectangular region for comparison.Negative and zero dimensions of this argument can +be passed in without returning a KErrArgument error. +@param aBitmap1Point, a const reference to a TPoint object denoting the top left +point of the rectangle in aBitmap1 used for comparison.. +@param aBitmap2Point, a const reference to a TPoint object denoting the top left +point of the rectangle in aBitmap2 used for comparison. +@param aBitmap1, a const reference to the first CFbsBitmap for use in comparison. +@param aBitmap2, a const reference to the second CFbsBitmap for use in comparison. +@param aComparisonMask, a bit mask to be applied to the bitmap pixel data before +performing the comparison, in the form 0xAARRGGBB. Defaults to 0xFFFFFFFF +@pre The rectanglular comparison region must reside wholly inside both of the bitmaps +@return KErrNone if the pixels contained in the bitmap rectangles are an exact match +or, otherwise, the count of the first unmatched pixel. Pixels are compared from TRUE +top-left to bottom-right in the horizontal direction (TRUE to cope with negative +dimensions of the aCompareSize object) An area of zero size will return KErrNone so +long as the pre-conditions are satisfied. +KErrArgument if the pre-conditions are not met. +*/ +EXPORT_C TInt CTGraphicsImageComparison::CompareBitmaps(const TSize& aCompareSize, + const TPoint& aBitmap1Point, + const TPoint& aBitmap2Point, + const CFbsBitmap& aBitmap1, + const CFbsBitmap& aBitmap2, + const TUint32 aComparisonMask) + { + TInt err = CheckArguments(aCompareSize, + aBitmap1Point, + aBitmap2Point, + aBitmap1, + aBitmap2); + + if(err == KErrNone) + { + //Take local copies as cannot modify static arguments + TSize localSize(aCompareSize); + TPoint localPoint1(aBitmap1Point); + TPoint localPoint2(aBitmap2Point); + + //Cope with negative aCompareSize dimensions + if(aCompareSize.iWidth < 0) + { + localSize.iWidth = -localSize.iWidth; + localPoint1.iX = localPoint1.iX - localSize.iWidth; + localPoint2.iX = localPoint2.iX - localSize.iWidth; + } + + if(aCompareSize.iHeight < 0) + { + localSize.iHeight = -localSize.iHeight; + localPoint1.iY = localPoint1.iY - localSize.iHeight; + localPoint2.iY = localPoint2.iY - localSize.iHeight; + } + + // Set up buffers for obtaining scanlines + TInt scanLineLength1 = aBitmap1.ScanLineLength(localSize.iWidth, ERgb); + TUint8* buffer1 = new TUint8[scanLineLength1]; + if(!buffer1) + { + return KErrNoMemory; + } + TPtr8 scanLine1(buffer1, scanLineLength1, scanLineLength1); + TInt scanLineLength2 = aBitmap2.ScanLineLength(localSize.iWidth, ERgb); + TUint8* buffer2 = new TUint8[scanLineLength2]; + if(!buffer2) + { + delete[] buffer1; + return KErrNoMemory; + } + TPtr8 scanLine2(buffer2, scanLineLength2, scanLineLength2); + + //Perform scanline to scanline comparison without comparison mask + for(TInt y=0; y= 0) + { + //Comparison rectangle is outside of the bitmap (rhs) + if(aPoint.iX + aSize.iWidth > aBitmap.SizeInPixels().iWidth) + { + return KErrArgument; + } + } + else + { + //Comparison rectangle is outside of the bitmap (lhs) + if(aPoint.iX + aSize.iWidth < 0) + { + return KErrArgument; + } + } + + if(aSize.iHeight >= 0) + { + //Comparison rectangle is outside of the bitmap (bottom) + if(aPoint.iY + aSize.iHeight > aBitmap.SizeInPixels().iHeight) + { + return KErrArgument; + } + } + else + { + //Comparison rectangle is outside of the bitmap (top) + if(aPoint.iY + aSize.iHeight < 0) + { + return KErrArgument; + } + } + + return KErrNone; + }