OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
3 * | 3 * |
4 * 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 |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkBitmap_DEFINED | 8 #ifndef SkBitmap_DEFINED |
9 #define SkBitmap_DEFINED | 9 #define SkBitmap_DEFINED |
10 | 10 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 SkBitmap& operator=(const SkBitmap& src); | 71 SkBitmap& operator=(const SkBitmap& src); |
72 /** Swap the fields of the two bitmaps. This routine is guaranteed to never
fail or throw. | 72 /** Swap the fields of the two bitmaps. This routine is guaranteed to never
fail or throw. |
73 */ | 73 */ |
74 // This method is not exported to java. | 74 // This method is not exported to java. |
75 void swap(SkBitmap& other); | 75 void swap(SkBitmap& other); |
76 | 76 |
77 /////////////////////////////////////////////////////////////////////////// | 77 /////////////////////////////////////////////////////////////////////////// |
78 | 78 |
79 const SkImageInfo& info() const { return fInfo; } | 79 const SkImageInfo& info() const { return fInfo; } |
80 | 80 |
81 int width() const { return fInfo.fWidth; } | 81 int width() const { return fInfo.width(); } |
82 int height() const { return fInfo.fHeight; } | 82 int height() const { return fInfo.height(); } |
83 SkColorType colorType() const { return fInfo.fColorType; } | 83 SkColorType colorType() const { return fInfo.colorType(); } |
84 SkAlphaType alphaType() const { return fInfo.fAlphaType; } | 84 SkAlphaType alphaType() const { return fInfo.alphaType(); } |
85 | 85 |
86 /** | 86 /** |
87 * Return the number of bytes per pixel based on the colortype. If the colo
rtype is | 87 * Return the number of bytes per pixel based on the colortype. If the colo
rtype is |
88 * kUnknown_SkColorType, then 0 is returned. | 88 * kUnknown_SkColorType, then 0 is returned. |
89 */ | 89 */ |
90 int bytesPerPixel() const { return fInfo.bytesPerPixel(); } | 90 int bytesPerPixel() const { return fInfo.bytesPerPixel(); } |
91 | 91 |
92 /** | 92 /** |
93 * Return the rowbytes expressed as a number of pixels (like width and heig
ht). | 93 * Return the rowbytes expressed as a number of pixels (like width and heig
ht). |
94 * If the colortype is kUnknown_SkColorType, then 0 is returned. | 94 * If the colortype is kUnknown_SkColorType, then 0 is returned. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 bool setAlphaType(SkAlphaType); | 135 bool setAlphaType(SkAlphaType); |
136 | 136 |
137 /** Return the address of the pixels for this SkBitmap. | 137 /** Return the address of the pixels for this SkBitmap. |
138 */ | 138 */ |
139 void* getPixels() const { return fPixels; } | 139 void* getPixels() const { return fPixels; } |
140 | 140 |
141 /** Return the byte size of the pixels, based on the height and rowBytes. | 141 /** Return the byte size of the pixels, based on the height and rowBytes. |
142 Note this truncates the result to 32bits. Call getSize64() to detect | 142 Note this truncates the result to 32bits. Call getSize64() to detect |
143 if the real size exceeds 32bits. | 143 if the real size exceeds 32bits. |
144 */ | 144 */ |
145 size_t getSize() const { return fInfo.fHeight * fRowBytes; } | 145 size_t getSize() const { return fInfo.height() * fRowBytes; } |
146 | 146 |
147 /** Return the number of bytes from the pointer returned by getPixels() | 147 /** Return the number of bytes from the pointer returned by getPixels() |
148 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 |
149 cases where extractSubset has been called. | 149 cases where extractSubset has been called. |
150 */ | 150 */ |
151 size_t getSafeSize() const { return fInfo.getSafeSize(fRowBytes); } | 151 size_t getSafeSize() const { return fInfo.getSafeSize(fRowBytes); } |
152 | 152 |
153 /** | 153 /** |
154 * Return the full size of the bitmap, in bytes. | 154 * Return the full size of the bitmap, in bytes. |
155 */ | 155 */ |
156 int64_t computeSize64() const { | 156 int64_t computeSize64() const { |
157 return sk_64_mul(fInfo.fHeight, fRowBytes); | 157 return sk_64_mul(fInfo.height(), fRowBytes); |
158 } | 158 } |
159 | 159 |
160 /** | 160 /** |
161 * Return the number of bytes from the pointer returned by getPixels() | 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 | 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. | 163 * than computeSize64() if there is any rowbytes padding beyond the width. |
164 */ | 164 */ |
165 int64_t computeSafeSize64() const { | 165 int64_t computeSafeSize64() const { |
166 return fInfo.getSafeSize64(fRowBytes); | 166 return fInfo.getSafeSize64(fRowBytes); |
167 } | 167 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 | 257 |
258 bool SK_WARN_UNUSED_RESULT tryAllocPixels(const SkImageInfo& info) { | 258 bool SK_WARN_UNUSED_RESULT tryAllocPixels(const SkImageInfo& info) { |
259 return this->tryAllocPixels(info, info.minRowBytes()); | 259 return this->tryAllocPixels(info, info.minRowBytes()); |
260 } | 260 } |
261 | 261 |
262 SK_ALLOCPIXELS_RETURN_TYPE allocPixels(const SkImageInfo& info) { | 262 SK_ALLOCPIXELS_RETURN_TYPE allocPixels(const SkImageInfo& info) { |
263 return this->allocPixels(info, info.minRowBytes()); | 263 return this->allocPixels(info, info.minRowBytes()); |
264 } | 264 } |
265 | 265 |
266 bool SK_WARN_UNUSED_RESULT tryAllocN32Pixels(int width, int height, bool isO
paque = false) { | 266 bool SK_WARN_UNUSED_RESULT tryAllocN32Pixels(int width, int height, bool isO
paque = false) { |
267 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); | 267 SkImageInfo info = SkImageInfo::MakeN32(width, height, |
268 if (isOpaque) { | 268 isOpaque ? kOpaque_SkAlphaType : kPr
emul_SkAlphaType); |
269 info.fAlphaType = kOpaque_SkAlphaType; | |
270 } | |
271 return this->tryAllocPixels(info); | 269 return this->tryAllocPixels(info); |
272 } | 270 } |
273 | 271 |
274 SK_ALLOCPIXELS_RETURN_TYPE allocN32Pixels(int width, int height, bool isOpaq
ue = false) { | 272 SK_ALLOCPIXELS_RETURN_TYPE allocN32Pixels(int width, int height, bool isOpaq
ue = false) { |
275 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); | 273 SkImageInfo info = SkImageInfo::MakeN32(width, height, |
276 if (isOpaque) { | 274 isOpaque ? kOpaque_SkAlphaType : kPr
emul_SkAlphaType); |
277 info.fAlphaType = kOpaque_SkAlphaType; | |
278 } | |
279 return this->allocPixels(info); | 275 return this->allocPixels(info); |
280 } | 276 } |
281 | 277 |
282 /** | 278 /** |
283 * Install a pixelref that wraps the specified pixels and rowBytes, and | 279 * Install a pixelref that wraps the specified pixels and rowBytes, and |
284 * optional ReleaseProc and context. When the pixels are no longer | 280 * optional ReleaseProc and context. When the pixels are no longer |
285 * referenced, if releaseProc is not null, it will be called with the | 281 * referenced, if releaseProc is not null, it will be called with the |
286 * pixels and context as parameters. | 282 * pixels and context as parameters. |
287 * On failure, the bitmap will be set to empty and return false. | 283 * On failure, the bitmap will be set to empty and return false. |
288 */ | 284 */ |
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
878 | 874 |
879 inline SkPMColor SkBitmap::getIndex8Color(int x, int y) const { | 875 inline SkPMColor SkBitmap::getIndex8Color(int x, int y) const { |
880 SkASSERT(fPixels); | 876 SkASSERT(fPixels); |
881 SkASSERT(kIndex_8_SkColorType == this->colorType()); | 877 SkASSERT(kIndex_8_SkColorType == this->colorType()); |
882 SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)th
is->height()); | 878 SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)th
is->height()); |
883 SkASSERT(fColorTable); | 879 SkASSERT(fColorTable); |
884 return (*fColorTable)[*((const uint8_t*)fPixels + y * fRowBytes + x)]; | 880 return (*fColorTable)[*((const uint8_t*)fPixels + y * fRowBytes + x)]; |
885 } | 881 } |
886 | 882 |
887 #endif | 883 #endif |
OLD | NEW |