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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 * Library General Public License for more details. | 12 * Library General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU Library General Public License | 14 * You should have received a copy of the GNU Library General Public License |
15 * along with this library; see the file COPYING.LIB. If not, write to | 15 * along with this library; see the file COPYING.LIB. If not, write to |
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 * Boston, MA 02110-1301, USA. | 17 * Boston, MA 02110-1301, USA. |
18 * | 18 * |
19 */ | 19 */ |
20 | 20 |
21 #include "platform/image-decoders/ImageDecoder.h" | 21 #include "platform/image-decoders/ImageDecoder.h" |
22 | 22 |
23 #include "platform/PlatformInstrumentation.h" | 23 #include "platform/PlatformInstrumentation.h" |
| 24 #include "platform/image-decoders/FastSharedBufferReader.h" |
24 #include "platform/image-decoders/bmp/BMPImageDecoder.h" | 25 #include "platform/image-decoders/bmp/BMPImageDecoder.h" |
25 #include "platform/image-decoders/gif/GIFImageDecoder.h" | 26 #include "platform/image-decoders/gif/GIFImageDecoder.h" |
26 #include "platform/image-decoders/ico/ICOImageDecoder.h" | 27 #include "platform/image-decoders/ico/ICOImageDecoder.h" |
27 #include "platform/image-decoders/jpeg/JPEGImageDecoder.h" | 28 #include "platform/image-decoders/jpeg/JPEGImageDecoder.h" |
28 #include "platform/image-decoders/png/PNGImageDecoder.h" | 29 #include "platform/image-decoders/png/PNGImageDecoder.h" |
29 #include "platform/image-decoders/webp/WEBPImageDecoder.h" | 30 #include "platform/image-decoders/webp/WEBPImageDecoder.h" |
30 #include "wtf/PtrUtil.h" | 31 #include "wtf/PtrUtil.h" |
31 #include <memory> | 32 #include <memory> |
32 | 33 |
33 namespace blink { | 34 namespace blink { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 inline bool matchesCURSignature(const char* contents) | 74 inline bool matchesCURSignature(const char* contents) |
74 { | 75 { |
75 return !memcmp(contents, "\x00\x00\x02\x00", 4); | 76 return !memcmp(contents, "\x00\x00\x02\x00", 4); |
76 } | 77 } |
77 | 78 |
78 inline bool matchesBMPSignature(const char* contents) | 79 inline bool matchesBMPSignature(const char* contents) |
79 { | 80 { |
80 return !memcmp(contents, "BM", 2); | 81 return !memcmp(contents, "BM", 2); |
81 } | 82 } |
82 | 83 |
| 84 namespace { |
| 85 |
| 86 // This needs to be updated if we ever add a matches*Signature() which requires
more characters. |
| 87 constexpr size_t kLongestSignatureLength = sizeof("RIFF????WEBPVP") - 1; |
| 88 |
| 89 } // anonymous ns |
| 90 |
83 std::unique_ptr<ImageDecoder> ImageDecoder::create(const char* contents, size_t
length, AlphaOption alphaOption, GammaAndColorProfileOption colorOptions) | 91 std::unique_ptr<ImageDecoder> ImageDecoder::create(const char* contents, size_t
length, AlphaOption alphaOption, GammaAndColorProfileOption colorOptions) |
84 { | 92 { |
85 const size_t longestSignatureLength = sizeof("RIFF????WEBPVP") - 1; | 93 if (length < kLongestSignatureLength) |
86 ASSERT(longestSignatureLength == 14); | |
87 | |
88 if (length < longestSignatureLength) | |
89 return nullptr; | 94 return nullptr; |
90 | 95 |
91 size_t maxDecodedBytes = Platform::current() ? Platform::current()->maxDecod
edImageBytes() : noDecodedImageByteLimit; | 96 size_t maxDecodedBytes = Platform::current() ? Platform::current()->maxDecod
edImageBytes() : noDecodedImageByteLimit; |
92 | 97 |
93 if (matchesJPEGSignature(contents)) | 98 if (matchesJPEGSignature(contents)) |
94 return wrapUnique(new JPEGImageDecoder(alphaOption, colorOptions, maxDec
odedBytes)); | 99 return wrapUnique(new JPEGImageDecoder(alphaOption, colorOptions, maxDec
odedBytes)); |
95 | 100 |
96 if (matchesPNGSignature(contents)) | 101 if (matchesPNGSignature(contents)) |
97 return wrapUnique(new PNGImageDecoder(alphaOption, colorOptions, maxDeco
dedBytes)); | 102 return wrapUnique(new PNGImageDecoder(alphaOption, colorOptions, maxDeco
dedBytes)); |
98 | 103 |
99 if (matchesGIFSignature(contents)) | 104 if (matchesGIFSignature(contents)) |
100 return wrapUnique(new GIFImageDecoder(alphaOption, colorOptions, maxDeco
dedBytes)); | 105 return wrapUnique(new GIFImageDecoder(alphaOption, colorOptions, maxDeco
dedBytes)); |
101 | 106 |
102 if (matchesWebPSignature(contents)) | 107 if (matchesWebPSignature(contents)) |
103 return wrapUnique(new WEBPImageDecoder(alphaOption, colorOptions, maxDec
odedBytes)); | 108 return wrapUnique(new WEBPImageDecoder(alphaOption, colorOptions, maxDec
odedBytes)); |
104 | 109 |
105 if (matchesICOSignature(contents) || matchesCURSignature(contents)) | 110 if (matchesICOSignature(contents) || matchesCURSignature(contents)) |
106 return wrapUnique(new ICOImageDecoder(alphaOption, colorOptions, maxDeco
dedBytes)); | 111 return wrapUnique(new ICOImageDecoder(alphaOption, colorOptions, maxDeco
dedBytes)); |
107 | 112 |
108 if (matchesBMPSignature(contents)) | 113 if (matchesBMPSignature(contents)) |
109 return wrapUnique(new BMPImageDecoder(alphaOption, colorOptions, maxDeco
dedBytes)); | 114 return wrapUnique(new BMPImageDecoder(alphaOption, colorOptions, maxDeco
dedBytes)); |
110 | 115 |
111 return nullptr; | 116 return nullptr; |
112 } | 117 } |
113 | 118 |
114 std::unique_ptr<ImageDecoder> ImageDecoder::create(const SharedBuffer& data, Alp
haOption alphaOption, GammaAndColorProfileOption colorOptions) | 119 std::unique_ptr<ImageDecoder> ImageDecoder::create(const SharedBuffer& data, Alp
haOption alphaOption, GammaAndColorProfileOption colorOptions) |
115 { | 120 { |
116 const char* contents; | 121 RefPtr<SegmentReader> reader = SegmentReader::createFromSharedBuffer(const_c
ast<SharedBuffer*>(&data)); |
117 const size_t length = data.getSomeData<size_t>(contents); | 122 return create(*reader, alphaOption, colorOptions); |
118 return create(contents, length, alphaOption, colorOptions); | |
119 } | 123 } |
120 | 124 |
121 std::unique_ptr<ImageDecoder> ImageDecoder::create(const SegmentReader& data, Al
phaOption alphaOption, GammaAndColorProfileOption colorOptions) | 125 std::unique_ptr<ImageDecoder> ImageDecoder::create(const SegmentReader& data, Al
phaOption alphaOption, GammaAndColorProfileOption colorOptions) |
122 { | 126 { |
123 const char* contents; | 127 const FastSharedBufferReader fastReader(const_cast<SegmentReader*>(&data)); |
124 const size_t length = data.getSomeData(contents, 0); | 128 char buffer[kLongestSignatureLength]; |
125 return create(contents, length, alphaOption, colorOptions); | 129 const size_t len = std::min(kLongestSignatureLength, data.size()); |
| 130 |
| 131 return create(fastReader.getConsecutiveData(0, len, buffer), len, alphaOpti
on, colorOptions); |
126 } | 132 } |
127 | 133 |
128 size_t ImageDecoder::frameCount() | 134 size_t ImageDecoder::frameCount() |
129 { | 135 { |
130 const size_t oldSize = m_frameBufferCache.size(); | 136 const size_t oldSize = m_frameBufferCache.size(); |
131 const size_t newSize = decodeFrameCount(); | 137 const size_t newSize = decodeFrameCount(); |
132 if (oldSize != newSize) { | 138 if (oldSize != newSize) { |
133 m_frameBufferCache.resize(newSize); | 139 m_frameBufferCache.resize(newSize); |
134 for (size_t i = oldSize; i < newSize; ++i) { | 140 for (size_t i = oldSize; i < newSize; ++i) { |
135 m_frameBufferCache[i].setPremultiplyAlpha(m_premultiplyAlpha); | 141 m_frameBufferCache[i].setPremultiplyAlpha(m_premultiplyAlpha); |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 } | 389 } |
384 | 390 |
385 bool ImageDecoder::hasColorProfile() const | 391 bool ImageDecoder::hasColorProfile() const |
386 { | 392 { |
387 return false; | 393 return false; |
388 } | 394 } |
389 | 395 |
390 #endif // USE(QCMSLIB) | 396 #endif // USE(QCMSLIB) |
391 | 397 |
392 } // namespace blink | 398 } // namespace blink |
OLD | NEW |