OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkBmpCodec.h" | 8 #include "SkBmpCodec.h" |
9 #include "SkCodec_libico.h" | 9 #include "SkCodec_libico.h" |
10 #include "SkCodec_libpng.h" | 10 #include "SkCodec_libpng.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 SkTQSort(directoryEntries.get(), directoryEntries.get() + numImages - 1, | 106 SkTQSort(directoryEntries.get(), directoryEntries.get() + numImages - 1, |
107 lessThan); | 107 lessThan); |
108 | 108 |
109 // Now will construct a candidate codec for each of the embedded images | 109 // Now will construct a candidate codec for each of the embedded images |
110 uint32_t bytesRead = kIcoDirectoryBytes + numImages * kIcoDirEntryBytes; | 110 uint32_t bytesRead = kIcoDirectoryBytes + numImages * kIcoDirEntryBytes; |
111 SkAutoTDelete<SkTArray<SkAutoTDelete<SkCodec>, true>> codecs( | 111 SkAutoTDelete<SkTArray<SkAutoTDelete<SkCodec>, true>> codecs( |
112 new (SkTArray<SkAutoTDelete<SkCodec>, true>)(numImages)); | 112 new (SkTArray<SkAutoTDelete<SkCodec>, true>)(numImages)); |
113 for (uint32_t i = 0; i < numImages; i++) { | 113 for (uint32_t i = 0; i < numImages; i++) { |
114 uint32_t offset = directoryEntries.get()[i].offset; | 114 uint32_t offset = directoryEntries.get()[i].offset; |
115 uint32_t size = directoryEntries.get()[i].size; | 115 uint32_t size = directoryEntries.get()[i].size; |
116 | 116 |
117 // Ensure that the offset is valid | 117 // Ensure that the offset is valid |
118 if (offset < bytesRead) { | 118 if (offset < bytesRead) { |
119 SkCodecPrintf("Warning: invalid ico offset.\n"); | 119 SkCodecPrintf("Warning: invalid ico offset.\n"); |
120 continue; | 120 continue; |
121 } | 121 } |
122 | 122 |
123 // If we cannot skip, assume we have reached the end of the stream and | 123 // If we cannot skip, assume we have reached the end of the stream and |
124 // stop trying to make codecs | 124 // stop trying to make codecs |
125 if (inputStream.get()->skip(offset - bytesRead) != offset - bytesRead) { | 125 if (inputStream.get()->skip(offset - bytesRead) != offset - bytesRead) { |
126 SkCodecPrintf("Warning: could not skip to ico offset.\n"); | 126 SkCodecPrintf("Warning: could not skip to ico offset.\n"); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 } | 235 } |
236 | 236 |
237 return false; | 237 return false; |
238 } | 238 } |
239 | 239 |
240 /* | 240 /* |
241 * Initiates the Ico decode | 241 * Initiates the Ico decode |
242 */ | 242 */ |
243 SkCodec::Result SkIcoCodec::onGetPixels(const SkImageInfo& dstInfo, | 243 SkCodec::Result SkIcoCodec::onGetPixels(const SkImageInfo& dstInfo, |
244 void* dst, size_t dstRowBytes, | 244 void* dst, size_t dstRowBytes, |
245 const Options& opts, SkPMColor* ct, | 245 const Options& opts, SkPMColor* colorTab
le, |
246 int* ptr) { | 246 int* colorCount, int* rowsDecoded) { |
247 if (opts.fSubset) { | 247 if (opts.fSubset) { |
248 // Subsets are not supported. | 248 // Subsets are not supported. |
249 return kUnimplemented; | 249 return kUnimplemented; |
250 } | 250 } |
251 | 251 |
252 if (!valid_alpha(dstInfo.alphaType(), this->getInfo().alphaType())) { | 252 if (!valid_alpha(dstInfo.alphaType(), this->getInfo().alphaType())) { |
253 return kInvalidConversion; | 253 return kInvalidConversion; |
254 } | 254 } |
255 | 255 |
256 // We return invalid scale if there is no candidate image with matching | 256 // We return invalid scale if there is no candidate image with matching |
(...skipping 15 matching lines...) Expand all Loading... |
272 embeddedAlpha = dstInfo.alphaType(); | 272 embeddedAlpha = dstInfo.alphaType(); |
273 break; | 273 break; |
274 case kOpaque_SkAlphaType: | 274 case kOpaque_SkAlphaType: |
275 // If the embedded codec claims it is opaque, decode as if i
t is opaque. | 275 // If the embedded codec claims it is opaque, decode as if i
t is opaque. |
276 break; | 276 break; |
277 default: | 277 default: |
278 SkASSERT(false); | 278 SkASSERT(false); |
279 break; | 279 break; |
280 } | 280 } |
281 SkImageInfo info = dstInfo.makeAlphaType(embeddedAlpha); | 281 SkImageInfo info = dstInfo.makeAlphaType(embeddedAlpha); |
282 result = embeddedCodec->getPixels(info, dst, dstRowBytes, &opts, ct,
ptr); | 282 result = embeddedCodec->getPixels(info, dst, dstRowBytes, &opts, col
orTable, |
| 283 colorCount); |
| 284 // The embedded codec will handle filling incomplete images, so we w
ill indicate |
| 285 // that all of the rows are initialized. |
| 286 *rowsDecoded = info.height(); |
283 | 287 |
284 // On a fatal error, keep trying to find an image to decode | 288 // On a fatal error, keep trying to find an image to decode |
285 if (kInvalidConversion == result || kInvalidInput == result || | 289 if (kInvalidConversion == result || kInvalidInput == result || |
286 kInvalidScale == result) { | 290 kInvalidScale == result) { |
287 SkCodecPrintf("Warning: Attempt to decode candidate ico failed.\
n"); | 291 SkCodecPrintf("Warning: Attempt to decode candidate ico failed.\
n"); |
288 continue; | 292 continue; |
289 } | 293 } |
290 | 294 |
291 // On success or partial success, return the result | 295 // On success or partial success, return the result |
292 return result; | 296 return result; |
293 } | 297 } |
294 } | 298 } |
295 | 299 |
296 SkCodecPrintf("Error: No matching candidate image in ico.\n"); | 300 SkCodecPrintf("Error: No matching candidate image in ico.\n"); |
297 return result; | 301 return result; |
298 } | 302 } |
OLD | NEW |