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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 } | 69 } |
70 | 70 |
71 SkCodec* SkCodec::NewFromData(SkData* data) { | 71 SkCodec* SkCodec::NewFromData(SkData* data) { |
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 : fSrcInfo(info) |
80 , fStream(stream) | 80 , fStream(stream) |
81 , fNeedsRewind(false) | 81 , fNeedsRewind(false) |
| 82 , fDstInfo() |
| 83 , fOptions() |
| 84 , fCurrScanline(-1) |
82 {} | 85 {} |
83 | 86 |
84 SkCodec::~SkCodec() {} | 87 SkCodec::~SkCodec() {} |
85 | 88 |
86 bool SkCodec::rewindIfNeeded() { | 89 bool SkCodec::rewindIfNeeded() { |
87 // Store the value of fNeedsRewind so we can update it. Next read will | 90 // Store the value of fNeedsRewind so we can update it. Next read will |
88 // require a rewind. | 91 // require a rewind. |
89 const bool needsRewind = fNeedsRewind; | 92 const bool needsRewind = fNeedsRewind; |
90 fNeedsRewind = true; | 93 fNeedsRewind = true; |
91 if (!needsRewind) { | 94 if (!needsRewind) { |
92 return true; | 95 return true; |
93 } | 96 } |
94 | 97 |
| 98 // start will need to be called before decoding scanlines. |
| 99 fCurrScanline = -1; |
| 100 |
95 if (!fStream->rewind()) { | 101 if (!fStream->rewind()) { |
96 return false; | 102 return false; |
97 } | 103 } |
98 | 104 |
99 return this->onRewind(); | 105 return this->onRewind(); |
100 } | 106 } |
101 | 107 |
102 SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t
rowBytes, | 108 SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t
rowBytes, |
103 const Options* options, SkPMColor ctable[], i
nt* ctableCount) { | 109 const Options* options, SkPMColor ctable[], i
nt* ctableCount) { |
104 if (kUnknown_SkColorType == info.colorType()) { | 110 if (kUnknown_SkColorType == info.colorType()) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 } |
145 return result; | 151 return result; |
146 } | 152 } |
147 | 153 |
148 SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t
rowBytes) { | 154 SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t
rowBytes) { |
149 return this->getPixels(info, pixels, rowBytes, nullptr, nullptr, nullptr); | 155 return this->getPixels(info, pixels, rowBytes, nullptr, nullptr, nullptr); |
150 } | 156 } |
| 157 |
| 158 SkCodec::Result SkCodec::start(const SkImageInfo& dstInfo, |
| 159 const SkCodec::Options* options, SkPMColor ctable[], int* ctableCount) { |
| 160 // Reset fCurrScanline in case of failure. |
| 161 fCurrScanline = -1; |
| 162 // Ensure that valid color ptrs are passed in for kIndex8 color type |
| 163 if (kIndex_8_SkColorType == dstInfo.colorType()) { |
| 164 if (nullptr == ctable || nullptr == ctableCount) { |
| 165 return SkCodec::kInvalidParameters; |
| 166 } |
| 167 } else { |
| 168 if (ctableCount) { |
| 169 *ctableCount = 0; |
| 170 } |
| 171 ctableCount = nullptr; |
| 172 ctable = nullptr; |
| 173 } |
| 174 |
| 175 // Set options. |
| 176 Options optsStorage; |
| 177 if (nullptr == options) { |
| 178 options = &optsStorage; |
| 179 } |
| 180 |
| 181 const Result result = this->onStart(dstInfo, *options, ctable, ctableCount); |
| 182 if (result != SkCodec::kSuccess) { |
| 183 return result; |
| 184 } |
| 185 |
| 186 fCurrScanline = 0; |
| 187 fDstInfo = dstInfo; |
| 188 fOptions = *options; |
| 189 return kSuccess; |
| 190 } |
| 191 |
| 192 SkCodec::Result SkCodec::start(const SkImageInfo& dstInfo) { |
| 193 return this->start(dstInfo, nullptr, nullptr, nullptr); |
| 194 } |
| 195 |
OLD | NEW |