From 853f6df7b5bf55bb1c056eaac5633ddb4abb0db5 Mon Sep 17 00:00:00 2001 From: "Arthur Brainville (Ybalrid)" Date: Sun, 3 Mar 2019 16:26:20 +0100 Subject: [PATCH] Simplify byteswap code to convert to big endian 16bit --- examples/gltfutil/texture_dumper.cc | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/examples/gltfutil/texture_dumper.cc b/examples/gltfutil/texture_dumper.cc index c46bc70..ff91e1b 100644 --- a/examples/gltfutil/texture_dumper.cc +++ b/examples/gltfutil/texture_dumper.cc @@ -44,21 +44,11 @@ static void ToBigEndian(std::vector* image) { return; } - auto swap2 = - [](uint16_t* val) { - uint16_t tmp = *val; - uint8_t* dst = reinterpret_cast(val); - uint8_t* src = reinterpret_cast(&tmp); - - dst[0] = src[1]; - dst[1] = src[0]; - }; - uint16_t *ptr = reinterpret_cast(image->data()); size_t n = image->size() / 2; for (size_t i = 0; i < n; i++) { - swap2(&ptr[i]); + ptr[i] = ((0xFF00 & ptr[i]) >> 8) | ((0x00FF & ptr[i]) << 8); } }