Endianness fixes to bilinear & fuzzy image compares
authorPyry Haulos <phaulos@google.com>
Tue, 28 Oct 2014 23:07:42 +0000 (16:07 -0700)
committerPyry Haulos <phaulos@google.com>
Tue, 11 Nov 2014 16:49:39 +0000 (16:49 +0000)
Bug: 18329517
Change-Id: I1f5560a60ed85ef4b4c6fa2a5417649eeb7a4c7f
(cherry picked from commit 74731a6adf5816339b00b854a513b1b950ad4357)

framework/common/tcuBilinearImageCompare.cpp
framework/common/tcuFuzzyImageCompare.cpp
framework/delibs/debase/deInt32.h

index 26e896b..9b53ff9 100644 (file)
@@ -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<int Channel>
 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)
 {
index fcf6252..cfcd576 100644 (file)
@@ -34,8 +34,6 @@ namespace tcu
 
 using std::vector;
 
-// \todo [2012-12-13 pyry] Big-endian architectures?
-
 template<int Channel>
 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<int NumChannels>
 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)
 {
index aa4c8cb..a360f62 100644 (file)
@@ -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;