OLD | NEW |
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 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 // If we cannot read enough rows, assume the input is incomplete | 348 // If we cannot read enough rows, assume the input is incomplete |
349 if (rowsDecoded != 1) { | 349 if (rowsDecoded != 1) { |
350 // Fill the remainder of the image with black. This error handling | 350 // Fill the remainder of the image with black. This error handling |
351 // behavior is unspecified but SkCodec consistently uses black as | 351 // behavior is unspecified but SkCodec consistently uses black as |
352 // the fill color for opaque images. If the destination is kGray, | 352 // the fill color for opaque images. If the destination is kGray, |
353 // the low 8 bits of SK_ColorBLACK will be used. Conveniently, | 353 // the low 8 bits of SK_ColorBLACK will be used. Conveniently, |
354 // these are zeros, which is the representation for black in kGray. | 354 // these are zeros, which is the representation for black in kGray. |
355 // If the destination is kRGB_565, the low 16 bits of SK_ColorBLACK | 355 // If the destination is kRGB_565, the low 16 bits of SK_ColorBLACK |
356 // will be used. Conveniently, these are zeros, which is the | 356 // will be used. Conveniently, these are zeros, which is the |
357 // representation for black in kRGB_565. | 357 // representation for black in kRGB_565. |
358 if (kNo_ZeroInitialized == options.fZeroInitialized || | 358 SkSwizzler::Fill(dstRow, dstInfo, dstRowBytes, dstHeight - y, |
359 kN32_SkColorType == dstInfo.colorType()) { | 359 SK_ColorBLACK, nullptr, options.fZeroInitialized); |
360 SkSwizzler::Fill(dstRow, dstInfo, dstRowBytes, dstHeight - y, | |
361 SK_ColorBLACK, nullptr); | |
362 } | |
363 | 360 |
364 // Prevent libjpeg from failing on incomplete decode | 361 // Prevent libjpeg from failing on incomplete decode |
365 dinfo->output_scanline = dstHeight; | 362 dinfo->output_scanline = dstHeight; |
366 | 363 |
367 // Finish the decode and indicate that the input was incomplete. | 364 // Finish the decode and indicate that the input was incomplete. |
368 chromium_jpeg_finish_decompress(dinfo); | 365 chromium_jpeg_finish_decompress(dinfo); |
369 return fDecoderMgr->returnFailure("Incomplete image data", kIncomple
teInput); | 366 return fDecoderMgr->returnFailure("Incomplete image data", kIncomple
teInput); |
370 } | 367 } |
371 | 368 |
372 // Convert to RGBA if necessary | 369 // Convert to RGBA if necessary |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 } else { | 506 } else { |
510 // write data directly to dst | 507 // write data directly to dst |
511 dstRow = (JSAMPLE*) dst; | 508 dstRow = (JSAMPLE*) dst; |
512 } | 509 } |
513 | 510 |
514 for (int y = 0; y < count; y++) { | 511 for (int y = 0; y < count; y++) { |
515 // Read row of the image | 512 // Read row of the image |
516 uint32_t rowsDecoded = | 513 uint32_t rowsDecoded = |
517 chromium_jpeg_read_scanlines(fCodec->fDecoderMgr->dinfo(), &
dstRow, 1); | 514 chromium_jpeg_read_scanlines(fCodec->fDecoderMgr->dinfo(), &
dstRow, 1); |
518 if (rowsDecoded != 1) { | 515 if (rowsDecoded != 1) { |
519 if (SkCodec::kNo_ZeroInitialized == fOpts.fZeroInitialized || | 516 SkSwizzler::Fill(dstRow, this->dstInfo(), rowBytes, count - y, |
520 kN32_SkColorType == this->dstInfo().colorType()) { | 517 SK_ColorBLACK, nullptr, fOpts.fZeroInitialized); |
521 SkSwizzler::Fill(dstRow, this->dstInfo(), rowBytes, | |
522 count - y, SK_ColorBLACK, nullptr); | |
523 } | |
524 fCodec->fDecoderMgr->dinfo()->output_scanline = this->dstInfo().
height(); | 518 fCodec->fDecoderMgr->dinfo()->output_scanline = this->dstInfo().
height(); |
525 return SkCodec::kIncompleteInput; | 519 return SkCodec::kIncompleteInput; |
526 } | 520 } |
527 | 521 |
528 // Convert to RGBA if necessary | 522 // Convert to RGBA if necessary |
529 if (JCS_CMYK == fCodec->fDecoderMgr->dinfo()->out_color_space) { | 523 if (JCS_CMYK == fCodec->fDecoderMgr->dinfo()->out_color_space) { |
530 convert_CMYK_to_RGBA(dstRow, fCodec->fDecoderMgr->dinfo()->outpu
t_width); | 524 convert_CMYK_to_RGBA(dstRow, fCodec->fDecoderMgr->dinfo()->outpu
t_width); |
531 } | 525 } |
532 | 526 |
533 if(fSwizzler) { | 527 if(fSwizzler) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 SkAutoTDelete<SkJpegCodec> codec(static_cast<SkJpegCodec*>(SkJpegCodec::NewF
romStream(stream))); | 575 SkAutoTDelete<SkJpegCodec> codec(static_cast<SkJpegCodec*>(SkJpegCodec::NewF
romStream(stream))); |
582 if (!codec) { | 576 if (!codec) { |
583 return nullptr; | 577 return nullptr; |
584 } | 578 } |
585 | 579 |
586 const SkImageInfo& srcInfo = codec->getInfo(); | 580 const SkImageInfo& srcInfo = codec->getInfo(); |
587 | 581 |
588 // Return the new scanline decoder | 582 // Return the new scanline decoder |
589 return new SkJpegScanlineDecoder(srcInfo, codec.detach()); | 583 return new SkJpegScanlineDecoder(srcInfo, codec.detach()); |
590 } | 584 } |
OLD | NEW |