Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(195)

Side by Side Diff: src/core/SkReadBuffer.cpp

Issue 2039813007: Add raw pixel serialization fallback for SkImages that cannot be encoded. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fixed only on Mac Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/core/SkWriteBuffer.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
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 #include "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkErrorInternals.h" 9 #include "SkErrorInternals.h"
10 #include "SkImage.h" 10 #include "SkImage.h"
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 } // anonymous namespace 269 } // anonymous namespace
270 270
271 SkImage* SkReadBuffer::readImage() { 271 SkImage* SkReadBuffer::readImage() {
272 int width = this->read32(); 272 int width = this->read32();
273 int height = this->read32(); 273 int height = this->read32();
274 if (width <= 0 || height <= 0) { // SkImage never has a zero dimension 274 if (width <= 0 || height <= 0) { // SkImage never has a zero dimension
275 this->validate(false); 275 this->validate(false);
276 return nullptr; 276 return nullptr;
277 } 277 }
278 278
279 sk_sp<SkData> encoded(this->readByteArrayAsData()); 279 auto placeholder = [=] {
280 if (encoded->size() == 0) {
281 // The image could not be encoded at serialization time - return an empt y placeholder.
282 return SkImage::MakeFromGenerator( 280 return SkImage::MakeFromGenerator(
283 new EmptyImageGenerator(SkImageInfo::MakeN32Premul(width, height))). release(); 281 new EmptyImageGenerator(SkImageInfo::MakeN32Premul(width, height))). release();
282 };
283
284 uint32_t encoded_size = this->getArrayCount();
285 if (encoded_size == 0) {
286 // The image could not be encoded at serialization time - return an empt y placeholder.
287 (void)this->readUInt(); // Swallow that encoded_size == 0 sentinel.
288 return placeholder();
284 } 289 }
290 if (encoded_size == 1) {
291 // We had to encode the image as raw pixels via SkBitmap.
292 (void)this->readUInt(); // Swallow that encoded_size == 1 sentinel.
293 SkBitmap bm;
294 if (SkBitmap::ReadRawPixels(this, &bm)) {
295 return SkImage::MakeFromBitmap(bm).release();
296 }
297 return placeholder();
298 }
299
300 // The SkImage encoded itself.
301 sk_sp<SkData> encoded(this->readByteArrayAsData());
285 302
286 int originX = this->read32(); 303 int originX = this->read32();
287 int originY = this->read32(); 304 int originY = this->read32();
288 if (originX < 0 || originY < 0) { 305 if (originX < 0 || originY < 0) {
289 this->validate(false); 306 this->validate(false);
290 return nullptr; 307 return nullptr;
291 } 308 }
292 309
293 const SkIRect subset = SkIRect::MakeXYWH(originX, originY, width, height); 310 const SkIRect subset = SkIRect::MakeXYWH(originX, originY, width, height);
294 SkImage* image = SkImage::MakeFromEncoded(std::move(encoded), &subset).relea se(); 311 SkImage* image = SkImage::MakeFromEncoded(std::move(encoded), &subset).relea se();
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 if (sizeRecorded != sizeRead) { 388 if (sizeRecorded != sizeRead) {
372 this->validate(false); 389 this->validate(false);
373 return nullptr; 390 return nullptr;
374 } 391 }
375 } else { 392 } else {
376 // we must skip the remaining data 393 // we must skip the remaining data
377 fReader.skip(sizeRecorded); 394 fReader.skip(sizeRecorded);
378 } 395 }
379 return obj.release(); 396 return obj.release();
380 } 397 }
OLDNEW
« no previous file with comments | « no previous file | src/core/SkWriteBuffer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698