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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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. |
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*) { |
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); |
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 |