Chromium Code Reviews| Index: include/core/SkImageInfo.h |
| diff --git a/include/core/SkImageInfo.h b/include/core/SkImageInfo.h |
| index 01318fd1aa95e5b64f445bcf952a2b8adadc4a88..daa50dcdb22a28fae6d4182dbe595471a0786e44 100644 |
| --- a/include/core/SkImageInfo.h |
| +++ b/include/core/SkImageInfo.h |
| @@ -111,6 +111,17 @@ static inline bool SkColorTypeIsValid(unsigned value) { |
| return value <= kLastEnum_SkColorType; |
| } |
| +static inline size_t SkColorTypeComputeOffset(SkColorType ct, int x, int y, size_t rowBytes) { |
| + int shift = 0; |
| + switch (SkColorTypeBytesPerPixel(ct)) { |
| + case 4: shift = 2; break; |
| + case 2: shift = 1; break; |
| + case 1: shift = 0; break; |
| + default: return 0; |
|
scroggo
2015/05/19 20:11:42
Should this SkASSERT(false)?
reed1
2015/05/21 20:02:00
kUnknown_SkColorType correctly should return 0
scroggo
2015/05/21 20:20:55
Right, but it seems like that is correct but not i
reed1
2015/05/21 21:19:02
This is calling SkColorTypeBytesPerPixels, which a
|
| + } |
| + return y * rowBytes + (x << shift); |
| +} |
| + |
| /////////////////////////////////////////////////////////////////////////////// |
| /** |
| @@ -247,6 +258,12 @@ public: |
| return (size_t)this->minRowBytes64(); |
| } |
| + size_t computeOffset(int x, int y, size_t rowBytes) const { |
| + SkASSERT((unsigned)x < (unsigned)fWidth); |
| + SkASSERT((unsigned)y < (unsigned)fHeight); |
| + return SkColorTypeComputeOffset(fColorType, x, y, rowBytes); |
| + } |
| + |
| bool operator==(const SkImageInfo& other) const { |
| return 0 == memcmp(this, &other, sizeof(other)); |
| } |