Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2015 Google Inc. | |
| 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 SkPixmap_DEFINED | |
| 9 #define SkPixmap_DEFINED | |
| 10 | |
| 11 #include "SkImageInfo.h" | |
| 12 | |
| 13 class SkColorTable; | |
| 14 | |
| 15 class SkPixmap { | |
|
scroggo
2015/05/19 20:11:42
Comments?
It looks like this is designed to be a
reed1
2015/05/21 20:59:35
Done.
| |
| 16 public: | |
| 17 SkPixmap() | |
| 18 : fPixels(NULL), fCTable(NULL), fRowBytes(0), fInfo(SkImageInfo::MakeUnk nown(0, 0)) | |
| 19 {} | |
| 20 | |
| 21 SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes, | |
| 22 SkColorTable* ctable = NULL) | |
| 23 : fPixels(addr), fCTable(ctable), fRowBytes(rowBytes), fInfo(info) | |
| 24 { | |
| 25 if (kIndex_8_SkColorType == info.colorType()) { | |
| 26 SkASSERT(ctable); | |
| 27 } else { | |
| 28 SkASSERT(NULL == ctable); | |
| 29 } | |
| 30 } | |
| 31 | |
| 32 const SkImageInfo& info() const { return fInfo; } | |
| 33 size_t rowBytes() const { return fRowBytes; } | |
| 34 const void* addr() const { return fPixels; } | |
| 35 SkColorTable* ctable() const { return fCTable; } | |
| 36 | |
| 37 int width() const { return fInfo.width(); } | |
| 38 int height() const { return fInfo.height(); } | |
| 39 SkColorType colorType() const { return fInfo.colorType(); } | |
| 40 SkAlphaType alphaType() const { return fInfo.alphaType(); } | |
| 41 bool isOpaque() const { return fInfo.isOpaque(); } | |
| 42 | |
| 43 int64_t getSafeSize64() const { return fInfo.getSafeSize64(fRowBytes); } | |
| 44 size_t getSafeSize() const { return fInfo.getSafeSize(fRowBytes); } | |
| 45 | |
| 46 const uint32_t* addr32() const { | |
| 47 SkASSERT(4 == SkColorTypeBytesPerPixel(fInfo.colorType())); | |
| 48 return reinterpret_cast<const uint32_t*>(fPixels); | |
| 49 } | |
| 50 | |
| 51 const uint16_t* addr16() const { | |
| 52 SkASSERT(2 == SkColorTypeBytesPerPixel(fInfo.colorType())); | |
| 53 return reinterpret_cast<const uint16_t*>(fPixels); | |
| 54 } | |
| 55 | |
| 56 const uint8_t* addr8() const { | |
| 57 SkASSERT(1 == SkColorTypeBytesPerPixel(fInfo.colorType())); | |
| 58 return reinterpret_cast<const uint8_t*>(fPixels); | |
| 59 } | |
| 60 | |
| 61 const uint32_t* addr32(int x, int y) const { | |
| 62 SkASSERT((unsigned)x < (unsigned)fInfo.width()); | |
| 63 SkASSERT((unsigned)y < (unsigned)fInfo.height()); | |
| 64 return (const uint32_t*)((const char*)this->addr32() + y * fRowBytes + ( x << 2)); | |
| 65 } | |
| 66 const uint16_t* addr16(int x, int y) const { | |
| 67 SkASSERT((unsigned)x < (unsigned)fInfo.width()); | |
| 68 SkASSERT((unsigned)y < (unsigned)fInfo.height()); | |
| 69 return (const uint16_t*)((const char*)this->addr16() + y * fRowBytes + ( x << 1)); | |
| 70 } | |
| 71 const uint8_t* addr8(int x, int y) const { | |
| 72 SkASSERT((unsigned)x < (unsigned)fInfo.width()); | |
| 73 SkASSERT((unsigned)y < (unsigned)fInfo.height()); | |
| 74 return (const uint8_t*)((const char*)this->addr8() + y * fRowBytes + (x << 0)); | |
| 75 } | |
| 76 const void* addr(int x, int y) const { | |
| 77 return (const char*)fPixels + fInfo.computeOffset(x, y, fRowBytes); | |
| 78 } | |
| 79 | |
| 80 // Writable versions | |
| 81 | |
| 82 void* writable_addr() const { return const_cast<void*>(fPixels); } | |
| 83 uint32_t* writable_addr32(int x, int y) const { | |
| 84 return const_cast<uint32_t*>(this->addr32(x, y)); | |
| 85 } | |
| 86 uint16_t* writable_addr16(int x, int y) const { | |
| 87 return const_cast<uint16_t*>(this->addr16(x, y)); | |
| 88 } | |
| 89 uint8_t* writable_addr8(int x, int y) const { | |
| 90 return const_cast<uint8_t*>(this->addr8(x, y)); | |
| 91 } | |
| 92 | |
| 93 private: | |
| 94 const void* fPixels; | |
| 95 SkColorTable* fCTable; | |
| 96 size_t fRowBytes; | |
| 97 SkImageInfo fInfo; | |
| 98 }; | |
| 99 | |
| 100 #endif | |
| OLD | NEW |