| 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 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 namespace blink { | 37 namespace blink { |
| 38 | 38 |
| 39 // Number of bits in .ICO/.CUR used to store the directory and its entries, | 39 // Number of bits in .ICO/.CUR used to store the directory and its entries, |
| 40 // respectively (doesn't match sizeof values for member structs since we omit | 40 // respectively (doesn't match sizeof values for member structs since we omit |
| 41 // some fields). | 41 // some fields). |
| 42 static const size_t sizeOfDirectory = 6; | 42 static const size_t sizeOfDirectory = 6; |
| 43 static const size_t sizeOfDirEntry = 16; | 43 static const size_t sizeOfDirEntry = 16; |
| 44 | 44 |
| 45 ICOImageDecoder::ICOImageDecoder(AlphaOption alphaOption, | 45 ICOImageDecoder::ICOImageDecoder(AlphaOption alphaOption, |
| 46 ColorSpaceOption colorOptions, | 46 const ColorBehavior& colorBehavior, |
| 47 sk_sp<SkColorSpace> targetColorSpace, | |
| 48 size_t maxDecodedBytes) | 47 size_t maxDecodedBytes) |
| 49 : ImageDecoder(alphaOption, | 48 : ImageDecoder(alphaOption, colorBehavior, maxDecodedBytes), |
| 50 colorOptions, | |
| 51 std::move(targetColorSpace), | |
| 52 maxDecodedBytes), | |
| 53 m_fastReader(nullptr), | 49 m_fastReader(nullptr), |
| 54 m_decodedOffset(0), | 50 m_decodedOffset(0), |
| 55 m_dirEntriesCount(0), | 51 m_dirEntriesCount(0), |
| 56 m_colorSpaceOption(colorOptions) {} | 52 m_colorBehavior(colorBehavior) {} |
| 57 | 53 |
| 58 ICOImageDecoder::~ICOImageDecoder() {} | 54 ICOImageDecoder::~ICOImageDecoder() {} |
| 59 | 55 |
| 60 void ICOImageDecoder::onSetData(SegmentReader* data) { | 56 void ICOImageDecoder::onSetData(SegmentReader* data) { |
| 61 m_fastReader.setData(data); | 57 m_fastReader.setData(data); |
| 62 | 58 |
| 63 for (BMPReaders::iterator i(m_bmpReaders.begin()); i != m_bmpReaders.end(); | 59 for (BMPReaders::iterator i(m_bmpReaders.begin()); i != m_bmpReaders.end(); |
| 64 ++i) { | 60 ++i) { |
| 65 if (*i) | 61 if (*i) |
| 66 (*i)->setData(data); | 62 (*i)->setData(data); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 m_frameSize = dirEntry.m_size; | 205 m_frameSize = dirEntry.m_size; |
| 210 bool result = m_bmpReaders[index]->decodeBMP(false); | 206 bool result = m_bmpReaders[index]->decodeBMP(false); |
| 211 m_frameSize = IntSize(); | 207 m_frameSize = IntSize(); |
| 212 return result; | 208 return result; |
| 213 } | 209 } |
| 214 | 210 |
| 215 if (!m_pngDecoders[index]) { | 211 if (!m_pngDecoders[index]) { |
| 216 AlphaOption alphaOption = | 212 AlphaOption alphaOption = |
| 217 m_premultiplyAlpha ? AlphaPremultiplied : AlphaNotPremultiplied; | 213 m_premultiplyAlpha ? AlphaPremultiplied : AlphaNotPremultiplied; |
| 218 m_pngDecoders[index] = wrapUnique( | 214 m_pngDecoders[index] = wrapUnique( |
| 219 new PNGImageDecoder(alphaOption, m_colorSpaceOption, m_targetColorSpace, | 215 new PNGImageDecoder(alphaOption, m_colorBehavior, m_maxDecodedBytes, |
| 220 m_maxDecodedBytes, dirEntry.m_imageOffset)); | 216 dirEntry.m_imageOffset)); |
| 221 setDataForPNGDecoderAtIndex(index); | 217 setDataForPNGDecoderAtIndex(index); |
| 222 } | 218 } |
| 223 // 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 |
| 224 // in the directory. | 220 // in the directory. |
| 225 if (m_pngDecoders[index]->isSizeAvailable() && | 221 if (m_pngDecoders[index]->isSizeAvailable() && |
| 226 (m_pngDecoders[index]->size() != dirEntry.m_size)) | 222 (m_pngDecoders[index]->size() != dirEntry.m_size)) |
| 227 return setFailed(); | 223 return setFailed(); |
| 228 m_frameBufferCache[index] = *m_pngDecoders[index]->frameBufferAtIndex(0); | 224 m_frameBufferCache[index] = *m_pngDecoders[index]->frameBufferAtIndex(0); |
| 229 m_frameBufferCache[index].setPremultiplyAlpha(m_premultiplyAlpha); | 225 m_frameBufferCache[index].setPremultiplyAlpha(m_premultiplyAlpha); |
| 230 return !m_pngDecoders[index]->failed() || setFailed(); | 226 return !m_pngDecoders[index]->failed() || setFailed(); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 SECURITY_DCHECK(index < m_dirEntries.size()); | 325 SECURITY_DCHECK(index < m_dirEntries.size()); |
| 330 const uint32_t imageOffset = m_dirEntries[index].m_imageOffset; | 326 const uint32_t imageOffset = m_dirEntries[index].m_imageOffset; |
| 331 if ((imageOffset > m_data->size()) || ((m_data->size() - imageOffset) < 4)) | 327 if ((imageOffset > m_data->size()) || ((m_data->size() - imageOffset) < 4)) |
| 332 return Unknown; | 328 return Unknown; |
| 333 char buffer[4]; | 329 char buffer[4]; |
| 334 const char* data = m_fastReader.getConsecutiveData(imageOffset, 4, buffer); | 330 const char* data = m_fastReader.getConsecutiveData(imageOffset, 4, buffer); |
| 335 return strncmp(data, "\x89PNG", 4) ? BMP : PNG; | 331 return strncmp(data, "\x89PNG", 4) ? BMP : PNG; |
| 336 } | 332 } |
| 337 | 333 |
| 338 } // namespace blink | 334 } // namespace blink |
| OLD | NEW |