Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Side by Side Diff: third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp

Issue 2173603003: Revert of Cancel image loads if decoding failed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/platform/image-decoders/ImageDecoder.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. 2 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 inline bool matchesCURSignature(const char* contents) 73 inline bool matchesCURSignature(const char* contents)
74 { 74 {
75 return !memcmp(contents, "\x00\x00\x02\x00", 4); 75 return !memcmp(contents, "\x00\x00\x02\x00", 4);
76 } 76 }
77 77
78 inline bool matchesBMPSignature(const char* contents) 78 inline bool matchesBMPSignature(const char* contents)
79 { 79 {
80 return !memcmp(contents, "BM", 2); 80 return !memcmp(contents, "BM", 2);
81 } 81 }
82 82
83 std::unique_ptr<ImageDecoder> ImageDecoder::create(SniffResult sniffResult, Alph aOption alphaOption, GammaAndColorProfileOption colorOptions) 83 std::unique_ptr<ImageDecoder> ImageDecoder::create(const char* contents, size_t length, AlphaOption alphaOption, GammaAndColorProfileOption colorOptions)
84 { 84 {
85 const size_t longestSignatureLength = sizeof("RIFF????WEBPVP") - 1;
86 ASSERT(longestSignatureLength == 14);
87
88 if (length < longestSignatureLength)
89 return nullptr;
90
85 size_t maxDecodedBytes = Platform::current() ? Platform::current()->maxDecod edImageBytes() : noDecodedImageByteLimit; 91 size_t maxDecodedBytes = Platform::current() ? Platform::current()->maxDecod edImageBytes() : noDecodedImageByteLimit;
86 92
87 switch (sniffResult) { 93 if (matchesJPEGSignature(contents))
88 case SniffResult::JPEG:
89 return wrapUnique(new JPEGImageDecoder(alphaOption, colorOptions, maxDec odedBytes)); 94 return wrapUnique(new JPEGImageDecoder(alphaOption, colorOptions, maxDec odedBytes));
90 case SniffResult::PNG: 95
96 if (matchesPNGSignature(contents))
91 return wrapUnique(new PNGImageDecoder(alphaOption, colorOptions, maxDeco dedBytes)); 97 return wrapUnique(new PNGImageDecoder(alphaOption, colorOptions, maxDeco dedBytes));
92 case SniffResult::GIF: 98
99 if (matchesGIFSignature(contents))
93 return wrapUnique(new GIFImageDecoder(alphaOption, colorOptions, maxDeco dedBytes)); 100 return wrapUnique(new GIFImageDecoder(alphaOption, colorOptions, maxDeco dedBytes));
94 case SniffResult::WEBP: 101
102 if (matchesWebPSignature(contents))
95 return wrapUnique(new WEBPImageDecoder(alphaOption, colorOptions, maxDec odedBytes)); 103 return wrapUnique(new WEBPImageDecoder(alphaOption, colorOptions, maxDec odedBytes));
96 case SniffResult::ICO: 104
105 if (matchesICOSignature(contents) || matchesCURSignature(contents))
97 return wrapUnique(new ICOImageDecoder(alphaOption, colorOptions, maxDeco dedBytes)); 106 return wrapUnique(new ICOImageDecoder(alphaOption, colorOptions, maxDeco dedBytes));
98 case SniffResult::BMP: 107
108 if (matchesBMPSignature(contents))
99 return wrapUnique(new BMPImageDecoder(alphaOption, colorOptions, maxDeco dedBytes)); 109 return wrapUnique(new BMPImageDecoder(alphaOption, colorOptions, maxDeco dedBytes));
100 case SniffResult::InsufficientData: 110
101 case SniffResult::Invalid:
102 return nullptr;
103 }
104 NOTREACHED();
105 return nullptr; 111 return nullptr;
106 } 112 }
107 113
108 ImageDecoder::SniffResult ImageDecoder::determineImageType(const char* contents, size_t length) 114 std::unique_ptr<ImageDecoder> ImageDecoder::create(const SharedBuffer& data, Alp haOption alphaOption, GammaAndColorProfileOption colorOptions)
109 {
110 const size_t longestSignatureLength = sizeof("RIFF????WEBPVP") - 1;
111 DCHECK_EQ(14u, longestSignatureLength);
112
113 if (length < longestSignatureLength)
114 return SniffResult::InsufficientData;
115 if (matchesJPEGSignature(contents))
116 return SniffResult::JPEG;
117 if (matchesPNGSignature(contents))
118 return SniffResult::PNG;
119 if (matchesGIFSignature(contents))
120 return SniffResult::GIF;
121 if (matchesWebPSignature(contents))
122 return SniffResult::WEBP;
123 if (matchesICOSignature(contents) || matchesCURSignature(contents))
124 return SniffResult::ICO;
125 if (matchesBMPSignature(contents))
126 return SniffResult::BMP;
127 return SniffResult::Invalid;
128 }
129
130 ImageDecoder::SniffResult ImageDecoder::determineImageType(const SharedBuffer& d ata)
131 { 115 {
132 const char* contents; 116 const char* contents;
133 const size_t length = data.getSomeData<size_t>(contents); 117 const size_t length = data.getSomeData<size_t>(contents);
134 return determineImageType(contents, length); 118 return create(contents, length, alphaOption, colorOptions);
135 } 119 }
136 120
137 ImageDecoder::SniffResult ImageDecoder::determineImageType(const SegmentReader& data) 121 std::unique_ptr<ImageDecoder> ImageDecoder::create(const SegmentReader& data, Al phaOption alphaOption, GammaAndColorProfileOption colorOptions)
138 { 122 {
139 const char* contents; 123 const char* contents;
140 const size_t length = data.getSomeData(contents, 0); 124 const size_t length = data.getSomeData(contents, 0);
141 return determineImageType(contents, length); 125 return create(contents, length, alphaOption, colorOptions);
142 } 126 }
143 127
144 size_t ImageDecoder::frameCount() 128 size_t ImageDecoder::frameCount()
145 { 129 {
146 const size_t oldSize = m_frameBufferCache.size(); 130 const size_t oldSize = m_frameBufferCache.size();
147 const size_t newSize = decodeFrameCount(); 131 const size_t newSize = decodeFrameCount();
148 if (oldSize != newSize) { 132 if (oldSize != newSize) {
149 m_frameBufferCache.resize(newSize); 133 m_frameBufferCache.resize(newSize);
150 for (size_t i = oldSize; i < newSize; ++i) { 134 for (size_t i = oldSize; i < newSize; ++i) {
151 m_frameBufferCache[i].setPremultiplyAlpha(m_premultiplyAlpha); 135 m_frameBufferCache[i].setPremultiplyAlpha(m_premultiplyAlpha);
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 } 383 }
400 384
401 bool ImageDecoder::hasColorProfile() const 385 bool ImageDecoder::hasColorProfile() const
402 { 386 {
403 return false; 387 return false;
404 } 388 }
405 389
406 #endif // USE(QCMSLIB) 390 #endif // USE(QCMSLIB)
407 391
408 } // namespace blink 392 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/image-decoders/ImageDecoder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698