Chromium Code Reviews| Index: src/codec/SkCodecPriv.h |
| diff --git a/src/codec/SkCodecPriv.h b/src/codec/SkCodecPriv.h |
| index 90b16323a76969dc691f00844bf00963a162fbf2..c781ee1521ebaa3d4313c1bec2be52f66e20fc9f 100644 |
| --- a/src/codec/SkCodecPriv.h |
| +++ b/src/codec/SkCodecPriv.h |
| @@ -8,6 +8,7 @@ |
| #ifndef SkCodecPriv_DEFINED |
| #define SkCodecPriv_DEFINED |
| +#include "SkBmpCodec.h" |
| #include "SkColorTable.h" |
| #include "SkImageInfo.h" |
| #include "SkSwizzler.h" |
| @@ -30,10 +31,30 @@ |
| #define COMPUTE_RESULT_ALPHA \ |
| SkSwizzler::GetResult(zeroAlpha, maxAlpha); |
| +static inline bool valid_alpha(SkAlphaType dstAlpha, SkAlphaType srcAlpha) { |
|
scroggo
2015/07/31 15:05:44
Is this used by all codecs? Or just BMP?
Nvm, it
msarett
2015/08/03 22:52:35
Acknowledged :)
|
| + // Check for supported alpha types |
| + if (srcAlpha != dstAlpha) { |
| + if (kOpaque_SkAlphaType == srcAlpha) { |
| + // If the source is opaque, we must decode to opaque |
| + return false; |
| + } |
| + |
| + // The source is not opaque |
| + switch (dstAlpha) { |
| + case kPremul_SkAlphaType: |
| + case kUnpremul_SkAlphaType: |
| + // The source is not opaque, so either of these is okay |
| + break; |
| + default: |
| + // We cannot decode a non-opaque image to opaque (or unknown) |
| + return false; |
| + } |
| + } |
| + return true; |
| +} |
| + |
| /* |
| - * |
| * Copy the codec color table back to the client when kIndex8 color type is requested |
| - * |
| */ |
| static inline void copy_color_table(const SkImageInfo& dstInfo, SkColorTable* colorTable, |
| SkPMColor* inputColorPtr, int* inputColorCount) { |
| @@ -46,27 +67,21 @@ static inline void copy_color_table(const SkImageInfo& dstInfo, SkColorTable* co |
| } |
| /* |
| - * |
| * Compute row bytes for an image using pixels per byte |
| - * |
| */ |
| static inline size_t compute_row_bytes_ppb(int width, uint32_t pixelsPerByte) { |
| return (width + pixelsPerByte - 1) / pixelsPerByte; |
| } |
| /* |
| - * |
| * Compute row bytes for an image using bytes per pixel |
| - * |
| */ |
| static inline size_t compute_row_bytes_bpp(int width, uint32_t bytesPerPixel) { |
| return width * bytesPerPixel; |
| } |
| /* |
| - * |
| * Compute row bytes for an image |
| - * |
| */ |
| static inline size_t compute_row_bytes(int width, uint32_t bitsPerPixel) { |
| if (bitsPerPixel < 16) { |
| @@ -81,20 +96,26 @@ static inline size_t compute_row_bytes(int width, uint32_t bitsPerPixel) { |
| } |
| /* |
| - * |
| + * Get the destination row to start filling from |
|
scroggo
2015/07/31 15:05:44
This probably belongs in SkBmpCodec.
msarett
2015/08/03 22:52:35
Done.
|
| + * Used to fill the remainder of the image on incomplete input for bmps |
| + */ |
| +static inline void* get_dst_start_row(void* dst, size_t dstRowBytes, int32_t y, |
| + SkBmpCodec::RowOrder rowOrder) { |
| + return (SkBmpCodec::kTopDown_RowOrder == rowOrder) ? |
| + SkTAddOffset<void*>(dst, y * dstRowBytes) : dst; |
| +} |
| + |
| +/* |
| * Get a byte from a buffer |
| * This method is unsafe, the caller is responsible for performing a check |
| - * |
| */ |
| static inline uint8_t get_byte(uint8_t* buffer, uint32_t i) { |
| return buffer[i]; |
| } |
| /* |
| - * |
| * Get a short from a buffer |
| * This method is unsafe, the caller is responsible for performing a check |
| - * |
| */ |
| static inline uint16_t get_short(uint8_t* buffer, uint32_t i) { |
| uint16_t result; |
| @@ -107,10 +128,8 @@ static inline uint16_t get_short(uint8_t* buffer, uint32_t i) { |
| } |
| /* |
| - * |
| * Get an int from a buffer |
| * This method is unsafe, the caller is responsible for performing a check |
| - * |
| */ |
| static inline uint32_t get_int(uint8_t* buffer, uint32_t i) { |
| uint32_t result; |