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/PassOwnPtr.h" | 35 #include "wtf/PtrUtil.h" |
36 #include "wtf/Threading.h" | 36 #include "wtf/Threading.h" |
37 | |
38 #include <algorithm> | 37 #include <algorithm> |
39 | 38 |
40 namespace blink { | 39 namespace blink { |
41 | 40 |
42 // Number of bits in .ICO/.CUR used to store the directory and its entries, | 41 // Number of bits in .ICO/.CUR used to store the directory and its entries, |
43 // respectively (doesn't match sizeof values for member structs since we omit | 42 // respectively (doesn't match sizeof values for member structs since we omit |
44 // some fields). | 43 // some fields). |
45 static const size_t sizeOfDirectory = 6; | 44 static const size_t sizeOfDirectory = 6; |
46 static const size_t sizeOfDirEntry = 16; | 45 static const size_t sizeOfDirEntry = 16; |
47 | 46 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 bool ICOImageDecoder::decodeAtIndex(size_t index) | 188 bool ICOImageDecoder::decodeAtIndex(size_t index) |
190 { | 189 { |
191 ASSERT_WITH_SECURITY_IMPLICATION(index < m_dirEntries.size()); | 190 ASSERT_WITH_SECURITY_IMPLICATION(index < m_dirEntries.size()); |
192 const IconDirectoryEntry& dirEntry = m_dirEntries[index]; | 191 const IconDirectoryEntry& dirEntry = m_dirEntries[index]; |
193 const ImageType imageType = imageTypeAtIndex(index); | 192 const ImageType imageType = imageTypeAtIndex(index); |
194 if (imageType == Unknown) | 193 if (imageType == Unknown) |
195 return false; // Not enough data to determine image type yet. | 194 return false; // Not enough data to determine image type yet. |
196 | 195 |
197 if (imageType == BMP) { | 196 if (imageType == BMP) { |
198 if (!m_bmpReaders[index]) { | 197 if (!m_bmpReaders[index]) { |
199 m_bmpReaders[index] = adoptPtr(new BMPImageReader(this, dirEntry.m_i
mageOffset, 0, true)); | 198 m_bmpReaders[index] = wrapUnique(new BMPImageReader(this, dirEntry.m
_imageOffset, 0, true)); |
200 m_bmpReaders[index]->setData(m_data.get()); | 199 m_bmpReaders[index]->setData(m_data.get()); |
201 } | 200 } |
202 // Update the pointer to the buffer as it could change after | 201 // Update the pointer to the buffer as it could change after |
203 // m_frameBufferCache.resize(). | 202 // m_frameBufferCache.resize(). |
204 m_bmpReaders[index]->setBuffer(&m_frameBufferCache[index]); | 203 m_bmpReaders[index]->setBuffer(&m_frameBufferCache[index]); |
205 m_frameSize = dirEntry.m_size; | 204 m_frameSize = dirEntry.m_size; |
206 bool result = m_bmpReaders[index]->decodeBMP(false); | 205 bool result = m_bmpReaders[index]->decodeBMP(false); |
207 m_frameSize = IntSize(); | 206 m_frameSize = IntSize(); |
208 return result; | 207 return result; |
209 } | 208 } |
210 | 209 |
211 if (!m_pngDecoders[index]) { | 210 if (!m_pngDecoders[index]) { |
212 AlphaOption alphaOption = m_premultiplyAlpha ? AlphaPremultiplied : Alph
aNotPremultiplied; | 211 AlphaOption alphaOption = m_premultiplyAlpha ? AlphaPremultiplied : Alph
aNotPremultiplied; |
213 GammaAndColorProfileOption colorOptions = m_ignoreGammaAndColorProfile ?
GammaAndColorProfileIgnored : GammaAndColorProfileApplied; | 212 GammaAndColorProfileOption colorOptions = m_ignoreGammaAndColorProfile ?
GammaAndColorProfileIgnored : GammaAndColorProfileApplied; |
214 m_pngDecoders[index] = adoptPtr(new PNGImageDecoder(alphaOption, colorOp
tions, m_maxDecodedBytes, dirEntry.m_imageOffset)); | 213 m_pngDecoders[index] = wrapUnique(new PNGImageDecoder(alphaOption, color
Options, m_maxDecodedBytes, dirEntry.m_imageOffset)); |
215 setDataForPNGDecoderAtIndex(index); | 214 setDataForPNGDecoderAtIndex(index); |
216 } | 215 } |
217 // Fail if the size the PNGImageDecoder calculated does not match the size | 216 // Fail if the size the PNGImageDecoder calculated does not match the size |
218 // in the directory. | 217 // in the directory. |
219 if (m_pngDecoders[index]->isSizeAvailable() && (m_pngDecoders[index]->size()
!= dirEntry.m_size)) | 218 if (m_pngDecoders[index]->isSizeAvailable() && (m_pngDecoders[index]->size()
!= dirEntry.m_size)) |
220 return setFailed(); | 219 return setFailed(); |
221 m_frameBufferCache[index] = *m_pngDecoders[index]->frameBufferAtIndex(0); | 220 m_frameBufferCache[index] = *m_pngDecoders[index]->frameBufferAtIndex(0); |
222 m_frameBufferCache[index].setPremultiplyAlpha(m_premultiplyAlpha); | 221 m_frameBufferCache[index].setPremultiplyAlpha(m_premultiplyAlpha); |
223 return !m_pngDecoders[index]->failed() || setFailed(); | 222 return !m_pngDecoders[index]->failed() || setFailed(); |
224 } | 223 } |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 ASSERT_WITH_SECURITY_IMPLICATION(index < m_dirEntries.size()); | 325 ASSERT_WITH_SECURITY_IMPLICATION(index < m_dirEntries.size()); |
327 const uint32_t imageOffset = m_dirEntries[index].m_imageOffset; | 326 const uint32_t imageOffset = m_dirEntries[index].m_imageOffset; |
328 if ((imageOffset > m_data->size()) || ((m_data->size() - imageOffset) < 4)) | 327 if ((imageOffset > m_data->size()) || ((m_data->size() - imageOffset) < 4)) |
329 return Unknown; | 328 return Unknown; |
330 char buffer[4]; | 329 char buffer[4]; |
331 const char* data = m_fastReader.getConsecutiveData(imageOffset, 4, buffer); | 330 const char* data = m_fastReader.getConsecutiveData(imageOffset, 4, buffer); |
332 return strncmp(data, "\x89PNG", 4) ? BMP : PNG; | 331 return strncmp(data, "\x89PNG", 4) ? BMP : PNG; |
333 } | 332 } |
334 | 333 |
335 } // namespace blink | 334 } // namespace blink |
OLD | NEW |