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 27 matching lines...) Expand all Loading... |
38 | 38 |
39 namespace blink { | 39 namespace blink { |
40 | 40 |
41 // 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, |
42 // 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 |
43 // some fields). | 43 // some fields). |
44 static const size_t sizeOfDirectory = 6; | 44 static const size_t sizeOfDirectory = 6; |
45 static const size_t sizeOfDirEntry = 16; | 45 static const size_t sizeOfDirEntry = 16; |
46 | 46 |
47 ICOImageDecoder::ICOImageDecoder(AlphaOption alphaOption, | 47 ICOImageDecoder::ICOImageDecoder(AlphaOption alphaOption, |
48 GammaAndColorProfileOption colorOptions, | 48 ColorSpaceOption colorOptions, |
49 size_t maxDecodedBytes) | 49 size_t maxDecodedBytes) |
50 : ImageDecoder(alphaOption, colorOptions, maxDecodedBytes), | 50 : ImageDecoder(alphaOption, colorOptions, maxDecodedBytes), |
51 m_fastReader(nullptr), | 51 m_fastReader(nullptr), |
52 m_decodedOffset(0), | 52 m_decodedOffset(0), |
53 m_dirEntriesCount(0), | 53 m_dirEntriesCount(0), |
54 m_gammaAndColorProfileOption(colorOptions) {} | 54 m_colorSpaceOption(colorOptions) {} |
55 | 55 |
56 ICOImageDecoder::~ICOImageDecoder() {} | 56 ICOImageDecoder::~ICOImageDecoder() {} |
57 | 57 |
58 void ICOImageDecoder::onSetData(SegmentReader* data) { | 58 void ICOImageDecoder::onSetData(SegmentReader* data) { |
59 m_fastReader.setData(data); | 59 m_fastReader.setData(data); |
60 | 60 |
61 for (BMPReaders::iterator i(m_bmpReaders.begin()); i != m_bmpReaders.end(); | 61 for (BMPReaders::iterator i(m_bmpReaders.begin()); i != m_bmpReaders.end(); |
62 ++i) { | 62 ++i) { |
63 if (*i) | 63 if (*i) |
64 (*i)->setData(data); | 64 (*i)->setData(data); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 m_frameSize = dirEntry.m_size; | 207 m_frameSize = dirEntry.m_size; |
208 bool result = m_bmpReaders[index]->decodeBMP(false); | 208 bool result = m_bmpReaders[index]->decodeBMP(false); |
209 m_frameSize = IntSize(); | 209 m_frameSize = IntSize(); |
210 return result; | 210 return result; |
211 } | 211 } |
212 | 212 |
213 if (!m_pngDecoders[index]) { | 213 if (!m_pngDecoders[index]) { |
214 AlphaOption alphaOption = | 214 AlphaOption alphaOption = |
215 m_premultiplyAlpha ? AlphaPremultiplied : AlphaNotPremultiplied; | 215 m_premultiplyAlpha ? AlphaPremultiplied : AlphaNotPremultiplied; |
216 m_pngDecoders[index] = wrapUnique( | 216 m_pngDecoders[index] = wrapUnique( |
217 new PNGImageDecoder(alphaOption, m_gammaAndColorProfileOption, | 217 new PNGImageDecoder(alphaOption, m_colorSpaceOption, m_maxDecodedBytes, |
218 m_maxDecodedBytes, dirEntry.m_imageOffset)); | 218 dirEntry.m_imageOffset)); |
219 setDataForPNGDecoderAtIndex(index); | 219 setDataForPNGDecoderAtIndex(index); |
220 } | 220 } |
221 // Fail if the size the PNGImageDecoder calculated does not match the size | 221 // Fail if the size the PNGImageDecoder calculated does not match the size |
222 // in the directory. | 222 // in the directory. |
223 if (m_pngDecoders[index]->isSizeAvailable() && | 223 if (m_pngDecoders[index]->isSizeAvailable() && |
224 (m_pngDecoders[index]->size() != dirEntry.m_size)) | 224 (m_pngDecoders[index]->size() != dirEntry.m_size)) |
225 return setFailed(); | 225 return setFailed(); |
226 m_frameBufferCache[index] = *m_pngDecoders[index]->frameBufferAtIndex(0); | 226 m_frameBufferCache[index] = *m_pngDecoders[index]->frameBufferAtIndex(0); |
227 m_frameBufferCache[index].setPremultiplyAlpha(m_premultiplyAlpha); | 227 m_frameBufferCache[index].setPremultiplyAlpha(m_premultiplyAlpha); |
228 return !m_pngDecoders[index]->failed() || setFailed(); | 228 return !m_pngDecoders[index]->failed() || setFailed(); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 ASSERT_WITH_SECURITY_IMPLICATION(index < m_dirEntries.size()); | 333 ASSERT_WITH_SECURITY_IMPLICATION(index < m_dirEntries.size()); |
334 const uint32_t imageOffset = m_dirEntries[index].m_imageOffset; | 334 const uint32_t imageOffset = m_dirEntries[index].m_imageOffset; |
335 if ((imageOffset > m_data->size()) || ((m_data->size() - imageOffset) < 4)) | 335 if ((imageOffset > m_data->size()) || ((m_data->size() - imageOffset) < 4)) |
336 return Unknown; | 336 return Unknown; |
337 char buffer[4]; | 337 char buffer[4]; |
338 const char* data = m_fastReader.getConsecutiveData(imageOffset, 4, buffer); | 338 const char* data = m_fastReader.getConsecutiveData(imageOffset, 4, buffer); |
339 return strncmp(data, "\x89PNG", 4) ? BMP : PNG; | 339 return strncmp(data, "\x89PNG", 4) ? BMP : PNG; |
340 } | 340 } |
341 | 341 |
342 } // namespace blink | 342 } // namespace blink |
OLD | NEW |