OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2015 The Android Open Source Project |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #ifndef SkCodecPriv_DEFINED |
| 9 #define SkCodecPriv_DEFINED |
| 10 |
| 11 #include "SkImageInfo.h" |
| 12 #include "SkTypes.h" |
| 13 |
| 14 /* |
| 15 * |
| 16 * Helper routine for alpha result codes |
| 17 * |
| 18 */ |
| 19 #define INIT_RESULT_ALPHA \ |
| 20 uint8_t zeroAlpha = 0; \ |
| 21 uint8_t maxAlpha = 0xFF; |
| 22 |
| 23 #define UPDATE_RESULT_ALPHA(alpha) \ |
| 24 zeroAlpha |= (alpha); \ |
| 25 maxAlpha &= (alpha); |
| 26 |
| 27 #define COMPUTE_RESULT_ALPHA \ |
| 28 SkSwizzler::GetResult(zeroAlpha, maxAlpha); |
| 29 |
| 30 /* |
| 31 * |
| 32 * Compute row bytes for an image using pixels per byte |
| 33 * |
| 34 */ |
| 35 static inline size_t compute_row_bytes_ppb(int width, uint32_t pixelsPerByte) { |
| 36 return (width + pixelsPerByte - 1) / pixelsPerByte; |
| 37 } |
| 38 |
| 39 /* |
| 40 * |
| 41 * Compute row bytes for an image using bytes per pixel |
| 42 * |
| 43 */ |
| 44 static inline size_t compute_row_bytes_bpp(int width, uint32_t bytesPerPixel) { |
| 45 return width * bytesPerPixel; |
| 46 } |
| 47 |
| 48 /* |
| 49 * |
| 50 * Compute row bytes for an image |
| 51 * |
| 52 */ |
| 53 static inline size_t compute_row_bytes(int width, uint32_t bitsPerPixel) { |
| 54 if (bitsPerPixel < 16) { |
| 55 SkASSERT(0 == 8 % bitsPerPixel); |
| 56 const uint32_t pixelsPerByte = 8 / bitsPerPixel; |
| 57 return compute_row_bytes_ppb(width, pixelsPerByte); |
| 58 } else { |
| 59 SkASSERT(0 == bitsPerPixel % 8); |
| 60 const uint32_t bytesPerPixel = bitsPerPixel / 8; |
| 61 return compute_row_bytes_bpp(width, bytesPerPixel); |
| 62 } |
| 63 } |
| 64 |
| 65 /* |
| 66 * |
| 67 * Checks if alpha types are premul and unpremul |
| 68 * |
| 69 */ |
| 70 static inline bool premul_and_unpremul(SkAlphaType dst, SkAlphaType src) { |
| 71 return kPremul_SkAlphaType == dst && kUnpremul_SkAlphaType == src; |
| 72 } |
| 73 |
| 74 /* |
| 75 * |
| 76 * Get a byte from a buffer |
| 77 * This method is unsafe, the caller is responsible for performing a check |
| 78 * |
| 79 */ |
| 80 static inline uint8_t get_byte(uint8_t* buffer, uint32_t i) { |
| 81 return buffer[i]; |
| 82 } |
| 83 |
| 84 /* |
| 85 * |
| 86 * Get a short from a buffer |
| 87 * This method is unsafe, the caller is responsible for performing a check |
| 88 * |
| 89 */ |
| 90 static inline uint16_t get_short(uint8_t* buffer, uint32_t i) { |
| 91 uint16_t result; |
| 92 memcpy(&result, &(buffer[i]), 2); |
| 93 #ifdef SK_CPU_BENDIAN |
| 94 return SkEndianSwap16(result); |
| 95 #else |
| 96 return result; |
| 97 #endif |
| 98 } |
| 99 |
| 100 /* |
| 101 * |
| 102 * Get an int from a buffer |
| 103 * This method is unsafe, the caller is responsible for performing a check |
| 104 * |
| 105 */ |
| 106 static inline uint32_t get_int(uint8_t* buffer, uint32_t i) { |
| 107 uint32_t result; |
| 108 memcpy(&result, &(buffer[i]), 4); |
| 109 #ifdef SK_CPU_BENDIAN |
| 110 return SkEndianSwap32(result); |
| 111 #else |
| 112 return result; |
| 113 #endif |
| 114 } |
| 115 |
| 116 #endif // SkCodecPriv_DEFINED |
OLD | NEW |