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

Side by Side Diff: src/codec/SkJpegCodec.cpp

Issue 1212593003: Destroy SkScanlineDecoder in the SkCodec subclass destructors (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 5 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
« include/codec/SkCodec.h ('K') | « src/codec/SkCodec_libpng.cpp ('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 * Copyright 2015 Google Inc. 2 * Copyright 2015 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 "SkCodec.h" 8 #include "SkCodec.h"
9 #include "SkJpegCodec.h" 9 #include "SkJpegCodec.h"
10 #include "SkJpegDecoderMgr.h" 10 #include "SkJpegDecoderMgr.h"
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 fSrcRowBytes = SkSwizzler::BytesPerPixel(srcConfig) * dstInfo.width(); 290 fSrcRowBytes = SkSwizzler::BytesPerPixel(srcConfig) * dstInfo.width();
291 } 291 }
292 292
293 /* 293 /*
294 * Performs the jpeg decode 294 * Performs the jpeg decode
295 */ 295 */
296 SkCodec::Result SkJpegCodec::onGetPixels(const SkImageInfo& dstInfo, 296 SkCodec::Result SkJpegCodec::onGetPixels(const SkImageInfo& dstInfo,
297 void* dst, size_t dstRowBytes, 297 void* dst, size_t dstRowBytes,
298 const Options& options, SkPMColor*, int *) { 298 const Options& options, SkPMColor*, int *) {
299 299
300 // Do not allow a regular decode if the caller has asked for a scanline deco der
301 if (NULL != this->scanlineDecoder()) {
302 fDecoderMgr->returnFailure("cannot getPixels() if a scanline decoder has been created",
scroggo 2015/06/29 21:33:22 I think this should be: return fDecoderMgr->.
msarett 2015/06/29 21:59:43 Yeah it should be!
303 kInvalidInput);
304 }
305
300 // Rewind the stream if needed 306 // Rewind the stream if needed
301 if (!this->handleRewind()) { 307 if (!this->handleRewind()) {
302 fDecoderMgr->returnFailure("could not rewind stream", kCouldNotRewind); 308 fDecoderMgr->returnFailure("could not rewind stream", kCouldNotRewind);
scroggo 2015/06/29 21:33:22 Again, this should be a return statement, right?
msarett 2015/06/29 21:59:43 Yep this is wrong too. That's what you get when y
303 } 309 }
304 310
305 // Get a pointer to the decompress info since we will use it quite frequentl y 311 // Get a pointer to the decompress info since we will use it quite frequentl y
306 jpeg_decompress_struct* dinfo = fDecoderMgr->dinfo(); 312 jpeg_decompress_struct* dinfo = fDecoderMgr->dinfo();
307 313
308 // Set the jump location for libjpeg errors 314 // Set the jump location for libjpeg errors
309 if (setjmp(fDecoderMgr->getJmpBuf())) { 315 if (setjmp(fDecoderMgr->getJmpBuf())) {
310 return fDecoderMgr->returnFailure("setjmp", kInvalidInput); 316 return fDecoderMgr->returnFailure("setjmp", kInvalidInput);
311 } 317 }
312 318
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 448
443 return SkImageGenerator::kSuccess; 449 return SkImageGenerator::kSuccess;
444 } 450 }
445 451
446 void onFinish() override { 452 void onFinish() override {
447 if (setjmp(fCodec->fDecoderMgr->getJmpBuf())) { 453 if (setjmp(fCodec->fDecoderMgr->getJmpBuf())) {
448 SkCodecPrintf("setjmp: Error in libjpeg finish_decompress\n"); 454 SkCodecPrintf("setjmp: Error in libjpeg finish_decompress\n");
449 return; 455 return;
450 } 456 }
451 457
458 // We may not have decoded the entire image. Prevent libjpeg-turbo from failing on a
459 // partial decode.
460 fCodec->fDecoderMgr->dinfo()->output_scanline = dstInfo().height();
452 jpeg_finish_decompress(fCodec->fDecoderMgr->dinfo()); 461 jpeg_finish_decompress(fCodec->fDecoderMgr->dinfo());
453 } 462 }
454 463
455 private: 464 private:
456 SkJpegCodec* fCodec; // unowned 465 SkJpegCodec* fCodec; // unowned
457 SkAutoMalloc fStorage; 466 SkAutoMalloc fStorage;
458 uint8_t* fSrcRow; // ptr into fStorage 467 uint8_t* fSrcRow; // ptr into fStorage
459 468
460 typedef SkScanlineDecoder INHERITED; 469 typedef SkScanlineDecoder INHERITED;
461 }; 470 };
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 // Create the swizzler 505 // Create the swizzler
497 this->initializeSwizzler(dstInfo, NULL, dstInfo.minRowBytes(), options); 506 this->initializeSwizzler(dstInfo, NULL, dstInfo.minRowBytes(), options);
498 if (NULL == fSwizzler) { 507 if (NULL == fSwizzler) {
499 SkCodecPrintf("Could not create swizzler\n"); 508 SkCodecPrintf("Could not create swizzler\n");
500 return NULL; 509 return NULL;
501 } 510 }
502 511
503 // Return the new scanline decoder 512 // Return the new scanline decoder
504 return SkNEW_ARGS(SkJpegScanlineDecoder, (dstInfo, this)); 513 return SkNEW_ARGS(SkJpegScanlineDecoder, (dstInfo, this));
505 } 514 }
OLDNEW
« include/codec/SkCodec.h ('K') | « src/codec/SkCodec_libpng.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698