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