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 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 embedded_color_space_ = color_space; | 516 embedded_color_space_ = color_space; |
517 source_to_target_color_transform_needs_update_ = true; | 517 source_to_target_color_transform_needs_update_ = true; |
518 } | 518 } |
519 | 519 |
520 SkColorSpaceXform* ImageDecoder::ColorTransform() { | 520 SkColorSpaceXform* ImageDecoder::ColorTransform() { |
521 if (!source_to_target_color_transform_needs_update_) | 521 if (!source_to_target_color_transform_needs_update_) |
522 return source_to_target_color_transform_.get(); | 522 return source_to_target_color_transform_.get(); |
523 source_to_target_color_transform_needs_update_ = false; | 523 source_to_target_color_transform_needs_update_ = false; |
524 source_to_target_color_transform_ = nullptr; | 524 source_to_target_color_transform_ = nullptr; |
525 | 525 |
526 if (!color_behavior_.IsTransformToTargetColorSpace()) | 526 if (color_behavior_.IsIgnore()) { |
527 return nullptr; | 527 return nullptr; |
528 | |
529 sk_sp<SkColorSpace> src_color_space = embedded_color_space_; | |
530 if (!src_color_space) { | |
531 if (RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) | |
532 src_color_space = SkColorSpace::MakeSRGB(); | |
533 else | |
534 return nullptr; | |
535 } | 528 } |
536 | 529 |
537 sk_sp<SkColorSpace> dst_color_space = | 530 sk_sp<SkColorSpace> src_color_space = nullptr; |
538 color_behavior_.TargetColorSpace().ToSkColorSpace(); | 531 sk_sp<SkColorSpace> dst_color_space = nullptr; |
| 532 if (color_behavior_.IsTransformToTargetColorSpace()) { |
| 533 if (!embedded_color_space_) { |
| 534 return nullptr; |
| 535 } |
| 536 |
| 537 src_color_space = embedded_color_space_; |
| 538 dst_color_space = color_behavior_.TargetColorSpace().ToSkColorSpace(); |
| 539 } else { |
| 540 DCHECK(color_behavior_.IsTag()); |
| 541 src_color_space = embedded_color_space_; |
| 542 if (!src_color_space) { |
| 543 src_color_space = SkColorSpace::MakeSRGB(); |
| 544 } |
| 545 |
| 546 // This will most likely be equal to the |src_color_space|. |
| 547 // In that case, we skip the xform when we check for equality below. |
| 548 dst_color_space = ColorSpaceForSkImages(); |
| 549 } |
539 | 550 |
540 if (SkColorSpace::Equals(src_color_space.get(), dst_color_space.get())) { | 551 if (SkColorSpace::Equals(src_color_space.get(), dst_color_space.get())) { |
541 return nullptr; | 552 return nullptr; |
542 } | 553 } |
543 | 554 |
544 source_to_target_color_transform_ = | 555 source_to_target_color_transform_ = |
545 SkColorSpaceXform::New(src_color_space.get(), dst_color_space.get()); | 556 SkColorSpaceXform::New(src_color_space.get(), dst_color_space.get()); |
546 return source_to_target_color_transform_.get(); | 557 return source_to_target_color_transform_.get(); |
547 } | 558 } |
548 | 559 |
549 sk_sp<SkColorSpace> ImageDecoder::ColorSpaceForSkImages() const { | 560 sk_sp<SkColorSpace> ImageDecoder::ColorSpaceForSkImages() const { |
550 if (!color_behavior_.IsTag()) | 561 if (!color_behavior_.IsTag()) |
551 return nullptr; | 562 return nullptr; |
552 | 563 |
553 if (embedded_color_space_) | 564 if (embedded_color_space_) { |
554 return embedded_color_space_; | 565 SkColorSpaceTransferFn fn; |
| 566 if (embedded_color_space_->isNumericalTransferFn(&fn)) { |
| 567 // The embedded color space is supported by Skia. |
| 568 return embedded_color_space_; |
| 569 } |
| 570 |
| 571 // In the rare case that the embedded color space is unsupported, xform at |
| 572 // decode time. |
| 573 SkMatrix44 to_xyz_d50(SkMatrix44::kUninitialized_Constructor); |
| 574 if (embedded_color_space_->toXYZD50(&to_xyz_d50)) { |
| 575 // Preserve the gamut, but convert to a standard transfer function. |
| 576 return SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma, |
| 577 to_xyz_d50); |
| 578 } |
| 579 |
| 580 // For color spaces without an identifiable gamut, just fall through to |
| 581 // sRGB. |
| 582 } |
| 583 |
555 return SkColorSpace::MakeSRGB(); | 584 return SkColorSpace::MakeSRGB(); |
556 } | 585 } |
557 | 586 |
558 } // namespace blink | 587 } // namespace blink |
OLD | NEW |