diff options
author | 2016-02-05 11:18:39 -0800 | |
---|---|---|
committer | 2016-02-05 11:18:39 -0800 | |
commit | 3601f280dc400cb75167393b0a2b6670b5f25ea4 (patch) | |
tree | a8aa9ff7658b049ca0aec0ea1729921122fe22d0 /include | |
parent | 06604b95622359640a1c2028b885646deda28d52 (diff) |
add kRGBA_F16_SkColorType
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1666343002
Review URL: https://codereview.chromium.org/1666343002
Diffstat (limited to 'include')
-rw-r--r-- | include/core/SkColor.h | 5 | ||||
-rw-r--r-- | include/core/SkImageInfo.h | 5 | ||||
-rw-r--r-- | include/core/SkPixmap.h | 59 |
3 files changed, 51 insertions, 18 deletions
diff --git a/include/core/SkColor.h b/include/core/SkColor.h index 90453f548c..b1571c7009 100644 --- a/include/core/SkColor.h +++ b/include/core/SkColor.h @@ -180,6 +180,11 @@ struct SkPM4f { static SkPM4f FromPMColor(SkPMColor); + // half-float routines + void toF16(uint16_t[4]) const; + uint64_t toF16() const; // 4 float16 values packed into uint64_t + static SkPM4f FromF16(const uint16_t[4]); + #ifdef SK_DEBUG void assertIsUnit() const; #else diff --git a/include/core/SkImageInfo.h b/include/core/SkImageInfo.h index 4b82ae6e2f..b2dda3f021 100644 --- a/include/core/SkImageInfo.h +++ b/include/core/SkImageInfo.h @@ -73,8 +73,9 @@ enum SkColorType { kBGRA_8888_SkColorType, kIndex_8_SkColorType, kGray_8_SkColorType, + kRGBA_F16_SkColorType, - kLastEnum_SkColorType = kGray_8_SkColorType, + kLastEnum_SkColorType = kRGBA_F16_SkColorType, #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A) kN32_SkColorType = kBGRA_8888_SkColorType, @@ -95,6 +96,7 @@ static int SkColorTypeBytesPerPixel(SkColorType ct) { 4, // BGRA_8888 1, // kIndex_8 1, // kGray_8 + 8, // kRGBA_F16 }; static_assert(SK_ARRAY_COUNT(gSize) == (size_t)(kLastEnum_SkColorType + 1), "size_mismatch_with_SkColorType_enum"); @@ -114,6 +116,7 @@ static inline bool SkColorTypeIsValid(unsigned value) { static inline size_t SkColorTypeComputeOffset(SkColorType ct, int x, int y, size_t rowBytes) { int shift = 0; switch (SkColorTypeBytesPerPixel(ct)) { + case 8: shift = 3; break; case 4: shift = 2; break; case 2: shift = 1; break; case 1: shift = 0; break; diff --git a/include/core/SkPixmap.h b/include/core/SkPixmap.h index 523c40f294..894b238196 100644 --- a/include/core/SkPixmap.h +++ b/include/core/SkPixmap.h @@ -75,51 +75,75 @@ public: uint64_t getSafeSize64() const { return fInfo.getSafeSize64(fRowBytes); } size_t getSafeSize() const { return fInfo.getSafeSize(fRowBytes); } + const void* addr(int x, int y) const { + return (const char*)fPixels + fInfo.computeOffset(x, y, fRowBytes); + } + const uint8_t* addr8() const { + SkASSERT(1 == SkColorTypeBytesPerPixel(fInfo.colorType())); + return reinterpret_cast<const uint8_t*>(fPixels); + } + const uint16_t* addr16() const { + SkASSERT(2 == SkColorTypeBytesPerPixel(fInfo.colorType())); + return reinterpret_cast<const uint16_t*>(fPixels); + } const uint32_t* addr32() const { SkASSERT(4 == SkColorTypeBytesPerPixel(fInfo.colorType())); return reinterpret_cast<const uint32_t*>(fPixels); } - - const uint16_t* addr16() const { - SkASSERT(2 == SkColorTypeBytesPerPixel(fInfo.colorType())); + const uint64_t* addr64() const { + SkASSERT(8 == SkColorTypeBytesPerPixel(fInfo.colorType())); + return reinterpret_cast<const uint64_t*>(fPixels); + } + const uint16_t* addrF16() const { + SkASSERT(8 == SkColorTypeBytesPerPixel(fInfo.colorType())); + SkASSERT(kRGBA_F16_SkColorType == fInfo.colorType()); return reinterpret_cast<const uint16_t*>(fPixels); } - const uint8_t* addr8() const { - SkASSERT(1 == SkColorTypeBytesPerPixel(fInfo.colorType())); - return reinterpret_cast<const uint8_t*>(fPixels); - } + // Offset by the specified x,y coordinates - const uint32_t* addr32(int x, int y) const { + const uint8_t* addr8(int x, int y) const { SkASSERT((unsigned)x < (unsigned)fInfo.width()); SkASSERT((unsigned)y < (unsigned)fInfo.height()); - return (const uint32_t*)((const char*)this->addr32() + y * fRowBytes + (x << 2)); + return (const uint8_t*)((const char*)this->addr8() + y * fRowBytes + (x << 0)); } const uint16_t* addr16(int x, int y) const { SkASSERT((unsigned)x < (unsigned)fInfo.width()); SkASSERT((unsigned)y < (unsigned)fInfo.height()); return (const uint16_t*)((const char*)this->addr16() + y * fRowBytes + (x << 1)); } - const uint8_t* addr8(int x, int y) const { + const uint32_t* addr32(int x, int y) const { SkASSERT((unsigned)x < (unsigned)fInfo.width()); SkASSERT((unsigned)y < (unsigned)fInfo.height()); - return (const uint8_t*)((const char*)this->addr8() + y * fRowBytes + (x << 0)); + return (const uint32_t*)((const char*)this->addr32() + y * fRowBytes + (x << 2)); } - const void* addr(int x, int y) const { - return (const char*)fPixels + fInfo.computeOffset(x, y, fRowBytes); + const uint64_t* addr64(int x, int y) const { + SkASSERT((unsigned)x < (unsigned)fInfo.width()); + SkASSERT((unsigned)y < (unsigned)fInfo.height()); + return (const uint64_t*)((const char*)this->addr64() + y * fRowBytes + (x << 3)); + } + const uint16_t* addrF16(int x, int y) const { + SkASSERT(kRGBA_F16_SkColorType == fInfo.colorType()); + return reinterpret_cast<const uint16_t*>(this->addr64(x, y)); } // Writable versions void* writable_addr() const { return const_cast<void*>(fPixels); } - uint32_t* writable_addr32(int x, int y) const { - return const_cast<uint32_t*>(this->addr32(x, y)); + uint8_t* writable_addr8(int x, int y) const { + return const_cast<uint8_t*>(this->addr8(x, y)); } uint16_t* writable_addr16(int x, int y) const { return const_cast<uint16_t*>(this->addr16(x, y)); } - uint8_t* writable_addr8(int x, int y) const { - return const_cast<uint8_t*>(this->addr8(x, y)); + uint32_t* writable_addr32(int x, int y) const { + return const_cast<uint32_t*>(this->addr32(x, y)); + } + uint64_t* writable_addr64(int x, int y) const { + return const_cast<uint64_t*>(this->addr64(x, y)); + } + uint16_t* writable_addrF16(int x, int y) const { + return reinterpret_cast<uint16_t*>(writable_addr64(x, y)); } // copy methods @@ -152,6 +176,7 @@ public: bool erase(SkColor, const SkIRect& subset) const; bool erase(SkColor color) const { return this->erase(color, this->bounds()); } + bool erase(const SkColor4f&, const SkIRect* subset = nullptr) const; private: const void* fPixels; |