OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. | 2 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. |
3 * | 3 * |
4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 m_embeddedColorSpace = colorSpace; | 515 m_embeddedColorSpace = colorSpace; |
516 m_sourceToTargetColorTransformNeedsUpdate = true; | 516 m_sourceToTargetColorTransformNeedsUpdate = true; |
517 } | 517 } |
518 | 518 |
519 SkColorSpaceXform* ImageDecoder::colorTransform() { | 519 SkColorSpaceXform* ImageDecoder::colorTransform() { |
520 if (!m_sourceToTargetColorTransformNeedsUpdate) | 520 if (!m_sourceToTargetColorTransformNeedsUpdate) |
521 return m_sourceToTargetColorTransform.get(); | 521 return m_sourceToTargetColorTransform.get(); |
522 m_sourceToTargetColorTransformNeedsUpdate = false; | 522 m_sourceToTargetColorTransformNeedsUpdate = false; |
523 m_sourceToTargetColorTransform = nullptr; | 523 m_sourceToTargetColorTransform = nullptr; |
524 | 524 |
525 if (!m_colorBehavior.isTransformToTargetColorSpace()) | 525 if (m_colorBehavior.isIgnore()) { |
526 return nullptr; | 526 return nullptr; |
527 | |
528 sk_sp<SkColorSpace> srcColorSpace = m_embeddedColorSpace; | |
529 if (!srcColorSpace) { | |
530 if (RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) | |
531 srcColorSpace = SkColorSpace::MakeSRGB(); | |
532 else | |
533 return nullptr; | |
534 } | 527 } |
535 | 528 |
536 sk_sp<SkColorSpace> dstColorSpace = | 529 sk_sp<SkColorSpace> srcColorSpace = nullptr; |
537 m_colorBehavior.targetColorSpace().ToSkColorSpace(); | 530 sk_sp<SkColorSpace> dstColorSpace = nullptr; |
| 531 if (m_colorBehavior.isTransformToTargetColorSpace()) { |
| 532 if (!m_embeddedColorSpace) { |
| 533 return nullptr; |
| 534 } |
| 535 |
| 536 srcColorSpace = m_embeddedColorSpace; |
| 537 dstColorSpace = m_colorBehavior.targetColorSpace().ToSkColorSpace(); |
| 538 } else { |
| 539 DCHECK(m_colorBehavior.isTag()); |
| 540 srcColorSpace = m_embeddedColorSpace; |
| 541 if (!srcColorSpace) { |
| 542 srcColorSpace = SkColorSpace::MakeSRGB(); |
| 543 } |
| 544 |
| 545 // This will most likely be equal to the |srcColorSpace|. |
| 546 // In that case, we skip the xform when we check for equality below. |
| 547 dstColorSpace = colorSpaceForSkImages(); |
| 548 } |
538 | 549 |
539 if (SkColorSpace::Equals(srcColorSpace.get(), dstColorSpace.get())) { | 550 if (SkColorSpace::Equals(srcColorSpace.get(), dstColorSpace.get())) { |
540 return nullptr; | 551 return nullptr; |
541 } | 552 } |
542 | 553 |
543 m_sourceToTargetColorTransform = | 554 m_sourceToTargetColorTransform = |
544 SkColorSpaceXform::New(srcColorSpace.get(), dstColorSpace.get()); | 555 SkColorSpaceXform::New(srcColorSpace.get(), dstColorSpace.get()); |
545 return m_sourceToTargetColorTransform.get(); | 556 return m_sourceToTargetColorTransform.get(); |
546 } | 557 } |
547 | 558 |
548 sk_sp<SkColorSpace> ImageDecoder::colorSpaceForSkImages() const { | 559 sk_sp<SkColorSpace> ImageDecoder::colorSpaceForSkImages() const { |
549 if (!m_colorBehavior.isTag()) | 560 if (!m_colorBehavior.isTag()) |
550 return nullptr; | 561 return nullptr; |
551 | 562 |
552 if (m_embeddedColorSpace) | 563 if (m_embeddedColorSpace) { |
553 return m_embeddedColorSpace; | 564 SkColorSpaceTransferFn fn; |
| 565 if (m_embeddedColorSpace->isNumericalTransferFn(&fn)) { |
| 566 // The embedded color space is supported by Skia. |
| 567 return m_embeddedColorSpace; |
| 568 } |
| 569 |
| 570 // In the rare case that the embedded color space is unsupported, xform at |
| 571 // decode time. |
| 572 SkMatrix44 toXYZD50(SkMatrix44::kUninitialized_Constructor); |
| 573 if (m_embeddedColorSpace->toXYZD50(&toXYZD50)) { |
| 574 // Preserve the gamut, but convert to a standard transfer function. |
| 575 return SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma, |
| 576 toXYZD50); |
| 577 } |
| 578 |
| 579 // For color spaces without an identifiable gamut, just fall through to |
| 580 // sRGB. |
| 581 } |
| 582 |
554 return SkColorSpace::MakeSRGB(); | 583 return SkColorSpace::MakeSRGB(); |
555 } | 584 } |
556 | 585 |
557 } // namespace blink | 586 } // namespace blink |
OLD | NEW |