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

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

Issue 2247743002: Fix color xform width bug when scaling/subsetting (Closed) Base URL: https://skia.googlesource.com/skia.git@skipstuff
Patch Set: Rebase Created 4 years, 4 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/codec/SkPngCodec.h » ('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 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 "SkMSAN.h" 9 #include "SkMSAN.h"
10 #include "SkJpegCodec.h" 10 #include "SkJpegCodec.h"
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 // we will always decode into fSwizzlerSrcRow before swizzling into the next buffer. 488 // we will always decode into fSwizzlerSrcRow before swizzling into the next buffer.
489 // We can never swizzle "in place" because the swizzler may perform sampling and/or 489 // We can never swizzle "in place" because the swizzler may perform sampling and/or
490 // subsetting. 490 // subsetting.
491 // When fColorXformSrcRow is non-null, it means that we need to color xform and that 491 // When fColorXformSrcRow is non-null, it means that we need to color xform and that
492 // we cannot color xform "in place" (many times we can, but not when the dst is F16). 492 // we cannot color xform "in place" (many times we can, but not when the dst is F16).
493 // In this case, we will color xform from fColorXformSrc into the dst. 493 // In this case, we will color xform from fColorXformSrc into the dst.
494 JSAMPLE* decodeDst = (JSAMPLE*) dst; 494 JSAMPLE* decodeDst = (JSAMPLE*) dst;
495 uint32_t* swizzleDst = (uint32_t*) dst; 495 uint32_t* swizzleDst = (uint32_t*) dst;
496 size_t decodeDstRowBytes = rowBytes; 496 size_t decodeDstRowBytes = rowBytes;
497 size_t swizzleDstRowBytes = rowBytes; 497 size_t swizzleDstRowBytes = rowBytes;
498 int dstWidth = dstInfo.width();
498 if (fSwizzleSrcRow && fColorXformSrcRow) { 499 if (fSwizzleSrcRow && fColorXformSrcRow) {
499 decodeDst = (JSAMPLE*) fSwizzleSrcRow; 500 decodeDst = (JSAMPLE*) fSwizzleSrcRow;
500 swizzleDst = fColorXformSrcRow; 501 swizzleDst = fColorXformSrcRow;
501 decodeDstRowBytes = 0; 502 decodeDstRowBytes = 0;
502 swizzleDstRowBytes = 0; 503 swizzleDstRowBytes = 0;
504 dstWidth = fSwizzler->swizzleWidth();
503 } else if (fColorXformSrcRow) { 505 } else if (fColorXformSrcRow) {
504 decodeDst = (JSAMPLE*) fColorXformSrcRow; 506 decodeDst = (JSAMPLE*) fColorXformSrcRow;
505 swizzleDst = fColorXformSrcRow; 507 swizzleDst = fColorXformSrcRow;
506 decodeDstRowBytes = 0; 508 decodeDstRowBytes = 0;
507 swizzleDstRowBytes = 0; 509 swizzleDstRowBytes = 0;
508 } else if (fSwizzleSrcRow) { 510 } else if (fSwizzleSrcRow) {
509 decodeDst = (JSAMPLE*) fSwizzleSrcRow; 511 decodeDst = (JSAMPLE*) fSwizzleSrcRow;
510 decodeDstRowBytes = 0; 512 decodeDstRowBytes = 0;
513 dstWidth = fSwizzler->swizzleWidth();
511 } 514 }
512 515
513 for (int y = 0; y < count; y++) { 516 for (int y = 0; y < count; y++) {
514 uint32_t lines = jpeg_read_scanlines(fDecoderMgr->dinfo(), &decodeDst, 1 ); 517 uint32_t lines = jpeg_read_scanlines(fDecoderMgr->dinfo(), &decodeDst, 1 );
515 size_t srcRowBytes = get_row_bytes(fDecoderMgr->dinfo()); 518 size_t srcRowBytes = get_row_bytes(fDecoderMgr->dinfo());
516 sk_msan_mark_initialized(decodeDst, decodeDst + srcRowBytes, "skbug.com/ 4550"); 519 sk_msan_mark_initialized(decodeDst, decodeDst + srcRowBytes, "skbug.com/ 4550");
517 if (0 == lines) { 520 if (0 == lines) {
518 return y; 521 return y;
519 } 522 }
520 523
521 if (fSwizzler) { 524 if (fSwizzler) {
522 fSwizzler->swizzle(swizzleDst, decodeDst); 525 fSwizzler->swizzle(swizzleDst, decodeDst);
523 } 526 }
524 527
525 if (fColorXform) { 528 if (fColorXform) {
526 fColorXform->apply(dst, swizzleDst, dstInfo.width(), dstInfo.colorTy pe(), 529 fColorXform->apply(dst, swizzleDst, dstWidth, dstInfo.colorType(), k Opaque_SkAlphaType);
527 kOpaque_SkAlphaType);
528 dst = SkTAddOffset<void>(dst, rowBytes); 530 dst = SkTAddOffset<void>(dst, rowBytes);
529 } 531 }
530 532
531 decodeDst = SkTAddOffset<JSAMPLE>(decodeDst, decodeDstRowBytes); 533 decodeDst = SkTAddOffset<JSAMPLE>(decodeDst, decodeDstRowBytes);
532 swizzleDst = SkTAddOffset<uint32_t>(swizzleDst, swizzleDstRowBytes); 534 swizzleDst = SkTAddOffset<uint32_t>(swizzleDst, swizzleDstRowBytes);
533 } 535 }
534 536
535 return count; 537 return count;
536 } 538 }
537 539
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 int rows = this->readRows(dstInfo, dst, dstRowBytes, dstInfo.height()); 585 int rows = this->readRows(dstInfo, dst, dstRowBytes, dstInfo.height());
584 if (rows < dstInfo.height()) { 586 if (rows < dstInfo.height()) {
585 *rowsDecoded = rows; 587 *rowsDecoded = rows;
586 return fDecoderMgr->returnFailure("Incomplete image data", kIncompleteIn put); 588 return fDecoderMgr->returnFailure("Incomplete image data", kIncompleteIn put);
587 } 589 }
588 590
589 return kSuccess; 591 return kSuccess;
590 } 592 }
591 593
592 void SkJpegCodec::allocateStorage(const SkImageInfo& dstInfo) { 594 void SkJpegCodec::allocateStorage(const SkImageInfo& dstInfo) {
595 int dstWidth = dstInfo.width();
596
593 size_t swizzleBytes = 0; 597 size_t swizzleBytes = 0;
594 if (fSwizzler) { 598 if (fSwizzler) {
595 swizzleBytes = get_row_bytes(fDecoderMgr->dinfo()); 599 swizzleBytes = get_row_bytes(fDecoderMgr->dinfo());
600 dstWidth = fSwizzler->swizzleWidth();
596 SkASSERT(!fColorXform || SkIsAlign4(swizzleBytes)); 601 SkASSERT(!fColorXform || SkIsAlign4(swizzleBytes));
597 } 602 }
598 603
599 size_t xformBytes = 0; 604 size_t xformBytes = 0;
600 if (kRGBA_F16_SkColorType == dstInfo.colorType()) { 605 if (kRGBA_F16_SkColorType == dstInfo.colorType()) {
601 SkASSERT(fColorXform); 606 SkASSERT(fColorXform);
602 xformBytes = dstInfo.width() * sizeof(uint32_t); 607 xformBytes = dstWidth * sizeof(uint32_t);
603 } 608 }
604 609
605 size_t totalBytes = swizzleBytes + xformBytes; 610 size_t totalBytes = swizzleBytes + xformBytes;
606 if (totalBytes > 0) { 611 if (totalBytes > 0) {
607 fStorage.reset(totalBytes); 612 fStorage.reset(totalBytes);
608 fSwizzleSrcRow = (swizzleBytes > 0) ? fStorage.get() : nullptr; 613 fSwizzleSrcRow = (swizzleBytes > 0) ? fStorage.get() : nullptr;
609 fColorXformSrcRow = (xformBytes > 0) ? 614 fColorXformSrcRow = (xformBytes > 0) ?
610 SkTAddOffset<uint32_t>(fStorage.get(), swizzleBytes) : nullptr; 615 SkTAddOffset<uint32_t>(fStorage.get(), swizzleBytes) : nullptr;
611 } 616 }
612 } 617 }
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
977 982
978 JDIMENSION linesRead = jpeg_read_raw_data(dinfo, yuv, numRowsPerBlock); 983 JDIMENSION linesRead = jpeg_read_raw_data(dinfo, yuv, numRowsPerBlock);
979 if (linesRead < remainingRows) { 984 if (linesRead < remainingRows) {
980 // FIXME: Handle incomplete YUV decodes without signalling an error. 985 // FIXME: Handle incomplete YUV decodes without signalling an error.
981 return kInvalidInput; 986 return kInvalidInput;
982 } 987 }
983 } 988 }
984 989
985 return kSuccess; 990 return kSuccess;
986 } 991 }
OLDNEW
« no previous file with comments | « no previous file | src/codec/SkPngCodec.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698