| 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 SkASSERT(minIndex >= 0); | 228 SkASSERT(minIndex >= 0); |
| 229 | 229 |
| 230 return fEmbeddedCodecs->operator[](minIndex)->getInfo().dimensions(); | 230 return fEmbeddedCodecs->operator[](minIndex)->getInfo().dimensions(); |
| 231 } | 231 } |
| 232 | 232 |
| 233 /* | 233 /* |
| 234 * Initiates the Ico decode | 234 * Initiates the Ico decode |
| 235 */ | 235 */ |
| 236 SkCodec::Result SkIcoCodec::onGetPixels(const SkImageInfo& dstInfo, | 236 SkCodec::Result SkIcoCodec::onGetPixels(const SkImageInfo& dstInfo, |
| 237 void* dst, size_t dstRowBytes, | 237 void* dst, size_t dstRowBytes, |
| 238 const Options& opts, SkPMColor* ct, | 238 const Options& opts, SkPMColor* colorTab
le, |
| 239 int* ptr) { | 239 int* colorCount, int* rowsDecoded) { |
| 240 if (opts.fSubset) { | 240 if (opts.fSubset) { |
| 241 // Subsets are not supported. | 241 // Subsets are not supported. |
| 242 return kUnimplemented; | 242 return kUnimplemented; |
| 243 } | 243 } |
| 244 | 244 |
| 245 if (!valid_alpha(dstInfo.alphaType(), this->getInfo().alphaType())) { | 245 if (!valid_alpha(dstInfo.alphaType(), this->getInfo().alphaType())) { |
| 246 return kInvalidConversion; | 246 return kInvalidConversion; |
| 247 } | 247 } |
| 248 | 248 |
| 249 // We return invalid scale if there is no candidate image with matching | 249 // We return invalid scale if there is no candidate image with matching |
| (...skipping 15 matching lines...) Expand all Loading... |
| 265 embeddedAlpha = dstInfo.alphaType(); | 265 embeddedAlpha = dstInfo.alphaType(); |
| 266 break; | 266 break; |
| 267 case kOpaque_SkAlphaType: | 267 case kOpaque_SkAlphaType: |
| 268 // If the embedded codec claims it is opaque, decode as if i
t is opaque. | 268 // If the embedded codec claims it is opaque, decode as if i
t is opaque. |
| 269 break; | 269 break; |
| 270 default: | 270 default: |
| 271 SkASSERT(false); | 271 SkASSERT(false); |
| 272 break; | 272 break; |
| 273 } | 273 } |
| 274 SkImageInfo info = dstInfo.makeAlphaType(embeddedAlpha); | 274 SkImageInfo info = dstInfo.makeAlphaType(embeddedAlpha); |
| 275 result = embeddedCodec->getPixels(info, dst, dstRowBytes, &opts, ct,
ptr); | 275 result = embeddedCodec->getPixels(info, dst, dstRowBytes, &opts, col
orTable, |
| 276 colorCount); |
| 277 // The embedded codec will handle filling incomplete images, so we w
ill indicate |
| 278 // that all of the rows are initialized. |
| 279 *rowsDecoded = info.height(); |
| 276 | 280 |
| 277 // On a fatal error, keep trying to find an image to decode | 281 // On a fatal error, keep trying to find an image to decode |
| 278 if (kInvalidConversion == result || kInvalidInput == result || | 282 if (kInvalidConversion == result || kInvalidInput == result || |
| 279 kInvalidScale == result) { | 283 kInvalidScale == result) { |
| 280 SkCodecPrintf("Warning: Attempt to decode candidate ico failed.\
n"); | 284 SkCodecPrintf("Warning: Attempt to decode candidate ico failed.\
n"); |
| 281 continue; | 285 continue; |
| 282 } | 286 } |
| 283 | 287 |
| 284 // On success or partial success, return the result | 288 // On success or partial success, return the result |
| 285 return result; | 289 return result; |
| 286 } | 290 } |
| 287 } | 291 } |
| 288 | 292 |
| 289 SkCodecPrintf("Error: No matching candidate image in ico.\n"); | 293 SkCodecPrintf("Error: No matching candidate image in ico.\n"); |
| 290 return result; | 294 return result; |
| 291 } | 295 } |
| OLD | NEW |