| OLD | NEW |
| 1 | |
| 2 /* | 1 /* |
| 3 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
| 4 * | 3 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 7 */ | 6 */ |
| 8 | 7 |
| 9 | |
| 10 #ifndef SkEndian_DEFINED | 8 #ifndef SkEndian_DEFINED |
| 11 #define SkEndian_DEFINED | 9 #define SkEndian_DEFINED |
| 12 | 10 |
| 13 #include "SkTypes.h" | 11 #include "SkTypes.h" |
| 14 | 12 |
| 15 /** \file SkEndian.h | 13 /** \file SkEndian.h |
| 16 | 14 |
| 17 Macros and helper functions for handling 16 and 32 bit values in | 15 Macros and helper functions for handling 16 and 32 bit values in |
| 18 big and little endian formats. | 16 big and little endian formats. |
| 19 */ | 17 */ |
| 20 | 18 |
| 21 #if defined(SK_CPU_LENDIAN) && defined(SK_CPU_BENDIAN) | 19 #if defined(SK_CPU_LENDIAN) && defined(SK_CPU_BENDIAN) |
| 22 #error "can't have both LENDIAN and BENDIAN defined" | 20 #error "can't have both LENDIAN and BENDIAN defined" |
| 23 #endif | 21 #endif |
| 24 | 22 |
| 25 #if !defined(SK_CPU_LENDIAN) && !defined(SK_CPU_BENDIAN) | 23 #if !defined(SK_CPU_LENDIAN) && !defined(SK_CPU_BENDIAN) |
| 26 #error "need either LENDIAN or BENDIAN defined" | 24 #error "need either LENDIAN or BENDIAN defined" |
| 27 #endif | 25 #endif |
| 28 | 26 |
| 29 /** Swap the two bytes in the low 16bits of the parameters. | 27 /** Swap the two bytes in the low 16bits of the parameters. |
| 30 e.g. 0x1234 -> 0x3412 | 28 e.g. 0x1234 -> 0x3412 |
| 31 */ | 29 */ |
| 32 static inline uint16_t SkEndianSwap16(U16CPU value) { | 30 static inline uint16_t SkEndianSwap16(uint16_t value) { |
| 33 SkASSERT(value == (uint16_t)value); | |
| 34 return static_cast<uint16_t>((value >> 8) | (value << 8)); | 31 return static_cast<uint16_t>((value >> 8) | (value << 8)); |
| 35 } | 32 } |
| 33 |
| 36 template<uint16_t N> struct SkTEndianSwap16 { | 34 template<uint16_t N> struct SkTEndianSwap16 { |
| 37 static const uint16_t value = static_cast<uint16_t>((N >> 8) | ((N & 0xFF) <
< 8)); | 35 static const uint16_t value = static_cast<uint16_t>((N >> 8) | ((N & 0xFF) <
< 8)); |
| 38 }; | 36 }; |
| 39 | 37 |
| 40 /** Vector version of SkEndianSwap16(), which swaps the | 38 /** Vector version of SkEndianSwap16(), which swaps the |
| 41 low two bytes of each value in the array. | 39 low two bytes of each value in the array. |
| 42 */ | 40 */ |
| 43 static inline void SkEndianSwap16s(uint16_t array[], int count) { | 41 static inline void SkEndianSwap16s(uint16_t array[], int count) { |
| 44 SkASSERT(count == 0 || array != NULL); | 42 SkASSERT(count == 0 || array != NULL); |
| 45 | 43 |
| 46 while (--count >= 0) { | 44 while (--count >= 0) { |
| 47 *array = SkEndianSwap16(*array); | 45 *array = SkEndianSwap16(*array); |
| 48 array += 1; | 46 array += 1; |
| 49 } | 47 } |
| 50 } | 48 } |
| 51 | 49 |
| 52 /** Reverse all 4 bytes in a 32bit value. | 50 /** Reverse all 4 bytes in a 32bit value. |
| 53 e.g. 0x12345678 -> 0x78563412 | 51 e.g. 0x12345678 -> 0x78563412 |
| 54 */ | 52 */ |
| 55 static inline uint32_t SkEndianSwap32(uint32_t value) { | 53 static inline uint32_t SkEndianSwap32(uint32_t value) { |
| 56 return ((value & 0xFF) << 24) | | 54 return ((value & 0xFF) << 24) | |
| 57 ((value & 0xFF00) << 8) | | 55 ((value & 0xFF00) << 8) | |
| 58 ((value & 0xFF0000) >> 8) | | 56 ((value & 0xFF0000) >> 8) | |
| 59 (value >> 24); | 57 (value >> 24); |
| 60 } | 58 } |
| 59 |
| 61 template<uint32_t N> struct SkTEndianSwap32 { | 60 template<uint32_t N> struct SkTEndianSwap32 { |
| 62 static const uint32_t value = ((N & 0xFF) << 24) | | 61 static const uint32_t value = ((N & 0xFF) << 24) | |
| 63 ((N & 0xFF00) << 8) | | 62 ((N & 0xFF00) << 8) | |
| 64 ((N & 0xFF0000) >> 8) | | 63 ((N & 0xFF0000) >> 8) | |
| 65 (N >> 24); | 64 (N >> 24); |
| 66 }; | 65 }; |
| 67 | 66 |
| 68 /** Vector version of SkEndianSwap32(), which swaps the | 67 /** Vector version of SkEndianSwap32(), which swaps the |
| 69 bytes of each value in the array. | 68 bytes of each value in the array. |
| 70 */ | 69 */ |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 SK_OT_BYTE f6 : 1; \ | 185 SK_OT_BYTE f6 : 1; \ |
| 187 SK_OT_BYTE f5 : 1; \ | 186 SK_OT_BYTE f5 : 1; \ |
| 188 SK_OT_BYTE f4 : 1; \ | 187 SK_OT_BYTE f4 : 1; \ |
| 189 SK_OT_BYTE f3 : 1; \ | 188 SK_OT_BYTE f3 : 1; \ |
| 190 SK_OT_BYTE f2 : 1; \ | 189 SK_OT_BYTE f2 : 1; \ |
| 191 SK_OT_BYTE f1 : 1; \ | 190 SK_OT_BYTE f1 : 1; \ |
| 192 SK_OT_BYTE f0 : 1; | 191 SK_OT_BYTE f0 : 1; |
| 193 #endif | 192 #endif |
| 194 | 193 |
| 195 #endif | 194 #endif |
| OLD | NEW |