OLD | NEW |
| 1 |
1 /* | 2 /* |
2 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
3 * | 4 * |
4 * 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 |
5 * found in the LICENSE file. | 6 * found in the LICENSE file. |
6 */ | 7 */ |
7 | 8 |
| 9 |
8 #ifndef SkBitmap_DEFINED | 10 #ifndef SkBitmap_DEFINED |
9 #define SkBitmap_DEFINED | 11 #define SkBitmap_DEFINED |
10 | 12 |
| 13 #include "Sk64.h" |
11 #include "SkColor.h" | 14 #include "SkColor.h" |
12 #include "SkColorTable.h" | 15 #include "SkColorTable.h" |
13 #include "SkImageInfo.h" | 16 #include "SkImageInfo.h" |
14 #include "SkPoint.h" | 17 #include "SkPoint.h" |
15 #include "SkRefCnt.h" | 18 #include "SkRefCnt.h" |
16 | 19 |
17 #ifdef SK_SUPPORT_LEGACY_SK64 | |
18 #include "Sk64.h" | |
19 #endif | |
20 | |
21 struct SkIRect; | 20 struct SkIRect; |
22 struct SkRect; | 21 struct SkRect; |
23 class SkPaint; | 22 class SkPaint; |
24 class SkPixelRef; | 23 class SkPixelRef; |
25 class SkRegion; | 24 class SkRegion; |
26 class SkString; | 25 class SkString; |
27 | 26 |
28 class GrTexture; | 27 class GrTexture; |
29 | 28 |
30 /** \class SkBitmap | 29 /** \class SkBitmap |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 if the real size exceeds 32bits. | 142 if the real size exceeds 32bits. |
144 */ | 143 */ |
145 size_t getSize() const { return fHeight * fRowBytes; } | 144 size_t getSize() const { return fHeight * fRowBytes; } |
146 | 145 |
147 /** Return the number of bytes from the pointer returned by getPixels() | 146 /** Return the number of bytes from the pointer returned by getPixels() |
148 to the end of the allocated space in the buffer. Required in | 147 to the end of the allocated space in the buffer. Required in |
149 cases where extractSubset has been called. | 148 cases where extractSubset has been called. |
150 */ | 149 */ |
151 size_t getSafeSize() const ; | 150 size_t getSafeSize() const ; |
152 | 151 |
153 /** | 152 /** Return the byte size of the pixels, based on the height and rowBytes. |
154 * Return the full size of the bitmap, in bytes. | 153 This routine is slightly slower than getSize(), but does not truncate |
155 */ | 154 the answer to 32bits. |
156 int64_t computeSize64() const { | 155 */ |
157 return sk_64_mul(fHeight, fRowBytes); | |
158 } | |
159 | |
160 /** | |
161 * Return the number of bytes from the pointer returned by getPixels() | |
162 * to the end of the allocated space in the buffer. This may be smaller | |
163 * than computeSize64() if there is any rowbytes padding beyond the width. | |
164 */ | |
165 int64_t computeSafeSize64() const { | |
166 return ComputeSafeSize64((Config)fConfig, fWidth, fHeight, fRowBytes); | |
167 } | |
168 | |
169 #ifdef SK_SUPPORT_LEGACY_SK64 | |
170 SK_ATTR_DEPRECATED("use getSize64()") | |
171 Sk64 getSize64() const { | 156 Sk64 getSize64() const { |
172 Sk64 size; | 157 Sk64 size; |
173 size.set64(this->computeSize64()); | 158 size.setMul(fHeight, fRowBytes); |
174 return size; | 159 return size; |
175 } | 160 } |
176 | 161 |
177 SK_ATTR_DEPRECATED("use getSafeSize64()") | 162 /** Same as getSafeSize(), but does not truncate the answer to 32bits. |
178 Sk64 getSafeSize64() const { | 163 */ |
179 Sk64 size; | 164 Sk64 getSafeSize64() const ; |
180 size.set64(this->computeSafeSize64()); | |
181 return size; | |
182 } | |
183 #endif | |
184 | 165 |
185 /** Returns true if this bitmap is marked as immutable, meaning that the | 166 /** Returns true if this bitmap is marked as immutable, meaning that the |
186 contents of its pixels will not change for the lifetime of the bitmap. | 167 contents of its pixels will not change for the lifetime of the bitmap. |
187 */ | 168 */ |
188 bool isImmutable() const; | 169 bool isImmutable() const; |
189 | 170 |
190 /** Marks this bitmap as immutable, meaning that the contents of its | 171 /** Marks this bitmap as immutable, meaning that the contents of its |
191 pixels will not change for the lifetime of the bitmap and of the | 172 pixels will not change for the lifetime of the bitmap and of the |
192 underlying pixelref. This state can be set, but it cannot be | 173 underlying pixelref. This state can be set, but it cannot be |
193 cleared once it is set. This state propagates to all other bitmaps | 174 cleared once it is set. This state propagates to all other bitmaps |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 */ | 210 */ |
230 static int ComputeBytesPerPixel(Config c); | 211 static int ComputeBytesPerPixel(Config c); |
231 | 212 |
232 /** Return the shift-per-pixel for the specified config. If the config is | 213 /** Return the shift-per-pixel for the specified config. If the config is |
233 not at least 1-byte per pixel, return 0, including for kNo_Config. | 214 not at least 1-byte per pixel, return 0, including for kNo_Config. |
234 */ | 215 */ |
235 static int ComputeShiftPerPixel(Config c) { | 216 static int ComputeShiftPerPixel(Config c) { |
236 return ComputeBytesPerPixel(c) >> 1; | 217 return ComputeBytesPerPixel(c) >> 1; |
237 } | 218 } |
238 | 219 |
239 static int64_t ComputeSize64(Config, int width, int height); | 220 static Sk64 ComputeSize64(Config, int width, int height); |
240 static size_t ComputeSize(Config, int width, int height); | 221 static size_t ComputeSize(Config, int width, int height); |
241 | 222 |
242 /** | 223 /** |
243 * This will brute-force return true if all of the pixels in the bitmap | 224 * This will brute-force return true if all of the pixels in the bitmap |
244 * are opaque. If it fails to read the pixels, or encounters an error, | 225 * are opaque. If it fails to read the pixels, or encounters an error, |
245 * it will return false. | 226 * it will return false. |
246 * | 227 * |
247 * Since this can be an expensive operation, the bitmap stores a flag for | 228 * Since this can be an expensive operation, the bitmap stores a flag for |
248 * this (isOpaque). Only call this if you need to compute this value from | 229 * this (isOpaque). Only call this if you need to compute this value from |
249 * "unknown" pixels. | 230 * "unknown" pixels. |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 uint32_t fHeight; | 671 uint32_t fHeight; |
691 uint8_t fConfig; | 672 uint8_t fConfig; |
692 uint8_t fAlphaType; | 673 uint8_t fAlphaType; |
693 uint8_t fFlags; | 674 uint8_t fFlags; |
694 uint8_t fBytesPerPixel; // based on config | 675 uint8_t fBytesPerPixel; // based on config |
695 | 676 |
696 void internalErase(const SkIRect&, U8CPU a, U8CPU r, U8CPU g, U8CPU b)const; | 677 void internalErase(const SkIRect&, U8CPU a, U8CPU r, U8CPU g, U8CPU b)const; |
697 | 678 |
698 /* Internal computations for safe size. | 679 /* Internal computations for safe size. |
699 */ | 680 */ |
700 static int64_t ComputeSafeSize64(Config config, | 681 static Sk64 ComputeSafeSize64(Config config, |
701 uint32_t width, | 682 uint32_t width, |
702 uint32_t height, | 683 uint32_t height, |
703 size_t rowBytes); | 684 size_t rowBytes); |
704 static size_t ComputeSafeSize(Config config, | 685 static size_t ComputeSafeSize(Config config, |
705 uint32_t width, | 686 uint32_t width, |
706 uint32_t height, | 687 uint32_t height, |
707 size_t rowBytes); | 688 size_t rowBytes); |
708 | 689 |
709 /* Unreference any pixelrefs or colortables | 690 /* Unreference any pixelrefs or colortables |
710 */ | 691 */ |
711 void freePixels(); | 692 void freePixels(); |
712 void updatePixelsFromRef() const; | 693 void updatePixelsFromRef() const; |
713 | 694 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 | 805 |
825 inline SkPMColor SkBitmap::getIndex8Color(int x, int y) const { | 806 inline SkPMColor SkBitmap::getIndex8Color(int x, int y) const { |
826 SkASSERT(fPixels); | 807 SkASSERT(fPixels); |
827 SkASSERT(fConfig == kIndex8_Config); | 808 SkASSERT(fConfig == kIndex8_Config); |
828 SkASSERT((unsigned)x < fWidth && (unsigned)y < fHeight); | 809 SkASSERT((unsigned)x < fWidth && (unsigned)y < fHeight); |
829 SkASSERT(fColorTable); | 810 SkASSERT(fColorTable); |
830 return (*fColorTable)[*((const uint8_t*)fPixels + y * fRowBytes + x)]; | 811 return (*fColorTable)[*((const uint8_t*)fPixels + y * fRowBytes + x)]; |
831 } | 812 } |
832 | 813 |
833 #endif | 814 #endif |
OLD | NEW |