| 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" |
| 11 #include "SkImage.h" |
| 12 #include "SkImageGenerator.h" |
| 11 #include "SkReadBuffer.h" | 13 #include "SkReadBuffer.h" |
| 12 #include "SkStream.h" | 14 #include "SkStream.h" |
| 13 #include "SkTypeface.h" | 15 #include "SkTypeface.h" |
| 14 | 16 |
| 15 static uint32_t default_flags() { | 17 static uint32_t default_flags() { |
| 16 uint32_t flags = 0; | 18 uint32_t flags = 0; |
| 17 flags |= SkReadBuffer::kScalarIsFloat_Flag; | 19 flags |= SkReadBuffer::kScalarIsFloat_Flag; |
| 18 if (8 == sizeof(void*)) { | 20 if (8 == sizeof(void*)) { |
| 19 flags |= SkReadBuffer::kPtrIs64Bit_Flag; | 21 flags |= SkReadBuffer::kPtrIs64Bit_Flag; |
| 20 } | 22 } |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 return true; | 269 return true; |
| 268 } else if (SkBitmap::ReadRawPixels(this, bitmap)) { | 270 } else if (SkBitmap::ReadRawPixels(this, bitmap)) { |
| 269 return true; | 271 return true; |
| 270 } | 272 } |
| 271 } | 273 } |
| 272 // Could not read the SkBitmap. Use a placeholder bitmap. | 274 // Could not read the SkBitmap. Use a placeholder bitmap. |
| 273 bitmap->setInfo(SkImageInfo::MakeUnknown(width, height)); | 275 bitmap->setInfo(SkImageInfo::MakeUnknown(width, height)); |
| 274 return false; | 276 return false; |
| 275 } | 277 } |
| 276 | 278 |
| 279 namespace { |
| 280 |
| 281 // This generator intentionally should always fail on all attempts to get its pi
xels, |
| 282 // simulating a bad or empty codec stream. |
| 283 class EmptyImageGenerator final : public SkImageGenerator { |
| 284 public: |
| 285 EmptyImageGenerator(const SkImageInfo& info) : INHERITED(info) { } |
| 286 |
| 287 private: |
| 288 typedef SkImageGenerator INHERITED; |
| 289 }; |
| 290 |
| 291 } // anonymous namespace |
| 292 |
| 293 SkImage* SkReadBuffer::readImage() { |
| 294 int width = this->read32(); |
| 295 int height = this->read32(); |
| 296 if (width <= 0 || height <= 0) { // SkImage never has a zero dimension |
| 297 this->validate(false); |
| 298 return nullptr; |
| 299 } |
| 300 |
| 301 SkAutoTUnref<SkData> encoded(this->readByteArrayAsData()); |
| 302 if (encoded->size() == 0) { |
| 303 // The image could not be encoded at serialization time - return an empt
y placeholder. |
| 304 return SkImage::NewFromGenerator( |
| 305 new EmptyImageGenerator(SkImageInfo::MakeN32Premul(width, height))); |
| 306 } |
| 307 |
| 308 int originX = this->read32(); |
| 309 int originY = this->read32(); |
| 310 if (originX < 0 || originY < 0) { |
| 311 this->validate(false); |
| 312 return nullptr; |
| 313 } |
| 314 |
| 315 const SkIRect subset = SkIRect::MakeXYWH(originX, originY, width, height); |
| 316 return SkImage::NewFromEncoded(encoded, &subset); |
| 317 } |
| 318 |
| 277 SkTypeface* SkReadBuffer::readTypeface() { | 319 SkTypeface* SkReadBuffer::readTypeface() { |
| 278 | 320 |
| 279 uint32_t index = fReader.readU32(); | 321 uint32_t index = fReader.readU32(); |
| 280 if (0 == index || index > (unsigned)fTFCount) { | 322 if (0 == index || index > (unsigned)fTFCount) { |
| 281 if (index) { | 323 if (index) { |
| 282 SkDebugf("====== typeface index %d\n", index); | 324 SkDebugf("====== typeface index %d\n", index); |
| 283 } | 325 } |
| 284 return nullptr; | 326 return nullptr; |
| 285 } else { | 327 } else { |
| 286 SkASSERT(fTFArray); | 328 SkASSERT(fTFArray); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 return; | 393 return; |
| 352 } | 394 } |
| 353 } else { | 395 } else { |
| 354 if (nullptr == this->readFunctionPtr()) { | 396 if (nullptr == this->readFunctionPtr()) { |
| 355 return; | 397 return; |
| 356 } | 398 } |
| 357 } | 399 } |
| 358 uint32_t sizeRecorded = fReader.readU32(); | 400 uint32_t sizeRecorded = fReader.readU32(); |
| 359 fReader.skip(sizeRecorded); | 401 fReader.skip(sizeRecorded); |
| 360 } | 402 } |
| OLD | NEW |