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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 | 61 |
62 inline bool MatchesBMPSignature(const char* contents) { | 62 inline bool MatchesBMPSignature(const char* contents) { |
63 return !memcmp(contents, "BM", 2); | 63 return !memcmp(contents, "BM", 2); |
64 } | 64 } |
65 | 65 |
66 // This needs to be updated if we ever add a matches*Signature() which requires | 66 // This needs to be updated if we ever add a matches*Signature() which requires |
67 // more characters. | 67 // more characters. |
68 static constexpr size_t kLongestSignatureLength = sizeof("RIFF????WEBPVP") - 1; | 68 static constexpr size_t kLongestSignatureLength = sizeof("RIFF????WEBPVP") - 1; |
69 | 69 |
70 std::unique_ptr<ImageDecoder> ImageDecoder::Create( | 70 std::unique_ptr<ImageDecoder> ImageDecoder::Create( |
71 PassRefPtr<SegmentReader> pass_data, | 71 RefPtr<SegmentReader> data, |
72 bool data_complete, | 72 bool data_complete, |
73 AlphaOption alpha_option, | 73 AlphaOption alpha_option, |
74 const ColorBehavior& color_behavior) { | 74 const ColorBehavior& color_behavior) { |
75 RefPtr<SegmentReader> data = pass_data; | |
76 | |
77 // We need at least kLongestSignatureLength bytes to run the signature | 75 // We need at least kLongestSignatureLength bytes to run the signature |
78 // matcher. | 76 // matcher. |
79 if (data->size() < kLongestSignatureLength) | 77 if (data->size() < kLongestSignatureLength) |
80 return nullptr; | 78 return nullptr; |
81 | 79 |
82 const size_t max_decoded_bytes = | 80 const size_t max_decoded_bytes = |
83 Platform::Current() ? Platform::Current()->MaxDecodedImageBytes() | 81 Platform::Current() ? Platform::Current()->MaxDecodedImageBytes() |
84 : kNoDecodedImageByteLimit; | 82 : kNoDecodedImageByteLimit; |
85 | 83 |
86 // Access the first kLongestSignatureLength chars to sniff the signature. | 84 // Access the first kLongestSignatureLength chars to sniff the signature. |
(...skipping 28 matching lines...) Expand all Loading... |
115 break; | 113 break; |
116 case SniffResult::BMP: | 114 case SniffResult::BMP: |
117 decoder.reset( | 115 decoder.reset( |
118 new BMPImageDecoder(alpha_option, color_behavior, max_decoded_bytes)); | 116 new BMPImageDecoder(alpha_option, color_behavior, max_decoded_bytes)); |
119 break; | 117 break; |
120 case SniffResult::kInvalid: | 118 case SniffResult::kInvalid: |
121 break; | 119 break; |
122 } | 120 } |
123 | 121 |
124 if (decoder) | 122 if (decoder) |
125 decoder->SetData(data.Release(), data_complete); | 123 decoder->SetData(std::move(data), data_complete); |
126 | 124 |
127 return decoder; | 125 return decoder; |
128 } | 126 } |
129 | 127 |
130 bool ImageDecoder::HasSufficientDataToSniffImageType(const SharedBuffer& data) { | 128 bool ImageDecoder::HasSufficientDataToSniffImageType(const SharedBuffer& data) { |
131 return data.size() >= kLongestSignatureLength; | 129 return data.size() >= kLongestSignatureLength; |
132 } | 130 } |
133 | 131 |
134 ImageDecoder::SniffResult ImageDecoder::DetermineImageType(const char* contents, | 132 ImageDecoder::SniffResult ImageDecoder::DetermineImageType(const char* contents, |
135 size_t length) { | 133 size_t length) { |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 sk_sp<SkColorSpace> ImageDecoder::ColorSpaceForSkImages() const { | 547 sk_sp<SkColorSpace> ImageDecoder::ColorSpaceForSkImages() const { |
550 if (!color_behavior_.IsTag()) | 548 if (!color_behavior_.IsTag()) |
551 return nullptr; | 549 return nullptr; |
552 | 550 |
553 if (embedded_color_space_) | 551 if (embedded_color_space_) |
554 return embedded_color_space_; | 552 return embedded_color_space_; |
555 return SkColorSpace::MakeSRGB(); | 553 return SkColorSpace::MakeSRGB(); |
556 } | 554 } |
557 | 555 |
558 } // namespace blink | 556 } // namespace blink |
OLD | NEW |