Chromium Code Reviews| 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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 } | 184 } |
| 185 | 185 |
| 186 bool SkReadBuffer::readScalarArray(SkScalar* values, size_t size) { | 186 bool SkReadBuffer::readScalarArray(SkScalar* values, size_t size) { |
| 187 return readArray(values, size, sizeof(SkScalar)); | 187 return readArray(values, size, sizeof(SkScalar)); |
| 188 } | 188 } |
| 189 | 189 |
| 190 uint32_t SkReadBuffer::getArrayCount() { | 190 uint32_t SkReadBuffer::getArrayCount() { |
| 191 return *(uint32_t*)fReader.peek(); | 191 return *(uint32_t*)fReader.peek(); |
| 192 } | 192 } |
| 193 | 193 |
| 194 void 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 = fReader.readU32(); |
| 203 fReader.readU32(); // bitmap generation ID (see SkWriteBuffer::writeBitm ap) | 203 fReader.readU32(); // bitmap generation ID (see SkWriteBuffer::writeBitm ap) |
| 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; | 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. |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 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); |
| 238 } | 238 } |
| 239 #endif // DEBUG_NON_DETERMINISTIC_ASSERT | 239 #endif // DEBUG_NON_DETERMINISTIC_ASSERT |
| 240 // If the width and height match, there should be no offset. | 240 // If the width and height match, there should be no offset. |
| 241 SkASSERT(0 == xOffset && 0 == yOffset); | 241 SkASSERT(0 == xOffset && 0 == yOffset); |
| 242 return; | 242 return true; |
| 243 } | 243 } |
| 244 | 244 |
| 245 // This case can only be reached if extractSubset was called, so | 245 // This case can only be reached if extractSubset was called, so |
| 246 // the recorded width and height must be smaller than or equal t o | 246 // the recorded width and height must be smaller than or equal t o |
| 247 // the encoded width and height. | 247 // the encoded width and height. |
| 248 // FIXME (scroggo): This assert assumes that our decoder and the | 248 // FIXME (scroggo): This assert assumes that our decoder and the |
| 249 // sources encoder agree on the width and height which may not | 249 // sources encoder agree on the width and height which may not |
| 250 // always be the case. Removing until it can be investigated | 250 // always be the case. Removing until it can be investigated |
| 251 // further. | 251 // further. |
| 252 //SkASSERT(width <= bitmap->width() && height <= bitmap->height( )); | 252 //SkASSERT(width <= bitmap->width() && height <= bitmap->height( )); |
| 253 | 253 |
| 254 SkBitmap subsetBm; | 254 SkBitmap subsetBm; |
| 255 SkIRect subset = SkIRect::MakeXYWH(xOffset, yOffset, width, heig ht); | 255 SkIRect subset = SkIRect::MakeXYWH(xOffset, yOffset, width, heig ht); |
| 256 if (bitmap->extractSubset(&subsetBm, subset)) { | 256 if (bitmap->extractSubset(&subsetBm, subset)) { |
| 257 bitmap->swap(subsetBm); | 257 bitmap->swap(subsetBm); |
| 258 return; | 258 return true; |
| 259 } | 259 } |
| 260 } | 260 } |
| 261 // This bitmap was encoded when written, but we are unable to decode , possibly due to | 261 // This bitmap was encoded when written, but we are unable to decode , possibly due to |
| 262 // not having a decoder. | 262 // not having a decoder. |
| 263 SkErrorInternals::SetError(kParseError_SkError, | 263 SkErrorInternals::SetError(kParseError_SkError, |
| 264 "Could not decode bitmap. Resulting bitma p will be red."); | 264 "Could not decode bitmap. Resulting bitma p will be red."); |
| 265 } else { | 265 } else { |
| 266 // A size of zero means the SkBitmap was simply flattened. | 266 // A size of zero means the SkBitmap was simply flattened. |
| 267 bitmap->unflatten(*this); | 267 if (this->pictureVersion() > 0 && this->pictureVersion() < 27) { |
|
scroggo
2014/05/20 13:27:50
Is there a valid reason for pictureVersion to be <
reed1
2014/05/20 17:49:58
When version is 0, we are an un-versioned buffer (
| |
| 268 return; | 268 SkBitmap tmp; |
| 269 tmp.unflatten(*this); | |
| 270 // just throw this guy away | |
| 271 } | |
| 269 } | 272 } |
| 270 } | 273 } |
| 271 // Could not read the SkBitmap. Use a placeholder bitmap. | 274 // Could not read the SkBitmap. Use a placeholder bitmap. |
| 272 bitmap->allocPixels(SkImageInfo::MakeN32Premul(width, height)); | 275 bitmap->setConfig(SkImageInfo::MakeUnknown(width, height)); |
| 273 bitmap->eraseColor(SK_ColorRED); | 276 return false; |
| 274 } | 277 } |
| 275 | 278 |
| 276 SkTypeface* SkReadBuffer::readTypeface() { | 279 SkTypeface* SkReadBuffer::readTypeface() { |
| 277 | 280 |
| 278 uint32_t index = fReader.readU32(); | 281 uint32_t index = fReader.readU32(); |
| 279 if (0 == index || index > (unsigned)fTFCount) { | 282 if (0 == index || index > (unsigned)fTFCount) { |
| 280 if (index) { | 283 if (index) { |
| 281 SkDebugf("====== typeface index %d\n", index); | 284 SkDebugf("====== typeface index %d\n", index); |
| 282 } | 285 } |
| 283 return NULL; | 286 return NULL; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 if (sizeRecorded != sizeRead) { | 331 if (sizeRecorded != sizeRead) { |
| 329 // we could try to fix up the offset... | 332 // we could try to fix up the offset... |
| 330 sk_throw(); | 333 sk_throw(); |
| 331 } | 334 } |
| 332 } else { | 335 } else { |
| 333 // we must skip the remaining data | 336 // we must skip the remaining data |
| 334 fReader.skip(sizeRecorded); | 337 fReader.skip(sizeRecorded); |
| 335 } | 338 } |
| 336 return obj; | 339 return obj; |
| 337 } | 340 } |
| OLD | NEW |