| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 The Android Open Source Project | 2 * Copyright 2015 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 SkCodecPriv_DEFINED | 8 #ifndef SkCodecPriv_DEFINED |
| 9 #define SkCodecPriv_DEFINED | 9 #define SkCodecPriv_DEFINED |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 uint8_t maxAlpha = 0xFF; | 22 uint8_t maxAlpha = 0xFF; |
| 23 | 23 |
| 24 #define UPDATE_RESULT_ALPHA(alpha) \ | 24 #define UPDATE_RESULT_ALPHA(alpha) \ |
| 25 zeroAlpha |= (alpha); \ | 25 zeroAlpha |= (alpha); \ |
| 26 maxAlpha &= (alpha); | 26 maxAlpha &= (alpha); |
| 27 | 27 |
| 28 #define COMPUTE_RESULT_ALPHA \ | 28 #define COMPUTE_RESULT_ALPHA \ |
| 29 SkSwizzler::GetResult(zeroAlpha, maxAlpha); | 29 SkSwizzler::GetResult(zeroAlpha, maxAlpha); |
| 30 | 30 |
| 31 /* | 31 /* |
| 32 * | |
| 33 * Compute row bytes for an image using pixels per byte | 32 * Compute row bytes for an image using pixels per byte |
| 34 * | |
| 35 */ | 33 */ |
| 36 static inline size_t compute_row_bytes_ppb(int width, uint32_t pixelsPerByte) { | 34 static inline size_t compute_row_bytes_ppb(int width, uint32_t pixelsPerByte) { |
| 37 return (width + pixelsPerByte - 1) / pixelsPerByte; | 35 return (width + pixelsPerByte - 1) / pixelsPerByte; |
| 38 } | 36 } |
| 39 | 37 |
| 40 /* | 38 /* |
| 41 * | |
| 42 * Compute row bytes for an image using bytes per pixel | 39 * Compute row bytes for an image using bytes per pixel |
| 43 * | |
| 44 */ | 40 */ |
| 45 static inline size_t compute_row_bytes_bpp(int width, uint32_t bytesPerPixel) { | 41 static inline size_t compute_row_bytes_bpp(int width, uint32_t bytesPerPixel) { |
| 46 return width * bytesPerPixel; | 42 return width * bytesPerPixel; |
| 47 } | 43 } |
| 48 | 44 |
| 49 /* | 45 /* |
| 50 * | |
| 51 * Compute row bytes for an image | 46 * Compute row bytes for an image |
| 52 * | |
| 53 */ | 47 */ |
| 54 static inline size_t compute_row_bytes(int width, uint32_t bitsPerPixel) { | 48 static inline size_t compute_row_bytes(int width, uint32_t bitsPerPixel) { |
| 55 if (bitsPerPixel < 16) { | 49 if (bitsPerPixel < 16) { |
| 56 SkASSERT(0 == 8 % bitsPerPixel); | 50 SkASSERT(0 == 8 % bitsPerPixel); |
| 57 const uint32_t pixelsPerByte = 8 / bitsPerPixel; | 51 const uint32_t pixelsPerByte = 8 / bitsPerPixel; |
| 58 return compute_row_bytes_ppb(width, pixelsPerByte); | 52 return compute_row_bytes_ppb(width, pixelsPerByte); |
| 59 } else { | 53 } else { |
| 60 SkASSERT(0 == bitsPerPixel % 8); | 54 SkASSERT(0 == bitsPerPixel % 8); |
| 61 const uint32_t bytesPerPixel = bitsPerPixel / 8; | 55 const uint32_t bytesPerPixel = bitsPerPixel / 8; |
| 62 return compute_row_bytes_bpp(width, bytesPerPixel); | 56 return compute_row_bytes_bpp(width, bytesPerPixel); |
| 63 } | 57 } |
| 64 } | 58 } |
| 65 | 59 |
| 66 /* | 60 /* |
| 67 * | |
| 68 * Get a byte from a buffer | 61 * Get a byte from a buffer |
| 69 * This method is unsafe, the caller is responsible for performing a check | 62 * This method is unsafe, the caller is responsible for performing a check |
| 70 * | |
| 71 */ | 63 */ |
| 72 static inline uint8_t get_byte(uint8_t* buffer, uint32_t i) { | 64 static inline uint8_t get_byte(uint8_t* buffer, uint32_t i) { |
| 73 return buffer[i]; | 65 return buffer[i]; |
| 74 } | 66 } |
| 75 | 67 |
| 76 /* | 68 /* |
| 77 * | |
| 78 * Get a short from a buffer | 69 * Get a short from a buffer |
| 79 * This method is unsafe, the caller is responsible for performing a check | 70 * This method is unsafe, the caller is responsible for performing a check |
| 80 * | |
| 81 */ | 71 */ |
| 82 static inline uint16_t get_short(uint8_t* buffer, uint32_t i) { | 72 static inline uint16_t get_short(uint8_t* buffer, uint32_t i) { |
| 83 uint16_t result; | 73 uint16_t result; |
| 84 memcpy(&result, &(buffer[i]), 2); | 74 memcpy(&result, &(buffer[i]), 2); |
| 85 #ifdef SK_CPU_BENDIAN | 75 #ifdef SK_CPU_BENDIAN |
| 86 return SkEndianSwap16(result); | 76 return SkEndianSwap16(result); |
| 87 #else | 77 #else |
| 88 return result; | 78 return result; |
| 89 #endif | 79 #endif |
| 90 } | 80 } |
| 91 | 81 |
| 92 /* | 82 /* |
| 93 * | |
| 94 * Get an int from a buffer | 83 * Get an int from a buffer |
| 95 * This method is unsafe, the caller is responsible for performing a check | 84 * This method is unsafe, the caller is responsible for performing a check |
| 96 * | |
| 97 */ | 85 */ |
| 98 static inline uint32_t get_int(uint8_t* buffer, uint32_t i) { | 86 static inline uint32_t get_int(uint8_t* buffer, uint32_t i) { |
| 99 uint32_t result; | 87 uint32_t result; |
| 100 memcpy(&result, &(buffer[i]), 4); | 88 memcpy(&result, &(buffer[i]), 4); |
| 101 #ifdef SK_CPU_BENDIAN | 89 #ifdef SK_CPU_BENDIAN |
| 102 return SkEndianSwap32(result); | 90 return SkEndianSwap32(result); |
| 103 #else | 91 #else |
| 104 return result; | 92 return result; |
| 105 #endif | 93 #endif |
| 106 } | 94 } |
| 107 | 95 |
| 108 #endif // SkCodecPriv_DEFINED | 96 #endif // SkCodecPriv_DEFINED |
| OLD | NEW |