From 366985e9a897a50439ac0d95d67660d2e4e376ee Mon Sep 17 00:00:00 2001 From: Pyry Haulos Date: Tue, 28 Oct 2014 16:07:42 -0700 Subject: [PATCH] Endianness fixes to bilinear & fuzzy image compares Bug: 18329517 Change-Id: I1f5560a60ed85ef4b4c6fa2a5417649eeb7a4c7f (cherry picked from commit 74731a6adf5816339b00b854a513b1b950ad4357) --- framework/common/tcuBilinearImageCompare.cpp | 10 +++++++++- framework/common/tcuFuzzyImageCompare.cpp | 6 ++++-- framework/delibs/debase/deInt32.h | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/framework/common/tcuBilinearImageCompare.cpp b/framework/common/tcuBilinearImageCompare.cpp index 26e896b..9b53ff9 100644 --- a/framework/common/tcuBilinearImageCompare.cpp +++ b/framework/common/tcuBilinearImageCompare.cpp @@ -37,7 +37,8 @@ enum NUM_SUBPIXEL_BITS = 8 //!< Number of subpixel bits used when doing bilinear interpolation. }; -// \todo [2013-03-26 pyry] Big-endian architectures? +// \note Algorithm assumes that colors are packed to 32-bit values as dictated by +// tcu::RGBA::*_SHIFT values. template static inline deUint8 getChannel (deUint32 color) @@ -45,10 +46,17 @@ static inline deUint8 getChannel (deUint32 color) return (deUint8)((color >> (Channel*8)) & 0xff); } +#if (DE_ENDIANNESS == DE_LITTLE_ENDIAN) inline deUint32 readRGBA8Raw (const ConstPixelBufferAccess& src, deUint32 x, deUint32 y) { return *(const deUint32*)((const deUint8*)src.getDataPtr() + y*src.getRowPitch() + x*4); } +#else +inline deUint32 readRGBA8Raw (const ConstPixelBufferAccess& src, deUint32 x, deUint32 y) +{ + return deReverseBytes32(*(const deUint32*)((const deUint8*)src.getDataPtr() + y*src.getRowPitch() + x*4)); +} +#endif inline RGBA readRGBA8 (const ConstPixelBufferAccess& src, deUint32 x, deUint32 y) { diff --git a/framework/common/tcuFuzzyImageCompare.cpp b/framework/common/tcuFuzzyImageCompare.cpp index fcf6252..cfcd576 100644 --- a/framework/common/tcuFuzzyImageCompare.cpp +++ b/framework/common/tcuFuzzyImageCompare.cpp @@ -34,8 +34,6 @@ namespace tcu using std::vector; -// \todo [2012-12-13 pyry] Big-endian architectures? - template static inline deUint8 getChannel (deUint32 color) { @@ -82,11 +80,13 @@ static inline deUint32 readUnorm8 (const tcu::ConstPixelBufferAccess& src, int x return v; } +#if (DE_ENDIANNESS == DE_LITTLE_ENDIAN) template<> inline deUint32 readUnorm8<4> (const tcu::ConstPixelBufferAccess& src, int x, int y) { return *(const deUint32*)((const deUint8*)src.getDataPtr() + src.getRowPitch()*y + x*4); } +#endif template static inline void writeUnorm8 (const tcu::PixelBufferAccess& dst, int x, int y, deUint32 val) @@ -97,11 +97,13 @@ static inline void writeUnorm8 (const tcu::PixelBufferAccess& dst, int x, int y, ptr[c] = getChannel(val, c); } +#if (DE_ENDIANNESS == DE_LITTLE_ENDIAN) template<> inline void writeUnorm8<4> (const tcu::PixelBufferAccess& dst, int x, int y, deUint32 val) { *(deUint32*)((deUint8*)dst.getDataPtr() + dst.getRowPitch()*y + x*4) = val; } +#endif static inline float compareColors (deUint32 pa, deUint32 pb, int minErrThreshold) { diff --git a/framework/delibs/debase/deInt32.h b/framework/delibs/debase/deInt32.h index aa4c8cb..a360f62 100644 --- a/framework/delibs/debase/deInt32.h +++ b/framework/delibs/debase/deInt32.h @@ -337,6 +337,20 @@ DE_INLINE int dePop32 (int a) return (int)t; } +/*--------------------------------------------------------------------*//*! + * \brief Reverse bytes in 32-bit integer (for example MSB -> LSB). + * \param a Input value. + * \return The input with bytes reversed + *//*--------------------------------------------------------------------*/ +DE_INLINE deUint32 deReverseBytes32 (deUint32 v) +{ + deUint32 b0 = v << 24; + deUint32 b1 = (v & 0x0000ff00) << 8; + deUint32 b2 = (v & 0x00ff0000) >> 8; + deUint32 b3 = v >> 24; + return b0|b1|b2|b3; +} + DE_INLINE deInt32 deSafeMul32 (deInt32 a, deInt32 b) { deInt32 res = a * b; -- 2.7.4