1/* -*- tab-width: 4; -*- */
2/* vi: set sw=2 ts=4 expandtab: */
3
4/* $Id: 02ea6de2d8db512ca3af08f48b98ab5f6c35e7e5 $ */
5
6/*
7 * Copyright 2010-2020 The Khronos Group Inc.
8 * SPDX-License-Identifier: Apache-2.0
9 */
10
11#include <KHR/khrplatform.h>
12#include "ktx.h"
13
14/*
15 * SwapEndian16: Swaps endianness in an array of 16-bit values
16 */
17void
18_ktxSwapEndian16(khronos_uint16_t* pData16, ktx_size_t count)
19{
20 for (ktx_size_t i = 0; i < count; ++i)
21 {
22 khronos_uint16_t x = *pData16;
23 *pData16++ = (x << 8) | (x >> 8);
24 }
25}
26
27/*
28 * SwapEndian32: Swaps endianness in an array of 32-bit values
29 */
30void
31_ktxSwapEndian32(khronos_uint32_t* pData32, ktx_size_t count)
32{
33 for (ktx_size_t i = 0; i < count; ++i)
34 {
35 khronos_uint32_t x = *pData32;
36 *pData32++ = (x << 24) | ((x & 0xFF00) << 8) | ((x & 0xFF0000) >> 8) | (x >> 24);
37 }
38}
39
40/*
41 * SwapEndian364: Swaps endianness in an array of 32-bit values
42 */
43void
44_ktxSwapEndian64(khronos_uint64_t* pData64, ktx_size_t count)
45{
46 for (ktx_size_t i = 0; i < count; ++i)
47 {
48 khronos_uint64_t x = *pData64;
49 *pData64++ = (x << 56) | ((x & 0xFF00) << 40) | ((x & 0xFF0000) << 24)
50 | ((x & 0xFF000000) << 8 ) | ((x & 0xFF00000000) >> 8)
51 | ((x & 0xFF0000000000) >> 24)
52 | ((x & 0xFF000000000000) << 40) | (x >> 56);
53 }
54}
55
56
57
58