OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #ifndef SkBitmap_DEFINED | 10 #ifndef SkBitmap_DEFINED |
11 #define SkBitmap_DEFINED | 11 #define SkBitmap_DEFINED |
12 | 12 |
13 #include "Sk64.h" | 13 #include "Sk64.h" |
14 #include "SkAlpha.h" | |
14 #include "SkColor.h" | 15 #include "SkColor.h" |
15 #include "SkColorTable.h" | 16 #include "SkColorTable.h" |
16 #include "SkPoint.h" | 17 #include "SkPoint.h" |
17 #include "SkRefCnt.h" | 18 #include "SkRefCnt.h" |
18 | 19 |
19 struct SkIRect; | 20 struct SkIRect; |
20 struct SkRect; | 21 struct SkRect; |
21 class SkPaint; | 22 class SkPaint; |
22 class SkPixelRef; | 23 class SkPixelRef; |
23 class SkRegion; | 24 class SkRegion; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 */ | 124 */ |
124 int bytesPerPixel() const { return fBytesPerPixel; } | 125 int bytesPerPixel() const { return fBytesPerPixel; } |
125 | 126 |
126 /** Return the rowbytes expressed as a number of pixels (like width and | 127 /** Return the rowbytes expressed as a number of pixels (like width and |
127 height). Note, for 1-byte per pixel configs like kA8_Config, this will | 128 height). Note, for 1-byte per pixel configs like kA8_Config, this will |
128 return the same as rowBytes(). Is undefined for configs that are less | 129 return the same as rowBytes(). Is undefined for configs that are less |
129 than 1-byte per pixel (e.g. kA1_Config) | 130 than 1-byte per pixel (e.g. kA1_Config) |
130 */ | 131 */ |
131 int rowBytesAsPixels() const { return fRowBytes >> (fBytesPerPixel >> 1); } | 132 int rowBytesAsPixels() const { return fRowBytes >> (fBytesPerPixel >> 1); } |
132 | 133 |
134 SkAlphaType alphaType() const { return (SkAlphaType)fAlphaType; } | |
135 | |
133 /** Return the address of the pixels for this SkBitmap. | 136 /** Return the address of the pixels for this SkBitmap. |
134 */ | 137 */ |
135 void* getPixels() const { return fPixels; } | 138 void* getPixels() const { return fPixels; } |
136 | 139 |
137 /** Return the byte size of the pixels, based on the height and rowBytes. | 140 /** Return the byte size of the pixels, based on the height and rowBytes. |
138 Note this truncates the result to 32bits. Call getSize64() to detect | 141 Note this truncates the result to 32bits. Call getSize64() to detect |
139 if the real size exceeds 32bits. | 142 if the real size exceeds 32bits. |
140 */ | 143 */ |
141 size_t getSize() const { return fHeight * fRowBytes; } | 144 size_t getSize() const { return fHeight * fRowBytes; } |
142 | 145 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 /** | 244 /** |
242 * Return the bitmap's bounds [0, 0, width, height] as an SkRect | 245 * Return the bitmap's bounds [0, 0, width, height] as an SkRect |
243 */ | 246 */ |
244 void getBounds(SkRect* bounds) const; | 247 void getBounds(SkRect* bounds) const; |
245 void getBounds(SkIRect* bounds) const; | 248 void getBounds(SkIRect* bounds) const; |
246 | 249 |
247 /** Set the bitmap's config and dimensions. If rowBytes is 0, then | 250 /** Set the bitmap's config and dimensions. If rowBytes is 0, then |
248 ComputeRowBytes() is called to compute the optimal value. This resets | 251 ComputeRowBytes() is called to compute the optimal value. This resets |
249 any pixel/colortable ownership, just like reset(). | 252 any pixel/colortable ownership, just like reset(). |
250 */ | 253 */ |
251 void setConfig(Config, int width, int height, size_t rowBytes = 0); | 254 bool setConfig(Config, int width, int height, size_t rowBytes, SkAlphaType); |
255 | |
256 bool setConfig(Config config, int width, int height, size_t rowBytes = 0) { | |
257 return this->setConfig(config, width, height, rowBytes, | |
258 kPremul_SkAlphaType); | |
259 } | |
260 | |
261 | |
252 /** Use this to assign a new pixel address for an existing bitmap. This | 262 /** Use this to assign a new pixel address for an existing bitmap. This |
253 will automatically release any pixelref previously installed. Only call | 263 will automatically release any pixelref previously installed. Only call |
254 this if you are handling ownership/lifetime of the pixel memory. | 264 this if you are handling ownership/lifetime of the pixel memory. |
255 | 265 |
256 If the bitmap retains a reference to the colortable (assuming it is | 266 If the bitmap retains a reference to the colortable (assuming it is |
257 not null) it will take care of incrementing the reference count. | 267 not null) it will take care of incrementing the reference count. |
258 | 268 |
259 @param pixels Address for the pixels, managed by the caller. | 269 @param pixels Address for the pixels, managed by the caller. |
260 @param ctable ColorTable (or null) that matches the specified pixels | 270 @param ctable ColorTable (or null) that matches the specified pixels |
261 */ | 271 */ |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
665 * is drawn scaled down. | 675 * is drawn scaled down. |
666 */ | 676 */ |
667 kHasHardwareMipMap_Flag = 0x08, | 677 kHasHardwareMipMap_Flag = 0x08, |
668 #endif | 678 #endif |
669 }; | 679 }; |
670 | 680 |
671 uint32_t fRowBytes; | 681 uint32_t fRowBytes; |
672 uint32_t fWidth; | 682 uint32_t fWidth; |
673 uint32_t fHeight; | 683 uint32_t fHeight; |
674 uint8_t fConfig; | 684 uint8_t fConfig; |
685 uint8_t fAlphaType; | |
scroggo
2013/09/30 19:01:28
This should be serialized, and we should bump the
| |
675 uint8_t fFlags; | 686 uint8_t fFlags; |
676 uint8_t fBytesPerPixel; // based on config | 687 uint8_t fBytesPerPixel; // based on config |
677 | 688 |
678 void internalErase(const SkIRect&, U8CPU a, U8CPU r, U8CPU g, U8CPU b)const; | 689 void internalErase(const SkIRect&, U8CPU a, U8CPU r, U8CPU g, U8CPU b)const; |
679 | 690 |
680 /* Internal computations for safe size. | 691 /* Internal computations for safe size. |
681 */ | 692 */ |
682 static Sk64 ComputeSafeSize64(Config config, | 693 static Sk64 ComputeSafeSize64(Config config, |
683 uint32_t width, | 694 uint32_t width, |
684 uint32_t height, | 695 uint32_t height, |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
811 | 822 |
812 // returns the address of the byte that contains the x coordinate | 823 // returns the address of the byte that contains the x coordinate |
813 inline uint8_t* SkBitmap::getAddr1(int x, int y) const { | 824 inline uint8_t* SkBitmap::getAddr1(int x, int y) const { |
814 SkASSERT(fPixels); | 825 SkASSERT(fPixels); |
815 SkASSERT(fConfig == kA1_Config); | 826 SkASSERT(fConfig == kA1_Config); |
816 SkASSERT((unsigned)x < fWidth && (unsigned)y < fHeight); | 827 SkASSERT((unsigned)x < fWidth && (unsigned)y < fHeight); |
817 return (uint8_t*)fPixels + y * fRowBytes + (x >> 3); | 828 return (uint8_t*)fPixels + y * fRowBytes + (x >> 3); |
818 } | 829 } |
819 | 830 |
820 #endif | 831 #endif |
OLD | NEW |