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