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

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

Issue 1737543002: Use SkPicture's InstallPixelRefProc to decode SkImages in an skp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 10 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 | « src/core/SkReadBuffer.h ('k') | no next file » | 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 /* 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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 = this->readInt(); 226 const int32_t xOffset = this->readInt();
227 const int32_t yOffset = this->readInt(); 227 const int32_t yOffset = this->readInt();
228 if (fBitmapDecoder != nullptr && fBitmapDecoder(data, length, bitmap )) { 228 SkIRect subset = SkIRect::MakeXYWH(xOffset, yOffset, width, height);
229 if (bitmap->width() == width && bitmap->height() == height) { 229 if (this->decodeBitmap(data, length, bitmap, subset)) {
230 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT 230 return true;
231 if (0 != xOffset || 0 != yOffset) { 231 }
232 SkDebugf("SkReadBuffer::readBitmap: heights match,"
233 " but offset is not zero. \nInfo about the bitm ap:"
234 "\n\tIndex: %d\n\tDimensions: [%d %d]\n\tEncode d"
235 " data size: %d\n\tOffset: (%d, %d)\n",
236 fDecodedBitmapIndex, width, height, length, xOf fset,
237 yOffset);
238 }
239 #endif // DEBUG_NON_DETERMINISTIC_ASSERT
240 // If the width and height match, there should be no offset.
241 SkASSERT(0 == xOffset && 0 == yOffset);
242 return true;
243 }
244 232
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
247 // the encoded width and height.
248 // FIXME (scroggo): This assert assumes that our decoder and the
249 // sources encoder agree on the width and height which may not
250 // always be the case. Removing until it can be investigated
251 // further.
252 //SkASSERT(width <= bitmap->width() && height <= bitmap->height( ));
253
254 SkBitmap subsetBm;
255 SkIRect subset = SkIRect::MakeXYWH(xOffset, yOffset, width, heig ht);
256 if (bitmap->extractSubset(&subsetBm, subset)) {
257 bitmap->swap(subsetBm);
258 return true;
259 }
260 }
261 // This bitmap was encoded when written, but we are unable to decode , possibly due to 233 // This bitmap was encoded when written, but we are unable to decode , possibly due to
262 // not having a decoder. 234 // not having a decoder.
263 SkErrorInternals::SetError(kParseError_SkError, 235 SkErrorInternals::SetError(kParseError_SkError,
264 "Could not decode bitmap. Resulting bitma p will be empty."); 236 "Could not decode bitmap. Resulting bitma p will be empty.");
265 // Even though we weren't able to decode the pixels, the readbuffer should still be 237 // Even though we weren't able to decode the pixels, the readbuffer should still be
266 // intact, so we return true with an empty bitmap, so we don't force an abort of the 238 // intact, so we return true with an empty bitmap, so we don't force an abort of the
267 // larger deserialize. 239 // larger deserialize.
268 bitmap->setInfo(SkImageInfo::MakeUnknown(width, height)); 240 bitmap->setInfo(SkImageInfo::MakeUnknown(width, height));
269 return true; 241 return true;
270 } else if (SkBitmap::ReadRawPixels(this, bitmap)) { 242 } else if (SkBitmap::ReadRawPixels(this, bitmap)) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 } 278 }
307 279
308 int originX = this->read32(); 280 int originX = this->read32();
309 int originY = this->read32(); 281 int originY = this->read32();
310 if (originX < 0 || originY < 0) { 282 if (originX < 0 || originY < 0) {
311 this->validate(false); 283 this->validate(false);
312 return nullptr; 284 return nullptr;
313 } 285 }
314 286
315 const SkIRect subset = SkIRect::MakeXYWH(originX, originY, width, height); 287 const SkIRect subset = SkIRect::MakeXYWH(originX, originY, width, height);
288 SkBitmap bitmap;
289 if (this->decodeBitmap(encoded->data(), encoded->size(), &bitmap, subset)) {
290 SkImage* image = SkImage::NewFromBitmap(bitmap);
msarett 2016/02/24 23:30:54 This is the quick and easy fix for tools/get_image
scroggo 2016/02/25 12:52:36 My preference is to replace InstallPixelRefProc, a
291 if (image) {
292 return image;
293 }
294 }
295
316 SkImage* image = SkImage::NewFromEncoded(encoded, &subset); 296 SkImage* image = SkImage::NewFromEncoded(encoded, &subset);
317 if (image) { 297 if (image) {
318 return image; 298 return image;
319 } 299 }
320 300
321 return SkImage::NewFromGenerator( 301 return SkImage::NewFromGenerator(
322 new EmptyImageGenerator(SkImageInfo::MakeN32Premul(width, height))); 302 new EmptyImageGenerator(SkImageInfo::MakeN32Premul(width, height)));
323 } 303 }
324 304
325 SkTypeface* SkReadBuffer::readTypeface() { 305 SkTypeface* SkReadBuffer::readTypeface() {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 return; 383 return;
404 } 384 }
405 } else { 385 } else {
406 if (nullptr == this->readFunctionPtr()) { 386 if (nullptr == this->readFunctionPtr()) {
407 return; 387 return;
408 } 388 }
409 } 389 }
410 uint32_t sizeRecorded = fReader.readU32(); 390 uint32_t sizeRecorded = fReader.readU32();
411 fReader.skip(sizeRecorded); 391 fReader.skip(sizeRecorded);
412 } 392 }
393
394 bool SkReadBuffer::decodeBitmap(const void* data, size_t length, SkBitmap* bitma p,
395 const SkIRect& subset) {
396 if (fBitmapDecoder != nullptr && fBitmapDecoder(data, length, bitmap)) {
397 if (bitmap->width() == subset.width() && bitmap->height() == subset.heig ht()) {
398 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT
399 if (0 != subset.x() || 0 != subset.y()) {
400 SkDebugf("SkReadBuffer::readBitmap: heights match,"
401 " but offset is not zero. \nInfo about the bitmap:"
402 "\n\tIndex: %d\n\tDimensions: [%d %d]\n\tEncoded"
403 " data size: %d\n\tOffset: (%d, %d)\n",
404 fDecodedBitmapIndex, subset.width(), subset.height(), l ength, subset.x(),
405 subset.y());
406 }
407 #endif // DEBUG_NON_DETERMINISTIC_ASSERT
408 // If the width and height match, there should be no offset.
409 SkASSERT(0 == subset.x() && 0 == subset.y());
410 return true;
411 }
412
413 // This case can only be reached if extractSubset was called, so
414 // the recorded width and height must be smaller than or equal to
415 // the encoded width and height.
416 // FIXME (scroggo): This assert assumes that our decoder and the
417 // sources encoder agree on the width and height which may not
418 // always be the case. Removing until it can be investigated
419 // further.
420 //SkASSERT(subset.width() <= bitmap->width() && subset.height() <= bitma p->height());
421 SkBitmap subsetBm;
422 if (bitmap->extractSubset(&subsetBm, subset)) {
423 bitmap->swap(subsetBm);
424 return true;
425 }
426 }
427
428 return false;
429 }
OLDNEW
« no previous file with comments | « src/core/SkReadBuffer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698