2
* Copyright (C) 2006 The Android Open Source Project
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
#ifndef SkEndian_DEFINED
18
#define SkEndian_DEFINED
24
Macros and helper functions for handling 16 and 32 bit values in
25
big and little endian formats.
28
#if defined(SK_CPU_LENDIAN) && defined(SK_CPU_BENDIAN)
29
#error "can't have both LENDIAN and BENDIAN defined"
32
#if !defined(SK_CPU_LENDIAN) && !defined(SK_CPU_BENDIAN)
33
#error "need either LENDIAN or BENDIAN defined"
36
/** Swap the two bytes in the low 16bits of the parameters.
39
inline uint16_t SkEndianSwap16(U16CPU value)
41
SkASSERT(value == (uint16_t)value);
42
return (uint16_t)((value >> 8) | (value << 8));
45
/** Vector version of SkEndianSwap16(), which swaps the
46
low two bytes of each value in the array.
48
inline void SkEndianSwap16s(uint16_t array[], int count)
50
SkASSERT(count == 0 || array != NULL);
54
*array = SkEndianSwap16(*array);
59
/** Reverse all 4 bytes in a 32bit value.
60
e.g. 0x12345678 -> 0x78563412
62
inline uint32_t SkEndianSwap32(uint32_t value)
64
return ((value & 0xFF) << 24) |
65
((value & 0xFF00) << 8) |
66
((value & 0xFF0000) >> 8) |
70
/** Vector version of SkEndianSwap16(), which swaps the
71
bytes of each value in the array.
73
inline void SkEndianSwap32s(uint32_t array[], int count)
75
SkASSERT(count == 0 || array != NULL);
79
*array = SkEndianSwap32(*array);
85
#define SkEndian_SwapBE16(n) SkEndianSwap16(n)
86
#define SkEndian_SwapBE32(n) SkEndianSwap32(n)
87
#define SkEndian_SwapLE16(n) (n)
88
#define SkEndian_SwapLE32(n) (n)
89
#else // SK_CPU_BENDIAN
90
#define SkEndian_SwapBE16(n) (n)
91
#define SkEndian_SwapBE32(n) (n)
92
#define SkEndian_SwapLE16(n) SkEndianSwap16(n)
93
#define SkEndian_SwapLE32(n) SkEndianSwap32(n)