Index: include/codec/SkCodec.h |
diff --git a/include/codec/SkCodec.h b/include/codec/SkCodec.h |
index beb9cb97b32bdb51bed7cc4d76d24b968fe0858d..590827059c16d17bebaf89e3b238431456c246d1 100644 |
--- a/include/codec/SkCodec.h |
+++ b/include/codec/SkCodec.h |
@@ -8,6 +8,7 @@ |
#ifndef SkCodec_DEFINED |
#define SkCodec_DEFINED |
+#include "SkEndian.h" |
#include "SkImageGenerator.h" |
#include "SkImageInfo.h" |
#include "SkSize.h" |
@@ -48,6 +49,15 @@ public: |
*/ |
SkISize getScaledDimensions(float desiredScale) const; |
+ /* |
+ * |
+ * Checks if alpha types are premul and unpremul |
+ * |
+ */ |
+ static bool premul_and_unpremul(SkAlphaType dst, SkAlphaType src) { |
scroggo
2015/03/12 15:19:57
I think it'd be better if we moved all these stati
msarett
2015/03/12 18:37:46
Agreed. I didn't really think they belonged here,
|
+ return kPremul_SkAlphaType == dst && kUnpremul_SkAlphaType == src; |
+ } |
+ |
protected: |
SkCodec(const SkImageInfo&, SkStream*); |
@@ -83,6 +93,59 @@ protected: |
* kCouldNotRewind. |
*/ |
bool SK_WARN_UNUSED_RESULT rewindIfNeeded(); |
+ |
+ // Additional helper methods for subclasses |
+ |
+ /* |
+ * |
+ * Get method for the input stream |
+ * |
+ */ |
+ SkStream* stream() { |
+ return fStream.get(); |
+ } |
+ |
+ /* |
+ * |
+ * Get a byte from a buffer |
+ * This method is unsafe, the caller is responsible for performing a check |
+ * |
+ */ |
+ static 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 uint16_t get_short(uint8_t* buffer, uint32_t i) { |
+ uint16_t result; |
+ memcpy(&result, &(buffer[i]), 2); |
+#ifdef SK_CPU_BENDIAN |
+ return SkEndianSwap16(result); |
+#else |
+ return result; |
+#endif |
+ } |
+ |
+ /* |
+ * |
+ * Get an int from a buffer |
+ * This method is unsafe, the caller is responsible for performing a check |
+ * |
+ */ |
+ static uint32_t get_int(uint8_t* buffer, uint32_t i) { |
+ uint32_t result; |
+ memcpy(&result, &(buffer[i]), 4); |
+#ifdef SK_CPU_BENDIAN |
+ return SkEndianSwap32(result); |
+#else |
+ return result; |
+#endif |
+ } |
private: |
const SkImageInfo fInfo; |