OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2008, 2009, Google Inc. All rights reserved. | 2 * Copyright (c) 2008, 2009, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 14 matching lines...) Expand all Loading... |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "platform/image-decoders/ico/ICOImageDecoder.h" | 31 #include "platform/image-decoders/ico/ICOImageDecoder.h" |
32 | 32 |
33 #include "platform/Histogram.h" | 33 #include "platform/Histogram.h" |
34 #include "platform/image-decoders/png/PNGImageDecoder.h" | 34 #include "platform/image-decoders/png/PNGImageDecoder.h" |
35 #include "wtf/PtrUtil.h" | 35 #include "wtf/PassOwnPtr.h" |
36 #include "wtf/Threading.h" | 36 #include "wtf/Threading.h" |
| 37 |
37 #include <algorithm> | 38 #include <algorithm> |
38 | 39 |
39 namespace blink { | 40 namespace blink { |
40 | 41 |
41 // Number of bits in .ICO/.CUR used to store the directory and its entries, | 42 // Number of bits in .ICO/.CUR used to store the directory and its entries, |
42 // respectively (doesn't match sizeof values for member structs since we omit | 43 // respectively (doesn't match sizeof values for member structs since we omit |
43 // some fields). | 44 // some fields). |
44 static const size_t sizeOfDirectory = 6; | 45 static const size_t sizeOfDirectory = 6; |
45 static const size_t sizeOfDirEntry = 16; | 46 static const size_t sizeOfDirEntry = 16; |
46 | 47 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 bool ICOImageDecoder::decodeAtIndex(size_t index) | 189 bool ICOImageDecoder::decodeAtIndex(size_t index) |
189 { | 190 { |
190 ASSERT_WITH_SECURITY_IMPLICATION(index < m_dirEntries.size()); | 191 ASSERT_WITH_SECURITY_IMPLICATION(index < m_dirEntries.size()); |
191 const IconDirectoryEntry& dirEntry = m_dirEntries[index]; | 192 const IconDirectoryEntry& dirEntry = m_dirEntries[index]; |
192 const ImageType imageType = imageTypeAtIndex(index); | 193 const ImageType imageType = imageTypeAtIndex(index); |
193 if (imageType == Unknown) | 194 if (imageType == Unknown) |
194 return false; // Not enough data to determine image type yet. | 195 return false; // Not enough data to determine image type yet. |
195 | 196 |
196 if (imageType == BMP) { | 197 if (imageType == BMP) { |
197 if (!m_bmpReaders[index]) { | 198 if (!m_bmpReaders[index]) { |
198 m_bmpReaders[index] = wrapUnique(new BMPImageReader(this, dirEntry.m
_imageOffset, 0, true)); | 199 m_bmpReaders[index] = adoptPtr(new BMPImageReader(this, dirEntry.m_i
mageOffset, 0, true)); |
199 m_bmpReaders[index]->setData(m_data.get()); | 200 m_bmpReaders[index]->setData(m_data.get()); |
200 } | 201 } |
201 // Update the pointer to the buffer as it could change after | 202 // Update the pointer to the buffer as it could change after |
202 // m_frameBufferCache.resize(). | 203 // m_frameBufferCache.resize(). |
203 m_bmpReaders[index]->setBuffer(&m_frameBufferCache[index]); | 204 m_bmpReaders[index]->setBuffer(&m_frameBufferCache[index]); |
204 m_frameSize = dirEntry.m_size; | 205 m_frameSize = dirEntry.m_size; |
205 bool result = m_bmpReaders[index]->decodeBMP(false); | 206 bool result = m_bmpReaders[index]->decodeBMP(false); |
206 m_frameSize = IntSize(); | 207 m_frameSize = IntSize(); |
207 return result; | 208 return result; |
208 } | 209 } |
209 | 210 |
210 if (!m_pngDecoders[index]) { | 211 if (!m_pngDecoders[index]) { |
211 AlphaOption alphaOption = m_premultiplyAlpha ? AlphaPremultiplied : Alph
aNotPremultiplied; | 212 AlphaOption alphaOption = m_premultiplyAlpha ? AlphaPremultiplied : Alph
aNotPremultiplied; |
212 GammaAndColorProfileOption colorOptions = m_ignoreGammaAndColorProfile ?
GammaAndColorProfileIgnored : GammaAndColorProfileApplied; | 213 GammaAndColorProfileOption colorOptions = m_ignoreGammaAndColorProfile ?
GammaAndColorProfileIgnored : GammaAndColorProfileApplied; |
213 m_pngDecoders[index] = wrapUnique(new PNGImageDecoder(alphaOption, color
Options, m_maxDecodedBytes, dirEntry.m_imageOffset)); | 214 m_pngDecoders[index] = adoptPtr(new PNGImageDecoder(alphaOption, colorOp
tions, m_maxDecodedBytes, dirEntry.m_imageOffset)); |
214 setDataForPNGDecoderAtIndex(index); | 215 setDataForPNGDecoderAtIndex(index); |
215 } | 216 } |
216 // Fail if the size the PNGImageDecoder calculated does not match the size | 217 // Fail if the size the PNGImageDecoder calculated does not match the size |
217 // in the directory. | 218 // in the directory. |
218 if (m_pngDecoders[index]->isSizeAvailable() && (m_pngDecoders[index]->size()
!= dirEntry.m_size)) | 219 if (m_pngDecoders[index]->isSizeAvailable() && (m_pngDecoders[index]->size()
!= dirEntry.m_size)) |
219 return setFailed(); | 220 return setFailed(); |
220 m_frameBufferCache[index] = *m_pngDecoders[index]->frameBufferAtIndex(0); | 221 m_frameBufferCache[index] = *m_pngDecoders[index]->frameBufferAtIndex(0); |
221 m_frameBufferCache[index].setPremultiplyAlpha(m_premultiplyAlpha); | 222 m_frameBufferCache[index].setPremultiplyAlpha(m_premultiplyAlpha); |
222 return !m_pngDecoders[index]->failed() || setFailed(); | 223 return !m_pngDecoders[index]->failed() || setFailed(); |
223 } | 224 } |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 ASSERT_WITH_SECURITY_IMPLICATION(index < m_dirEntries.size()); | 326 ASSERT_WITH_SECURITY_IMPLICATION(index < m_dirEntries.size()); |
326 const uint32_t imageOffset = m_dirEntries[index].m_imageOffset; | 327 const uint32_t imageOffset = m_dirEntries[index].m_imageOffset; |
327 if ((imageOffset > m_data->size()) || ((m_data->size() - imageOffset) < 4)) | 328 if ((imageOffset > m_data->size()) || ((m_data->size() - imageOffset) < 4)) |
328 return Unknown; | 329 return Unknown; |
329 char buffer[4]; | 330 char buffer[4]; |
330 const char* data = m_fastReader.getConsecutiveData(imageOffset, 4, buffer); | 331 const char* data = m_fastReader.getConsecutiveData(imageOffset, 4, buffer); |
331 return strncmp(data, "\x89PNG", 4) ? BMP : PNG; | 332 return strncmp(data, "\x89PNG", 4) ? BMP : PNG; |
332 } | 333 } |
333 | 334 |
334 } // namespace blink | 335 } // namespace blink |
OLD | NEW |