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