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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 inline bool matchesCURSignature(const char* contents) | 73 inline bool matchesCURSignature(const char* contents) |
74 { | 74 { |
75 return !memcmp(contents, "\x00\x00\x02\x00", 4); | 75 return !memcmp(contents, "\x00\x00\x02\x00", 4); |
76 } | 76 } |
77 | 77 |
78 inline bool matchesBMPSignature(const char* contents) | 78 inline bool matchesBMPSignature(const char* contents) |
79 { | 79 { |
80 return !memcmp(contents, "BM", 2); | 80 return !memcmp(contents, "BM", 2); |
81 } | 81 } |
82 | 82 |
83 std::unique_ptr<ImageDecoder> ImageDecoder::create(const char* contents, size_t
length, AlphaOption alphaOption, GammaAndColorProfileOption colorOptions) | 83 std::unique_ptr<ImageDecoder> ImageDecoder::create(SniffResult sniffResult, Alph
aOption alphaOption, GammaAndColorProfileOption colorOptions) |
84 { | 84 { |
85 const size_t longestSignatureLength = sizeof("RIFF????WEBPVP") - 1; | |
86 ASSERT(longestSignatureLength == 14); | |
87 | |
88 if (length < longestSignatureLength) | |
89 return nullptr; | |
90 | |
91 size_t maxDecodedBytes = Platform::current() ? Platform::current()->maxDecod
edImageBytes() : noDecodedImageByteLimit; | 85 size_t maxDecodedBytes = Platform::current() ? Platform::current()->maxDecod
edImageBytes() : noDecodedImageByteLimit; |
92 | 86 |
93 if (matchesJPEGSignature(contents)) | 87 switch (sniffResult) { |
| 88 case SniffResult::JPEG: |
94 return wrapUnique(new JPEGImageDecoder(alphaOption, colorOptions, maxDec
odedBytes)); | 89 return wrapUnique(new JPEGImageDecoder(alphaOption, colorOptions, maxDec
odedBytes)); |
95 | 90 case SniffResult::PNG: |
96 if (matchesPNGSignature(contents)) | |
97 return wrapUnique(new PNGImageDecoder(alphaOption, colorOptions, maxDeco
dedBytes)); | 91 return wrapUnique(new PNGImageDecoder(alphaOption, colorOptions, maxDeco
dedBytes)); |
98 | 92 case SniffResult::GIF: |
99 if (matchesGIFSignature(contents)) | |
100 return wrapUnique(new GIFImageDecoder(alphaOption, colorOptions, maxDeco
dedBytes)); | 93 return wrapUnique(new GIFImageDecoder(alphaOption, colorOptions, maxDeco
dedBytes)); |
101 | 94 case SniffResult::WEBP: |
102 if (matchesWebPSignature(contents)) | |
103 return wrapUnique(new WEBPImageDecoder(alphaOption, colorOptions, maxDec
odedBytes)); | 95 return wrapUnique(new WEBPImageDecoder(alphaOption, colorOptions, maxDec
odedBytes)); |
104 | 96 case SniffResult::ICO: |
105 if (matchesICOSignature(contents) || matchesCURSignature(contents)) | |
106 return wrapUnique(new ICOImageDecoder(alphaOption, colorOptions, maxDeco
dedBytes)); | 97 return wrapUnique(new ICOImageDecoder(alphaOption, colorOptions, maxDeco
dedBytes)); |
107 | 98 case SniffResult::BMP: |
108 if (matchesBMPSignature(contents)) | |
109 return wrapUnique(new BMPImageDecoder(alphaOption, colorOptions, maxDeco
dedBytes)); | 99 return wrapUnique(new BMPImageDecoder(alphaOption, colorOptions, maxDeco
dedBytes)); |
110 | 100 case SniffResult::InsufficientData: |
| 101 case SniffResult::Invalid: |
| 102 return nullptr; |
| 103 } |
| 104 NOTREACHED(); |
111 return nullptr; | 105 return nullptr; |
112 } | 106 } |
113 | 107 |
114 std::unique_ptr<ImageDecoder> ImageDecoder::create(const SharedBuffer& data, Alp
haOption alphaOption, GammaAndColorProfileOption colorOptions) | 108 ImageDecoder::SniffResult ImageDecoder::determineImageType(const char* contents,
size_t length) |
| 109 { |
| 110 const size_t longestSignatureLength = sizeof("RIFF????WEBPVP") - 1; |
| 111 DCHECK_EQ(14u, longestSignatureLength); |
| 112 |
| 113 if (length < longestSignatureLength) |
| 114 return SniffResult::InsufficientData; |
| 115 if (matchesJPEGSignature(contents)) |
| 116 return SniffResult::JPEG; |
| 117 if (matchesPNGSignature(contents)) |
| 118 return SniffResult::PNG; |
| 119 if (matchesGIFSignature(contents)) |
| 120 return SniffResult::GIF; |
| 121 if (matchesWebPSignature(contents)) |
| 122 return SniffResult::WEBP; |
| 123 if (matchesICOSignature(contents) || matchesCURSignature(contents)) |
| 124 return SniffResult::ICO; |
| 125 if (matchesBMPSignature(contents)) |
| 126 return SniffResult::BMP; |
| 127 return SniffResult::Invalid; |
| 128 } |
| 129 |
| 130 ImageDecoder::SniffResult ImageDecoder::determineImageType(const SharedBuffer& d
ata) |
115 { | 131 { |
116 const char* contents; | 132 const char* contents; |
117 const size_t length = data.getSomeData<size_t>(contents); | 133 const size_t length = data.getSomeData<size_t>(contents); |
118 return create(contents, length, alphaOption, colorOptions); | 134 return determineImageType(contents, length); |
119 } | 135 } |
120 | 136 |
121 std::unique_ptr<ImageDecoder> ImageDecoder::create(const SegmentReader& data, Al
phaOption alphaOption, GammaAndColorProfileOption colorOptions) | 137 ImageDecoder::SniffResult ImageDecoder::determineImageType(const SegmentReader&
data) |
122 { | 138 { |
123 const char* contents; | 139 const char* contents; |
124 const size_t length = data.getSomeData(contents, 0); | 140 const size_t length = data.getSomeData(contents, 0); |
125 return create(contents, length, alphaOption, colorOptions); | 141 return determineImageType(contents, length); |
126 } | 142 } |
127 | 143 |
128 size_t ImageDecoder::frameCount() | 144 size_t ImageDecoder::frameCount() |
129 { | 145 { |
130 const size_t oldSize = m_frameBufferCache.size(); | 146 const size_t oldSize = m_frameBufferCache.size(); |
131 const size_t newSize = decodeFrameCount(); | 147 const size_t newSize = decodeFrameCount(); |
132 if (oldSize != newSize) { | 148 if (oldSize != newSize) { |
133 m_frameBufferCache.resize(newSize); | 149 m_frameBufferCache.resize(newSize); |
134 for (size_t i = oldSize; i < newSize; ++i) { | 150 for (size_t i = oldSize; i < newSize; ++i) { |
135 m_frameBufferCache[i].setPremultiplyAlpha(m_premultiplyAlpha); | 151 m_frameBufferCache[i].setPremultiplyAlpha(m_premultiplyAlpha); |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 } | 399 } |
384 | 400 |
385 bool ImageDecoder::hasColorProfile() const | 401 bool ImageDecoder::hasColorProfile() const |
386 { | 402 { |
387 return false; | 403 return false; |
388 } | 404 } |
389 | 405 |
390 #endif // USE(QCMSLIB) | 406 #endif // USE(QCMSLIB) |
391 | 407 |
392 } // namespace blink | 408 } // namespace blink |
OLD | NEW |