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.h" | 9 #include "SkCodec.h" |
| 10 #include "SkData.h" | 10 #include "SkData.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 if (!data) { | 72 if (!data) { |
| 73 return nullptr; | 73 return nullptr; |
| 74 } | 74 } |
| 75 return NewFromStream(new SkMemoryStream(data)); | 75 return NewFromStream(new SkMemoryStream(data)); |
| 76 } | 76 } |
| 77 | 77 |
| 78 SkCodec::SkCodec(const SkImageInfo& info, SkStream* stream) | 78 SkCodec::SkCodec(const SkImageInfo& info, SkStream* stream) |
| 79 : fInfo(info) | 79 : fInfo(info) |
| 80 , fStream(stream) | 80 , fStream(stream) |
| 81 , fNeedsRewind(false) | 81 , fNeedsRewind(false) |
| 82 , fIncompleteScanlines(0) | |
| 82 {} | 83 {} |
| 83 | 84 |
| 84 SkCodec::~SkCodec() {} | 85 SkCodec::~SkCodec() {} |
| 85 | 86 |
| 86 bool SkCodec::rewindIfNeeded() { | 87 bool SkCodec::rewindIfNeeded() { |
| 87 // Store the value of fNeedsRewind so we can update it. Next read will | 88 // Store the value of fNeedsRewind so we can update it. Next read will |
| 88 // require a rewind. | 89 // require a rewind. |
| 89 const bool needsRewind = fNeedsRewind; | 90 const bool needsRewind = fNeedsRewind; |
| 90 fNeedsRewind = true; | 91 fNeedsRewind = true; |
| 91 if (!needsRewind) { | 92 if (!needsRewind) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 { | 131 { |
| 131 return kInvalidConversion; | 132 return kInvalidConversion; |
| 132 } | 133 } |
| 133 } | 134 } |
| 134 | 135 |
| 135 // Default options. | 136 // Default options. |
| 136 Options optsStorage; | 137 Options optsStorage; |
| 137 if (nullptr == options) { | 138 if (nullptr == options) { |
| 138 options = &optsStorage; | 139 options = &optsStorage; |
| 139 } | 140 } |
| 140 const Result result = this->onGetPixels(info, pixels, rowBytes, *options, ct able, ctableCount); | 141 |
| 142 // On an incomplete decode, the subclass can specify the number of scanlines that it failed | |
| 143 // to decode. | |
| 144 int incompleteScanlines = 0; | |
| 145 const Result result = this->onGetPixels(info, pixels, rowBytes, *options, ct able, ctableCount, | |
| 146 &incompleteScanlines); | |
| 141 | 147 |
| 142 if ((kIncompleteInput == result || kSuccess == result) && ctableCount) { | 148 if ((kIncompleteInput == result || kSuccess == result) && ctableCount) { |
| 143 SkASSERT(*ctableCount >= 0 && *ctableCount <= 256); | 149 SkASSERT(*ctableCount >= 0 && *ctableCount <= 256); |
| 144 } | 150 } |
| 151 | |
| 152 // A return value of kIncompleteInput indicates a truncated image stream. | |
| 153 // In this case, we will fill any uninitialized memory with a default value. | |
| 154 if (kIncompleteInput == result && 0 != incompleteScanlines) { | |
| 155 void* fillDst = this->getFillDst(pixels, rowBytes, info.height() - incom pleteScanlines); | |
|
scroggo
2015/09/25 15:55:05
My mistake, you end up doing another subtract. If
msarett
2015/10/01 12:44:52
Acknowledged.
| |
| 156 const SkImageInfo fillInfo = info.makeWH(info.width(), incompleteScanlin es); | |
| 157 const uint32_t fillValue = this->getFillValue(fillInfo); | |
| 158 SkSwizzler::Fill(fillDst, fillInfo, rowBytes, fillValue, options->fZeroI nitialized); | |
| 159 } | |
| 160 | |
| 145 return result; | 161 return result; |
| 146 } | 162 } |
| 147 | 163 |
| 148 SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes) { | 164 SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes) { |
| 149 return this->getPixels(info, pixels, rowBytes, nullptr, nullptr, nullptr); | 165 return this->getPixels(info, pixels, rowBytes, nullptr, nullptr, nullptr); |
| 150 } | 166 } |
| OLD | NEW |