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