epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2008 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 4 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 10 | #include "SkBitmap.h" |
| 11 | #include "SkColorPriv.h" |
| 12 | #include "SkDither.h" |
| 13 | #include "SkFlattenable.h" |
commit-bot@chromium.org | 6e3e422 | 2013-11-06 10:08:30 +0000 | [diff] [blame] | 14 | #include "SkImagePriv.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 15 | #include "SkMallocPixelRef.h" |
| 16 | #include "SkMask.h" |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 17 | #include "SkReadBuffer.h" |
| 18 | #include "SkWriteBuffer.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 19 | #include "SkPixelRef.h" |
| 20 | #include "SkThread.h" |
vandebo@chromium.org | 112706d | 2011-02-24 22:50:55 +0000 | [diff] [blame] | 21 | #include "SkUnPreMultiply.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 22 | #include "SkUtils.h" |
commit-bot@chromium.org | c0b7e10 | 2013-10-23 17:06:21 +0000 | [diff] [blame] | 23 | #include "SkValidationUtils.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 24 | #include "SkPackBits.h" |
| 25 | #include <new> |
| 26 | |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 27 | static bool reset_return_false(SkBitmap* bm) { |
| 28 | bm->reset(); |
| 29 | return false; |
| 30 | } |
| 31 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 32 | SkBitmap::SkBitmap() { |
reed@android.com | 4516f47 | 2009-06-29 16:25:36 +0000 | [diff] [blame] | 33 | sk_bzero(this, sizeof(*this)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | SkBitmap::SkBitmap(const SkBitmap& src) { |
| 37 | SkDEBUGCODE(src.validate();) |
reed@android.com | 4516f47 | 2009-06-29 16:25:36 +0000 | [diff] [blame] | 38 | sk_bzero(this, sizeof(*this)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 39 | *this = src; |
| 40 | SkDEBUGCODE(this->validate();) |
| 41 | } |
| 42 | |
| 43 | SkBitmap::~SkBitmap() { |
| 44 | SkDEBUGCODE(this->validate();) |
| 45 | this->freePixels(); |
| 46 | } |
| 47 | |
| 48 | SkBitmap& SkBitmap::operator=(const SkBitmap& src) { |
| 49 | if (this != &src) { |
| 50 | this->freePixels(); |
| 51 | memcpy(this, &src, sizeof(src)); |
| 52 | |
| 53 | // inc src reference counts |
reed@android.com | 83f7bc3 | 2009-07-17 02:42:41 +0000 | [diff] [blame] | 54 | SkSafeRef(src.fPixelRef); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 55 | |
| 56 | // we reset our locks if we get blown away |
| 57 | fPixelLockCount = 0; |
weita@google.com | f9ab99a | 2009-05-03 18:23:30 +0000 | [diff] [blame] | 58 | |
reed@google.com | 5f62ed7 | 2014-01-15 19:59:45 +0000 | [diff] [blame] | 59 | if (fPixelRef) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 60 | // ignore the values from the memcpy |
| 61 | fPixels = NULL; |
| 62 | fColorTable = NULL; |
bsalomon@google.com | 586f48c | 2011-04-14 15:07:22 +0000 | [diff] [blame] | 63 | // Note that what to for genID is somewhat arbitrary. We have no |
| 64 | // way to track changes to raw pixels across multiple SkBitmaps. |
| 65 | // Would benefit from an SkRawPixelRef type created by |
| 66 | // setPixels. |
| 67 | // Just leave the memcpy'ed one but they'll get out of sync |
| 68 | // as soon either is modified. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 69 | } |
| 70 | } |
| 71 | |
| 72 | SkDEBUGCODE(this->validate();) |
| 73 | return *this; |
| 74 | } |
| 75 | |
| 76 | void SkBitmap::swap(SkBitmap& other) { |
bsalomon@google.com | 586f48c | 2011-04-14 15:07:22 +0000 | [diff] [blame] | 77 | SkTSwap(fColorTable, other.fColorTable); |
| 78 | SkTSwap(fPixelRef, other.fPixelRef); |
reed@google.com | 672588b | 2014-01-08 15:42:01 +0000 | [diff] [blame] | 79 | SkTSwap(fPixelRefOrigin, other.fPixelRefOrigin); |
bsalomon@google.com | 586f48c | 2011-04-14 15:07:22 +0000 | [diff] [blame] | 80 | SkTSwap(fPixelLockCount, other.fPixelLockCount); |
bsalomon@google.com | 586f48c | 2011-04-14 15:07:22 +0000 | [diff] [blame] | 81 | SkTSwap(fPixels, other.fPixels); |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 82 | SkTSwap(fInfo, other.fInfo); |
bsalomon@google.com | 586f48c | 2011-04-14 15:07:22 +0000 | [diff] [blame] | 83 | SkTSwap(fRowBytes, other.fRowBytes); |
bsalomon@google.com | 586f48c | 2011-04-14 15:07:22 +0000 | [diff] [blame] | 84 | SkTSwap(fFlags, other.fFlags); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 85 | |
| 86 | SkDEBUGCODE(this->validate();) |
| 87 | } |
| 88 | |
| 89 | void SkBitmap::reset() { |
| 90 | this->freePixels(); |
reed@android.com | 4516f47 | 2009-06-29 16:25:36 +0000 | [diff] [blame] | 91 | sk_bzero(this, sizeof(*this)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 92 | } |
| 93 | |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 94 | SkBitmap::Config SkBitmap::config() const { |
| 95 | return SkColorTypeToBitmapConfig(fInfo.colorType()); |
| 96 | } |
| 97 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 98 | int SkBitmap::ComputeBytesPerPixel(SkBitmap::Config config) { |
| 99 | int bpp; |
| 100 | switch (config) { |
| 101 | case kNo_Config: |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 102 | bpp = 0; // not applicable |
| 103 | break; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 104 | case kA8_Config: |
| 105 | case kIndex8_Config: |
| 106 | bpp = 1; |
| 107 | break; |
| 108 | case kRGB_565_Config: |
| 109 | case kARGB_4444_Config: |
| 110 | bpp = 2; |
| 111 | break; |
| 112 | case kARGB_8888_Config: |
| 113 | bpp = 4; |
| 114 | break; |
| 115 | default: |
tomhudson@google.com | 0c00f21 | 2011-12-28 14:59:50 +0000 | [diff] [blame] | 116 | SkDEBUGFAIL("unknown config"); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 117 | bpp = 0; // error |
| 118 | break; |
| 119 | } |
| 120 | return bpp; |
| 121 | } |
| 122 | |
scroggo@google.com | 0ba4bf4 | 2013-02-25 16:02:36 +0000 | [diff] [blame] | 123 | size_t SkBitmap::ComputeRowBytes(Config c, int width) { |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 124 | return SkColorTypeMinRowBytes(SkBitmapConfigToColorType(c), width); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 125 | } |
| 126 | |
reed@google.com | 57212f9 | 2013-12-30 14:40:38 +0000 | [diff] [blame] | 127 | int64_t SkBitmap::ComputeSize64(Config config, int width, int height) { |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 128 | SkColorType ct = SkBitmapConfigToColorType(config); |
| 129 | int64_t rowBytes = sk_64_mul(SkColorTypeBytesPerPixel(ct), width); |
reed@google.com | 57212f9 | 2013-12-30 14:40:38 +0000 | [diff] [blame] | 130 | return rowBytes * height; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | size_t SkBitmap::ComputeSize(Config c, int width, int height) { |
reed@google.com | 57212f9 | 2013-12-30 14:40:38 +0000 | [diff] [blame] | 134 | int64_t size = SkBitmap::ComputeSize64(c, width, height); |
| 135 | return sk_64_isS32(size) ? sk_64_asS32(size) : 0; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 136 | } |
| 137 | |
reed@google.com | 57212f9 | 2013-12-30 14:40:38 +0000 | [diff] [blame] | 138 | int64_t SkBitmap::ComputeSafeSize64(Config config, |
| 139 | uint32_t width, |
| 140 | uint32_t height, |
| 141 | size_t rowBytes) { |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 142 | SkImageInfo info = SkImageInfo::Make(width, height, |
| 143 | SkBitmapConfigToColorType(config), |
| 144 | kPremul_SkAlphaType); |
| 145 | return info.getSafeSize64(rowBytes); |
wjmaclean@chromium.org | 86bff1f | 2010-11-16 20:22:41 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | size_t SkBitmap::ComputeSafeSize(Config config, |
| 149 | uint32_t width, |
| 150 | uint32_t height, |
scroggo@google.com | 0ba4bf4 | 2013-02-25 16:02:36 +0000 | [diff] [blame] | 151 | size_t rowBytes) { |
reed@google.com | 57212f9 | 2013-12-30 14:40:38 +0000 | [diff] [blame] | 152 | int64_t safeSize = ComputeSafeSize64(config, width, height, rowBytes); |
| 153 | int32_t safeSize32 = (int32_t)safeSize; |
skia.committer@gmail.com | f5e1f63 | 2013-12-31 07:01:36 +0000 | [diff] [blame] | 154 | |
reed@google.com | 57212f9 | 2013-12-30 14:40:38 +0000 | [diff] [blame] | 155 | if (safeSize32 != safeSize) { |
| 156 | safeSize32 = 0; |
| 157 | } |
| 158 | return safeSize32; |
wjmaclean@chromium.org | 86bff1f | 2010-11-16 20:22:41 +0000 | [diff] [blame] | 159 | } |
| 160 | |
reed@google.com | 86b2e43 | 2012-03-15 21:17:03 +0000 | [diff] [blame] | 161 | void SkBitmap::getBounds(SkRect* bounds) const { |
| 162 | SkASSERT(bounds); |
| 163 | bounds->set(0, 0, |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 164 | SkIntToScalar(fInfo.fWidth), SkIntToScalar(fInfo.fHeight)); |
reed@google.com | 86b2e43 | 2012-03-15 21:17:03 +0000 | [diff] [blame] | 165 | } |
| 166 | |
reed@google.com | 80e1459 | 2012-03-16 14:58:07 +0000 | [diff] [blame] | 167 | void SkBitmap::getBounds(SkIRect* bounds) const { |
| 168 | SkASSERT(bounds); |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 169 | bounds->set(0, 0, fInfo.fWidth, fInfo.fHeight); |
reed@google.com | 80e1459 | 2012-03-16 14:58:07 +0000 | [diff] [blame] | 170 | } |
| 171 | |
reed@google.com | 86b2e43 | 2012-03-15 21:17:03 +0000 | [diff] [blame] | 172 | /////////////////////////////////////////////////////////////////////////////// |
| 173 | |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 174 | static bool validate_alphaType(SkColorType colorType, SkAlphaType alphaType, |
commit-bot@chromium.org | c0b7e10 | 2013-10-23 17:06:21 +0000 | [diff] [blame] | 175 | SkAlphaType* canonical = NULL) { |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 176 | switch (colorType) { |
| 177 | case kUnknown_SkColorType: |
reed@google.com | 383a697 | 2013-10-21 14:00:07 +0000 | [diff] [blame] | 178 | alphaType = kIgnore_SkAlphaType; |
| 179 | break; |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 180 | case kAlpha_8_SkColorType: |
reed@google.com | 383a697 | 2013-10-21 14:00:07 +0000 | [diff] [blame] | 181 | if (kUnpremul_SkAlphaType == alphaType) { |
| 182 | alphaType = kPremul_SkAlphaType; |
| 183 | } |
| 184 | // fall-through |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 185 | case kIndex_8_SkColorType: |
| 186 | case kARGB_4444_SkColorType: |
| 187 | case kRGBA_8888_SkColorType: |
| 188 | case kBGRA_8888_SkColorType: |
reed@google.com | 383a697 | 2013-10-21 14:00:07 +0000 | [diff] [blame] | 189 | if (kIgnore_SkAlphaType == alphaType) { |
| 190 | return false; |
| 191 | } |
| 192 | break; |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 193 | case kRGB_565_SkColorType: |
reed@google.com | 383a697 | 2013-10-21 14:00:07 +0000 | [diff] [blame] | 194 | alphaType = kOpaque_SkAlphaType; |
| 195 | break; |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 196 | default: |
| 197 | return false; |
reed@android.com | 149e2f6 | 2009-05-22 14:39:03 +0000 | [diff] [blame] | 198 | } |
reed@google.com | 383a697 | 2013-10-21 14:00:07 +0000 | [diff] [blame] | 199 | if (canonical) { |
| 200 | *canonical = alphaType; |
| 201 | } |
| 202 | return true; |
| 203 | } |
reed@android.com | 149e2f6 | 2009-05-22 14:39:03 +0000 | [diff] [blame] | 204 | |
commit-bot@chromium.org | a3264e5 | 2014-05-30 13:26:10 +0000 | [diff] [blame] | 205 | bool SkBitmap::setInfo(const SkImageInfo& origInfo, size_t rowBytes) { |
commit-bot@chromium.org | d5414e5 | 2014-02-13 22:30:38 +0000 | [diff] [blame] | 206 | SkImageInfo info = origInfo; |
| 207 | |
| 208 | if (!validate_alphaType(info.fColorType, info.fAlphaType, |
| 209 | &info.fAlphaType)) { |
| 210 | return reset_return_false(this); |
| 211 | } |
skia.committer@gmail.com | 02d6f54 | 2014-02-14 03:02:05 +0000 | [diff] [blame] | 212 | |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 213 | // require that rowBytes fit in 31bits |
| 214 | int64_t mrb = info.minRowBytes64(); |
| 215 | if ((int32_t)mrb != mrb) { |
| 216 | return reset_return_false(this); |
reed@google.com | 383a697 | 2013-10-21 14:00:07 +0000 | [diff] [blame] | 217 | } |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 218 | if ((int64_t)rowBytes != (int32_t)rowBytes) { |
| 219 | return reset_return_false(this); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 220 | } |
reed@android.com | 89bb83a | 2009-05-29 21:30:42 +0000 | [diff] [blame] | 221 | |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 222 | if (info.width() < 0 || info.height() < 0) { |
| 223 | return reset_return_false(this); |
| 224 | } |
| 225 | |
| 226 | if (kUnknown_SkColorType == info.colorType()) { |
| 227 | rowBytes = 0; |
| 228 | } else if (0 == rowBytes) { |
| 229 | rowBytes = (size_t)mrb; |
| 230 | } else if (rowBytes < info.minRowBytes()) { |
| 231 | return reset_return_false(this); |
reed@google.com | 383a697 | 2013-10-21 14:00:07 +0000 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | this->freePixels(); |
| 235 | |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 236 | fInfo = info; |
| 237 | fRowBytes = SkToU32(rowBytes); |
reed@google.com | 383a697 | 2013-10-21 14:00:07 +0000 | [diff] [blame] | 238 | return true; |
reed@google.com | 383a697 | 2013-10-21 14:00:07 +0000 | [diff] [blame] | 239 | } |
| 240 | |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 241 | bool SkBitmap::setConfig(Config config, int width, int height, size_t rowBytes, |
| 242 | SkAlphaType alphaType) { |
| 243 | SkColorType ct = SkBitmapConfigToColorType(config); |
commit-bot@chromium.org | a3264e5 | 2014-05-30 13:26:10 +0000 | [diff] [blame] | 244 | return this->setInfo(SkImageInfo::Make(width, height, ct, alphaType), rowBytes); |
commit-bot@chromium.org | 6e3e422 | 2013-11-06 10:08:30 +0000 | [diff] [blame] | 245 | } |
| 246 | |
reed@google.com | 383a697 | 2013-10-21 14:00:07 +0000 | [diff] [blame] | 247 | bool SkBitmap::setAlphaType(SkAlphaType alphaType) { |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 248 | if (!validate_alphaType(fInfo.fColorType, alphaType, &alphaType)) { |
reed@google.com | 383a697 | 2013-10-21 14:00:07 +0000 | [diff] [blame] | 249 | return false; |
| 250 | } |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 251 | if (fInfo.fAlphaType != alphaType) { |
| 252 | fInfo.fAlphaType = alphaType; |
commit-bot@chromium.org | 0e8d0d6 | 2014-01-27 15:41:07 +0000 | [diff] [blame] | 253 | if (fPixelRef) { |
reed@google.com | c1587f9 | 2014-01-28 16:05:39 +0000 | [diff] [blame] | 254 | fPixelRef->changeAlphaType(alphaType); |
commit-bot@chromium.org | 0e8d0d6 | 2014-01-27 15:41:07 +0000 | [diff] [blame] | 255 | } |
| 256 | } |
reed@google.com | 383a697 | 2013-10-21 14:00:07 +0000 | [diff] [blame] | 257 | return true; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | void SkBitmap::updatePixelsFromRef() const { |
| 261 | if (NULL != fPixelRef) { |
| 262 | if (fPixelLockCount > 0) { |
reed@google.com | ff0da4f | 2012-05-17 13:14:52 +0000 | [diff] [blame] | 263 | SkASSERT(fPixelRef->isLocked()); |
weita@google.com | f9ab99a | 2009-05-03 18:23:30 +0000 | [diff] [blame] | 264 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 265 | void* p = fPixelRef->pixels(); |
| 266 | if (NULL != p) { |
reed@google.com | 672588b | 2014-01-08 15:42:01 +0000 | [diff] [blame] | 267 | p = (char*)p |
reed@google.com | 303c475 | 2014-01-09 20:00:14 +0000 | [diff] [blame] | 268 | + fPixelRefOrigin.fY * fRowBytes |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 269 | + fPixelRefOrigin.fX * fInfo.bytesPerPixel(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 270 | } |
| 271 | fPixels = p; |
reed@google.com | 5f62ed7 | 2014-01-15 19:59:45 +0000 | [diff] [blame] | 272 | fColorTable = fPixelRef->colorTable(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 273 | } else { |
| 274 | SkASSERT(0 == fPixelLockCount); |
| 275 | fPixels = NULL; |
reed@google.com | 5f62ed7 | 2014-01-15 19:59:45 +0000 | [diff] [blame] | 276 | fColorTable = NULL; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 277 | } |
| 278 | } |
| 279 | } |
| 280 | |
reed@google.com | 9230ea2 | 2013-12-09 22:01:03 +0000 | [diff] [blame] | 281 | static bool config_to_colorType(SkBitmap::Config config, SkColorType* ctOut) { |
| 282 | SkColorType ct; |
| 283 | switch (config) { |
| 284 | case SkBitmap::kA8_Config: |
| 285 | ct = kAlpha_8_SkColorType; |
| 286 | break; |
| 287 | case SkBitmap::kIndex8_Config: |
| 288 | ct = kIndex_8_SkColorType; |
| 289 | break; |
| 290 | case SkBitmap::kRGB_565_Config: |
| 291 | ct = kRGB_565_SkColorType; |
| 292 | break; |
| 293 | case SkBitmap::kARGB_4444_Config: |
| 294 | ct = kARGB_4444_SkColorType; |
| 295 | break; |
| 296 | case SkBitmap::kARGB_8888_Config: |
commit-bot@chromium.org | 28fcae2 | 2014-04-11 17:15:40 +0000 | [diff] [blame] | 297 | ct = kN32_SkColorType; |
reed@google.com | 9230ea2 | 2013-12-09 22:01:03 +0000 | [diff] [blame] | 298 | break; |
| 299 | case SkBitmap::kNo_Config: |
| 300 | default: |
| 301 | return false; |
| 302 | } |
| 303 | if (ctOut) { |
| 304 | *ctOut = ct; |
| 305 | } |
| 306 | return true; |
| 307 | } |
| 308 | |
reed@google.com | 672588b | 2014-01-08 15:42:01 +0000 | [diff] [blame] | 309 | SkPixelRef* SkBitmap::setPixelRef(SkPixelRef* pr, int dx, int dy) { |
reed@google.com | dcea530 | 2014-01-03 13:43:01 +0000 | [diff] [blame] | 310 | #ifdef SK_DEBUG |
reed@google.com | 672588b | 2014-01-08 15:42:01 +0000 | [diff] [blame] | 311 | if (pr) { |
commit-bot@chromium.org | 466f5f3 | 2014-05-27 21:30:37 +0000 | [diff] [blame] | 312 | if (kUnknown_SkColorType != fInfo.colorType()) { |
reed@google.com | dcea530 | 2014-01-03 13:43:01 +0000 | [diff] [blame] | 313 | const SkImageInfo& prInfo = pr->info(); |
commit-bot@chromium.org | 466f5f3 | 2014-05-27 21:30:37 +0000 | [diff] [blame] | 314 | SkASSERT(fInfo.fWidth <= prInfo.fWidth); |
| 315 | SkASSERT(fInfo.fHeight <= prInfo.fHeight); |
| 316 | SkASSERT(fInfo.fColorType == prInfo.fColorType); |
reed@google.com | dcea530 | 2014-01-03 13:43:01 +0000 | [diff] [blame] | 317 | switch (prInfo.fAlphaType) { |
| 318 | case kIgnore_SkAlphaType: |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 319 | SkASSERT(fInfo.fAlphaType == kIgnore_SkAlphaType); |
reed@google.com | dcea530 | 2014-01-03 13:43:01 +0000 | [diff] [blame] | 320 | break; |
| 321 | case kOpaque_SkAlphaType: |
| 322 | case kPremul_SkAlphaType: |
commit-bot@chromium.org | 466f5f3 | 2014-05-27 21:30:37 +0000 | [diff] [blame] | 323 | SkASSERT(fInfo.fAlphaType == kOpaque_SkAlphaType || |
| 324 | fInfo.fAlphaType == kPremul_SkAlphaType); |
reed@google.com | dcea530 | 2014-01-03 13:43:01 +0000 | [diff] [blame] | 325 | break; |
| 326 | case kUnpremul_SkAlphaType: |
commit-bot@chromium.org | 466f5f3 | 2014-05-27 21:30:37 +0000 | [diff] [blame] | 327 | SkASSERT(fInfo.fAlphaType == kOpaque_SkAlphaType || |
| 328 | fInfo.fAlphaType == kUnpremul_SkAlphaType); |
reed@google.com | dcea530 | 2014-01-03 13:43:01 +0000 | [diff] [blame] | 329 | break; |
| 330 | } |
| 331 | } |
| 332 | } |
| 333 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 334 | |
reed@google.com | 672588b | 2014-01-08 15:42:01 +0000 | [diff] [blame] | 335 | if (pr) { |
| 336 | const SkImageInfo& info = pr->info(); |
| 337 | fPixelRefOrigin.set(SkPin32(dx, 0, info.fWidth), |
| 338 | SkPin32(dy, 0, info.fHeight)); |
| 339 | } else { |
| 340 | // ignore dx,dy if there is no pixelref |
| 341 | fPixelRefOrigin.setZero(); |
| 342 | } |
| 343 | |
| 344 | if (fPixelRef != pr) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 345 | if (fPixelRef != pr) { |
| 346 | this->freePixels(); |
| 347 | SkASSERT(NULL == fPixelRef); |
weita@google.com | f9ab99a | 2009-05-03 18:23:30 +0000 | [diff] [blame] | 348 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 349 | SkSafeRef(pr); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 350 | fPixelRef = pr; |
| 351 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 352 | this->updatePixelsFromRef(); |
| 353 | } |
| 354 | |
| 355 | SkDEBUGCODE(this->validate();) |
| 356 | return pr; |
| 357 | } |
| 358 | |
| 359 | void SkBitmap::lockPixels() const { |
djsollen@google.com | 7c6d264 | 2013-08-06 12:19:38 +0000 | [diff] [blame] | 360 | if (NULL != fPixelRef && 0 == sk_atomic_inc(&fPixelLockCount)) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 361 | fPixelRef->lockPixels(); |
| 362 | this->updatePixelsFromRef(); |
| 363 | } |
| 364 | SkDEBUGCODE(this->validate();) |
| 365 | } |
| 366 | |
| 367 | void SkBitmap::unlockPixels() const { |
| 368 | SkASSERT(NULL == fPixelRef || fPixelLockCount > 0); |
| 369 | |
djsollen@google.com | 7c6d264 | 2013-08-06 12:19:38 +0000 | [diff] [blame] | 370 | if (NULL != fPixelRef && 1 == sk_atomic_dec(&fPixelLockCount)) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 371 | fPixelRef->unlockPixels(); |
| 372 | this->updatePixelsFromRef(); |
| 373 | } |
| 374 | SkDEBUGCODE(this->validate();) |
| 375 | } |
| 376 | |
reed@google.com | 9c49bc3 | 2011-07-07 13:42:37 +0000 | [diff] [blame] | 377 | bool SkBitmap::lockPixelsAreWritable() const { |
djsollen@google.com | c84b833 | 2012-07-27 13:41:44 +0000 | [diff] [blame] | 378 | return (fPixelRef) ? fPixelRef->lockPixelsAreWritable() : false; |
reed@google.com | 9c49bc3 | 2011-07-07 13:42:37 +0000 | [diff] [blame] | 379 | } |
| 380 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 381 | void SkBitmap::setPixels(void* p, SkColorTable* ctable) { |
reed@google.com | 8e1034e | 2012-07-30 13:16:35 +0000 | [diff] [blame] | 382 | if (NULL == p) { |
reed@google.com | 672588b | 2014-01-08 15:42:01 +0000 | [diff] [blame] | 383 | this->setPixelRef(NULL); |
reed@google.com | 8e1034e | 2012-07-30 13:16:35 +0000 | [diff] [blame] | 384 | return; |
| 385 | } |
| 386 | |
commit-bot@chromium.org | 466f5f3 | 2014-05-27 21:30:37 +0000 | [diff] [blame] | 387 | if (kUnknown_SkColorType == fInfo.colorType()) { |
reed@google.com | 672588b | 2014-01-08 15:42:01 +0000 | [diff] [blame] | 388 | this->setPixelRef(NULL); |
reed@google.com | bf79023 | 2013-12-13 19:45:58 +0000 | [diff] [blame] | 389 | return; |
| 390 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 391 | |
commit-bot@chromium.org | 466f5f3 | 2014-05-27 21:30:37 +0000 | [diff] [blame] | 392 | SkPixelRef* pr = SkMallocPixelRef::NewDirect(fInfo, p, fRowBytes, ctable); |
reed@google.com | bf79023 | 2013-12-13 19:45:58 +0000 | [diff] [blame] | 393 | if (NULL == pr) { |
reed@google.com | 672588b | 2014-01-08 15:42:01 +0000 | [diff] [blame] | 394 | this->setPixelRef(NULL); |
reed@google.com | bf79023 | 2013-12-13 19:45:58 +0000 | [diff] [blame] | 395 | return; |
| 396 | } |
| 397 | |
| 398 | this->setPixelRef(pr)->unref(); |
| 399 | |
djsollen@google.com | c84b833 | 2012-07-27 13:41:44 +0000 | [diff] [blame] | 400 | // since we're already allocated, we lockPixels right away |
| 401 | this->lockPixels(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 402 | SkDEBUGCODE(this->validate();) |
| 403 | } |
| 404 | |
| 405 | bool SkBitmap::allocPixels(Allocator* allocator, SkColorTable* ctable) { |
| 406 | HeapAllocator stdalloc; |
skia.committer@gmail.com | d2ac07b | 2014-01-25 07:01:49 +0000 | [diff] [blame] | 407 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 408 | if (NULL == allocator) { |
| 409 | allocator = &stdalloc; |
| 410 | } |
| 411 | return allocator->allocPixelRef(this, ctable); |
| 412 | } |
| 413 | |
reed@google.com | 9ebcac5 | 2014-01-24 18:53:42 +0000 | [diff] [blame] | 414 | /////////////////////////////////////////////////////////////////////////////// |
| 415 | |
reed@google.com | 9ebcac5 | 2014-01-24 18:53:42 +0000 | [diff] [blame] | 416 | bool SkBitmap::allocPixels(const SkImageInfo& info, SkPixelRefFactory* factory, |
| 417 | SkColorTable* ctable) { |
| 418 | if (kIndex_8_SkColorType == info.fColorType && NULL == ctable) { |
| 419 | return reset_return_false(this); |
| 420 | } |
commit-bot@chromium.org | a3264e5 | 2014-05-30 13:26:10 +0000 | [diff] [blame] | 421 | if (!this->setInfo(info)) { |
reed@google.com | 9ebcac5 | 2014-01-24 18:53:42 +0000 | [diff] [blame] | 422 | return reset_return_false(this); |
| 423 | } |
| 424 | |
| 425 | SkMallocPixelRef::PRFactory defaultFactory; |
| 426 | if (NULL == factory) { |
| 427 | factory = &defaultFactory; |
| 428 | } |
skia.committer@gmail.com | d2ac07b | 2014-01-25 07:01:49 +0000 | [diff] [blame] | 429 | |
reed@google.com | 9ebcac5 | 2014-01-24 18:53:42 +0000 | [diff] [blame] | 430 | SkPixelRef* pr = factory->create(info, ctable); |
| 431 | if (NULL == pr) { |
| 432 | return reset_return_false(this); |
| 433 | } |
| 434 | this->setPixelRef(pr)->unref(); |
| 435 | |
| 436 | // TODO: lockPixels could/should return bool or void*/NULL |
| 437 | this->lockPixels(); |
| 438 | if (NULL == this->getPixels()) { |
| 439 | return reset_return_false(this); |
| 440 | } |
| 441 | return true; |
| 442 | } |
| 443 | |
commit-bot@chromium.org | 00f8d6c | 2014-05-29 15:57:20 +0000 | [diff] [blame] | 444 | bool SkBitmap::installPixels(const SkImageInfo& info, void* pixels, size_t rb, SkColorTable* ct, |
| 445 | void (*releaseProc)(void* addr, void* context), void* context) { |
commit-bot@chromium.org | a3264e5 | 2014-05-30 13:26:10 +0000 | [diff] [blame] | 446 | if (!this->setInfo(info, rb)) { |
reed@google.com | 9ebcac5 | 2014-01-24 18:53:42 +0000 | [diff] [blame] | 447 | this->reset(); |
| 448 | return false; |
| 449 | } |
| 450 | |
commit-bot@chromium.org | 00f8d6c | 2014-05-29 15:57:20 +0000 | [diff] [blame] | 451 | SkPixelRef* pr = SkMallocPixelRef::NewWithProc(info, rb, ct, pixels, releaseProc, context); |
reed@google.com | 9ebcac5 | 2014-01-24 18:53:42 +0000 | [diff] [blame] | 452 | if (!pr) { |
| 453 | this->reset(); |
| 454 | return false; |
| 455 | } |
| 456 | |
| 457 | this->setPixelRef(pr)->unref(); |
mike@reedtribe.org | 6e58cf3 | 2014-02-16 20:54:21 +0000 | [diff] [blame] | 458 | |
| 459 | // since we're already allocated, we lockPixels right away |
| 460 | this->lockPixels(); |
mike@reedtribe.org | 6e58cf3 | 2014-02-16 20:54:21 +0000 | [diff] [blame] | 461 | SkDEBUGCODE(this->validate();) |
reed@google.com | 9ebcac5 | 2014-01-24 18:53:42 +0000 | [diff] [blame] | 462 | return true; |
| 463 | } |
| 464 | |
commit-bot@chromium.org | dac5225 | 2014-02-17 21:21:46 +0000 | [diff] [blame] | 465 | bool SkBitmap::installMaskPixels(const SkMask& mask) { |
| 466 | if (SkMask::kA8_Format != mask.fFormat) { |
| 467 | this->reset(); |
| 468 | return false; |
| 469 | } |
| 470 | return this->installPixels(SkImageInfo::MakeA8(mask.fBounds.width(), |
| 471 | mask.fBounds.height()), |
| 472 | mask.fImage, mask.fRowBytes); |
| 473 | } |
| 474 | |
reed@google.com | eb9a46c | 2014-01-25 16:46:20 +0000 | [diff] [blame] | 475 | bool SkBitmap::allocConfigPixels(Config config, int width, int height, |
| 476 | bool isOpaque) { |
| 477 | SkColorType ct; |
| 478 | if (!config_to_colorType(config, &ct)) { |
| 479 | return false; |
| 480 | } |
skia.committer@gmail.com | 33c749a | 2014-01-26 07:01:45 +0000 | [diff] [blame] | 481 | |
reed@google.com | eb9a46c | 2014-01-25 16:46:20 +0000 | [diff] [blame] | 482 | SkAlphaType at = isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; |
reed@google.com | eb9a46c | 2014-01-25 16:46:20 +0000 | [diff] [blame] | 483 | return this->allocPixels(SkImageInfo::Make(width, height, ct, at)); |
| 484 | } |
| 485 | |
| 486 | /////////////////////////////////////////////////////////////////////////////// |
| 487 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 488 | void SkBitmap::freePixels() { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 489 | if (NULL != fPixelRef) { |
| 490 | if (fPixelLockCount > 0) { |
| 491 | fPixelRef->unlockPixels(); |
| 492 | } |
| 493 | fPixelRef->unref(); |
| 494 | fPixelRef = NULL; |
reed@google.com | 672588b | 2014-01-08 15:42:01 +0000 | [diff] [blame] | 495 | fPixelRefOrigin.setZero(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 496 | } |
| 497 | fPixelLockCount = 0; |
| 498 | fPixels = NULL; |
reed@google.com | 5f62ed7 | 2014-01-15 19:59:45 +0000 | [diff] [blame] | 499 | fColorTable = NULL; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 500 | } |
| 501 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 502 | uint32_t SkBitmap::getGenerationID() const { |
djsollen@google.com | c84b833 | 2012-07-27 13:41:44 +0000 | [diff] [blame] | 503 | return (fPixelRef) ? fPixelRef->getGenerationID() : 0; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | void SkBitmap::notifyPixelsChanged() const { |
junov@chromium.org | b052129 | 2011-12-15 20:14:06 +0000 | [diff] [blame] | 507 | SkASSERT(!this->isImmutable()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 508 | if (fPixelRef) { |
| 509 | fPixelRef->notifyPixelsChanged(); |
| 510 | } |
| 511 | } |
| 512 | |
commit-bot@chromium.org | b8d00db | 2013-06-26 19:18:23 +0000 | [diff] [blame] | 513 | GrTexture* SkBitmap::getTexture() const { |
reed@android.com | ce4e53a | 2010-09-09 16:01:26 +0000 | [diff] [blame] | 514 | return fPixelRef ? fPixelRef->getTexture() : NULL; |
| 515 | } |
| 516 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 517 | /////////////////////////////////////////////////////////////////////////////// |
| 518 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 519 | /** We explicitly use the same allocator for our pixels that SkMask does, |
| 520 | so that we can freely assign memory allocated by one class to the other. |
| 521 | */ |
| 522 | bool SkBitmap::HeapAllocator::allocPixelRef(SkBitmap* dst, |
| 523 | SkColorTable* ctable) { |
commit-bot@chromium.org | 466f5f3 | 2014-05-27 21:30:37 +0000 | [diff] [blame] | 524 | const SkImageInfo info = dst->info(); |
| 525 | if (kUnknown_SkColorType == info.colorType()) { |
reed@google.com | bf79023 | 2013-12-13 19:45:58 +0000 | [diff] [blame] | 526 | // SkDebugf("unsupported config for info %d\n", dst->config()); |
| 527 | return false; |
| 528 | } |
skia.committer@gmail.com | 96f5fa0 | 2013-12-16 07:01:40 +0000 | [diff] [blame] | 529 | |
commit-bot@chromium.org | 466f5f3 | 2014-05-27 21:30:37 +0000 | [diff] [blame] | 530 | SkPixelRef* pr = SkMallocPixelRef::NewAllocate(info, dst->rowBytes(), ctable); |
reed@google.com | bf79023 | 2013-12-13 19:45:58 +0000 | [diff] [blame] | 531 | if (NULL == pr) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 532 | return false; |
| 533 | } |
weita@google.com | f9ab99a | 2009-05-03 18:23:30 +0000 | [diff] [blame] | 534 | |
reed@google.com | 672588b | 2014-01-08 15:42:01 +0000 | [diff] [blame] | 535 | dst->setPixelRef(pr)->unref(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 536 | // since we're already allocated, we lockPixels right away |
| 537 | dst->lockPixels(); |
| 538 | return true; |
| 539 | } |
| 540 | |
| 541 | /////////////////////////////////////////////////////////////////////////////// |
| 542 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 543 | bool SkBitmap::copyPixelsTo(void* const dst, size_t dstSize, |
scroggo@google.com | 0ba4bf4 | 2013-02-25 16:02:36 +0000 | [diff] [blame] | 544 | size_t dstRowBytes, bool preserveDstPad) const { |
wjmaclean@chromium.org | 86bff1f | 2010-11-16 20:22:41 +0000 | [diff] [blame] | 545 | |
scroggo@google.com | 0ba4bf4 | 2013-02-25 16:02:36 +0000 | [diff] [blame] | 546 | if (0 == dstRowBytes) { |
wjmaclean@chromium.org | 86bff1f | 2010-11-16 20:22:41 +0000 | [diff] [blame] | 547 | dstRowBytes = fRowBytes; |
scroggo@google.com | 0ba4bf4 | 2013-02-25 16:02:36 +0000 | [diff] [blame] | 548 | } |
wjmaclean@chromium.org | 86bff1f | 2010-11-16 20:22:41 +0000 | [diff] [blame] | 549 | |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 550 | if (dstRowBytes < fInfo.minRowBytes() || |
| 551 | dst == NULL || (getPixels() == NULL && pixelRef() == NULL)) { |
wjmaclean@chromium.org | 86bff1f | 2010-11-16 20:22:41 +0000 | [diff] [blame] | 552 | return false; |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 553 | } |
wjmaclean@chromium.org | 86bff1f | 2010-11-16 20:22:41 +0000 | [diff] [blame] | 554 | |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 555 | if (!preserveDstPad && static_cast<uint32_t>(dstRowBytes) == fRowBytes) { |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 556 | size_t safeSize = this->getSafeSize(); |
wjmaclean@chromium.org | 86bff1f | 2010-11-16 20:22:41 +0000 | [diff] [blame] | 557 | if (safeSize > dstSize || safeSize == 0) |
| 558 | return false; |
| 559 | else { |
| 560 | SkAutoLockPixels lock(*this); |
| 561 | // This implementation will write bytes beyond the end of each row, |
| 562 | // excluding the last row, if the bitmap's stride is greater than |
| 563 | // strictly required by the current config. |
| 564 | memcpy(dst, getPixels(), safeSize); |
| 565 | |
| 566 | return true; |
| 567 | } |
| 568 | } else { |
| 569 | // If destination has different stride than us, then copy line by line. |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 570 | if (fInfo.getSafeSize(dstRowBytes) > dstSize) { |
wjmaclean@chromium.org | 86bff1f | 2010-11-16 20:22:41 +0000 | [diff] [blame] | 571 | return false; |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 572 | } else { |
wjmaclean@chromium.org | 86bff1f | 2010-11-16 20:22:41 +0000 | [diff] [blame] | 573 | // Just copy what we need on each line. |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 574 | size_t rowBytes = fInfo.minRowBytes(); |
wjmaclean@chromium.org | 86bff1f | 2010-11-16 20:22:41 +0000 | [diff] [blame] | 575 | SkAutoLockPixels lock(*this); |
| 576 | const uint8_t* srcP = reinterpret_cast<const uint8_t*>(getPixels()); |
| 577 | uint8_t* dstP = reinterpret_cast<uint8_t*>(dst); |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 578 | for (int row = 0; row < fInfo.fHeight; |
wjmaclean@chromium.org | 86bff1f | 2010-11-16 20:22:41 +0000 | [diff] [blame] | 579 | row++, srcP += fRowBytes, dstP += dstRowBytes) { |
| 580 | memcpy(dstP, srcP, rowBytes); |
| 581 | } |
| 582 | |
| 583 | return true; |
| 584 | } |
| 585 | } |
| 586 | } |
| 587 | |
wjmaclean@chromium.org | 86bff1f | 2010-11-16 20:22:41 +0000 | [diff] [blame] | 588 | /////////////////////////////////////////////////////////////////////////////// |
| 589 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 590 | bool SkBitmap::isImmutable() const { |
junov@chromium.org | b052129 | 2011-12-15 20:14:06 +0000 | [diff] [blame] | 591 | return fPixelRef ? fPixelRef->isImmutable() : |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 592 | fFlags & kImageIsImmutable_Flag; |
junov@chromium.org | b052129 | 2011-12-15 20:14:06 +0000 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | void SkBitmap::setImmutable() { |
| 596 | if (fPixelRef) { |
| 597 | fPixelRef->setImmutable(); |
| 598 | } else { |
| 599 | fFlags |= kImageIsImmutable_Flag; |
| 600 | } |
| 601 | } |
| 602 | |
junov@google.com | 4ee7ae5 | 2011-06-30 17:30:49 +0000 | [diff] [blame] | 603 | bool SkBitmap::isVolatile() const { |
| 604 | return (fFlags & kImageIsVolatile_Flag) != 0; |
| 605 | } |
| 606 | |
| 607 | void SkBitmap::setIsVolatile(bool isVolatile) { |
| 608 | if (isVolatile) { |
| 609 | fFlags |= kImageIsVolatile_Flag; |
| 610 | } else { |
| 611 | fFlags &= ~kImageIsVolatile_Flag; |
| 612 | } |
| 613 | } |
| 614 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 615 | void* SkBitmap::getAddr(int x, int y) const { |
| 616 | SkASSERT((unsigned)x < (unsigned)this->width()); |
| 617 | SkASSERT((unsigned)y < (unsigned)this->height()); |
| 618 | |
| 619 | char* base = (char*)this->getPixels(); |
| 620 | if (base) { |
| 621 | base += y * this->rowBytes(); |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 622 | switch (this->colorType()) { |
| 623 | case kRGBA_8888_SkColorType: |
| 624 | case kBGRA_8888_SkColorType: |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 625 | base += x << 2; |
| 626 | break; |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 627 | case kARGB_4444_SkColorType: |
| 628 | case kRGB_565_SkColorType: |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 629 | base += x << 1; |
| 630 | break; |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 631 | case kAlpha_8_SkColorType: |
| 632 | case kIndex_8_SkColorType: |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 633 | base += x; |
| 634 | break; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 635 | default: |
tomhudson@google.com | 0c00f21 | 2011-12-28 14:59:50 +0000 | [diff] [blame] | 636 | SkDEBUGFAIL("Can't return addr for config"); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 637 | base = NULL; |
| 638 | break; |
| 639 | } |
| 640 | } |
| 641 | return base; |
| 642 | } |
| 643 | |
vandebo@chromium.org | 112706d | 2011-02-24 22:50:55 +0000 | [diff] [blame] | 644 | SkColor SkBitmap::getColor(int x, int y) const { |
| 645 | SkASSERT((unsigned)x < (unsigned)this->width()); |
| 646 | SkASSERT((unsigned)y < (unsigned)this->height()); |
| 647 | |
commit-bot@chromium.org | cba7378 | 2014-05-29 15:57:47 +0000 | [diff] [blame] | 648 | switch (this->colorType()) { |
| 649 | case kAlpha_8_SkColorType: { |
reed@google.com | 3b521d0 | 2011-04-29 11:53:41 +0000 | [diff] [blame] | 650 | uint8_t* addr = this->getAddr8(x, y); |
vandebo@chromium.org | 112706d | 2011-02-24 22:50:55 +0000 | [diff] [blame] | 651 | return SkColorSetA(0, addr[0]); |
| 652 | } |
commit-bot@chromium.org | cba7378 | 2014-05-29 15:57:47 +0000 | [diff] [blame] | 653 | case kIndex_8_SkColorType: { |
reed@google.com | 3b521d0 | 2011-04-29 11:53:41 +0000 | [diff] [blame] | 654 | SkPMColor c = this->getIndex8Color(x, y); |
vandebo@chromium.org | 112706d | 2011-02-24 22:50:55 +0000 | [diff] [blame] | 655 | return SkUnPreMultiply::PMColorToColor(c); |
| 656 | } |
commit-bot@chromium.org | cba7378 | 2014-05-29 15:57:47 +0000 | [diff] [blame] | 657 | case kRGB_565_SkColorType: { |
reed@google.com | 3b521d0 | 2011-04-29 11:53:41 +0000 | [diff] [blame] | 658 | uint16_t* addr = this->getAddr16(x, y); |
vandebo@chromium.org | 112706d | 2011-02-24 22:50:55 +0000 | [diff] [blame] | 659 | return SkPixel16ToColor(addr[0]); |
| 660 | } |
commit-bot@chromium.org | cba7378 | 2014-05-29 15:57:47 +0000 | [diff] [blame] | 661 | case kARGB_4444_SkColorType: { |
reed@google.com | 3b521d0 | 2011-04-29 11:53:41 +0000 | [diff] [blame] | 662 | uint16_t* addr = this->getAddr16(x, y); |
vandebo@chromium.org | 112706d | 2011-02-24 22:50:55 +0000 | [diff] [blame] | 663 | SkPMColor c = SkPixel4444ToPixel32(addr[0]); |
| 664 | return SkUnPreMultiply::PMColorToColor(c); |
| 665 | } |
commit-bot@chromium.org | cba7378 | 2014-05-29 15:57:47 +0000 | [diff] [blame] | 666 | case kBGRA_8888_SkColorType: |
| 667 | case kRGBA_8888_SkColorType: { |
reed@google.com | 3b521d0 | 2011-04-29 11:53:41 +0000 | [diff] [blame] | 668 | uint32_t* addr = this->getAddr32(x, y); |
vandebo@chromium.org | 112706d | 2011-02-24 22:50:55 +0000 | [diff] [blame] | 669 | return SkUnPreMultiply::PMColorToColor(addr[0]); |
| 670 | } |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 671 | default: |
vandebo@chromium.org | 112706d | 2011-02-24 22:50:55 +0000 | [diff] [blame] | 672 | SkASSERT(false); |
| 673 | return 0; |
| 674 | } |
| 675 | SkASSERT(false); // Not reached. |
| 676 | return 0; |
| 677 | } |
| 678 | |
reed@google.com | 2a7579d | 2012-11-07 18:30:18 +0000 | [diff] [blame] | 679 | bool SkBitmap::ComputeIsOpaque(const SkBitmap& bm) { |
| 680 | SkAutoLockPixels alp(bm); |
| 681 | if (!bm.getPixels()) { |
| 682 | return false; |
| 683 | } |
| 684 | |
| 685 | const int height = bm.height(); |
| 686 | const int width = bm.width(); |
| 687 | |
commit-bot@chromium.org | cba7378 | 2014-05-29 15:57:47 +0000 | [diff] [blame] | 688 | switch (bm.colorType()) { |
| 689 | case kAlpha_8_SkColorType: { |
reed@google.com | 2a7579d | 2012-11-07 18:30:18 +0000 | [diff] [blame] | 690 | unsigned a = 0xFF; |
| 691 | for (int y = 0; y < height; ++y) { |
| 692 | const uint8_t* row = bm.getAddr8(0, y); |
| 693 | for (int x = 0; x < width; ++x) { |
| 694 | a &= row[x]; |
| 695 | } |
| 696 | if (0xFF != a) { |
| 697 | return false; |
| 698 | } |
| 699 | } |
| 700 | return true; |
| 701 | } break; |
commit-bot@chromium.org | cba7378 | 2014-05-29 15:57:47 +0000 | [diff] [blame] | 702 | case kIndex_8_SkColorType: { |
reed@google.com | 2a7579d | 2012-11-07 18:30:18 +0000 | [diff] [blame] | 703 | SkAutoLockColors alc(bm); |
| 704 | const SkPMColor* table = alc.colors(); |
| 705 | if (!table) { |
| 706 | return false; |
| 707 | } |
reed@google.com | 140d728 | 2013-01-07 20:25:04 +0000 | [diff] [blame] | 708 | SkPMColor c = (SkPMColor)~0; |
reed@google.com | 2a7579d | 2012-11-07 18:30:18 +0000 | [diff] [blame] | 709 | for (int i = bm.getColorTable()->count() - 1; i >= 0; --i) { |
| 710 | c &= table[i]; |
| 711 | } |
| 712 | return 0xFF == SkGetPackedA32(c); |
| 713 | } break; |
commit-bot@chromium.org | cba7378 | 2014-05-29 15:57:47 +0000 | [diff] [blame] | 714 | case kRGB_565_SkColorType: |
reed@google.com | 2a7579d | 2012-11-07 18:30:18 +0000 | [diff] [blame] | 715 | return true; |
| 716 | break; |
commit-bot@chromium.org | cba7378 | 2014-05-29 15:57:47 +0000 | [diff] [blame] | 717 | case kARGB_4444_SkColorType: { |
reed@google.com | 2a7579d | 2012-11-07 18:30:18 +0000 | [diff] [blame] | 718 | unsigned c = 0xFFFF; |
| 719 | for (int y = 0; y < height; ++y) { |
| 720 | const SkPMColor16* row = bm.getAddr16(0, y); |
| 721 | for (int x = 0; x < width; ++x) { |
| 722 | c &= row[x]; |
| 723 | } |
| 724 | if (0xF != SkGetPackedA4444(c)) { |
| 725 | return false; |
| 726 | } |
| 727 | } |
| 728 | return true; |
| 729 | } break; |
commit-bot@chromium.org | cba7378 | 2014-05-29 15:57:47 +0000 | [diff] [blame] | 730 | case kBGRA_8888_SkColorType: |
| 731 | case kRGBA_8888_SkColorType: { |
reed@google.com | 140d728 | 2013-01-07 20:25:04 +0000 | [diff] [blame] | 732 | SkPMColor c = (SkPMColor)~0; |
reed@google.com | 2a7579d | 2012-11-07 18:30:18 +0000 | [diff] [blame] | 733 | for (int y = 0; y < height; ++y) { |
| 734 | const SkPMColor* row = bm.getAddr32(0, y); |
| 735 | for (int x = 0; x < width; ++x) { |
| 736 | c &= row[x]; |
| 737 | } |
| 738 | if (0xFF != SkGetPackedA32(c)) { |
| 739 | return false; |
| 740 | } |
| 741 | } |
| 742 | return true; |
| 743 | } |
| 744 | default: |
| 745 | break; |
| 746 | } |
| 747 | return false; |
| 748 | } |
| 749 | |
| 750 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 751 | /////////////////////////////////////////////////////////////////////////////// |
| 752 | /////////////////////////////////////////////////////////////////////////////// |
| 753 | |
reed@google.com | 45f746f | 2013-06-21 19:51:31 +0000 | [diff] [blame] | 754 | static uint16_t pack_8888_to_4444(unsigned a, unsigned r, unsigned g, unsigned b) { |
| 755 | unsigned pixel = (SkA32To4444(a) << SK_A4444_SHIFT) | |
| 756 | (SkR32To4444(r) << SK_R4444_SHIFT) | |
| 757 | (SkG32To4444(g) << SK_G4444_SHIFT) | |
| 758 | (SkB32To4444(b) << SK_B4444_SHIFT); |
| 759 | return SkToU16(pixel); |
| 760 | } |
| 761 | |
reed@google.com | 60d3235 | 2013-06-28 19:40:50 +0000 | [diff] [blame] | 762 | void SkBitmap::internalErase(const SkIRect& area, |
| 763 | U8CPU a, U8CPU r, U8CPU g, U8CPU b) const { |
| 764 | #ifdef SK_DEBUG |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 765 | SkDEBUGCODE(this->validate();) |
reed@google.com | 60d3235 | 2013-06-28 19:40:50 +0000 | [diff] [blame] | 766 | SkASSERT(!area.isEmpty()); |
| 767 | { |
reed@google.com | 92833f9 | 2013-06-28 19:47:43 +0000 | [diff] [blame] | 768 | SkIRect total = { 0, 0, this->width(), this->height() }; |
reed@google.com | 60d3235 | 2013-06-28 19:40:50 +0000 | [diff] [blame] | 769 | SkASSERT(total.contains(area)); |
| 770 | } |
| 771 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 772 | |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 773 | switch (fInfo.colorType()) { |
| 774 | case kUnknown_SkColorType: |
| 775 | case kIndex_8_SkColorType: |
commit-bot@chromium.org | 7669a77 | 2014-03-27 15:30:35 +0000 | [diff] [blame] | 776 | return; // can't erase. Should we bzero so the memory is not uninitialized? |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 777 | default: |
| 778 | break; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | SkAutoLockPixels alp(*this); |
| 782 | // perform this check after the lock call |
| 783 | if (!this->readyToDraw()) { |
| 784 | return; |
| 785 | } |
| 786 | |
reed@google.com | 60d3235 | 2013-06-28 19:40:50 +0000 | [diff] [blame] | 787 | int height = area.height(); |
| 788 | const int width = area.width(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 789 | const int rowBytes = fRowBytes; |
| 790 | |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 791 | switch (this->colorType()) { |
| 792 | case kAlpha_8_SkColorType: { |
reed@google.com | 60d3235 | 2013-06-28 19:40:50 +0000 | [diff] [blame] | 793 | uint8_t* p = this->getAddr8(area.fLeft, area.fTop); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 794 | while (--height >= 0) { |
| 795 | memset(p, a, width); |
| 796 | p += rowBytes; |
| 797 | } |
| 798 | break; |
| 799 | } |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 800 | case kARGB_4444_SkColorType: |
| 801 | case kRGB_565_SkColorType: { |
reed@google.com | 60d3235 | 2013-06-28 19:40:50 +0000 | [diff] [blame] | 802 | uint16_t* p = this->getAddr16(area.fLeft, area.fTop);; |
reed@google.com | 45f746f | 2013-06-21 19:51:31 +0000 | [diff] [blame] | 803 | uint16_t v; |
skia.committer@gmail.com | 020b25b | 2013-06-22 07:00:58 +0000 | [diff] [blame] | 804 | |
commit-bot@chromium.org | 7669a77 | 2014-03-27 15:30:35 +0000 | [diff] [blame] | 805 | // make rgb premultiplied |
| 806 | if (255 != a) { |
| 807 | r = SkAlphaMul(r, a); |
| 808 | g = SkAlphaMul(g, a); |
| 809 | b = SkAlphaMul(b, a); |
| 810 | } |
| 811 | |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 812 | if (kARGB_4444_SkColorType == this->colorType()) { |
reed@google.com | 45f746f | 2013-06-21 19:51:31 +0000 | [diff] [blame] | 813 | v = pack_8888_to_4444(a, r, g, b); |
| 814 | } else { |
| 815 | v = SkPackRGB16(r >> (8 - SK_R16_BITS), |
| 816 | g >> (8 - SK_G16_BITS), |
| 817 | b >> (8 - SK_B16_BITS)); |
| 818 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 819 | while (--height >= 0) { |
| 820 | sk_memset16(p, v, width); |
| 821 | p = (uint16_t*)((char*)p + rowBytes); |
| 822 | } |
| 823 | break; |
| 824 | } |
commit-bot@chromium.org | 7669a77 | 2014-03-27 15:30:35 +0000 | [diff] [blame] | 825 | case kBGRA_8888_SkColorType: |
| 826 | case kRGBA_8888_SkColorType: { |
reed@google.com | 60d3235 | 2013-06-28 19:40:50 +0000 | [diff] [blame] | 827 | uint32_t* p = this->getAddr32(area.fLeft, area.fTop); |
commit-bot@chromium.org | 7669a77 | 2014-03-27 15:30:35 +0000 | [diff] [blame] | 828 | |
| 829 | if (255 != a && kPremul_SkAlphaType == this->alphaType()) { |
| 830 | r = SkAlphaMul(r, a); |
| 831 | g = SkAlphaMul(g, a); |
| 832 | b = SkAlphaMul(b, a); |
| 833 | } |
| 834 | uint32_t v = kRGBA_8888_SkColorType == this->colorType() ? |
| 835 | SkPackARGB_as_RGBA(a, r, g, b) : SkPackARGB_as_BGRA(a, r, g, b); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 836 | |
| 837 | while (--height >= 0) { |
| 838 | sk_memset32(p, v, width); |
| 839 | p = (uint32_t*)((char*)p + rowBytes); |
| 840 | } |
| 841 | break; |
| 842 | } |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 843 | default: |
| 844 | return; // no change, so don't call notifyPixelsChanged() |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 845 | } |
weita@google.com | f9ab99a | 2009-05-03 18:23:30 +0000 | [diff] [blame] | 846 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 847 | this->notifyPixelsChanged(); |
| 848 | } |
| 849 | |
reed@google.com | 60d3235 | 2013-06-28 19:40:50 +0000 | [diff] [blame] | 850 | void SkBitmap::eraseARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) const { |
reed@google.com | 92833f9 | 2013-06-28 19:47:43 +0000 | [diff] [blame] | 851 | SkIRect area = { 0, 0, this->width(), this->height() }; |
reed@google.com | 60d3235 | 2013-06-28 19:40:50 +0000 | [diff] [blame] | 852 | if (!area.isEmpty()) { |
| 853 | this->internalErase(area, a, r, g, b); |
| 854 | } |
| 855 | } |
| 856 | |
| 857 | void SkBitmap::eraseArea(const SkIRect& rect, SkColor c) const { |
reed@google.com | 92833f9 | 2013-06-28 19:47:43 +0000 | [diff] [blame] | 858 | SkIRect area = { 0, 0, this->width(), this->height() }; |
reed@google.com | 60d3235 | 2013-06-28 19:40:50 +0000 | [diff] [blame] | 859 | if (area.intersect(rect)) { |
| 860 | this->internalErase(area, SkColorGetA(c), SkColorGetR(c), |
| 861 | SkColorGetG(c), SkColorGetB(c)); |
| 862 | } |
| 863 | } |
| 864 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 865 | ////////////////////////////////////////////////////////////////////////////////////// |
| 866 | ////////////////////////////////////////////////////////////////////////////////////// |
| 867 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 868 | bool SkBitmap::extractSubset(SkBitmap* result, const SkIRect& subset) const { |
| 869 | SkDEBUGCODE(this->validate();) |
| 870 | |
djsollen@google.com | c84b833 | 2012-07-27 13:41:44 +0000 | [diff] [blame] | 871 | if (NULL == result || NULL == fPixelRef) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 872 | return false; // no src pixels |
| 873 | } |
| 874 | |
| 875 | SkIRect srcRect, r; |
| 876 | srcRect.set(0, 0, this->width(), this->height()); |
| 877 | if (!r.intersect(srcRect, subset)) { |
| 878 | return false; // r is empty (i.e. no intersection) |
| 879 | } |
| 880 | |
scroggo@google.com | a2a3192 | 2012-12-07 19:14:45 +0000 | [diff] [blame] | 881 | if (fPixelRef->getTexture() != NULL) { |
| 882 | // Do a deep copy |
commit-bot@chromium.org | eeef0cc | 2014-05-21 15:58:00 +0000 | [diff] [blame] | 883 | SkPixelRef* pixelRef = fPixelRef->deepCopy(this->config(), &subset); |
scroggo@google.com | a2a3192 | 2012-12-07 19:14:45 +0000 | [diff] [blame] | 884 | if (pixelRef != NULL) { |
| 885 | SkBitmap dst; |
commit-bot@chromium.org | a3264e5 | 2014-05-30 13:26:10 +0000 | [diff] [blame] | 886 | dst.setInfo(SkImageInfo::Make(subset.width(), subset.height(), |
| 887 | this->colorType(), this->alphaType())); |
scroggo@google.com | a2a3192 | 2012-12-07 19:14:45 +0000 | [diff] [blame] | 888 | dst.setIsVolatile(this->isVolatile()); |
scroggo@google.com | a2a3192 | 2012-12-07 19:14:45 +0000 | [diff] [blame] | 889 | dst.setPixelRef(pixelRef)->unref(); |
| 890 | SkDEBUGCODE(dst.validate()); |
| 891 | result->swap(dst); |
| 892 | return true; |
| 893 | } |
| 894 | } |
| 895 | |
scroggo@google.com | a2a3192 | 2012-12-07 19:14:45 +0000 | [diff] [blame] | 896 | // If the upper left of the rectangle was outside the bounds of this SkBitmap, we should have |
| 897 | // exited above. |
| 898 | SkASSERT(static_cast<unsigned>(r.fLeft) < static_cast<unsigned>(this->width())); |
| 899 | SkASSERT(static_cast<unsigned>(r.fTop) < static_cast<unsigned>(this->height())); |
| 900 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 901 | SkBitmap dst; |
commit-bot@chromium.org | a3264e5 | 2014-05-30 13:26:10 +0000 | [diff] [blame] | 902 | dst.setInfo(SkImageInfo::Make(r.width(), r.height(), this->colorType(), this->alphaType()), |
| 903 | this->rowBytes()); |
skyostil@google.com | 0eb7576 | 2012-01-16 10:45:53 +0000 | [diff] [blame] | 904 | dst.setIsVolatile(this->isVolatile()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 905 | |
| 906 | if (fPixelRef) { |
reed@google.com | 672588b | 2014-01-08 15:42:01 +0000 | [diff] [blame] | 907 | SkIPoint origin = fPixelRefOrigin; |
| 908 | origin.fX += r.fLeft; |
| 909 | origin.fY += r.fTop; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 910 | // share the pixelref with a custom offset |
reed@google.com | 672588b | 2014-01-08 15:42:01 +0000 | [diff] [blame] | 911 | dst.setPixelRef(fPixelRef, origin); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 912 | } |
| 913 | SkDEBUGCODE(dst.validate();) |
| 914 | |
| 915 | // we know we're good, so commit to result |
| 916 | result->swap(dst); |
| 917 | return true; |
| 918 | } |
| 919 | |
| 920 | /////////////////////////////////////////////////////////////////////////////// |
| 921 | |
| 922 | #include "SkCanvas.h" |
| 923 | #include "SkPaint.h" |
| 924 | |
commit-bot@chromium.org | 8a2ad3c | 2014-02-23 03:59:35 +0000 | [diff] [blame] | 925 | bool SkBitmap::canCopyTo(SkColorType dstColorType) const { |
| 926 | if (this->colorType() == kUnknown_SkColorType) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 927 | return false; |
| 928 | } |
| 929 | |
commit-bot@chromium.org | 8a2ad3c | 2014-02-23 03:59:35 +0000 | [diff] [blame] | 930 | bool sameConfigs = (this->colorType() == dstColorType); |
| 931 | switch (dstColorType) { |
| 932 | case kAlpha_8_SkColorType: |
| 933 | case kRGB_565_SkColorType: |
commit-bot@chromium.org | 60b5dce | 2014-04-22 20:24:33 +0000 | [diff] [blame] | 934 | case kRGBA_8888_SkColorType: |
| 935 | case kBGRA_8888_SkColorType: |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 936 | break; |
commit-bot@chromium.org | 8a2ad3c | 2014-02-23 03:59:35 +0000 | [diff] [blame] | 937 | case kIndex_8_SkColorType: |
weita@google.com | f9ab99a | 2009-05-03 18:23:30 +0000 | [diff] [blame] | 938 | if (!sameConfigs) { |
| 939 | return false; |
| 940 | } |
| 941 | break; |
commit-bot@chromium.org | 8a2ad3c | 2014-02-23 03:59:35 +0000 | [diff] [blame] | 942 | case kARGB_4444_SkColorType: |
commit-bot@chromium.org | 28fcae2 | 2014-04-11 17:15:40 +0000 | [diff] [blame] | 943 | return sameConfigs || kN32_SkColorType == this->colorType(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 944 | default: |
| 945 | return false; |
| 946 | } |
reed@android.com | fbaa88d | 2009-05-06 17:44:34 +0000 | [diff] [blame] | 947 | return true; |
| 948 | } |
| 949 | |
commit-bot@chromium.org | 8a2ad3c | 2014-02-23 03:59:35 +0000 | [diff] [blame] | 950 | bool SkBitmap::copyTo(SkBitmap* dst, SkColorType dstColorType, |
| 951 | Allocator* alloc) const { |
| 952 | if (!this->canCopyTo(dstColorType)) { |
reed@android.com | fbaa88d | 2009-05-06 17:44:34 +0000 | [diff] [blame] | 953 | return false; |
| 954 | } |
| 955 | |
reed@google.com | 50dfa01 | 2011-04-01 19:05:36 +0000 | [diff] [blame] | 956 | // if we have a texture, first get those pixels |
| 957 | SkBitmap tmpSrc; |
| 958 | const SkBitmap* src = this; |
| 959 | |
scroggo@google.com | a2a3192 | 2012-12-07 19:14:45 +0000 | [diff] [blame] | 960 | if (fPixelRef) { |
| 961 | SkIRect subset; |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 962 | subset.setXYWH(fPixelRefOrigin.fX, fPixelRefOrigin.fY, |
| 963 | fInfo.width(), fInfo.height()); |
reed@google.com | 672588b | 2014-01-08 15:42:01 +0000 | [diff] [blame] | 964 | if (fPixelRef->readPixels(&tmpSrc, &subset)) { |
| 965 | SkASSERT(tmpSrc.width() == this->width()); |
| 966 | SkASSERT(tmpSrc.height() == this->height()); |
reed@google.com | 50dfa01 | 2011-04-01 19:05:36 +0000 | [diff] [blame] | 967 | |
reed@google.com | 672588b | 2014-01-08 15:42:01 +0000 | [diff] [blame] | 968 | // did we get lucky and we can just return tmpSrc? |
commit-bot@chromium.org | 8a2ad3c | 2014-02-23 03:59:35 +0000 | [diff] [blame] | 969 | if (tmpSrc.colorType() == dstColorType && NULL == alloc) { |
reed@google.com | 672588b | 2014-01-08 15:42:01 +0000 | [diff] [blame] | 970 | dst->swap(tmpSrc); |
scroggo@google.com | 5ccae2c | 2014-01-15 16:56:52 +0000 | [diff] [blame] | 971 | // If the result is an exact copy, clone the gen ID. |
| 972 | if (dst->pixelRef() && dst->pixelRef()->info() == fPixelRef->info()) { |
reed@google.com | 672588b | 2014-01-08 15:42:01 +0000 | [diff] [blame] | 973 | dst->pixelRef()->cloneGenID(*fPixelRef); |
scroggo@google.com | a2a3192 | 2012-12-07 19:14:45 +0000 | [diff] [blame] | 974 | } |
reed@google.com | 672588b | 2014-01-08 15:42:01 +0000 | [diff] [blame] | 975 | return true; |
scroggo@google.com | d5764e8 | 2012-08-22 15:00:05 +0000 | [diff] [blame] | 976 | } |
reed@google.com | 672588b | 2014-01-08 15:42:01 +0000 | [diff] [blame] | 977 | |
| 978 | // fall through to the raster case |
| 979 | src = &tmpSrc; |
reed@google.com | 50dfa01 | 2011-04-01 19:05:36 +0000 | [diff] [blame] | 980 | } |
reed@android.com | fbaa88d | 2009-05-06 17:44:34 +0000 | [diff] [blame] | 981 | } |
reed@android.com | 311c82d | 2009-05-05 23:13:23 +0000 | [diff] [blame] | 982 | |
reed@google.com | 50dfa01 | 2011-04-01 19:05:36 +0000 | [diff] [blame] | 983 | // we lock this now, since we may need its colortable |
| 984 | SkAutoLockPixels srclock(*src); |
| 985 | if (!src->readyToDraw()) { |
| 986 | return false; |
| 987 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 988 | |
scroggo@google.com | 5ccae2c | 2014-01-15 16:56:52 +0000 | [diff] [blame] | 989 | // The only way to be readyToDraw is if fPixelRef is non NULL. |
| 990 | SkASSERT(fPixelRef != NULL); |
| 991 | |
commit-bot@chromium.org | 8a2ad3c | 2014-02-23 03:59:35 +0000 | [diff] [blame] | 992 | SkImageInfo dstInfo = src->info(); |
| 993 | dstInfo.fColorType = dstColorType; |
| 994 | |
reed@google.com | 50dfa01 | 2011-04-01 19:05:36 +0000 | [diff] [blame] | 995 | SkBitmap tmpDst; |
commit-bot@chromium.org | a3264e5 | 2014-05-30 13:26:10 +0000 | [diff] [blame] | 996 | if (!tmpDst.setInfo(dstInfo)) { |
commit-bot@chromium.org | 8a2ad3c | 2014-02-23 03:59:35 +0000 | [diff] [blame] | 997 | return false; |
| 998 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 999 | |
weita@google.com | f9ab99a | 2009-05-03 18:23:30 +0000 | [diff] [blame] | 1000 | // allocate colortable if srcConfig == kIndex8_Config |
commit-bot@chromium.org | 8a2ad3c | 2014-02-23 03:59:35 +0000 | [diff] [blame] | 1001 | SkAutoTUnref<SkColorTable> ctable; |
| 1002 | if (dstColorType == kIndex_8_SkColorType) { |
| 1003 | // TODO: can we just ref() the src colortable? Is it reentrant-safe? |
| 1004 | ctable.reset(SkNEW_ARGS(SkColorTable, (*src->getColorTable()))); |
| 1005 | } |
reed@google.com | 50dfa01 | 2011-04-01 19:05:36 +0000 | [diff] [blame] | 1006 | if (!tmpDst.allocPixels(alloc, ctable)) { |
weita@google.com | f9ab99a | 2009-05-03 18:23:30 +0000 | [diff] [blame] | 1007 | return false; |
| 1008 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1009 | |
reed@google.com | 50dfa01 | 2011-04-01 19:05:36 +0000 | [diff] [blame] | 1010 | if (!tmpDst.readyToDraw()) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1011 | // allocator/lock failed |
| 1012 | return false; |
| 1013 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1014 | |
scroggo@google.com | 5ccae2c | 2014-01-15 16:56:52 +0000 | [diff] [blame] | 1015 | // pixelRef must be non NULL or tmpDst.readyToDraw() would have |
| 1016 | // returned false. |
| 1017 | SkASSERT(tmpDst.pixelRef() != NULL); |
| 1018 | |
reed@android.com | fbaa88d | 2009-05-06 17:44:34 +0000 | [diff] [blame] | 1019 | /* do memcpy for the same configs cases, else use drawing |
weita@google.com | f9ab99a | 2009-05-03 18:23:30 +0000 | [diff] [blame] | 1020 | */ |
commit-bot@chromium.org | 8a2ad3c | 2014-02-23 03:59:35 +0000 | [diff] [blame] | 1021 | if (src->colorType() == dstColorType) { |
reed@google.com | 50dfa01 | 2011-04-01 19:05:36 +0000 | [diff] [blame] | 1022 | if (tmpDst.getSize() == src->getSize()) { |
| 1023 | memcpy(tmpDst.getPixels(), src->getPixels(), src->getSafeSize()); |
scroggo@google.com | d5764e8 | 2012-08-22 15:00:05 +0000 | [diff] [blame] | 1024 | SkPixelRef* pixelRef = tmpDst.pixelRef(); |
scroggo@google.com | 5ccae2c | 2014-01-15 16:56:52 +0000 | [diff] [blame] | 1025 | |
| 1026 | // In order to reach this point, we know that the width, config and |
| 1027 | // rowbytes of the SkPixelRefs are the same, but it is possible for |
| 1028 | // the heights to differ, if this SkBitmap's height is a subset of |
| 1029 | // fPixelRef. Only if the SkPixelRefs' heights match are we |
| 1030 | // guaranteed that this is an exact copy, meaning we should clone |
| 1031 | // the genID. |
| 1032 | if (pixelRef->info().fHeight == fPixelRef->info().fHeight) { |
| 1033 | // TODO: what to do if the two infos match, BUT |
| 1034 | // fPixelRef is premul and pixelRef is opaque? |
| 1035 | // skipping assert for now |
| 1036 | // https://code.google.com/p/skia/issues/detail?id=2012 |
| 1037 | // SkASSERT(pixelRef->info() == fPixelRef->info()); |
| 1038 | SkASSERT(pixelRef->info().fWidth == fPixelRef->info().fWidth); |
| 1039 | SkASSERT(pixelRef->info().fColorType == fPixelRef->info().fColorType); |
commit-bot@chromium.org | 50a3043 | 2013-10-24 17:44:27 +0000 | [diff] [blame] | 1040 | pixelRef->cloneGenID(*fPixelRef); |
scroggo@google.com | d5764e8 | 2012-08-22 15:00:05 +0000 | [diff] [blame] | 1041 | } |
reed@android.com | 311c82d | 2009-05-05 23:13:23 +0000 | [diff] [blame] | 1042 | } else { |
reed@google.com | 50dfa01 | 2011-04-01 19:05:36 +0000 | [diff] [blame] | 1043 | const char* srcP = reinterpret_cast<const char*>(src->getPixels()); |
| 1044 | char* dstP = reinterpret_cast<char*>(tmpDst.getPixels()); |
reed@android.com | 311c82d | 2009-05-05 23:13:23 +0000 | [diff] [blame] | 1045 | // to be sure we don't read too much, only copy our logical pixels |
reed@google.com | 50dfa01 | 2011-04-01 19:05:36 +0000 | [diff] [blame] | 1046 | size_t bytesToCopy = tmpDst.width() * tmpDst.bytesPerPixel(); |
| 1047 | for (int y = 0; y < tmpDst.height(); y++) { |
reed@android.com | 311c82d | 2009-05-05 23:13:23 +0000 | [diff] [blame] | 1048 | memcpy(dstP, srcP, bytesToCopy); |
reed@google.com | 50dfa01 | 2011-04-01 19:05:36 +0000 | [diff] [blame] | 1049 | srcP += src->rowBytes(); |
| 1050 | dstP += tmpDst.rowBytes(); |
reed@android.com | 311c82d | 2009-05-05 23:13:23 +0000 | [diff] [blame] | 1051 | } |
| 1052 | } |
commit-bot@chromium.org | 8a2ad3c | 2014-02-23 03:59:35 +0000 | [diff] [blame] | 1053 | } else if (kARGB_4444_SkColorType == dstColorType |
commit-bot@chromium.org | 28fcae2 | 2014-04-11 17:15:40 +0000 | [diff] [blame] | 1054 | && kN32_SkColorType == src->colorType()) { |
scroggo@google.com | 8dc8bc5 | 2013-08-07 19:16:05 +0000 | [diff] [blame] | 1055 | SkASSERT(src->height() == tmpDst.height()); |
| 1056 | SkASSERT(src->width() == tmpDst.width()); |
| 1057 | for (int y = 0; y < src->height(); ++y) { |
| 1058 | SkPMColor16* SK_RESTRICT dstRow = (SkPMColor16*) tmpDst.getAddr16(0, y); |
| 1059 | SkPMColor* SK_RESTRICT srcRow = (SkPMColor*) src->getAddr32(0, y); |
| 1060 | DITHER_4444_SCAN(y); |
| 1061 | for (int x = 0; x < src->width(); ++x) { |
| 1062 | dstRow[x] = SkDitherARGB32To4444(srcRow[x], |
| 1063 | DITHER_VALUE(x)); |
| 1064 | } |
| 1065 | } |
weita@google.com | f9ab99a | 2009-05-03 18:23:30 +0000 | [diff] [blame] | 1066 | } else { |
robertphillips@google.com | 0197b32 | 2013-10-10 15:48:16 +0000 | [diff] [blame] | 1067 | // Always clear the dest in case one of the blitters accesses it |
| 1068 | // TODO: switch the allocation of tmpDst to call sk_calloc_throw |
| 1069 | tmpDst.eraseColor(SK_ColorTRANSPARENT); |
weita@google.com | f9ab99a | 2009-05-03 18:23:30 +0000 | [diff] [blame] | 1070 | |
reed@google.com | 50dfa01 | 2011-04-01 19:05:36 +0000 | [diff] [blame] | 1071 | SkCanvas canvas(tmpDst); |
weita@google.com | f9ab99a | 2009-05-03 18:23:30 +0000 | [diff] [blame] | 1072 | SkPaint paint; |
| 1073 | |
| 1074 | paint.setDither(true); |
reed@google.com | 50dfa01 | 2011-04-01 19:05:36 +0000 | [diff] [blame] | 1075 | canvas.drawBitmap(*src, 0, 0, &paint); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1076 | } |
| 1077 | |
reed@google.com | 50dfa01 | 2011-04-01 19:05:36 +0000 | [diff] [blame] | 1078 | dst->swap(tmpDst); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1079 | return true; |
| 1080 | } |
| 1081 | |
commit-bot@chromium.org | fab349c | 2014-03-05 02:34:58 +0000 | [diff] [blame] | 1082 | bool SkBitmap::deepCopyTo(SkBitmap* dst) const { |
commit-bot@chromium.org | eeef0cc | 2014-05-21 15:58:00 +0000 | [diff] [blame] | 1083 | const SkBitmap::Config dstConfig = this->config(); |
| 1084 | const SkColorType dstCT = SkBitmapConfigToColorType(dstConfig); |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 1085 | |
commit-bot@chromium.org | 8a2ad3c | 2014-02-23 03:59:35 +0000 | [diff] [blame] | 1086 | if (!this->canCopyTo(dstCT)) { |
senorblanco@chromium.org | ef843cd | 2011-12-02 19:11:17 +0000 | [diff] [blame] | 1087 | return false; |
| 1088 | } |
| 1089 | |
| 1090 | // If we have a PixelRef, and it supports deep copy, use it. |
| 1091 | // Currently supported only by texture-backed bitmaps. |
| 1092 | if (fPixelRef) { |
commit-bot@chromium.org | eeef0cc | 2014-05-21 15:58:00 +0000 | [diff] [blame] | 1093 | SkPixelRef* pixelRef = fPixelRef->deepCopy(dstConfig); |
| 1094 | if (pixelRef) { |
| 1095 | uint32_t rowBytes; |
| 1096 | if (this->colorType() == dstCT) { |
| 1097 | // Since there is no subset to pass to deepCopy, and deepCopy |
| 1098 | // succeeded, the new pixel ref must be identical. |
| 1099 | SkASSERT(fPixelRef->info() == pixelRef->info()); |
| 1100 | pixelRef->cloneGenID(*fPixelRef); |
| 1101 | // Use the same rowBytes as the original. |
| 1102 | rowBytes = fRowBytes; |
| 1103 | } else { |
commit-bot@chromium.org | a3264e5 | 2014-05-30 13:26:10 +0000 | [diff] [blame] | 1104 | // With the new config, an appropriate fRowBytes will be computed by setInfo. |
commit-bot@chromium.org | eeef0cc | 2014-05-21 15:58:00 +0000 | [diff] [blame] | 1105 | rowBytes = 0; |
| 1106 | } |
| 1107 | |
| 1108 | SkImageInfo info = fInfo; |
| 1109 | info.fColorType = dstCT; |
commit-bot@chromium.org | a3264e5 | 2014-05-30 13:26:10 +0000 | [diff] [blame] | 1110 | if (!dst->setInfo(info, rowBytes)) { |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 1111 | return false; |
| 1112 | } |
commit-bot@chromium.org | eeef0cc | 2014-05-21 15:58:00 +0000 | [diff] [blame] | 1113 | dst->setPixelRef(pixelRef, fPixelRefOrigin)->unref(); |
senorblanco@chromium.org | ef843cd | 2011-12-02 19:11:17 +0000 | [diff] [blame] | 1114 | return true; |
| 1115 | } |
| 1116 | } |
| 1117 | |
| 1118 | if (this->getTexture()) { |
| 1119 | return false; |
| 1120 | } else { |
commit-bot@chromium.org | 8a2ad3c | 2014-02-23 03:59:35 +0000 | [diff] [blame] | 1121 | return this->copyTo(dst, dstCT, NULL); |
senorblanco@chromium.org | ef843cd | 2011-12-02 19:11:17 +0000 | [diff] [blame] | 1122 | } |
| 1123 | } |
| 1124 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1125 | /////////////////////////////////////////////////////////////////////////////// |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1126 | |
tomhudson@google.com | a87cd2a | 2011-06-15 16:50:27 +0000 | [diff] [blame] | 1127 | static bool GetBitmapAlpha(const SkBitmap& src, uint8_t* SK_RESTRICT alpha, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1128 | int alphaRowBytes) { |
| 1129 | SkASSERT(alpha != NULL); |
| 1130 | SkASSERT(alphaRowBytes >= src.width()); |
| 1131 | |
commit-bot@chromium.org | cba7378 | 2014-05-29 15:57:47 +0000 | [diff] [blame] | 1132 | SkColorType colorType = src.colorType(); |
| 1133 | int w = src.width(); |
| 1134 | int h = src.height(); |
| 1135 | size_t rb = src.rowBytes(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1136 | |
reed@android.com | 1cdcb51 | 2009-08-24 19:11:00 +0000 | [diff] [blame] | 1137 | SkAutoLockPixels alp(src); |
| 1138 | if (!src.readyToDraw()) { |
| 1139 | // zero out the alpha buffer and return |
| 1140 | while (--h >= 0) { |
| 1141 | memset(alpha, 0, w); |
| 1142 | alpha += alphaRowBytes; |
| 1143 | } |
| 1144 | return false; |
| 1145 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 1146 | |
commit-bot@chromium.org | cba7378 | 2014-05-29 15:57:47 +0000 | [diff] [blame] | 1147 | if (kAlpha_8_SkColorType == colorType && !src.isOpaque()) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1148 | const uint8_t* s = src.getAddr8(0, 0); |
| 1149 | while (--h >= 0) { |
| 1150 | memcpy(alpha, s, w); |
| 1151 | s += rb; |
| 1152 | alpha += alphaRowBytes; |
| 1153 | } |
commit-bot@chromium.org | cba7378 | 2014-05-29 15:57:47 +0000 | [diff] [blame] | 1154 | } else if (kN32_SkColorType == colorType && !src.isOpaque()) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1155 | const SkPMColor* SK_RESTRICT s = src.getAddr32(0, 0); |
| 1156 | while (--h >= 0) { |
| 1157 | for (int x = 0; x < w; x++) { |
| 1158 | alpha[x] = SkGetPackedA32(s[x]); |
| 1159 | } |
| 1160 | s = (const SkPMColor*)((const char*)s + rb); |
| 1161 | alpha += alphaRowBytes; |
| 1162 | } |
commit-bot@chromium.org | cba7378 | 2014-05-29 15:57:47 +0000 | [diff] [blame] | 1163 | } else if (kARGB_4444_SkColorType == colorType && !src.isOpaque()) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1164 | const SkPMColor16* SK_RESTRICT s = src.getAddr16(0, 0); |
| 1165 | while (--h >= 0) { |
| 1166 | for (int x = 0; x < w; x++) { |
| 1167 | alpha[x] = SkPacked4444ToA32(s[x]); |
| 1168 | } |
| 1169 | s = (const SkPMColor16*)((const char*)s + rb); |
| 1170 | alpha += alphaRowBytes; |
| 1171 | } |
commit-bot@chromium.org | cba7378 | 2014-05-29 15:57:47 +0000 | [diff] [blame] | 1172 | } else if (kIndex_8_SkColorType == colorType && !src.isOpaque()) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1173 | SkColorTable* ct = src.getColorTable(); |
| 1174 | if (ct) { |
| 1175 | const SkPMColor* SK_RESTRICT table = ct->lockColors(); |
| 1176 | const uint8_t* SK_RESTRICT s = src.getAddr8(0, 0); |
| 1177 | while (--h >= 0) { |
| 1178 | for (int x = 0; x < w; x++) { |
| 1179 | alpha[x] = SkGetPackedA32(table[s[x]]); |
| 1180 | } |
| 1181 | s += rb; |
| 1182 | alpha += alphaRowBytes; |
| 1183 | } |
reed@google.com | 0a6151d | 2013-10-10 14:44:56 +0000 | [diff] [blame] | 1184 | ct->unlockColors(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1185 | } |
| 1186 | } else { // src is opaque, so just fill alpha[] with 0xFF |
| 1187 | memset(alpha, 0xFF, h * alphaRowBytes); |
| 1188 | } |
reed@android.com | 1cdcb51 | 2009-08-24 19:11:00 +0000 | [diff] [blame] | 1189 | return true; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1190 | } |
| 1191 | |
| 1192 | #include "SkPaint.h" |
| 1193 | #include "SkMaskFilter.h" |
| 1194 | #include "SkMatrix.h" |
| 1195 | |
djsollen@google.com | cd9d69b | 2011-03-14 20:30:14 +0000 | [diff] [blame] | 1196 | bool SkBitmap::extractAlpha(SkBitmap* dst, const SkPaint* paint, |
djsollen@google.com | 57f4969 | 2011-02-23 20:46:31 +0000 | [diff] [blame] | 1197 | Allocator *allocator, SkIPoint* offset) const { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1198 | SkDEBUGCODE(this->validate();) |
| 1199 | |
djsollen@google.com | cd9d69b | 2011-03-14 20:30:14 +0000 | [diff] [blame] | 1200 | SkBitmap tmpBitmap; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1201 | SkMatrix identity; |
| 1202 | SkMask srcM, dstM; |
| 1203 | |
| 1204 | srcM.fBounds.set(0, 0, this->width(), this->height()); |
| 1205 | srcM.fRowBytes = SkAlign4(this->width()); |
| 1206 | srcM.fFormat = SkMask::kA8_Format; |
| 1207 | |
| 1208 | SkMaskFilter* filter = paint ? paint->getMaskFilter() : NULL; |
| 1209 | |
| 1210 | // compute our (larger?) dst bounds if we have a filter |
| 1211 | if (NULL != filter) { |
| 1212 | identity.reset(); |
| 1213 | srcM.fImage = NULL; |
| 1214 | if (!filter->filterMask(&dstM, srcM, identity, NULL)) { |
| 1215 | goto NO_FILTER_CASE; |
| 1216 | } |
| 1217 | dstM.fRowBytes = SkAlign4(dstM.fBounds.width()); |
| 1218 | } else { |
| 1219 | NO_FILTER_CASE: |
commit-bot@chromium.org | a3264e5 | 2014-05-30 13:26:10 +0000 | [diff] [blame] | 1220 | tmpBitmap.setInfo(SkImageInfo::MakeA8(this->width(), this->height()), srcM.fRowBytes); |
djsollen@google.com | cd9d69b | 2011-03-14 20:30:14 +0000 | [diff] [blame] | 1221 | if (!tmpBitmap.allocPixels(allocator, NULL)) { |
| 1222 | // Allocation of pixels for alpha bitmap failed. |
| 1223 | SkDebugf("extractAlpha failed to allocate (%d,%d) alpha bitmap\n", |
| 1224 | tmpBitmap.width(), tmpBitmap.height()); |
| 1225 | return false; |
| 1226 | } |
| 1227 | GetBitmapAlpha(*this, tmpBitmap.getAddr8(0, 0), srcM.fRowBytes); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1228 | if (offset) { |
| 1229 | offset->set(0, 0); |
| 1230 | } |
djsollen@google.com | cd9d69b | 2011-03-14 20:30:14 +0000 | [diff] [blame] | 1231 | tmpBitmap.swap(*dst); |
| 1232 | return true; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1233 | } |
bungeman@google.com | 02f5584 | 2011-10-04 21:25:00 +0000 | [diff] [blame] | 1234 | srcM.fImage = SkMask::AllocImage(srcM.computeImageSize()); |
| 1235 | SkAutoMaskFreeImage srcCleanup(srcM.fImage); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1236 | |
| 1237 | GetBitmapAlpha(*this, srcM.fImage, srcM.fRowBytes); |
| 1238 | if (!filter->filterMask(&dstM, srcM, identity, NULL)) { |
| 1239 | goto NO_FILTER_CASE; |
| 1240 | } |
bungeman@google.com | 02f5584 | 2011-10-04 21:25:00 +0000 | [diff] [blame] | 1241 | SkAutoMaskFreeImage dstCleanup(dstM.fImage); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1242 | |
commit-bot@chromium.org | a3264e5 | 2014-05-30 13:26:10 +0000 | [diff] [blame] | 1243 | tmpBitmap.setInfo(SkImageInfo::MakeA8(dstM.fBounds.width(), dstM.fBounds.height()), |
| 1244 | dstM.fRowBytes); |
djsollen@google.com | cd9d69b | 2011-03-14 20:30:14 +0000 | [diff] [blame] | 1245 | if (!tmpBitmap.allocPixels(allocator, NULL)) { |
| 1246 | // Allocation of pixels for alpha bitmap failed. |
| 1247 | SkDebugf("extractAlpha failed to allocate (%d,%d) alpha bitmap\n", |
| 1248 | tmpBitmap.width(), tmpBitmap.height()); |
| 1249 | return false; |
| 1250 | } |
| 1251 | memcpy(tmpBitmap.getPixels(), dstM.fImage, dstM.computeImageSize()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1252 | if (offset) { |
| 1253 | offset->set(dstM.fBounds.fLeft, dstM.fBounds.fTop); |
| 1254 | } |
djsollen@google.com | cd9d69b | 2011-03-14 20:30:14 +0000 | [diff] [blame] | 1255 | SkDEBUGCODE(tmpBitmap.validate();) |
| 1256 | |
| 1257 | tmpBitmap.swap(*dst); |
| 1258 | return true; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1259 | } |
| 1260 | |
| 1261 | /////////////////////////////////////////////////////////////////////////////// |
| 1262 | |
commit-bot@chromium.org | 968edca | 2014-05-23 13:21:55 +0000 | [diff] [blame] | 1263 | void SkBitmap::WriteRawPixels(SkWriteBuffer* buffer, const SkBitmap& bitmap) { |
| 1264 | const SkImageInfo info = bitmap.info(); |
| 1265 | SkAutoLockPixels alp(bitmap); |
| 1266 | if (0 == info.width() || 0 == info.height() || NULL == bitmap.getPixels()) { |
| 1267 | buffer->writeUInt(0); // instead of snugRB, signaling no pixels |
| 1268 | return; |
| 1269 | } |
| 1270 | |
| 1271 | const size_t snugRB = info.width() * info.bytesPerPixel(); |
| 1272 | const char* src = (const char*)bitmap.getPixels(); |
| 1273 | const size_t ramRB = bitmap.rowBytes(); |
skia.committer@gmail.com | 3c134a9 | 2014-05-24 03:05:26 +0000 | [diff] [blame] | 1274 | |
commit-bot@chromium.org | 968edca | 2014-05-23 13:21:55 +0000 | [diff] [blame] | 1275 | buffer->write32(SkToU32(snugRB)); |
| 1276 | info.flatten(*buffer); |
| 1277 | |
| 1278 | const size_t size = snugRB * info.height(); |
| 1279 | SkAutoMalloc storage(size); |
| 1280 | char* dst = (char*)storage.get(); |
| 1281 | for (int y = 0; y < info.height(); ++y) { |
| 1282 | memcpy(dst, src, snugRB); |
| 1283 | dst += snugRB; |
| 1284 | src += ramRB; |
| 1285 | } |
| 1286 | buffer->writeByteArray(storage.get(), size); |
| 1287 | |
| 1288 | SkColorTable* ct = bitmap.getColorTable(); |
| 1289 | if (kIndex_8_SkColorType == info.colorType() && ct) { |
| 1290 | buffer->writeBool(true); |
| 1291 | ct->writeToBuffer(*buffer); |
| 1292 | } else { |
| 1293 | buffer->writeBool(false); |
| 1294 | } |
| 1295 | } |
| 1296 | |
| 1297 | bool SkBitmap::ReadRawPixels(SkReadBuffer* buffer, SkBitmap* bitmap) { |
| 1298 | const size_t snugRB = buffer->readUInt(); |
| 1299 | if (0 == snugRB) { // no pixels |
| 1300 | return false; |
| 1301 | } |
| 1302 | |
| 1303 | SkImageInfo info; |
| 1304 | info.unflatten(*buffer); |
| 1305 | |
| 1306 | const size_t ramRB = info.minRowBytes(); |
| 1307 | const int height = info.height(); |
| 1308 | const size_t snugSize = snugRB * height; |
| 1309 | const size_t ramSize = ramRB * height; |
commit-bot@chromium.org | 0585843 | 2014-05-30 01:06:44 +0000 | [diff] [blame] | 1310 | if (!buffer->validate(snugSize <= ramSize)) { |
| 1311 | return false; |
| 1312 | } |
commit-bot@chromium.org | 968edca | 2014-05-23 13:21:55 +0000 | [diff] [blame] | 1313 | |
| 1314 | char* dst = (char*)sk_malloc_throw(ramSize); |
| 1315 | buffer->readByteArray(dst, snugSize); |
| 1316 | SkAutoDataUnref data(SkData::NewFromMalloc(dst, ramSize)); |
| 1317 | |
| 1318 | if (snugSize != ramSize) { |
| 1319 | const char* srcRow = dst + snugRB * (height - 1); |
| 1320 | char* dstRow = dst + ramRB * (height - 1); |
| 1321 | for (int y = height - 1; y >= 1; --y) { |
| 1322 | memmove(dstRow, srcRow, snugRB); |
| 1323 | srcRow -= snugRB; |
| 1324 | dstRow -= ramRB; |
| 1325 | } |
| 1326 | SkASSERT(srcRow == dstRow); // first row does not need to be moved |
| 1327 | } |
skia.committer@gmail.com | 3c134a9 | 2014-05-24 03:05:26 +0000 | [diff] [blame] | 1328 | |
commit-bot@chromium.org | 968edca | 2014-05-23 13:21:55 +0000 | [diff] [blame] | 1329 | SkAutoTUnref<SkColorTable> ctable; |
| 1330 | if (buffer->readBool()) { |
| 1331 | ctable.reset(SkNEW_ARGS(SkColorTable, (*buffer))); |
| 1332 | } |
skia.committer@gmail.com | 3c134a9 | 2014-05-24 03:05:26 +0000 | [diff] [blame] | 1333 | |
commit-bot@chromium.org | 968edca | 2014-05-23 13:21:55 +0000 | [diff] [blame] | 1334 | SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewWithData(info, info.minRowBytes(), |
| 1335 | ctable.get(), data.get())); |
commit-bot@chromium.org | a3264e5 | 2014-05-30 13:26:10 +0000 | [diff] [blame] | 1336 | bitmap->setInfo(pr->info()); |
commit-bot@chromium.org | 968edca | 2014-05-23 13:21:55 +0000 | [diff] [blame] | 1337 | bitmap->setPixelRef(pr, 0, 0); |
| 1338 | return true; |
| 1339 | } |
| 1340 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1341 | enum { |
| 1342 | SERIALIZE_PIXELTYPE_NONE, |
djsollen@google.com | 21830d9 | 2012-08-07 19:49:41 +0000 | [diff] [blame] | 1343 | SERIALIZE_PIXELTYPE_REF_DATA |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1344 | }; |
| 1345 | |
commit-bot@chromium.org | 851155c | 2014-05-27 14:03:51 +0000 | [diff] [blame] | 1346 | void SkBitmap::legacyUnflatten(SkReadBuffer& buffer) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1347 | this->reset(); |
weita@google.com | f9ab99a | 2009-05-03 18:23:30 +0000 | [diff] [blame] | 1348 | |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 1349 | SkImageInfo info; |
| 1350 | info.unflatten(buffer); |
| 1351 | size_t rowBytes = buffer.readInt(); |
commit-bot@chromium.org | 33fed14 | 2014-02-13 18:46:13 +0000 | [diff] [blame] | 1352 | if (!buffer.validate((info.width() >= 0) && (info.height() >= 0) && |
| 1353 | SkColorTypeIsValid(info.fColorType) && |
| 1354 | SkAlphaTypeIsValid(info.fAlphaType) && |
| 1355 | validate_alphaType(info.fColorType, info.fAlphaType) && |
| 1356 | info.validRowBytes(rowBytes))) { |
| 1357 | return; |
| 1358 | } |
weita@google.com | f9ab99a | 2009-05-03 18:23:30 +0000 | [diff] [blame] | 1359 | |
commit-bot@chromium.org | a3264e5 | 2014-05-30 13:26:10 +0000 | [diff] [blame] | 1360 | bool configIsValid = this->setInfo(info, rowBytes); |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 1361 | buffer.validate(configIsValid); |
weita@google.com | f9ab99a | 2009-05-03 18:23:30 +0000 | [diff] [blame] | 1362 | |
djsollen@google.com | c73dd5c | 2012-08-07 15:54:32 +0000 | [diff] [blame] | 1363 | int reftype = buffer.readInt(); |
commit-bot@chromium.org | ce33d60 | 2013-11-25 21:46:31 +0000 | [diff] [blame] | 1364 | if (buffer.validate((SERIALIZE_PIXELTYPE_REF_DATA == reftype) || |
| 1365 | (SERIALIZE_PIXELTYPE_NONE == reftype))) { |
| 1366 | switch (reftype) { |
| 1367 | case SERIALIZE_PIXELTYPE_REF_DATA: { |
reed@google.com | 672588b | 2014-01-08 15:42:01 +0000 | [diff] [blame] | 1368 | SkIPoint origin; |
| 1369 | origin.fX = buffer.readInt(); |
| 1370 | origin.fY = buffer.readInt(); |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 1371 | size_t offset = origin.fY * rowBytes + origin.fX * info.bytesPerPixel(); |
commit-bot@chromium.org | ce33d60 | 2013-11-25 21:46:31 +0000 | [diff] [blame] | 1372 | SkPixelRef* pr = buffer.readPixelRef(); |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 1373 | if (!buffer.validate((NULL == pr) || |
| 1374 | (pr->getAllocatedSizeInBytes() >= (offset + this->getSafeSize())))) { |
reed@google.com | 672588b | 2014-01-08 15:42:01 +0000 | [diff] [blame] | 1375 | origin.setZero(); |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 1376 | } |
reed@google.com | 672588b | 2014-01-08 15:42:01 +0000 | [diff] [blame] | 1377 | SkSafeUnref(this->setPixelRef(pr, origin)); |
commit-bot@chromium.org | ce33d60 | 2013-11-25 21:46:31 +0000 | [diff] [blame] | 1378 | break; |
| 1379 | } |
| 1380 | case SERIALIZE_PIXELTYPE_NONE: |
| 1381 | break; |
| 1382 | default: |
| 1383 | SkDEBUGFAIL("unrecognized pixeltype in serialized data"); |
| 1384 | sk_throw(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1385 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1386 | } |
| 1387 | } |
| 1388 | |
| 1389 | /////////////////////////////////////////////////////////////////////////////// |
| 1390 | |
| 1391 | SkBitmap::RLEPixels::RLEPixels(int width, int height) { |
| 1392 | fHeight = height; |
commit-bot@chromium.org | 235002f | 2013-10-09 18:39:59 +0000 | [diff] [blame] | 1393 | fYPtrs = (uint8_t**)sk_calloc_throw(height * sizeof(uint8_t*)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1394 | } |
| 1395 | |
| 1396 | SkBitmap::RLEPixels::~RLEPixels() { |
| 1397 | sk_free(fYPtrs); |
| 1398 | } |
| 1399 | |
| 1400 | /////////////////////////////////////////////////////////////////////////////// |
| 1401 | |
| 1402 | #ifdef SK_DEBUG |
| 1403 | void SkBitmap::validate() const { |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 1404 | fInfo.validate(); |
commit-bot@chromium.org | d5414e5 | 2014-02-13 22:30:38 +0000 | [diff] [blame] | 1405 | |
| 1406 | // ImageInfo may not require this, but Bitmap ensures that opaque-only |
| 1407 | // colorTypes report opaque for their alphatype |
| 1408 | if (kRGB_565_SkColorType == fInfo.colorType()) { |
| 1409 | SkASSERT(kOpaque_SkAlphaType == fInfo.alphaType()); |
| 1410 | } |
| 1411 | |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 1412 | SkASSERT(fInfo.validRowBytes(fRowBytes)); |
scroggo@google.com | 8e990eb | 2013-06-14 15:55:56 +0000 | [diff] [blame] | 1413 | uint8_t allFlags = kImageIsOpaque_Flag | kImageIsVolatile_Flag | kImageIsImmutable_Flag; |
| 1414 | #ifdef SK_BUILD_FOR_ANDROID |
| 1415 | allFlags |= kHasHardwareMipMap_Flag; |
| 1416 | #endif |
| 1417 | SkASSERT(fFlags <= allFlags); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1418 | SkASSERT(fPixelLockCount >= 0); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1419 | |
reed@google.com | 615316c | 2014-01-15 19:15:23 +0000 | [diff] [blame] | 1420 | if (fPixels) { |
| 1421 | SkASSERT(fPixelRef); |
| 1422 | SkASSERT(fPixelLockCount > 0); |
| 1423 | SkASSERT(fPixelRef->isLocked()); |
| 1424 | SkASSERT(fPixelRef->rowBytes() == fRowBytes); |
| 1425 | SkASSERT(fPixelRefOrigin.fX >= 0); |
| 1426 | SkASSERT(fPixelRefOrigin.fY >= 0); |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 1427 | SkASSERT(fPixelRef->info().width() >= (int)this->width() + fPixelRefOrigin.fX); |
| 1428 | SkASSERT(fPixelRef->info().fHeight >= (int)this->height() + fPixelRefOrigin.fY); |
| 1429 | SkASSERT(fPixelRef->rowBytes() >= fInfo.minRowBytes()); |
reed@google.com | 615316c | 2014-01-15 19:15:23 +0000 | [diff] [blame] | 1430 | } else { |
| 1431 | SkASSERT(NULL == fColorTable); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1432 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1433 | } |
| 1434 | #endif |
robertphillips@google.com | 76f9e93 | 2013-01-15 20:17:47 +0000 | [diff] [blame] | 1435 | |
commit-bot@chromium.org | 0f10f7b | 2014-03-13 18:02:17 +0000 | [diff] [blame] | 1436 | #ifndef SK_IGNORE_TO_STRING |
robertphillips@google.com | 76f9e93 | 2013-01-15 20:17:47 +0000 | [diff] [blame] | 1437 | void SkBitmap::toString(SkString* str) const { |
| 1438 | |
commit-bot@chromium.org | cba7378 | 2014-05-29 15:57:47 +0000 | [diff] [blame] | 1439 | static const char* gColorTypeNames[kLastEnum_SkColorType + 1] = { |
| 1440 | "UNKNOWN", "A8", "565", "4444", "RGBA", "BGRA", "INDEX8", |
robertphillips@google.com | 76f9e93 | 2013-01-15 20:17:47 +0000 | [diff] [blame] | 1441 | }; |
| 1442 | |
| 1443 | str->appendf("bitmap: ((%d, %d) %s", this->width(), this->height(), |
commit-bot@chromium.org | cba7378 | 2014-05-29 15:57:47 +0000 | [diff] [blame] | 1444 | gColorTypeNames[this->colorType()]); |
robertphillips@google.com | 76f9e93 | 2013-01-15 20:17:47 +0000 | [diff] [blame] | 1445 | |
| 1446 | str->append(" ("); |
| 1447 | if (this->isOpaque()) { |
| 1448 | str->append("opaque"); |
| 1449 | } else { |
| 1450 | str->append("transparent"); |
| 1451 | } |
| 1452 | if (this->isImmutable()) { |
| 1453 | str->append(", immutable"); |
| 1454 | } else { |
| 1455 | str->append(", not-immutable"); |
| 1456 | } |
| 1457 | str->append(")"); |
| 1458 | |
| 1459 | SkPixelRef* pr = this->pixelRef(); |
| 1460 | if (NULL == pr) { |
| 1461 | // show null or the explicit pixel address (rare) |
| 1462 | str->appendf(" pixels:%p", this->getPixels()); |
| 1463 | } else { |
| 1464 | const char* uri = pr->getURI(); |
| 1465 | if (NULL != uri) { |
| 1466 | str->appendf(" uri:\"%s\"", uri); |
| 1467 | } else { |
| 1468 | str->appendf(" pixelref:%p", pr); |
| 1469 | } |
| 1470 | } |
| 1471 | |
| 1472 | str->append(")"); |
| 1473 | } |
| 1474 | #endif |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 1475 | |
| 1476 | /////////////////////////////////////////////////////////////////////////////// |
| 1477 | |
| 1478 | #ifdef SK_DEBUG |
| 1479 | void SkImageInfo::validate() const { |
| 1480 | SkASSERT(fWidth >= 0); |
| 1481 | SkASSERT(fHeight >= 0); |
| 1482 | SkASSERT(SkColorTypeIsValid(fColorType)); |
| 1483 | SkASSERT(SkAlphaTypeIsValid(fAlphaType)); |
| 1484 | } |
| 1485 | #endif |