Chromium Code Reviews| 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 // The size calculated inside the BMPImageReader had better match the one in | 95 // The size calculated inside the BMPImageReader had better match the one in |
| 96 // the icon directory. | 96 // the icon directory. |
| 97 return m_frameSize.isEmpty() ? ImageDecoder::setSize(width, height) : ((IntS ize(width, height) == m_frameSize) || setFailed()); | 97 return m_frameSize.isEmpty() ? ImageDecoder::setSize(width, height) : ((IntS ize(width, height) == m_frameSize) || setFailed()); |
| 98 } | 98 } |
| 99 | 99 |
| 100 size_t ICOImageDecoder::frameCount() | 100 size_t ICOImageDecoder::frameCount() |
| 101 { | 101 { |
| 102 decode(0, true); | 102 decode(0, true); |
| 103 if (m_frameBufferCache.isEmpty()) { | 103 if (m_frameBufferCache.isEmpty()) { |
| 104 m_frameBufferCache.resize(m_dirEntries.size()); | 104 m_frameBufferCache.resize(m_dirEntries.size()); |
| 105 for (size_t i = 0; i < m_dirEntries.size(); ++i) | 105 for (size_t i = 0; i < m_dirEntries.size(); ++i) { |
| 106 m_frameBufferCache[i].setPremultiplyAlpha(m_premultiplyAlpha); | 106 m_frameBufferCache[i].setPremultiplyAlpha(m_premultiplyAlpha); |
| 107 m_frameBufferCache[i].setRequiredPreviousFrameIndex(notFound); | |
| 108 } | |
| 107 } | 109 } |
| 108 // CAUTION: We must not resize m_frameBufferCache again after this, as | 110 // CAUTION: We must not resize m_frameBufferCache again after this, as |
| 109 // decodeAtIndex() may give a BMPImageReader a pointer to one of the | 111 // decodeAtIndex() may give a BMPImageReader a pointer to one of the |
| 110 // entries. | 112 // entries. |
| 111 return m_frameBufferCache.size(); | 113 return m_frameBufferCache.size(); |
| 112 } | 114 } |
| 113 | 115 |
| 114 ImageFrame* ICOImageDecoder::frameBufferAtIndex(size_t index) | 116 ImageFrame* ICOImageDecoder::frameBufferAtIndex(size_t index) |
| 115 { | 117 { |
| 116 // Ensure |index| is valid. | 118 // Ensure |index| is valid. |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 228 m_pngDecoders[index] = adoptPtr( | 230 m_pngDecoders[index] = adoptPtr( |
| 229 new PNGImageDecoder(m_premultiplyAlpha ? ImageSource::AlphaPremultip lied : ImageSource::AlphaNotPremultiplied, | 231 new PNGImageDecoder(m_premultiplyAlpha ? ImageSource::AlphaPremultip lied : ImageSource::AlphaNotPremultiplied, |
| 230 m_ignoreGammaAndColorProfile ? ImageSource::Gamm aAndColorProfileIgnored : ImageSource::GammaAndColorProfileApplied)); | 232 m_ignoreGammaAndColorProfile ? ImageSource::Gamm aAndColorProfileIgnored : ImageSource::GammaAndColorProfileApplied)); |
| 231 setDataForPNGDecoderAtIndex(index); | 233 setDataForPNGDecoderAtIndex(index); |
| 232 } | 234 } |
| 233 // Fail if the size the PNGImageDecoder calculated does not match the size | 235 // Fail if the size the PNGImageDecoder calculated does not match the size |
| 234 // in the directory. | 236 // in the directory. |
| 235 if (m_pngDecoders[index]->isSizeAvailable() && (m_pngDecoders[index]->size() != dirEntry.m_size)) | 237 if (m_pngDecoders[index]->isSizeAvailable() && (m_pngDecoders[index]->size() != dirEntry.m_size)) |
| 236 return setFailed(); | 238 return setFailed(); |
| 237 m_frameBufferCache[index] = *m_pngDecoders[index]->frameBufferAtIndex(0); | 239 m_frameBufferCache[index] = *m_pngDecoders[index]->frameBufferAtIndex(0); |
| 240 m_frameBufferCache[index].setRequiredPreviousFrameIndex(notFound); | |
|
Peter Kasting
2013/06/03 18:39:10
Do you need to call setPremultiplyAlpha here as in
Xianzhu
2013/06/03 18:44:44
Yes, we need it. Done.
| |
| 238 return !m_pngDecoders[index]->failed() || setFailed(); | 241 return !m_pngDecoders[index]->failed() || setFailed(); |
| 239 } | 242 } |
| 240 | 243 |
| 241 bool ICOImageDecoder::processDirectory() | 244 bool ICOImageDecoder::processDirectory() |
| 242 { | 245 { |
| 243 // Read directory. | 246 // Read directory. |
| 244 ASSERT(!m_decodedOffset); | 247 ASSERT(!m_decodedOffset); |
| 245 if (m_data->size() < sizeOfDirectory) | 248 if (m_data->size() < sizeOfDirectory) |
| 246 return false; | 249 return false; |
| 247 const uint16_t fileType = readUint16(2); | 250 const uint16_t fileType = readUint16(2); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 333 // Check if this entry is a BMP or a PNG; we need 4 bytes to check the magic | 336 // Check if this entry is a BMP or a PNG; we need 4 bytes to check the magic |
| 334 // number. | 337 // number. |
| 335 ASSERT_WITH_SECURITY_IMPLICATION(index < m_dirEntries.size()); | 338 ASSERT_WITH_SECURITY_IMPLICATION(index < m_dirEntries.size()); |
| 336 const uint32_t imageOffset = m_dirEntries[index].m_imageOffset; | 339 const uint32_t imageOffset = m_dirEntries[index].m_imageOffset; |
| 337 if ((imageOffset > m_data->size()) || ((m_data->size() - imageOffset) < 4)) | 340 if ((imageOffset > m_data->size()) || ((m_data->size() - imageOffset) < 4)) |
| 338 return Unknown; | 341 return Unknown; |
| 339 return strncmp(&m_data->data()[imageOffset], "\x89PNG", 4) ? BMP : PNG; | 342 return strncmp(&m_data->data()[imageOffset], "\x89PNG", 4) ? BMP : PNG; |
| 340 } | 343 } |
| 341 | 344 |
| 342 } | 345 } |
| OLD | NEW |