OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
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 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkErrorInternals.h" | 10 #include "SkErrorInternals.h" |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 } | 192 } |
193 | 193 |
194 bool SkReadBuffer::readBitmap(SkBitmap* bitmap) { | 194 bool SkReadBuffer::readBitmap(SkBitmap* bitmap) { |
195 const int width = this->readInt(); | 195 const int width = this->readInt(); |
196 const int height = this->readInt(); | 196 const int height = this->readInt(); |
197 // The writer stored a boolean value to determine whether an SkBitmapHeap wa
s used during | 197 // The writer stored a boolean value to determine whether an SkBitmapHeap wa
s used during |
198 // writing. | 198 // writing. |
199 if (this->readBool()) { | 199 if (this->readBool()) { |
200 // An SkBitmapHeap was used for writing. Read the index from the stream
and find the | 200 // An SkBitmapHeap was used for writing. Read the index from the stream
and find the |
201 // corresponding SkBitmap in fBitmapStorage. | 201 // corresponding SkBitmap in fBitmapStorage. |
202 const uint32_t index = fReader.readU32(); | 202 const uint32_t index = this->readUInt(); |
203 fReader.readU32(); // bitmap generation ID (see SkWriteBuffer::writeBitm
ap) | 203 this->readUInt(); // bitmap generation ID (see SkWriteBuffer::writeBitma
p) |
204 if (fBitmapStorage) { | 204 if (fBitmapStorage) { |
205 *bitmap = *fBitmapStorage->getBitmap(index); | 205 *bitmap = *fBitmapStorage->getBitmap(index); |
206 fBitmapStorage->releaseRef(index); | 206 fBitmapStorage->releaseRef(index); |
207 return true; | 207 return true; |
208 } else { | 208 } else { |
209 // The bitmap was stored in a heap, but there is no way to access it
. Set an error and | 209 // The bitmap was stored in a heap, but there is no way to access it
. Set an error and |
210 // fall through to use a place holder bitmap. | 210 // fall through to use a place holder bitmap. |
211 SkErrorInternals::SetError(kParseError_SkError, "SkWriteBuffer::writ
eBitmap " | 211 SkErrorInternals::SetError(kParseError_SkError, "SkWriteBuffer::writ
eBitmap " |
212 "stored the SkBitmap in an SkBitmapHeap,
but " | 212 "stored the SkBitmap in an SkBitmapHeap,
but " |
213 "SkReadBuffer has no SkBitmapHeapReader t
o " | 213 "SkReadBuffer has no SkBitmapHeapReader t
o " |
214 "retrieve the SkBitmap."); | 214 "retrieve the SkBitmap."); |
215 } | 215 } |
216 } else { | 216 } else { |
217 // The writer stored false, meaning the SkBitmap was not stored in an Sk
BitmapHeap. | 217 // The writer stored false, meaning the SkBitmap was not stored in an Sk
BitmapHeap. |
218 const size_t length = this->readUInt(); | 218 const size_t length = this->readUInt(); |
219 if (length > 0) { | 219 if (length > 0) { |
220 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT | 220 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT |
221 fDecodedBitmapIndex++; | 221 fDecodedBitmapIndex++; |
222 #endif // DEBUG_NON_DETERMINISTIC_ASSERT | 222 #endif // DEBUG_NON_DETERMINISTIC_ASSERT |
223 // A non-zero size means the SkBitmap was encoded. Read the data and
pixel | 223 // A non-zero size means the SkBitmap was encoded. Read the data and
pixel |
224 // offset. | 224 // offset. |
225 const void* data = this->skip(length); | 225 const void* data = this->skip(length); |
226 const int32_t xOffset = fReader.readS32(); | 226 const int32_t xOffset = this->readInt(); |
227 const int32_t yOffset = fReader.readS32(); | 227 const int32_t yOffset = this->readInt(); |
228 if (fBitmapDecoder != NULL && fBitmapDecoder(data, length, bitmap))
{ | 228 if (fBitmapDecoder != NULL && fBitmapDecoder(data, length, bitmap))
{ |
229 if (bitmap->width() == width && bitmap->height() == height) { | 229 if (bitmap->width() == width && bitmap->height() == height) { |
230 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT | 230 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT |
231 if (0 != xOffset || 0 != yOffset) { | 231 if (0 != xOffset || 0 != yOffset) { |
232 SkDebugf("SkReadBuffer::readBitmap: heights match," | 232 SkDebugf("SkReadBuffer::readBitmap: heights match," |
233 " but offset is not zero. \nInfo about the bitm
ap:" | 233 " but offset is not zero. \nInfo about the bitm
ap:" |
234 "\n\tIndex: %d\n\tDimensions: [%d %d]\n\tEncode
d" | 234 "\n\tIndex: %d\n\tDimensions: [%d %d]\n\tEncode
d" |
235 " data size: %d\n\tOffset: (%d, %d)\n", | 235 " data size: %d\n\tOffset: (%d, %d)\n", |
236 fDecodedBitmapIndex, width, height, length, xOf
fset, | 236 fDecodedBitmapIndex, width, height, length, xOf
fset, |
237 yOffset); | 237 yOffset); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 return; | 357 return; |
358 } | 358 } |
359 } else { | 359 } else { |
360 if (NULL == this->readFunctionPtr()) { | 360 if (NULL == this->readFunctionPtr()) { |
361 return; | 361 return; |
362 } | 362 } |
363 } | 363 } |
364 uint32_t sizeRecorded = fReader.readU32(); | 364 uint32_t sizeRecorded = fReader.readU32(); |
365 fReader.skip(sizeRecorded); | 365 fReader.skip(sizeRecorded); |
366 } | 366 } |
OLD | NEW |