OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
3 * | 3 * |
4 * 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 |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkEndian_DEFINED | 8 #ifndef SkEndian_DEFINED |
9 #define SkEndian_DEFINED | 9 #define SkEndian_DEFINED |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 } | 32 } |
33 | 33 |
34 template<uint16_t N> struct SkTEndianSwap16 { | 34 template<uint16_t N> struct SkTEndianSwap16 { |
35 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)); |
36 }; | 36 }; |
37 | 37 |
38 /** Vector version of SkEndianSwap16(), which swaps the | 38 /** Vector version of SkEndianSwap16(), which swaps the |
39 low two bytes of each value in the array. | 39 low two bytes of each value in the array. |
40 */ | 40 */ |
41 static inline void SkEndianSwap16s(uint16_t array[], int count) { | 41 static inline void SkEndianSwap16s(uint16_t array[], int count) { |
42 SkASSERT(count == 0 || array != NULL); | 42 SkASSERT(count == 0 || array != nullptr); |
43 | 43 |
44 while (--count >= 0) { | 44 while (--count >= 0) { |
45 *array = SkEndianSwap16(*array); | 45 *array = SkEndianSwap16(*array); |
46 array += 1; | 46 array += 1; |
47 } | 47 } |
48 } | 48 } |
49 | 49 |
50 /** Reverse all 4 bytes in a 32bit value. | 50 /** Reverse all 4 bytes in a 32bit value. |
51 e.g. 0x12345678 -> 0x78563412 | 51 e.g. 0x12345678 -> 0x78563412 |
52 */ | 52 */ |
53 static inline uint32_t SkEndianSwap32(uint32_t value) { | 53 static inline uint32_t SkEndianSwap32(uint32_t value) { |
54 return ((value & 0xFF) << 24) | | 54 return ((value & 0xFF) << 24) | |
55 ((value & 0xFF00) << 8) | | 55 ((value & 0xFF00) << 8) | |
56 ((value & 0xFF0000) >> 8) | | 56 ((value & 0xFF0000) >> 8) | |
57 (value >> 24); | 57 (value >> 24); |
58 } | 58 } |
59 | 59 |
60 template<uint32_t N> struct SkTEndianSwap32 { | 60 template<uint32_t N> struct SkTEndianSwap32 { |
61 static const uint32_t value = ((N & 0xFF) << 24) | | 61 static const uint32_t value = ((N & 0xFF) << 24) | |
62 ((N & 0xFF00) << 8) | | 62 ((N & 0xFF00) << 8) | |
63 ((N & 0xFF0000) >> 8) | | 63 ((N & 0xFF0000) >> 8) | |
64 (N >> 24); | 64 (N >> 24); |
65 }; | 65 }; |
66 | 66 |
67 /** Vector version of SkEndianSwap32(), which swaps the | 67 /** Vector version of SkEndianSwap32(), which swaps the |
68 bytes of each value in the array. | 68 bytes of each value in the array. |
69 */ | 69 */ |
70 static inline void SkEndianSwap32s(uint32_t array[], int count) { | 70 static inline void SkEndianSwap32s(uint32_t array[], int count) { |
71 SkASSERT(count == 0 || array != NULL); | 71 SkASSERT(count == 0 || array != nullptr); |
72 | 72 |
73 while (--count >= 0) { | 73 while (--count >= 0) { |
74 *array = SkEndianSwap32(*array); | 74 *array = SkEndianSwap32(*array); |
75 array += 1; | 75 array += 1; |
76 } | 76 } |
77 } | 77 } |
78 | 78 |
79 /** Reverse all 8 bytes in a 64bit value. | 79 /** Reverse all 8 bytes in a 64bit value. |
80 e.g. 0x1122334455667788 -> 0x8877665544332211 | 80 e.g. 0x1122334455667788 -> 0x8877665544332211 |
81 */ | 81 */ |
(...skipping 15 matching lines...) Expand all Loading... |
97 ((N & 0x000000FF00000000ULL) >> (8*1)) | | 97 ((N & 0x000000FF00000000ULL) >> (8*1)) | |
98 ((N & 0x0000FF0000000000ULL) >> (8*3)) | | 98 ((N & 0x0000FF0000000000ULL) >> (8*3)) | |
99 ((N & 0x00FF000000000000ULL) >> (8*5)) | | 99 ((N & 0x00FF000000000000ULL) >> (8*5)) | |
100 ((N) >> (8*7))); | 100 ((N) >> (8*7))); |
101 }; | 101 }; |
102 | 102 |
103 /** Vector version of SkEndianSwap64(), which swaps the | 103 /** Vector version of SkEndianSwap64(), which swaps the |
104 bytes of each value in the array. | 104 bytes of each value in the array. |
105 */ | 105 */ |
106 static inline void SkEndianSwap64s(uint64_t array[], int count) { | 106 static inline void SkEndianSwap64s(uint64_t array[], int count) { |
107 SkASSERT(count == 0 || array != NULL); | 107 SkASSERT(count == 0 || array != nullptr); |
108 | 108 |
109 while (--count >= 0) { | 109 while (--count >= 0) { |
110 *array = SkEndianSwap64(*array); | 110 *array = SkEndianSwap64(*array); |
111 array += 1; | 111 array += 1; |
112 } | 112 } |
113 } | 113 } |
114 | 114 |
115 #ifdef SK_CPU_LENDIAN | 115 #ifdef SK_CPU_LENDIAN |
116 #define SkEndian_SwapBE16(n) SkEndianSwap16(n) | 116 #define SkEndian_SwapBE16(n) SkEndianSwap16(n) |
117 #define SkEndian_SwapBE32(n) SkEndianSwap32(n) | 117 #define SkEndian_SwapBE32(n) SkEndianSwap32(n) |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 SK_OT_BYTE f6 : 1; \ | 185 SK_OT_BYTE f6 : 1; \ |
186 SK_OT_BYTE f5 : 1; \ | 186 SK_OT_BYTE f5 : 1; \ |
187 SK_OT_BYTE f4 : 1; \ | 187 SK_OT_BYTE f4 : 1; \ |
188 SK_OT_BYTE f3 : 1; \ | 188 SK_OT_BYTE f3 : 1; \ |
189 SK_OT_BYTE f2 : 1; \ | 189 SK_OT_BYTE f2 : 1; \ |
190 SK_OT_BYTE f1 : 1; \ | 190 SK_OT_BYTE f1 : 1; \ |
191 SK_OT_BYTE f0 : 1; | 191 SK_OT_BYTE f0 : 1; |
192 #endif | 192 #endif |
193 | 193 |
194 #endif | 194 #endif |
OLD | NEW |