Chromium Code Reviews| 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"); |
| 127 break; | 127 break; |
| 128 } | 128 } |
| 129 bytesRead = offset; | 129 bytesRead = offset; |
| 130 | 130 |
| 131 // Create a new stream for the embedded codec | 131 // Create a new stream for the embedded codec |
| 132 SkAutoTUnref<SkData> data( | 132 SkAutoTUnref<SkData> data( |
| 133 SkData::NewFromStream(inputStream.get(), size)); | 133 SkData::NewFromStream(inputStream.get(), size)); |
| 134 if (nullptr == data.get()) { | 134 if (nullptr == data.get()) { |
| 135 SkCodecPrintf("Warning: could not create embedded stream.\n"); | 135 SkCodecPrintf("Warning: could not create embedded stream.\n"); |
| 136 // FIXME: This is a good solution if we have already created at | |
| 137 // least one valid codec. Otherwise, we may want to try to | |
| 138 // partially decode this incomplete embedded image. | |
|
scroggo
2015/10/01 14:48:31
Is there anything to partially decode if no embedd
msarett
2015/10/01 18:14:14
Good point, this comment makes no sense.
| |
| 136 break; | 139 break; |
| 137 } | 140 } |
| 138 SkAutoTDelete<SkMemoryStream> embeddedStream(new SkMemoryStream(data.get ())); | 141 SkAutoTDelete<SkMemoryStream> embeddedStream(new SkMemoryStream(data.get ())); |
| 139 bytesRead += size; | 142 bytesRead += size; |
| 140 | 143 |
| 141 // Check if the embedded codec is bmp or png and create the codec | 144 // Check if the embedded codec is bmp or png and create the codec |
| 142 const bool isPng = SkPngCodec::IsPng(embeddedStream); | 145 const bool isPng = SkPngCodec::IsPng(embeddedStream); |
| 143 SkAssertResult(embeddedStream->rewind()); | 146 SkAssertResult(embeddedStream->rewind()); |
| 144 SkCodec* codec = nullptr; | 147 SkCodec* codec = nullptr; |
| 145 if (isPng) { | 148 if (isPng) { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 228 SkASSERT(minIndex >= 0); | 231 SkASSERT(minIndex >= 0); |
| 229 | 232 |
| 230 return fEmbeddedCodecs->operator[](minIndex)->getInfo().dimensions(); | 233 return fEmbeddedCodecs->operator[](minIndex)->getInfo().dimensions(); |
| 231 } | 234 } |
| 232 | 235 |
| 233 /* | 236 /* |
| 234 * Initiates the Ico decode | 237 * Initiates the Ico decode |
| 235 */ | 238 */ |
| 236 SkCodec::Result SkIcoCodec::onGetPixels(const SkImageInfo& dstInfo, | 239 SkCodec::Result SkIcoCodec::onGetPixels(const SkImageInfo& dstInfo, |
| 237 void* dst, size_t dstRowBytes, | 240 void* dst, size_t dstRowBytes, |
| 238 const Options& opts, SkPMColor* ct, | 241 const Options& opts, SkPMColor* colorTab le, |
| 239 int* ptr) { | 242 int* colorCount, int* rowsDecoded) { |
| 240 if (opts.fSubset) { | 243 if (opts.fSubset) { |
| 241 // Subsets are not supported. | 244 // Subsets are not supported. |
| 242 return kUnimplemented; | 245 return kUnimplemented; |
| 243 } | 246 } |
| 244 | 247 |
| 245 if (!valid_alpha(dstInfo.alphaType(), this->getInfo().alphaType())) { | 248 if (!valid_alpha(dstInfo.alphaType(), this->getInfo().alphaType())) { |
| 246 return kInvalidConversion; | 249 return kInvalidConversion; |
| 247 } | 250 } |
| 248 | 251 |
| 249 // We return invalid scale if there is no candidate image with matching | 252 // We return invalid scale if there is no candidate image with matching |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 265 embeddedAlpha = dstInfo.alphaType(); | 268 embeddedAlpha = dstInfo.alphaType(); |
| 266 break; | 269 break; |
| 267 case kOpaque_SkAlphaType: | 270 case kOpaque_SkAlphaType: |
| 268 // If the embedded codec claims it is opaque, decode as if i t is opaque. | 271 // If the embedded codec claims it is opaque, decode as if i t is opaque. |
| 269 break; | 272 break; |
| 270 default: | 273 default: |
| 271 SkASSERT(false); | 274 SkASSERT(false); |
| 272 break; | 275 break; |
| 273 } | 276 } |
| 274 SkImageInfo info = dstInfo.makeAlphaType(embeddedAlpha); | 277 SkImageInfo info = dstInfo.makeAlphaType(embeddedAlpha); |
| 275 result = embeddedCodec->getPixels(info, dst, dstRowBytes, &opts, ct, ptr); | 278 result = embeddedCodec->getPixels(info, dst, dstRowBytes, &opts, col orTable, |
| 279 colorCount); | |
| 280 // The embedded codec will handle filling incomplete images, so we w ill indicate | |
| 281 // that all of the rows are initialized. | |
| 282 *rowsDecoded = info.height(); | |
|
msarett
2015/10/01 12:44:52
It's a bit strange when a call to getPixels() call
| |
| 276 | 283 |
| 277 // On a fatal error, keep trying to find an image to decode | 284 // On a fatal error, keep trying to find an image to decode |
| 278 if (kInvalidConversion == result || kInvalidInput == result || | 285 if (kInvalidConversion == result || kInvalidInput == result || |
| 279 kInvalidScale == result) { | 286 kInvalidScale == result) { |
| 280 SkCodecPrintf("Warning: Attempt to decode candidate ico failed.\ n"); | 287 SkCodecPrintf("Warning: Attempt to decode candidate ico failed.\ n"); |
| 281 continue; | 288 continue; |
| 282 } | 289 } |
| 283 | 290 |
| 284 // On success or partial success, return the result | 291 // On success or partial success, return the result |
| 285 return result; | 292 return result; |
| 286 } | 293 } |
| 287 } | 294 } |
| 288 | 295 |
| 289 SkCodecPrintf("Error: No matching candidate image in ico.\n"); | 296 SkCodecPrintf("Error: No matching candidate image in ico.\n"); |
| 290 return result; | 297 return result; |
| 291 } | 298 } |
| OLD | NEW |