18a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/* 2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2006 The Android Open Source Project 38a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 68a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkBitmap_DEFINED 98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkBitmap_DEFINED 108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkColor.h" 1264a0ec36555352ec31aa7c5a7630a5d042b010badjsollen@google.com#include "SkColorTable.h" 133443fd88862e25199973c2e98075d2e12ef21be0reed@google.com#include "SkImageInfo.h" 148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPoint.h" 158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRefCnt.h" 168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 17848250415eddc54075f7eb8795e8db79e749c6abreed#ifdef SK_SUPPORT_LEGACY_ALLOCPIXELS_BOOL 18848250415eddc54075f7eb8795e8db79e749c6abreed #define SK_ALLOCPIXELS_RETURN_TYPE bool 19848250415eddc54075f7eb8795e8db79e749c6abreed #define SK_ALLOCPIXELS_RETURN_TRUE return true 20848250415eddc54075f7eb8795e8db79e749c6abreed #define SK_ALLOCPIXELS_RETURN_FAIL return false 21848250415eddc54075f7eb8795e8db79e749c6abreed#else 22848250415eddc54075f7eb8795e8db79e749c6abreed #define SK_ALLOCPIXELS_RETURN_TYPE void 23848250415eddc54075f7eb8795e8db79e749c6abreed #define SK_ALLOCPIXELS_RETURN_TRUE return 24848250415eddc54075f7eb8795e8db79e749c6abreed #define SK_ALLOCPIXELS_RETURN_FAIL sk_throw() 25848250415eddc54075f7eb8795e8db79e749c6abreed#endif 26848250415eddc54075f7eb8795e8db79e749c6abreed 27dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.orgstruct SkMask; 288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstruct SkIRect; 29fb2d3c69816253ab7d2df576718c252ae1158c65reed@google.comstruct SkRect; 308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkPaint; 318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkPixelRef; 329ebcac54635cde63110d73ad7c43d70772e7872freed@google.comclass SkPixelRefFactory; 338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkRegion; 3476f9e938df0b5826fd4c80b854ceafaf385cfbe1robertphillips@google.comclass SkString; 35b8d00db075b5ea09e353508a26ef5ced50722a6ccommit-bot@chromium.orgclass GrTexture; 36ce4e53a2347040a3c145768c193a7a7958c0d4ecreed@android.com 378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkBitmap 388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com The SkBitmap class specifies a raster bitmap. A bitmap has an integer width 40ddd014e65264e3f18b2d4305dd2fbc81549f5180reed and height, and a format (colortype), and a pointer to the actual pixels. 414b33d28eb369622964d22d5cc4a6e3f0eb11a14ctomhudson@google.com Bitmaps can be drawn into a SkCanvas, but they are also used to specify the 424b33d28eb369622964d22d5cc4a6e3f0eb11a14ctomhudson@google.com target of a SkCanvas' drawing operations. 434b33d28eb369622964d22d5cc4a6e3f0eb11a14ctomhudson@google.com A const SkBitmap exposes getAddr(), which lets a caller write its pixels; 444b33d28eb369622964d22d5cc4a6e3f0eb11a14ctomhudson@google.com the constness is considered to apply to the bitmap's configuration, not 454b33d28eb369622964d22d5cc4a6e3f0eb11a14ctomhudson@google.com its contents. 468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/ 477ffb1b21abcc7bbed5a0fc711f6dd7b9dbb4f577ctguil@chromium.orgclass SK_API SkBitmap { 488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 49eddb02c82d6e35a05f84798b23aac48a446c1aa6commit-bot@chromium.org class SK_API Allocator; 508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 515dd510f1d277a31752a4c6046c4e42385605a393reed@google.com /** 525dd510f1d277a31752a4c6046c4e42385605a393reed@google.com * Default construct creates a bitmap with zero width and height, and no pixels. 53ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * Its colortype is set to kUnknown_SkColorType. 545dd510f1d277a31752a4c6046c4e42385605a393reed@google.com */ 558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBitmap(); 565dd510f1d277a31752a4c6046c4e42385605a393reed@google.com 575dd510f1d277a31752a4c6046c4e42385605a393reed@google.com /** 585dd510f1d277a31752a4c6046c4e42385605a393reed@google.com * Copy the settings from the src into this bitmap. If the src has pixels 595dd510f1d277a31752a4c6046c4e42385605a393reed@google.com * allocated, they will be shared, not copied, so that the two bitmaps will 605dd510f1d277a31752a4c6046c4e42385605a393reed@google.com * reference the same memory for the pixels. If a deep copy is needed, 615dd510f1d277a31752a4c6046c4e42385605a393reed@google.com * where the new bitmap has its own separate copy of the pixels, use 625dd510f1d277a31752a4c6046c4e42385605a393reed@google.com * deepCopyTo(). 635dd510f1d277a31752a4c6046c4e42385605a393reed@google.com */ 648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBitmap(const SkBitmap& src); 655dd510f1d277a31752a4c6046c4e42385605a393reed@google.com 668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ~SkBitmap(); 678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Copies the src bitmap into this bitmap. Ownership of the src bitmap's pixels remains 698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com with the src bitmap. 708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBitmap& operator=(const SkBitmap& src); 728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Swap the fields of the two bitmaps. This routine is guaranteed to never fail or throw. 738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // This method is not exported to java. 758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void swap(SkBitmap& other); 76f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 7761e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org /////////////////////////////////////////////////////////////////////////// 7861e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org 7961e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org const SkImageInfo& info() const { return fInfo; } 8061e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org 81e5ea500d4714a7d84de2bf913e81be3b65d2de68reed int width() const { return fInfo.width(); } 82e5ea500d4714a7d84de2bf913e81be3b65d2de68reed int height() const { return fInfo.height(); } 83e5ea500d4714a7d84de2bf913e81be3b65d2de68reed SkColorType colorType() const { return fInfo.colorType(); } 84e5ea500d4714a7d84de2bf913e81be3b65d2de68reed SkAlphaType alphaType() const { return fInfo.alphaType(); } 8561e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org 86ddd014e65264e3f18b2d4305dd2fbc81549f5180reed /** 87ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * Return the number of bytes per pixel based on the colortype. If the colortype is 88ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * kUnknown_SkColorType, then 0 is returned. 8961e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org */ 9061e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org int bytesPerPixel() const { return fInfo.bytesPerPixel(); } 9161e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org 92ddd014e65264e3f18b2d4305dd2fbc81549f5180reed /** 93ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * Return the rowbytes expressed as a number of pixels (like width and height). 94ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * If the colortype is kUnknown_SkColorType, then 0 is returned. 9561e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org */ 9661e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org int rowBytesAsPixels() const { 9761e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org return fRowBytes >> this->shiftPerPixel(); 9861e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org } 9961e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org 100ddd014e65264e3f18b2d4305dd2fbc81549f5180reed /** 101ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * Return the shift amount per pixel (i.e. 0 for 1-byte per pixel, 1 for 2-bytes per pixel 102ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * colortypes, 2 for 4-bytes per pixel colortypes). Return 0 for kUnknown_SkColorType. 10361e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org */ 10461e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org int shiftPerPixel() const { return this->bytesPerPixel() >> 1; } 10561e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org 10661e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org /////////////////////////////////////////////////////////////////////////// 10761e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org 1088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return true iff the bitmap has empty dimensions. 10950b393a768c0311b3210f723325fd27bf161136bcommit-bot@chromium.org * Hey! Before you use this, see if you really want to know drawsNothing() instead. 11050b393a768c0311b3210f723325fd27bf161136bcommit-bot@chromium.org */ 11161e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org bool empty() const { return fInfo.isEmpty(); } 112f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 113c84b8335ee4fd864c30a4703afc643cf4b5010d9djsollen@google.com /** Return true iff the bitmap has no pixelref. Note: this can return true even if the 11450b393a768c0311b3210f723325fd27bf161136bcommit-bot@chromium.org * dimensions of the bitmap are > 0 (see empty()). 11550b393a768c0311b3210f723325fd27bf161136bcommit-bot@chromium.org * Hey! Before you use this, see if you really want to know drawsNothing() instead. 11650b393a768c0311b3210f723325fd27bf161136bcommit-bot@chromium.org */ 117c84b8335ee4fd864c30a4703afc643cf4b5010d9djsollen@google.com bool isNull() const { return NULL == fPixelRef; } 1188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11950b393a768c0311b3210f723325fd27bf161136bcommit-bot@chromium.org /** Return true iff drawing this bitmap has no effect. 12050b393a768c0311b3210f723325fd27bf161136bcommit-bot@chromium.org */ 12150b393a768c0311b3210f723325fd27bf161136bcommit-bot@chromium.org bool drawsNothing() const { return this->empty() || this->isNull(); } 12250b393a768c0311b3210f723325fd27bf161136bcommit-bot@chromium.org 1234469938e92d779dff05e745559e67907bbf21e78reed@google.com /** Return the number of bytes between subsequent rows of the bitmap. */ 1240ba4bf427acbd7707d04192a98c77ef194a0f25ascroggo@google.com size_t rowBytes() const { return fRowBytes; } 125f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 126383a697692cf46951fd451f6f4c3d03634a6a1cbreed@google.com /** 127383a697692cf46951fd451f6f4c3d03634a6a1cbreed@google.com * Set the bitmap's alphaType, returning true on success. If false is 128383a697692cf46951fd451f6f4c3d03634a6a1cbreed@google.com * returned, then the specified new alphaType is incompatible with the 129ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * colortype, and the current alphaType is unchanged. 1300e8d0d6cdc2e02946b099006d0a47e60764905e5commit-bot@chromium.org * 1310e8d0d6cdc2e02946b099006d0a47e60764905e5commit-bot@chromium.org * Note: this changes the alphatype for the underlying pixels, which means 1320e8d0d6cdc2e02946b099006d0a47e60764905e5commit-bot@chromium.org * that all bitmaps that might be sharing (subsets of) the pixels will 133c1587f94a77eaafe257a6ecf504364d40362c66areed@google.com * be affected. 134383a697692cf46951fd451f6f4c3d03634a6a1cbreed@google.com */ 135383a697692cf46951fd451f6f4c3d03634a6a1cbreed@google.com bool setAlphaType(SkAlphaType); 136383a697692cf46951fd451f6f4c3d03634a6a1cbreed@google.com 1378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the address of the pixels for this SkBitmap. 1388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void* getPixels() const { return fPixels; } 1408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the byte size of the pixels, based on the height and rowBytes. 1428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Note this truncates the result to 32bits. Call getSize64() to detect 1438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if the real size exceeds 32bits. 1448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 145e5ea500d4714a7d84de2bf913e81be3b65d2de68reed size_t getSize() const { return fInfo.height() * fRowBytes; } 146f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 14786bff1f008308267c4ff75456b202a9cf60c6193wjmaclean@chromium.org /** Return the number of bytes from the pointer returned by getPixels() 14886bff1f008308267c4ff75456b202a9cf60c6193wjmaclean@chromium.org to the end of the allocated space in the buffer. Required in 149d27fe34d1eb7640bb17062aa8529283e297de18eepoger@google.com cases where extractSubset has been called. 15086bff1f008308267c4ff75456b202a9cf60c6193wjmaclean@chromium.org */ 15161e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org size_t getSafeSize() const { return fInfo.getSafeSize(fRowBytes); } 15286bff1f008308267c4ff75456b202a9cf60c6193wjmaclean@chromium.org 15357212f9469c8056bab3c85243dbb904e386eab95reed@google.com /** 15457212f9469c8056bab3c85243dbb904e386eab95reed@google.com * Return the full size of the bitmap, in bytes. 15557212f9469c8056bab3c85243dbb904e386eab95reed@google.com */ 15657212f9469c8056bab3c85243dbb904e386eab95reed@google.com int64_t computeSize64() const { 157e5ea500d4714a7d84de2bf913e81be3b65d2de68reed return sk_64_mul(fInfo.height(), fRowBytes); 15857212f9469c8056bab3c85243dbb904e386eab95reed@google.com } 15957212f9469c8056bab3c85243dbb904e386eab95reed@google.com 16057212f9469c8056bab3c85243dbb904e386eab95reed@google.com /** 16157212f9469c8056bab3c85243dbb904e386eab95reed@google.com * Return the number of bytes from the pointer returned by getPixels() 16257212f9469c8056bab3c85243dbb904e386eab95reed@google.com * to the end of the allocated space in the buffer. This may be smaller 16357212f9469c8056bab3c85243dbb904e386eab95reed@google.com * than computeSize64() if there is any rowbytes padding beyond the width. 16457212f9469c8056bab3c85243dbb904e386eab95reed@google.com */ 16557212f9469c8056bab3c85243dbb904e386eab95reed@google.com int64_t computeSafeSize64() const { 16661e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org return fInfo.getSafeSize64(fRowBytes); 16757212f9469c8056bab3c85243dbb904e386eab95reed@google.com } 16857212f9469c8056bab3c85243dbb904e386eab95reed@google.com 169b052129a4121c1e3f051e374541a93d3d7a98064junov@chromium.org /** Returns true if this bitmap is marked as immutable, meaning that the 170b052129a4121c1e3f051e374541a93d3d7a98064junov@chromium.org contents of its pixels will not change for the lifetime of the bitmap. 171b052129a4121c1e3f051e374541a93d3d7a98064junov@chromium.org */ 172b052129a4121c1e3f051e374541a93d3d7a98064junov@chromium.org bool isImmutable() const; 173b052129a4121c1e3f051e374541a93d3d7a98064junov@chromium.org 174b052129a4121c1e3f051e374541a93d3d7a98064junov@chromium.org /** Marks this bitmap as immutable, meaning that the contents of its 175b052129a4121c1e3f051e374541a93d3d7a98064junov@chromium.org pixels will not change for the lifetime of the bitmap and of the 176fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com underlying pixelref. This state can be set, but it cannot be 177b052129a4121c1e3f051e374541a93d3d7a98064junov@chromium.org cleared once it is set. This state propagates to all other bitmaps 178b052129a4121c1e3f051e374541a93d3d7a98064junov@chromium.org that share the same pixelref. 179b052129a4121c1e3f051e374541a93d3d7a98064junov@chromium.org */ 180b052129a4121c1e3f051e374541a93d3d7a98064junov@chromium.org void setImmutable(); 181b052129a4121c1e3f051e374541a93d3d7a98064junov@chromium.org 1828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns true if the bitmap is opaque (has no translucent/transparent pixels). 1838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 184383a697692cf46951fd451f6f4c3d03634a6a1cbreed@google.com bool isOpaque() const { 185383a697692cf46951fd451f6f4c3d03634a6a1cbreed@google.com return SkAlphaTypeIsOpaque(this->alphaType()); 186383a697692cf46951fd451f6f4c3d03634a6a1cbreed@google.com } 1874ee7ae5dcfe2055cfcfc21bf2cec1d790330eb4ajunov@google.com 1884ee7ae5dcfe2055cfcfc21bf2cec1d790330eb4ajunov@google.com /** Returns true if the bitmap is volatile (i.e. should not be cached by devices.) 1894ee7ae5dcfe2055cfcfc21bf2cec1d790330eb4ajunov@google.com */ 1904ee7ae5dcfe2055cfcfc21bf2cec1d790330eb4ajunov@google.com bool isVolatile() const; 1914ee7ae5dcfe2055cfcfc21bf2cec1d790330eb4ajunov@google.com 192fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com /** Specify whether this bitmap is volatile. Bitmaps are not volatile by 1934ee7ae5dcfe2055cfcfc21bf2cec1d790330eb4ajunov@google.com default. Temporary bitmaps that are discarded after use should be 1944ee7ae5dcfe2055cfcfc21bf2cec1d790330eb4ajunov@google.com marked as volatile. This provides a hint to the device that the bitmap 195fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com should not be cached. Providing this hint when appropriate can 196fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com improve performance by avoiding unnecessary overhead and resource 1974ee7ae5dcfe2055cfcfc21bf2cec1d790330eb4ajunov@google.com consumption on the device. 1984ee7ae5dcfe2055cfcfc21bf2cec1d790330eb4ajunov@google.com */ 1994ee7ae5dcfe2055cfcfc21bf2cec1d790330eb4ajunov@google.com void setIsVolatile(bool); 2004ee7ae5dcfe2055cfcfc21bf2cec1d790330eb4ajunov@google.com 2018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Reset the bitmap to its initial state (see default constructor). If we are a (shared) 2028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com owner of the pixels, that ownership is decremented. 2038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void reset(); 2058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 20686b2e43a33c486a0b150aa14fadf7af8323a11f5reed@google.com /** 2072a7579d11796866b0026755ab52597d09f4509ccreed@google.com * This will brute-force return true if all of the pixels in the bitmap 2082a7579d11796866b0026755ab52597d09f4509ccreed@google.com * are opaque. If it fails to read the pixels, or encounters an error, 2092a7579d11796866b0026755ab52597d09f4509ccreed@google.com * it will return false. 2102a7579d11796866b0026755ab52597d09f4509ccreed@google.com * 2112a7579d11796866b0026755ab52597d09f4509ccreed@google.com * Since this can be an expensive operation, the bitmap stores a flag for 21221a0b10d7c28e2ca123ddbe32fd8388687b3ef2ccommit-bot@chromium.org * this (isOpaque). Only call this if you need to compute this value from 21321a0b10d7c28e2ca123ddbe32fd8388687b3ef2ccommit-bot@chromium.org * "unknown" pixels. 2142a7579d11796866b0026755ab52597d09f4509ccreed@google.com */ 2152a7579d11796866b0026755ab52597d09f4509ccreed@google.com static bool ComputeIsOpaque(const SkBitmap&); 2162a7579d11796866b0026755ab52597d09f4509ccreed@google.com 2172a7579d11796866b0026755ab52597d09f4509ccreed@google.com /** 21886b2e43a33c486a0b150aa14fadf7af8323a11f5reed@google.com * Return the bitmap's bounds [0, 0, width, height] as an SkRect 21986b2e43a33c486a0b150aa14fadf7af8323a11f5reed@google.com */ 22086b2e43a33c486a0b150aa14fadf7af8323a11f5reed@google.com void getBounds(SkRect* bounds) const; 22180e1459c32f5f3acbc688ae4f0e046aa283e8c3areed@google.com void getBounds(SkIRect* bounds) const; 22286b2e43a33c486a0b150aa14fadf7af8323a11f5reed@google.com 223a3264e53ee3f3c5d6a2c813df7e44b5b96d207f2commit-bot@chromium.org bool setInfo(const SkImageInfo&, size_t rowBytes = 0); 224a3264e53ee3f3c5d6a2c813df7e44b5b96d207f2commit-bot@chromium.org 2259230ea29718bcf1a92a89a1a518fb896bbbe00cfreed@google.com /** 226bae704b050491a8a98c67cb23eaccb10852d2bd5reed * Allocate the bitmap's pixels to match the requested image info. If the Factory 2279ebcac54635cde63110d73ad7c43d70772e7872freed@google.com * is non-null, call it to allcoate the pixelref. If the ImageInfo requires 2289ebcac54635cde63110d73ad7c43d70772e7872freed@google.com * a colortable, then ColorTable must be non-null, and will be ref'd. 2299ebcac54635cde63110d73ad7c43d70772e7872freed@google.com * On failure, the bitmap will be set to empty and return false. 2309ebcac54635cde63110d73ad7c43d70772e7872freed@google.com */ 231848250415eddc54075f7eb8795e8db79e749c6abreed bool SK_WARN_UNUSED_RESULT tryAllocPixels(const SkImageInfo&, SkPixelRefFactory*, SkColorTable*); 232848250415eddc54075f7eb8795e8db79e749c6abreed 233848250415eddc54075f7eb8795e8db79e749c6abreed SK_ALLOCPIXELS_RETURN_TYPE allocPixels(const SkImageInfo& info, SkPixelRefFactory* factory, 234848250415eddc54075f7eb8795e8db79e749c6abreed SkColorTable* ctable) { 235848250415eddc54075f7eb8795e8db79e749c6abreed if (!this->tryAllocPixels(info, factory, ctable)) { 236848250415eddc54075f7eb8795e8db79e749c6abreed SK_ALLOCPIXELS_RETURN_FAIL; 237848250415eddc54075f7eb8795e8db79e749c6abreed } 238848250415eddc54075f7eb8795e8db79e749c6abreed SK_ALLOCPIXELS_RETURN_TRUE; 239848250415eddc54075f7eb8795e8db79e749c6abreed } 240d2ac07b64b7d46e81d00d389781f9f83810f0095skia.committer@gmail.com 2419ebcac54635cde63110d73ad7c43d70772e7872freed@google.com /** 242bae704b050491a8a98c67cb23eaccb10852d2bd5reed * Allocate the bitmap's pixels to match the requested image info and 243bae704b050491a8a98c67cb23eaccb10852d2bd5reed * rowBytes. If the request cannot be met (e.g. the info is invalid or 244bae704b050491a8a98c67cb23eaccb10852d2bd5reed * the requested rowBytes are not compatible with the info 245bae704b050491a8a98c67cb23eaccb10852d2bd5reed * (e.g. rowBytes < info.minRowBytes() or rowBytes is not aligned with 246bae704b050491a8a98c67cb23eaccb10852d2bd5reed * the pixel size specified by info.colorType()) then false is returned 247bae704b050491a8a98c67cb23eaccb10852d2bd5reed * and the bitmap is set to empty. 248bae704b050491a8a98c67cb23eaccb10852d2bd5reed */ 249848250415eddc54075f7eb8795e8db79e749c6abreed bool SK_WARN_UNUSED_RESULT tryAllocPixels(const SkImageInfo& info, size_t rowBytes); 250bae704b050491a8a98c67cb23eaccb10852d2bd5reed 251848250415eddc54075f7eb8795e8db79e749c6abreed SK_ALLOCPIXELS_RETURN_TYPE allocPixels(const SkImageInfo& info, size_t rowBytes) { 252848250415eddc54075f7eb8795e8db79e749c6abreed if (!this->tryAllocPixels(info, rowBytes)) { 253848250415eddc54075f7eb8795e8db79e749c6abreed SK_ALLOCPIXELS_RETURN_FAIL; 254848250415eddc54075f7eb8795e8db79e749c6abreed } 255848250415eddc54075f7eb8795e8db79e749c6abreed SK_ALLOCPIXELS_RETURN_TRUE; 256848250415eddc54075f7eb8795e8db79e749c6abreed } 257848250415eddc54075f7eb8795e8db79e749c6abreed 258848250415eddc54075f7eb8795e8db79e749c6abreed bool SK_WARN_UNUSED_RESULT tryAllocPixels(const SkImageInfo& info) { 259848250415eddc54075f7eb8795e8db79e749c6abreed return this->tryAllocPixels(info, info.minRowBytes()); 260848250415eddc54075f7eb8795e8db79e749c6abreed } 261848250415eddc54075f7eb8795e8db79e749c6abreed 262848250415eddc54075f7eb8795e8db79e749c6abreed SK_ALLOCPIXELS_RETURN_TYPE allocPixels(const SkImageInfo& info) { 263bae704b050491a8a98c67cb23eaccb10852d2bd5reed return this->allocPixels(info, info.minRowBytes()); 2649ebcac54635cde63110d73ad7c43d70772e7872freed@google.com } 265d2ac07b64b7d46e81d00d389781f9f83810f0095skia.committer@gmail.com 266848250415eddc54075f7eb8795e8db79e749c6abreed bool SK_WARN_UNUSED_RESULT tryAllocN32Pixels(int width, int height, bool isOpaque = false) { 267e5ea500d4714a7d84de2bf913e81be3b65d2de68reed SkImageInfo info = SkImageInfo::MakeN32(width, height, 268e5ea500d4714a7d84de2bf913e81be3b65d2de68reed isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); 269848250415eddc54075f7eb8795e8db79e749c6abreed return this->tryAllocPixels(info); 270848250415eddc54075f7eb8795e8db79e749c6abreed } 271848250415eddc54075f7eb8795e8db79e749c6abreed 272848250415eddc54075f7eb8795e8db79e749c6abreed SK_ALLOCPIXELS_RETURN_TYPE allocN32Pixels(int width, int height, bool isOpaque = false) { 273e5ea500d4714a7d84de2bf913e81be3b65d2de68reed SkImageInfo info = SkImageInfo::MakeN32(width, height, 274e5ea500d4714a7d84de2bf913e81be3b65d2de68reed isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); 275eb9a46cbbb475e862a084aa2224ec18d4ac5e95breed@google.com return this->allocPixels(info); 276eb9a46cbbb475e862a084aa2224ec18d4ac5e95breed@google.com } 277848250415eddc54075f7eb8795e8db79e749c6abreed 278eb9a46cbbb475e862a084aa2224ec18d4ac5e95breed@google.com /** 2799ebcac54635cde63110d73ad7c43d70772e7872freed@google.com * Install a pixelref that wraps the specified pixels and rowBytes, and 2809ebcac54635cde63110d73ad7c43d70772e7872freed@google.com * optional ReleaseProc and context. When the pixels are no longer 28100f8d6c75d22ce8f95f932c5b101354b196fa0dfcommit-bot@chromium.org * referenced, if releaseProc is not null, it will be called with the 2829ebcac54635cde63110d73ad7c43d70772e7872freed@google.com * pixels and context as parameters. 2839ebcac54635cde63110d73ad7c43d70772e7872freed@google.com * On failure, the bitmap will be set to empty and return false. 2849ebcac54635cde63110d73ad7c43d70772e7872freed@google.com */ 28500f8d6c75d22ce8f95f932c5b101354b196fa0dfcommit-bot@chromium.org bool installPixels(const SkImageInfo&, void* pixels, size_t rowBytes, SkColorTable*, 28600f8d6c75d22ce8f95f932c5b101354b196fa0dfcommit-bot@chromium.org void (*releaseProc)(void* addr, void* context), void* context); 28700f8d6c75d22ce8f95f932c5b101354b196fa0dfcommit-bot@chromium.org 288dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org /** 289dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org * Call installPixels with no ReleaseProc specified. This means that the 290dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org * caller must ensure that the specified pixels are valid for the lifetime 291dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org * of the created bitmap (and its pixelRef). 292dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org */ 293dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org bool installPixels(const SkImageInfo& info, void* pixels, size_t rowBytes) { 29400f8d6c75d22ce8f95f932c5b101354b196fa0dfcommit-bot@chromium.org return this->installPixels(info, pixels, rowBytes, NULL, NULL, NULL); 295dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org } 296dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org 297dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org /** 298dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org * Calls installPixels() with the value in the SkMask. The caller must 299dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org * ensure that the specified mask pixels are valid for the lifetime 300dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org * of the created bitmap (and its pixelRef). 301dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org */ 302dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org bool installMaskPixels(const SkMask&); 303d2ac07b64b7d46e81d00d389781f9f83810f0095skia.committer@gmail.com 3048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Use this to assign a new pixel address for an existing bitmap. This 3058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com will automatically release any pixelref previously installed. Only call 3068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this if you are handling ownership/lifetime of the pixel memory. 307f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 3088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com If the bitmap retains a reference to the colortable (assuming it is 3098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com not null) it will take care of incrementing the reference count. 3108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param pixels Address for the pixels, managed by the caller. 3128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param ctable ColorTable (or null) that matches the specified pixels 3138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setPixels(void* p, SkColorTable* ctable = NULL); 3158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 31686bff1f008308267c4ff75456b202a9cf60c6193wjmaclean@chromium.org /** Copies the bitmap's pixels to the location pointed at by dst and returns 31786bff1f008308267c4ff75456b202a9cf60c6193wjmaclean@chromium.org true if possible, returns false otherwise. 31886bff1f008308267c4ff75456b202a9cf60c6193wjmaclean@chromium.org 319c69809745e6496564639e42ef998ad39adf7dfb8bsalomon@google.com In the case when the dstRowBytes matches the bitmap's rowBytes, the copy 320c69809745e6496564639e42ef998ad39adf7dfb8bsalomon@google.com may be made faster by copying over the dst's per-row padding (for all 321c69809745e6496564639e42ef998ad39adf7dfb8bsalomon@google.com rows but the last). By setting preserveDstPad to true the caller can 322c69809745e6496564639e42ef998ad39adf7dfb8bsalomon@google.com disable this optimization and ensure that pixels in the padding are not 323c69809745e6496564639e42ef998ad39adf7dfb8bsalomon@google.com overwritten. 32486bff1f008308267c4ff75456b202a9cf60c6193wjmaclean@chromium.org 32586bff1f008308267c4ff75456b202a9cf60c6193wjmaclean@chromium.org Always returns false for RLE formats. 32686bff1f008308267c4ff75456b202a9cf60c6193wjmaclean@chromium.org 32786bff1f008308267c4ff75456b202a9cf60c6193wjmaclean@chromium.org @param dst Location of destination buffer. 32886bff1f008308267c4ff75456b202a9cf60c6193wjmaclean@chromium.org @param dstSize Size of destination buffer. Must be large enough to hold 32986bff1f008308267c4ff75456b202a9cf60c6193wjmaclean@chromium.org pixels using indicated stride. 3300ba4bf427acbd7707d04192a98c77ef194a0f25ascroggo@google.com @param dstRowBytes Width of each line in the buffer. If 0, uses 33186bff1f008308267c4ff75456b202a9cf60c6193wjmaclean@chromium.org bitmap's internal stride. 332c69809745e6496564639e42ef998ad39adf7dfb8bsalomon@google.com @param preserveDstPad Must we preserve padding in the dst 33386bff1f008308267c4ff75456b202a9cf60c6193wjmaclean@chromium.org */ 3340ba4bf427acbd7707d04192a98c77ef194a0f25ascroggo@google.com bool copyPixelsTo(void* const dst, size_t dstSize, size_t dstRowBytes = 0, 3350ba4bf427acbd7707d04192a98c77ef194a0f25ascroggo@google.com bool preserveDstPad = false) const; 33686bff1f008308267c4ff75456b202a9cf60c6193wjmaclean@chromium.org 3378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Use the standard HeapAllocator to create the pixelref that manages the 338ddd014e65264e3f18b2d4305dd2fbc81549f5180reed pixel memory. It will be sized based on the current ImageInfo. 3398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com If this is called multiple times, a new pixelref object will be created 3408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com each time. 341f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 3428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com If the bitmap retains a reference to the colortable (assuming it is 3438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com not null) it will take care of incrementing the reference count. 3448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param ctable ColorTable (or null) to use with the pixels that will 346ddd014e65264e3f18b2d4305dd2fbc81549f5180reed be allocated. Only used if colortype == kIndex_8_SkColorType 3478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return true if the allocation succeeds. If not the pixelref field of 3488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the bitmap will be unchanged. 3498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 350848250415eddc54075f7eb8795e8db79e749c6abreed bool SK_WARN_UNUSED_RESULT tryAllocPixels(SkColorTable* ctable = NULL) { 351848250415eddc54075f7eb8795e8db79e749c6abreed return this->tryAllocPixels(NULL, ctable); 352848250415eddc54075f7eb8795e8db79e749c6abreed } 353848250415eddc54075f7eb8795e8db79e749c6abreed 354848250415eddc54075f7eb8795e8db79e749c6abreed SK_ALLOCPIXELS_RETURN_TYPE allocPixels(SkColorTable* ctable = NULL) { 3558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return this->allocPixels(NULL, ctable); 3568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 357f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 3588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Use the specified Allocator to create the pixelref that manages the 359ddd014e65264e3f18b2d4305dd2fbc81549f5180reed pixel memory. It will be sized based on the current ImageInfo. 3608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com If this is called multiple times, a new pixelref object will be created 3618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com each time. 362f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 3638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com If the bitmap retains a reference to the colortable (assuming it is 3648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com not null) it will take care of incrementing the reference count. 365f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 3668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param allocator The Allocator to use to create a pixelref that can 367ddd014e65264e3f18b2d4305dd2fbc81549f5180reed manage the pixel memory for the current ImageInfo. 368ddd014e65264e3f18b2d4305dd2fbc81549f5180reed If allocator is NULL, the standard HeapAllocator will be used. 3698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param ctable ColorTable (or null) to use with the pixels that will 370ddd014e65264e3f18b2d4305dd2fbc81549f5180reed be allocated. Only used if colortype == kIndex_8_SkColorType. 371ddd014e65264e3f18b2d4305dd2fbc81549f5180reed If it is non-null and the colortype is not indexed, it will 3728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com be ignored. 3738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return true if the allocation succeeds. If not the pixelref field of 3748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the bitmap will be unchanged. 3758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 376848250415eddc54075f7eb8795e8db79e749c6abreed bool SK_WARN_UNUSED_RESULT tryAllocPixels(Allocator* allocator, SkColorTable* ctable); 377848250415eddc54075f7eb8795e8db79e749c6abreed 378848250415eddc54075f7eb8795e8db79e749c6abreed SK_ALLOCPIXELS_RETURN_TYPE allocPixels(Allocator* allocator, SkColorTable* ctable) { 379848250415eddc54075f7eb8795e8db79e749c6abreed if (!this->tryAllocPixels(allocator, ctable)) { 380848250415eddc54075f7eb8795e8db79e749c6abreed SK_ALLOCPIXELS_RETURN_FAIL; 381848250415eddc54075f7eb8795e8db79e749c6abreed } 382848250415eddc54075f7eb8795e8db79e749c6abreed SK_ALLOCPIXELS_RETURN_TRUE; 383848250415eddc54075f7eb8795e8db79e749c6abreed } 384f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 385672588b684d484dce6ae251e9e163e4a46924322reed@google.com /** 386672588b684d484dce6ae251e9e163e4a46924322reed@google.com * Return the current pixelref object or NULL if there is none. This does 387672588b684d484dce6ae251e9e163e4a46924322reed@google.com * not affect the refcount of the pixelref. 388672588b684d484dce6ae251e9e163e4a46924322reed@google.com */ 3898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPixelRef* pixelRef() const { return fPixelRef; } 390672588b684d484dce6ae251e9e163e4a46924322reed@google.com 391672588b684d484dce6ae251e9e163e4a46924322reed@google.com /** 392672588b684d484dce6ae251e9e163e4a46924322reed@google.com * A bitmap can reference a subset of a pixelref's pixels. That means the 393672588b684d484dce6ae251e9e163e4a46924322reed@google.com * bitmap's width/height can be <= the dimensions of the pixelref. The 394672588b684d484dce6ae251e9e163e4a46924322reed@google.com * pixelref origin is the x,y location within the pixelref's pixels for 395672588b684d484dce6ae251e9e163e4a46924322reed@google.com * the bitmap's top/left corner. To be valid the following must be true: 396672588b684d484dce6ae251e9e163e4a46924322reed@google.com * 397672588b684d484dce6ae251e9e163e4a46924322reed@google.com * origin_x + bitmap_width <= pixelref_width 398672588b684d484dce6ae251e9e163e4a46924322reed@google.com * origin_y + bitmap_height <= pixelref_height 399672588b684d484dce6ae251e9e163e4a46924322reed@google.com * 400672588b684d484dce6ae251e9e163e4a46924322reed@google.com * pixelRefOrigin() returns this origin, or (0,0) if there is no pixelRef. 401672588b684d484dce6ae251e9e163e4a46924322reed@google.com */ 402672588b684d484dce6ae251e9e163e4a46924322reed@google.com SkIPoint pixelRefOrigin() const { return fPixelRefOrigin; } 403672588b684d484dce6ae251e9e163e4a46924322reed@google.com 404672588b684d484dce6ae251e9e163e4a46924322reed@google.com /** 405672588b684d484dce6ae251e9e163e4a46924322reed@google.com * Assign a pixelref and origin to the bitmap. Pixelrefs are reference, 406672588b684d484dce6ae251e9e163e4a46924322reed@google.com * so the existing one (if any) will be unref'd and the new one will be 407672588b684d484dce6ae251e9e163e4a46924322reed@google.com * ref'd. (x,y) specify the offset within the pixelref's pixels for the 408672588b684d484dce6ae251e9e163e4a46924322reed@google.com * top/left corner of the bitmap. For a bitmap that encompases the entire 409672588b684d484dce6ae251e9e163e4a46924322reed@google.com * pixels of the pixelref, these will be (0,0). 410672588b684d484dce6ae251e9e163e4a46924322reed@google.com */ 411672588b684d484dce6ae251e9e163e4a46924322reed@google.com SkPixelRef* setPixelRef(SkPixelRef* pr, int dx, int dy); 412672588b684d484dce6ae251e9e163e4a46924322reed@google.com 413672588b684d484dce6ae251e9e163e4a46924322reed@google.com SkPixelRef* setPixelRef(SkPixelRef* pr, const SkIPoint& origin) { 414672588b684d484dce6ae251e9e163e4a46924322reed@google.com return this->setPixelRef(pr, origin.fX, origin.fY); 415672588b684d484dce6ae251e9e163e4a46924322reed@google.com } 4161ae9111f33db7640ce87d55156c1b6d491237db2skia.committer@gmail.com 417672588b684d484dce6ae251e9e163e4a46924322reed@google.com SkPixelRef* setPixelRef(SkPixelRef* pr) { 418672588b684d484dce6ae251e9e163e4a46924322reed@google.com return this->setPixelRef(pr, 0, 0); 419672588b684d484dce6ae251e9e163e4a46924322reed@google.com } 420f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 4218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Call this to ensure that the bitmap points to the current pixel address 4228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com in the pixelref. Balance it with a call to unlockPixels(). These calls 4238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com are harmless if there is no pixelref. 4248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void lockPixels() const; 4268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** When you are finished access the pixel memory, call this to balance a 4278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com previous call to lockPixels(). This allows pixelrefs that implement 4288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com cached/deferred image decoding to know when there are active clients of 4298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com a given image. 4308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void unlockPixels() const; 432f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 4339c49bc3e643c435677727c1c0904c4a7cb7a6907reed@google.com /** 4349c49bc3e643c435677727c1c0904c4a7cb7a6907reed@google.com * Some bitmaps can return a copy of their pixels for lockPixels(), but 4359c49bc3e643c435677727c1c0904c4a7cb7a6907reed@google.com * that copy, if modified, will not be pushed back. These bitmaps should 4369c49bc3e643c435677727c1c0904c4a7cb7a6907reed@google.com * not be used as targets for a raster device/canvas (since all pixels 4379c49bc3e643c435677727c1c0904c4a7cb7a6907reed@google.com * modifications will be lost when unlockPixels() is called.) 4389c49bc3e643c435677727c1c0904c4a7cb7a6907reed@google.com */ 4399c49bc3e643c435677727c1c0904c4a7cb7a6907reed@google.com bool lockPixelsAreWritable() const; 4409c49bc3e643c435677727c1c0904c4a7cb7a6907reed@google.com 4418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Call this to be sure that the bitmap is valid enough to be drawn (i.e. 442ddd014e65264e3f18b2d4305dd2fbc81549f5180reed it has non-null pixels, and if required by its colortype, it has a 4438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com non-null colortable. Returns true if all of the above are met. 4448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool readyToDraw() const { 4468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return this->getPixels() != NULL && 44749f085dddff10473b6ebf832a974288300224e60bsalomon (this->colorType() != kIndex_8_SkColorType || fColorTable); 4488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 450ce4e53a2347040a3c145768c193a7a7958c0d4ecreed@android.com /** Returns the pixelRef's texture, or NULL 451ce4e53a2347040a3c145768c193a7a7958c0d4ecreed@android.com */ 452b8d00db075b5ea09e353508a26ef5ced50722a6ccommit-bot@chromium.org GrTexture* getTexture() const; 453ce4e53a2347040a3c145768c193a7a7958c0d4ecreed@android.com 45461e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org /** Return the bitmap's colortable, if it uses one (i.e. colorType is 45561e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org Index_8) and the pixels are locked. 456665b2cca88e25b821a69c9ce8a4fd7f551532012scroggo@google.com Otherwise returns NULL. Does not affect the colortable's 4578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com reference count. 4588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkColorTable* getColorTable() const { return fColorTable; } 4608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns a non-zero, unique value corresponding to the pixels in our 462c84b8335ee4fd864c30a4703afc643cf4b5010d9djsollen@google.com pixelref. Each time the pixels are changed (and notifyPixelsChanged 463c84b8335ee4fd864c30a4703afc643cf4b5010d9djsollen@google.com is called), a different generation ID will be returned. Finally, if 46458edea89627d347010cadc26ce3c092a9265a8eescroggo there is no pixelRef then zero is returned. 4658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint32_t getGenerationID() const; 467f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 4688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Call this if you have changed the contents of the pixels. This will in- 4698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com turn cause a different generation ID value to be returned from 4708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com getGenerationID(). 4718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void notifyPixelsChanged() const; 4738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 47460d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com /** 47560d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com * Fill the entire bitmap with the specified color. 476ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * If the bitmap's colortype does not support alpha (e.g. 565) then the alpha 477ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * of the color is ignored (treated as opaque). If the colortype only supports 47860d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com * alpha (e.g. A1 or A8) then the color's r,g,b components are ignored. 47960d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com */ 4808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void eraseColor(SkColor c) const { 4818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->eraseARGB(SkColorGetA(c), SkColorGetR(c), SkColorGetG(c), 4828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkColorGetB(c)); 4838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 484f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 48560d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com /** 48660d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com * Fill the entire bitmap with the specified color. 487ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * If the bitmap's colortype does not support alpha (e.g. 565) then the alpha 488ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * of the color is ignored (treated as opaque). If the colortype only supports 48960d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com * alpha (e.g. A1 or A8) then the color's r,g,b components are ignored. 49060d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com */ 49160d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com void eraseARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) const; 49260d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com 4934469938e92d779dff05e745559e67907bbf21e78reed@google.com SK_ATTR_DEPRECATED("use eraseARGB or eraseColor") 49460d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com void eraseRGB(U8CPU r, U8CPU g, U8CPU b) const { 49560d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com this->eraseARGB(0xFF, r, g, b); 49660d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com } 49760d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com 49860d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com /** 49960d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com * Fill the specified area of this bitmap with the specified color. 500ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * If the bitmap's colortype does not support alpha (e.g. 565) then the alpha 501ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * of the color is ignored (treated as opaque). If the colortype only supports 50260d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com * alpha (e.g. A1 or A8) then the color's r,g,b components are ignored. 50360d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com */ 50460d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com void eraseArea(const SkIRect& area, SkColor c) const; 50560d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com 5068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Scroll (a subset of) the contents of this bitmap by dx/dy. If there are 5078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com no pixels allocated (i.e. getPixels() returns null) the method will 5086a9368d41154890b6c316fdae704bf56ca4c70ccscroggo@google.com still update the inval region (if present). If the bitmap is immutable, 5096a9368d41154890b6c316fdae704bf56ca4c70ccscroggo@google.com do nothing and return false. 5108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param subset The subset of the bitmap to scroll/move. To scroll the 5128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com entire contents, specify [0, 0, width, height] or just 5138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pass null. 5148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dx The amount to scroll in X 5158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dy The amount to scroll in Y 5168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param inval Optional (may be null). Returns the area of the bitmap that 5178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com was scrolled away. E.g. if dx = dy = 0, then inval would 5188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com be set to empty. If dx >= width or dy >= height, then 5198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com inval would be set to the entire bounds of the bitmap. 520ddd014e65264e3f18b2d4305dd2fbc81549f5180reed @return true if the scroll was doable. Will return false if the colortype is kUnkown or 521ddd014e65264e3f18b2d4305dd2fbc81549f5180reed if the bitmap is immutable. 5228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com If no pixels are present (i.e. getPixels() returns false) 5238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com inval will still be updated, and true will be returned. 5248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 5258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool scrollRect(const SkIRect* subset, int dx, int dy, 5268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRegion* inval = NULL) const; 5278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5283b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com /** 5293b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com * Return the SkColor of the specified pixel. In most cases this will 530ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * require un-premultiplying the color. Alpha only colortypes (e.g. kAlpha_8_SkColorType) 5313b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com * return black with the appropriate alpha set. The value is undefined 532ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * for kUnknown_SkColorType or if x or y are out of bounds, or if the bitmap 5333b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com * does not have any pixels (or has not be locked with lockPixels()). 5343b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com */ 5353b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com SkColor getColor(int x, int y) const; 536fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 5378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns the address of the specified pixel. This performs a runtime 5388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com check to know the size of the pixels, and will return the same answer 5398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com as the corresponding size-specific method (e.g. getAddr16). Since the 5408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com check happens at runtime, it is much slower than using a size-specific 5418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com version. Unlike the size-specific methods, this routine also checks if 5428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com getPixels() returns null, and returns that. The size-specific routines 5438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com perform a debugging assert that getPixels() is not null, but they do 5448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com not do any runtime checks. 5458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 5468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void* getAddr(int x, int y) const; 5478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns the address of the pixel specified by x,y for 32bit pixels. 5493b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com * In debug build, this asserts that the pixels are allocated and locked, 550ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * and that the colortype is 32-bit, however none of these checks are performed 5513b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com * in the release build. 5523b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com */ 5538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com inline uint32_t* getAddr32(int x, int y) const; 5543b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com 5558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns the address of the pixel specified by x,y for 16bit pixels. 5563b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com * In debug build, this asserts that the pixels are allocated and locked, 557ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * and that the colortype is 16-bit, however none of these checks are performed 5583b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com * in the release build. 5593b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com */ 5608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com inline uint16_t* getAddr16(int x, int y) const; 5613b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com 5628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns the address of the pixel specified by x,y for 8bit pixels. 5633b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com * In debug build, this asserts that the pixels are allocated and locked, 564ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * and that the colortype is 8-bit, however none of these checks are performed 5653b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com * in the release build. 5663b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com */ 5678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com inline uint8_t* getAddr8(int x, int y) const; 5683b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com 5698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns the color corresponding to the pixel specified by x,y for 5703b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com * colortable based bitmaps. 5713b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com * In debug build, this asserts that the pixels are allocated and locked, 572ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * that the colortype is indexed, and that the colortable is allocated, 5733b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com * however none of these checks are performed in the release build. 5743b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com */ 5758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com inline SkPMColor getIndex8Color(int x, int y) const; 5768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5779ef2d8382f5238cc54d211e3cc228def7a93b133epoger@google.com /** Set dst to be a setset of this bitmap. If possible, it will share the 578ddd014e65264e3f18b2d4305dd2fbc81549f5180reed pixel memory, and just point into a subset of it. However, if the colortype 5798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com does not support this, a local copy will be made and associated with 5808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the dst bitmap. If the subset rectangle, intersected with the bitmap's 581ddd014e65264e3f18b2d4305dd2fbc81549f5180reed dimensions is empty, or if there is an unsupported colortype, false will be 5828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com returned and dst will be untouched. 5838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dst The bitmap that will be set to a subset of this bitmap 5848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param subset The rectangle of pixels in this bitmap that dst will 5858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com reference. 5868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return true if the subset copy was successfully made. 5878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 5888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool extractSubset(SkBitmap* dst, const SkIRect& subset) const; 5898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5908a2ad3cae710f05cca57e48dd1732d575dba2dc7commit-bot@chromium.org /** Makes a deep copy of this bitmap, respecting the requested colorType, 591ef843cdcd1be858fe55cc99ff134ffbd080c9a51senorblanco@chromium.org * and allocating the dst pixels on the cpu. 592ef843cdcd1be858fe55cc99ff134ffbd080c9a51senorblanco@chromium.org * Returns false if either there is an error (i.e. the src does not have 593ef843cdcd1be858fe55cc99ff134ffbd080c9a51senorblanco@chromium.org * pixels) or the request cannot be satisfied (e.g. the src has per-pixel 594ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * alpha, and the requested colortype does not support alpha). 595ef843cdcd1be858fe55cc99ff134ffbd080c9a51senorblanco@chromium.org * @param dst The bitmap to be sized and allocated 5968a2ad3cae710f05cca57e48dd1732d575dba2dc7commit-bot@chromium.org * @param ct The desired colorType for dst 597ef843cdcd1be858fe55cc99ff134ffbd080c9a51senorblanco@chromium.org * @param allocator Allocator used to allocate the pixelref for the dst 598ef843cdcd1be858fe55cc99ff134ffbd080c9a51senorblanco@chromium.org * bitmap. If this is null, the standard HeapAllocator 599ef843cdcd1be858fe55cc99ff134ffbd080c9a51senorblanco@chromium.org * will be used. 6008a2ad3cae710f05cca57e48dd1732d575dba2dc7commit-bot@chromium.org * @return true if the copy was made. 601ef843cdcd1be858fe55cc99ff134ffbd080c9a51senorblanco@chromium.org */ 6028a2ad3cae710f05cca57e48dd1732d575dba2dc7commit-bot@chromium.org bool copyTo(SkBitmap* dst, SkColorType ct, Allocator* = NULL) const; 6038a2ad3cae710f05cca57e48dd1732d575dba2dc7commit-bot@chromium.org 6048a2ad3cae710f05cca57e48dd1732d575dba2dc7commit-bot@chromium.org bool copyTo(SkBitmap* dst, Allocator* allocator = NULL) const { 6058a2ad3cae710f05cca57e48dd1732d575dba2dc7commit-bot@chromium.org return this->copyTo(dst, this->colorType(), allocator); 6068a2ad3cae710f05cca57e48dd1732d575dba2dc7commit-bot@chromium.org } 6078a2ad3cae710f05cca57e48dd1732d575dba2dc7commit-bot@chromium.org 6088a2ad3cae710f05cca57e48dd1732d575dba2dc7commit-bot@chromium.org /** 609b184f7f52b2a94e95aee326a3ca37110d2e43336reed * Copy the bitmap's pixels into the specified buffer (pixels + rowBytes), 610b184f7f52b2a94e95aee326a3ca37110d2e43336reed * converting them into the requested format (SkImageInfo). The src pixels are read 611b184f7f52b2a94e95aee326a3ca37110d2e43336reed * starting at the specified (srcX,srcY) offset, relative to the top-left corner. 612b184f7f52b2a94e95aee326a3ca37110d2e43336reed * 613b184f7f52b2a94e95aee326a3ca37110d2e43336reed * The specified ImageInfo and (srcX,srcY) offset specifies a source rectangle 614b184f7f52b2a94e95aee326a3ca37110d2e43336reed * 615b184f7f52b2a94e95aee326a3ca37110d2e43336reed * srcR.setXYWH(srcX, srcY, dstInfo.width(), dstInfo.height()); 616b184f7f52b2a94e95aee326a3ca37110d2e43336reed * 617b184f7f52b2a94e95aee326a3ca37110d2e43336reed * srcR is intersected with the bounds of the bitmap. If this intersection is not empty, 618b184f7f52b2a94e95aee326a3ca37110d2e43336reed * then we have two sets of pixels (of equal size). Replace the dst pixels with the 619b184f7f52b2a94e95aee326a3ca37110d2e43336reed * corresponding src pixels, performing any colortype/alphatype transformations needed 620b184f7f52b2a94e95aee326a3ca37110d2e43336reed * (in the case where the src and dst have different colortypes or alphatypes). 621b184f7f52b2a94e95aee326a3ca37110d2e43336reed * 622b184f7f52b2a94e95aee326a3ca37110d2e43336reed * This call can fail, returning false, for several reasons: 623b184f7f52b2a94e95aee326a3ca37110d2e43336reed * - If srcR does not intersect the bitmap bounds. 624b184f7f52b2a94e95aee326a3ca37110d2e43336reed * - If the requested colortype/alphatype cannot be converted from the src's types. 625b184f7f52b2a94e95aee326a3ca37110d2e43336reed * - If the src pixels are not available. 626b184f7f52b2a94e95aee326a3ca37110d2e43336reed */ 627b184f7f52b2a94e95aee326a3ca37110d2e43336reed bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, 628b184f7f52b2a94e95aee326a3ca37110d2e43336reed int srcX, int srcY) const; 629b184f7f52b2a94e95aee326a3ca37110d2e43336reed 630b184f7f52b2a94e95aee326a3ca37110d2e43336reed /** 6318a2ad3cae710f05cca57e48dd1732d575dba2dc7commit-bot@chromium.org * Returns true if this bitmap's pixels can be converted into the requested 6328a2ad3cae710f05cca57e48dd1732d575dba2dc7commit-bot@chromium.org * colorType, such that copyTo() could succeed. 6338a2ad3cae710f05cca57e48dd1732d575dba2dc7commit-bot@chromium.org */ 6348a2ad3cae710f05cca57e48dd1732d575dba2dc7commit-bot@chromium.org bool canCopyTo(SkColorType colorType) const; 63589bb83abb420c126b02fcdd4047fd6574e9b73fcreed@android.com 6366285f4f7662853336b788d6ee3e177c396f7fb01commit-bot@chromium.org /** Makes a deep copy of this bitmap, keeping the copied pixels 6376285f4f7662853336b788d6ee3e177c396f7fb01commit-bot@chromium.org * in the same domain as the source: If the src pixels are allocated for 6386285f4f7662853336b788d6ee3e177c396f7fb01commit-bot@chromium.org * the cpu, then so will the dst. If the src pixels are allocated on the 6396285f4f7662853336b788d6ee3e177c396f7fb01commit-bot@chromium.org * gpu (typically as a texture), the it will do the same for the dst. 6406285f4f7662853336b788d6ee3e177c396f7fb01commit-bot@chromium.org * If the request cannot be fulfilled, returns false and dst is unmodified. 6416285f4f7662853336b788d6ee3e177c396f7fb01commit-bot@chromium.org */ 6426285f4f7662853336b788d6ee3e177c396f7fb01commit-bot@chromium.org bool deepCopyTo(SkBitmap* dst) const; 643ef843cdcd1be858fe55cc99ff134ffbd080c9a51senorblanco@chromium.org 6444bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com#ifdef SK_BUILD_FOR_ANDROID 6454bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com bool hasHardwareMipMap() const { 6464bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com return (fFlags & kHasHardwareMipMap_Flag) != 0; 6474bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com } 6484bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com 6494bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com void setHasHardwareMipMap(bool hasHardwareMipMap) { 6504bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com if (hasHardwareMipMap) { 6514bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com fFlags |= kHasHardwareMipMap_Flag; 6524bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com } else { 6534bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com fFlags &= ~kHasHardwareMipMap_Flag; 6544bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com } 6554bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com } 6564bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com#endif 6574bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com 658cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com bool extractAlpha(SkBitmap* dst) const { 659cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com return this->extractAlpha(dst, NULL, NULL, NULL); 6608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 6618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 662cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com bool extractAlpha(SkBitmap* dst, const SkPaint* paint, 66357f4969724a1dd88c8d9ae35a863e6cf621181d5djsollen@google.com SkIPoint* offset) const { 664cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com return this->extractAlpha(dst, paint, NULL, offset); 66557f4969724a1dd88c8d9ae35a863e6cf621181d5djsollen@google.com } 66657f4969724a1dd88c8d9ae35a863e6cf621181d5djsollen@google.com 667cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com /** Set dst to contain alpha layer of this bitmap. If destination bitmap 668cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com fails to be initialized, e.g. because allocator can't allocate pixels 669cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com for it, dst will not be modified and false will be returned. 670cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 671cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com @param dst The bitmap to be filled with alpha layer 672cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com @param paint The paint to draw with 673cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com @param allocator Allocator used to allocate the pixelref for the dst 674cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com bitmap. If this is null, the standard HeapAllocator 675cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com will be used. 676cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com @param offset If not null, it is set to top-left coordinate to position 677cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com the returned bitmap so that it visually lines up with the 678cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com original 679cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com */ 680cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com bool extractAlpha(SkBitmap* dst, const SkPaint* paint, Allocator* allocator, 6818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIPoint* offset) const; 682f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 6838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDEBUGCODE(void validate() const;) 6848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com class Allocator : public SkRefCnt { 6868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com public: 68715e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com SK_DECLARE_INST_COUNT(Allocator) 68815e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com 6898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Allocate the pixel memory for the bitmap, given its dimensions and 690ddd014e65264e3f18b2d4305dd2fbc81549f5180reed colortype. Return true on success, where success means either setPixels 6918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com or setPixelRef was called. The pixels need not be locked when this 692ddd014e65264e3f18b2d4305dd2fbc81549f5180reed returns. If the colortype requires a colortable, it also must be 6938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com installed via setColorTable. If false is returned, the bitmap and 6948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com colortable should be left unchanged. 6958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 6968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual bool allocPixelRef(SkBitmap*, SkColorTable*) = 0; 69715e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com private: 69815e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com typedef SkRefCnt INHERITED; 6998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 7008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Subclass of Allocator that returns a pixelref that allocates its pixel 7028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com memory from the heap. This is the default Allocator invoked by 7038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com allocPixels(). 7048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 7058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com class HeapAllocator : public Allocator { 7068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com public: 7079ebcac54635cde63110d73ad7c43d70772e7872freed@google.com virtual bool allocPixelRef(SkBitmap*, SkColorTable*) SK_OVERRIDE; 7088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 7098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com class RLEPixels { 7118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com public: 7128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com RLEPixels(int width, int height); 7138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual ~RLEPixels(); 714f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 7158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint8_t* packedAtY(int y) const { 7168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT((unsigned)y < (unsigned)fHeight); 7178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return fYPtrs[y]; 7188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 719f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 7208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // called by subclasses during creation 7218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setPackedAtY(int y, uint8_t* addr) { 7228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT((unsigned)y < (unsigned)fHeight); 7238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fYPtrs[y] = addr; 7248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 725f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 7268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com private: 7278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint8_t** fYPtrs; 7288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int fHeight; 7298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 730f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 7310f10f7bf1fb43ca6346dc220a076773b1f19a367commit-bot@chromium.org SK_TO_STRING_NONVIRT() 73276f9e938df0b5826fd4c80b854ceafaf385cfbe1robertphillips@google.com 7338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 7348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mutable SkPixelRef* fPixelRef; 7358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mutable int fPixelLockCount; 7365f62ed74342e44cb1b9671ffdac47c6a81416136reed@google.com // These are just caches from the locked pixelref 7378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mutable void* fPixels; 7388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mutable SkColorTable* fColorTable; // only meaningful for kIndex8 7398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 740672588b684d484dce6ae251e9e163e4a46924322reed@google.com SkIPoint fPixelRefOrigin; 741672588b684d484dce6ae251e9e163e4a46924322reed@google.com 7428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum Flags { 743b052129a4121c1e3f051e374541a93d3d7a98064junov@chromium.org kImageIsVolatile_Flag = 0x02, 7444bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com#ifdef SK_BUILD_FOR_ANDROID 7454bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com /* A hint for the renderer responsible for drawing this bitmap 7464bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com * indicating that it should attempt to use mipmaps when this bitmap 7474bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com * is drawn scaled down. 7484bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com */ 7494bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com kHasHardwareMipMap_Flag = 0x08, 7504bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com#endif 7518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 7528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 75361e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org SkImageInfo fInfo; 75461e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org 755e5f48243bdbed2662be7a31be0888abc273b09e8scroggo@google.com uint32_t fRowBytes; 75661e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org 7578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint8_t fFlags; 7588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 75960d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com void internalErase(const SkIRect&, U8CPU a, U8CPU r, U8CPU g, U8CPU b)const; 76060d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com 7618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /* Unreference any pixelrefs or colortables 7628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 7638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void freePixels(); 7648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void updatePixelsFromRef() const; 7653c134a97ed128ca95345e13619512df0f42e95f8skia.committer@gmail.com 766851155c28e18e3f5b702ef15ee7bfb12f3cbacdacommit-bot@chromium.org void legacyUnflatten(SkReadBuffer&); 767851155c28e18e3f5b702ef15ee7bfb12f3cbacdacommit-bot@chromium.org 768968edcafa61442dc4f7f8ed8f89523d0f353e9fbcommit-bot@chromium.org static void WriteRawPixels(SkWriteBuffer*, const SkBitmap&); 769968edcafa61442dc4f7f8ed8f89523d0f353e9fbcommit-bot@chromium.org static bool ReadRawPixels(SkReadBuffer*, SkBitmap*); 770f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 771968edcafa61442dc4f7f8ed8f89523d0f353e9fbcommit-bot@chromium.org friend class SkBitmapSource; // unflatten 772968edcafa61442dc4f7f8ed8f89523d0f353e9fbcommit-bot@chromium.org friend class SkReadBuffer; // unflatten, rawpixels 773968edcafa61442dc4f7f8ed8f89523d0f353e9fbcommit-bot@chromium.org friend class SkWriteBuffer; // rawpixels 7744a551d49cf44397a99c73787f63409568cf85009reed@google.com friend struct SkBitmapProcState; 7758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 7768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 777e3beb6bd7de7fa211681abbb0be58e80b19885e0commit-bot@chromium.orgclass SkAutoLockPixels : SkNoncopyable { 7788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 7799c49bc3e643c435677727c1c0904c4a7cb7a6907reed@google.com SkAutoLockPixels(const SkBitmap& bm, bool doLock = true) : fBitmap(bm) { 7809c49bc3e643c435677727c1c0904c4a7cb7a6907reed@google.com fDidLock = doLock; 7819c49bc3e643c435677727c1c0904c4a7cb7a6907reed@google.com if (doLock) { 7829c49bc3e643c435677727c1c0904c4a7cb7a6907reed@google.com bm.lockPixels(); 7839c49bc3e643c435677727c1c0904c4a7cb7a6907reed@google.com } 7848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ~SkAutoLockPixels() { 7869c49bc3e643c435677727c1c0904c4a7cb7a6907reed@google.com if (fDidLock) { 7879c49bc3e643c435677727c1c0904c4a7cb7a6907reed@google.com fBitmap.unlockPixels(); 7889c49bc3e643c435677727c1c0904c4a7cb7a6907reed@google.com } 7898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 7928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkBitmap& fBitmap; 7939c49bc3e643c435677727c1c0904c4a7cb7a6907reed@google.com bool fDidLock; 7948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 7950f6dc21e324a0829ed7f4ff4c4238f75f62683b5mtklein@google.com//TODO(mtklein): uncomment when 71713004 lands and Chromium's fixed. 7960f6dc21e324a0829ed7f4ff4c4238f75f62683b5mtklein@google.com//#define SkAutoLockPixels(...) SK_REQUIRE_LOCAL_VAR(SkAutoLockPixels) 7978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** Helper class that performs the lock/unlockColors calls on a colortable. 7998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com The destructor will call unlockColors(false) if it has a bitmap's colortable 8008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/ 801e3beb6bd7de7fa211681abbb0be58e80b19885e0commit-bot@chromium.orgclass SkAutoLockColors : SkNoncopyable { 8028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 8038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Initialize with no bitmap. Call lockColors(bitmap) to lock bitmap's 8048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com colortable 8058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 8068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoLockColors() : fCTable(NULL), fColors(NULL) {} 8078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Initialize with bitmap, locking its colortable if present 8088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 8098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com explicit SkAutoLockColors(const SkBitmap& bm) { 8108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fCTable = bm.getColorTable(); 8118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fColors = fCTable ? fCTable->lockColors() : NULL; 8128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 8138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Initialize with a colortable (may be null) 8148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 8158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com explicit SkAutoLockColors(SkColorTable* ctable) { 8168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fCTable = ctable; 8178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fColors = ctable ? ctable->lockColors() : NULL; 8188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 8198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ~SkAutoLockColors() { 8208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fCTable) { 8210a6151d66cc32d91eca037c91e557158cf8a2be2reed@google.com fCTable->unlockColors(); 8228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 8238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 824f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 8258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the currently locked colors, or NULL if no bitmap's colortable 8268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com is currently locked. 8278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 8288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPMColor* colors() const { return fColors; } 829f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 8301134426f6b1c4130e8dbe4c38a4aa976fbb18b4breed@android.com /** Locks the table and returns is colors (assuming ctable is not null) and 8311134426f6b1c4130e8dbe4c38a4aa976fbb18b4breed@android.com unlocks the previous table if one was present 8321134426f6b1c4130e8dbe4c38a4aa976fbb18b4breed@android.com */ 8331134426f6b1c4130e8dbe4c38a4aa976fbb18b4breed@android.com const SkPMColor* lockColors(SkColorTable* ctable) { 8348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fCTable) { 8350a6151d66cc32d91eca037c91e557158cf8a2be2reed@google.com fCTable->unlockColors(); 8368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 8371134426f6b1c4130e8dbe4c38a4aa976fbb18b4breed@android.com fCTable = ctable; 8381134426f6b1c4130e8dbe4c38a4aa976fbb18b4breed@android.com fColors = ctable ? ctable->lockColors() : NULL; 8398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return fColors; 8408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 8418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8421134426f6b1c4130e8dbe4c38a4aa976fbb18b4breed@android.com const SkPMColor* lockColors(const SkBitmap& bm) { 8431134426f6b1c4130e8dbe4c38a4aa976fbb18b4breed@android.com return this->lockColors(bm.getColorTable()); 8441134426f6b1c4130e8dbe4c38a4aa976fbb18b4breed@android.com } 8451134426f6b1c4130e8dbe4c38a4aa976fbb18b4breed@android.com 8468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 8478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkColorTable* fCTable; 8488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPMColor* fColors; 8498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 850e61a86cfa00ea393ecc4a71fca94e1d476a37ecccommit-bot@chromium.org#define SkAutoLockColors(...) SK_REQUIRE_LOCAL_VAR(SkAutoLockColors) 8518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/////////////////////////////////////////////////////////////////////////////// 8538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.cominline uint32_t* SkBitmap::getAddr32(int x, int y) const { 8558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(fPixels); 85669e64637925d51f746560b2da21c4b0a10eed48areed@google.com SkASSERT(4 == this->bytesPerPixel()); 85761e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)this->height()); 8588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return (uint32_t*)((char*)fPixels + y * fRowBytes + (x << 2)); 8598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 8608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.cominline uint16_t* SkBitmap::getAddr16(int x, int y) const { 8628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(fPixels); 86369e64637925d51f746560b2da21c4b0a10eed48areed@google.com SkASSERT(2 == this->bytesPerPixel()); 86461e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)this->height()); 8658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return (uint16_t*)((char*)fPixels + y * fRowBytes + (x << 1)); 8668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 8678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.cominline uint8_t* SkBitmap::getAddr8(int x, int y) const { 8698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(fPixels); 87069e64637925d51f746560b2da21c4b0a10eed48areed@google.com SkASSERT(1 == this->bytesPerPixel()); 87161e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)this->height()); 8728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return (uint8_t*)fPixels + y * fRowBytes + x; 8738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 8748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.cominline SkPMColor SkBitmap::getIndex8Color(int x, int y) const { 8768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(fPixels); 87769e64637925d51f746560b2da21c4b0a10eed48areed@google.com SkASSERT(kIndex_8_SkColorType == this->colorType()); 87861e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)this->height()); 8798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(fColorTable); 8808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return (*fColorTable)[*((const uint8_t*)fPixels + y * fRowBytes + x)]; 8818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 8828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 884