OLD | NEW |
1 // Copyright 2013 Google Inc. All Rights Reserved. | 1 // Copyright 2013 Google Inc. All Rights Reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 19 matching lines...) Expand all Loading... |
30 dst[offset + 2] = x >> 8; | 30 dst[offset + 2] = x >> 8; |
31 dst[offset + 3] = x; | 31 dst[offset + 3] = x; |
32 return offset + 4; | 32 return offset + 4; |
33 } | 33 } |
34 | 34 |
35 inline size_t Store16(uint8_t* dst, size_t offset, int x) { | 35 inline size_t Store16(uint8_t* dst, size_t offset, int x) { |
36 #if (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) | 36 #if (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) |
37 *reinterpret_cast<uint16_t*>(dst + offset) = | 37 *reinterpret_cast<uint16_t*>(dst + offset) = |
38 ((x & 0xFF) << 8) | ((x & 0xFF00) >> 8); | 38 ((x & 0xFF) << 8) | ((x & 0xFF00) >> 8); |
39 #elif (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)) | 39 #elif (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)) |
40 *reinterpret_cast<uint16_t*>(dst + offset) = reinterpret_cast<uint16_t>(x); | 40 *reinterpret_cast<uint16_t*>(dst + offset) = static_cast<uint16_t>(x); |
41 #else | 41 #else |
42 dst[offset] = x >> 8; | 42 dst[offset] = x >> 8; |
43 dst[offset + 1] = x; | 43 dst[offset + 1] = x; |
44 #endif | 44 #endif |
45 return offset + 2; | 45 return offset + 2; |
46 } | 46 } |
47 | 47 |
48 inline void StoreU32(uint32_t val, size_t* offset, uint8_t* dst) { | 48 inline void StoreU32(uint32_t val, size_t* offset, uint8_t* dst) { |
49 dst[(*offset)++] = val >> 24; | 49 dst[(*offset)++] = val >> 24; |
50 dst[(*offset)++] = val >> 16; | 50 dst[(*offset)++] = val >> 16; |
51 dst[(*offset)++] = val >> 8; | 51 dst[(*offset)++] = val >> 8; |
52 dst[(*offset)++] = val; | 52 dst[(*offset)++] = val; |
53 } | 53 } |
54 | 54 |
55 inline void Store16(int val, size_t* offset, uint8_t* dst) { | 55 inline void Store16(int val, size_t* offset, uint8_t* dst) { |
56 #if (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) | 56 #if (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) |
57 *reinterpret_cast<uint16_t*>(dst + *offset) = | 57 *reinterpret_cast<uint16_t*>(dst + *offset) = |
58 ((val & 0xFF) << 8) | ((val & 0xFF00) >> 8); | 58 ((val & 0xFF) << 8) | ((val & 0xFF00) >> 8); |
59 *offset += 2; | 59 *offset += 2; |
60 #elif (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)) | 60 #elif (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)) |
61 *reinterpret_cast<uint16_t*>(dst + *offset) = | 61 *reinterpret_cast<uint16_t*>(dst + *offset) = static_cast<uint16_t>(val); |
62 reinterpret_cast<uint16_t>(val); | |
63 *offset += 2; | 62 *offset += 2; |
64 #else | 63 #else |
65 dst[(*offset)++] = val >> 8; | 64 dst[(*offset)++] = val >> 8; |
66 dst[(*offset)++] = val; | 65 dst[(*offset)++] = val; |
67 #endif | 66 #endif |
68 } | 67 } |
69 | 68 |
70 inline void StoreBytes(const uint8_t* data, size_t len, | 69 inline void StoreBytes(const uint8_t* data, size_t len, |
71 size_t* offset, uint8_t* dst) { | 70 size_t* offset, uint8_t* dst) { |
72 memcpy(&dst[*offset], data, len); | 71 memcpy(&dst[*offset], data, len); |
73 *offset += len; | 72 *offset += len; |
74 } | 73 } |
75 | 74 |
76 } // namespace woff2 | 75 } // namespace woff2 |
77 | 76 |
78 #endif // WOFF2_STORE_BYTES_H_ | 77 #endif // WOFF2_STORE_BYTES_H_ |
OLD | NEW |