| 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 28 matching lines...) Expand all Loading... |
| 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 ColorSpaceOption colorOptions, | 48 ColorSpaceOption colorOptions, |
| 49 sk_sp<SkColorSpace> targetColorSpace, |
| 49 size_t maxDecodedBytes) | 50 size_t maxDecodedBytes) |
| 50 : ImageDecoder(alphaOption, colorOptions, maxDecodedBytes), | 51 : ImageDecoder(alphaOption, |
| 52 colorOptions, |
| 53 std::move(targetColorSpace), |
| 54 maxDecodedBytes), |
| 51 m_fastReader(nullptr), | 55 m_fastReader(nullptr), |
| 52 m_decodedOffset(0), | 56 m_decodedOffset(0), |
| 53 m_dirEntriesCount(0), | 57 m_dirEntriesCount(0), |
| 54 m_colorSpaceOption(colorOptions) {} | 58 m_colorSpaceOption(colorOptions) {} |
| 55 | 59 |
| 56 ICOImageDecoder::~ICOImageDecoder() {} | 60 ICOImageDecoder::~ICOImageDecoder() {} |
| 57 | 61 |
| 58 void ICOImageDecoder::onSetData(SegmentReader* data) { | 62 void ICOImageDecoder::onSetData(SegmentReader* data) { |
| 59 m_fastReader.setData(data); | 63 m_fastReader.setData(data); |
| 60 | 64 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 m_frameSize = dirEntry.m_size; | 211 m_frameSize = dirEntry.m_size; |
| 208 bool result = m_bmpReaders[index]->decodeBMP(false); | 212 bool result = m_bmpReaders[index]->decodeBMP(false); |
| 209 m_frameSize = IntSize(); | 213 m_frameSize = IntSize(); |
| 210 return result; | 214 return result; |
| 211 } | 215 } |
| 212 | 216 |
| 213 if (!m_pngDecoders[index]) { | 217 if (!m_pngDecoders[index]) { |
| 214 AlphaOption alphaOption = | 218 AlphaOption alphaOption = |
| 215 m_premultiplyAlpha ? AlphaPremultiplied : AlphaNotPremultiplied; | 219 m_premultiplyAlpha ? AlphaPremultiplied : AlphaNotPremultiplied; |
| 216 m_pngDecoders[index] = wrapUnique( | 220 m_pngDecoders[index] = wrapUnique( |
| 217 new PNGImageDecoder(alphaOption, m_colorSpaceOption, m_maxDecodedBytes, | 221 new PNGImageDecoder(alphaOption, m_colorSpaceOption, m_targetColorSpace, |
| 218 dirEntry.m_imageOffset)); | 222 m_maxDecodedBytes, dirEntry.m_imageOffset)); |
| 219 setDataForPNGDecoderAtIndex(index); | 223 setDataForPNGDecoderAtIndex(index); |
| 220 } | 224 } |
| 221 // Fail if the size the PNGImageDecoder calculated does not match the size | 225 // Fail if the size the PNGImageDecoder calculated does not match the size |
| 222 // in the directory. | 226 // in the directory. |
| 223 if (m_pngDecoders[index]->isSizeAvailable() && | 227 if (m_pngDecoders[index]->isSizeAvailable() && |
| 224 (m_pngDecoders[index]->size() != dirEntry.m_size)) | 228 (m_pngDecoders[index]->size() != dirEntry.m_size)) |
| 225 return setFailed(); | 229 return setFailed(); |
| 226 m_frameBufferCache[index] = *m_pngDecoders[index]->frameBufferAtIndex(0); | 230 m_frameBufferCache[index] = *m_pngDecoders[index]->frameBufferAtIndex(0); |
| 227 m_frameBufferCache[index].setPremultiplyAlpha(m_premultiplyAlpha); | 231 m_frameBufferCache[index].setPremultiplyAlpha(m_premultiplyAlpha); |
| 228 return !m_pngDecoders[index]->failed() || setFailed(); | 232 return !m_pngDecoders[index]->failed() || setFailed(); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 SECURITY_DCHECK(index < m_dirEntries.size()); | 337 SECURITY_DCHECK(index < m_dirEntries.size()); |
| 334 const uint32_t imageOffset = m_dirEntries[index].m_imageOffset; | 338 const uint32_t imageOffset = m_dirEntries[index].m_imageOffset; |
| 335 if ((imageOffset > m_data->size()) || ((m_data->size() - imageOffset) < 4)) | 339 if ((imageOffset > m_data->size()) || ((m_data->size() - imageOffset) < 4)) |
| 336 return Unknown; | 340 return Unknown; |
| 337 char buffer[4]; | 341 char buffer[4]; |
| 338 const char* data = m_fastReader.getConsecutiveData(imageOffset, 4, buffer); | 342 const char* data = m_fastReader.getConsecutiveData(imageOffset, 4, buffer); |
| 339 return strncmp(data, "\x89PNG", 4) ? BMP : PNG; | 343 return strncmp(data, "\x89PNG", 4) ? BMP : PNG; |
| 340 } | 344 } |
| 341 | 345 |
| 342 } // namespace blink | 346 } // namespace blink |
| OLD | NEW |