| 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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 | 188 |
| 189 bool ICOImageDecoder::decodeAtIndex(size_t index) { | 189 bool ICOImageDecoder::decodeAtIndex(size_t index) { |
| 190 SECURITY_DCHECK(index < m_dirEntries.size()); | 190 SECURITY_DCHECK(index < m_dirEntries.size()); |
| 191 const IconDirectoryEntry& dirEntry = m_dirEntries[index]; | 191 const IconDirectoryEntry& dirEntry = m_dirEntries[index]; |
| 192 const ImageType imageType = imageTypeAtIndex(index); | 192 const ImageType imageType = imageTypeAtIndex(index); |
| 193 if (imageType == Unknown) | 193 if (imageType == Unknown) |
| 194 return false; // Not enough data to determine image type yet. | 194 return false; // Not enough data to determine image type yet. |
| 195 | 195 |
| 196 if (imageType == BMP) { | 196 if (imageType == BMP) { |
| 197 if (!m_bmpReaders[index]) { | 197 if (!m_bmpReaders[index]) { |
| 198 m_bmpReaders[index] = | 198 m_bmpReaders[index] = WTF::wrapUnique( |
| 199 wrapUnique(new BMPImageReader(this, dirEntry.m_imageOffset, 0, true)); | 199 new BMPImageReader(this, dirEntry.m_imageOffset, 0, true)); |
| 200 m_bmpReaders[index]->setData(m_data.get()); | 200 m_bmpReaders[index]->setData(m_data.get()); |
| 201 } | 201 } |
| 202 // Update the pointer to the buffer as it could change after | 202 // Update the pointer to the buffer as it could change after |
| 203 // m_frameBufferCache.resize(). | 203 // m_frameBufferCache.resize(). |
| 204 m_bmpReaders[index]->setBuffer(&m_frameBufferCache[index]); | 204 m_bmpReaders[index]->setBuffer(&m_frameBufferCache[index]); |
| 205 m_frameSize = dirEntry.m_size; | 205 m_frameSize = dirEntry.m_size; |
| 206 bool result = m_bmpReaders[index]->decodeBMP(false); | 206 bool result = m_bmpReaders[index]->decodeBMP(false); |
| 207 m_frameSize = IntSize(); | 207 m_frameSize = IntSize(); |
| 208 return result; | 208 return result; |
| 209 } | 209 } |
| 210 | 210 |
| 211 if (!m_pngDecoders[index]) { | 211 if (!m_pngDecoders[index]) { |
| 212 AlphaOption alphaOption = | 212 AlphaOption alphaOption = |
| 213 m_premultiplyAlpha ? AlphaPremultiplied : AlphaNotPremultiplied; | 213 m_premultiplyAlpha ? AlphaPremultiplied : AlphaNotPremultiplied; |
| 214 m_pngDecoders[index] = wrapUnique( | 214 m_pngDecoders[index] = WTF::wrapUnique( |
| 215 new PNGImageDecoder(alphaOption, m_colorBehavior, m_maxDecodedBytes, | 215 new PNGImageDecoder(alphaOption, m_colorBehavior, m_maxDecodedBytes, |
| 216 dirEntry.m_imageOffset)); | 216 dirEntry.m_imageOffset)); |
| 217 setDataForPNGDecoderAtIndex(index); | 217 setDataForPNGDecoderAtIndex(index); |
| 218 } | 218 } |
| 219 // Fail if the size the PNGImageDecoder calculated does not match the size | 219 // Fail if the size the PNGImageDecoder calculated does not match the size |
| 220 // in the directory. | 220 // in the directory. |
| 221 if (m_pngDecoders[index]->isSizeAvailable() && | 221 if (m_pngDecoders[index]->isSizeAvailable() && |
| 222 (m_pngDecoders[index]->size() != dirEntry.m_size)) | 222 (m_pngDecoders[index]->size() != dirEntry.m_size)) |
| 223 return setFailed(); | 223 return setFailed(); |
| 224 m_frameBufferCache[index] = *m_pngDecoders[index]->frameBufferAtIndex(0); | 224 m_frameBufferCache[index] = *m_pngDecoders[index]->frameBufferAtIndex(0); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 SECURITY_DCHECK(index < m_dirEntries.size()); | 325 SECURITY_DCHECK(index < m_dirEntries.size()); |
| 326 const uint32_t imageOffset = m_dirEntries[index].m_imageOffset; | 326 const uint32_t imageOffset = m_dirEntries[index].m_imageOffset; |
| 327 if ((imageOffset > m_data->size()) || ((m_data->size() - imageOffset) < 4)) | 327 if ((imageOffset > m_data->size()) || ((m_data->size() - imageOffset) < 4)) |
| 328 return Unknown; | 328 return Unknown; |
| 329 char buffer[4]; | 329 char buffer[4]; |
| 330 const char* data = m_fastReader.getConsecutiveData(imageOffset, 4, buffer); | 330 const char* data = m_fastReader.getConsecutiveData(imageOffset, 4, buffer); |
| 331 return strncmp(data, "\x89PNG", 4) ? BMP : PNG; | 331 return strncmp(data, "\x89PNG", 4) ? BMP : PNG; |
| 332 } | 332 } |
| 333 | 333 |
| 334 } // namespace blink | 334 } // namespace blink |
| OLD | NEW |