Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(360)

Side by Side Diff: src/codec/SkCodec.cpp

Issue 1365313002: Merge SkCodec with SkScanlineDecoder (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Skip ICO in SkScaledCodec for now Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/codec/SkBmpStandardCodec.cpp ('k') | src/codec/SkCodec_libgif.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // startScanlineDecode 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
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::startScanlineDecode(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->onStartScanlineDecode(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::startScanlineDecode(const SkImageInfo& dstInfo) {
193 return this->startScanlineDecode(dstInfo, nullptr, nullptr, nullptr);
194 }
195
196 SkCodec::Result SkCodec::getScanlines(void* dst, int countLines, size_t rowBytes ) {
197 if (fCurrScanline < 0) {
198 return kScanlineDecodingNotStarted;
199 }
200
201 SkASSERT(!fDstInfo.isEmpty());
202 if ((rowBytes < fDstInfo.minRowBytes() && countLines > 1 ) || countLines <= 0
203 || fCurrScanline + countLines > fDstInfo.height()) {
204 return kInvalidParameters;
205 }
206
207 const Result result = this->onGetScanlines(dst, countLines, rowBytes);
208 fCurrScanline += countLines;
209 return result;
210 }
211
212 SkCodec::Result SkCodec::skipScanlines(int countLines) {
213 if (fCurrScanline < 0) {
214 return kScanlineDecodingNotStarted;
215 }
216
217 SkASSERT(!fDstInfo.isEmpty());
218 if (fCurrScanline + countLines > fDstInfo.height()) {
219 // Arguably, we could just skip the scanlines which are remaining,
220 // and return kSuccess. We choose to return invalid so the client
221 // can catch their bug.
222 return SkCodec::kInvalidParameters;
223 }
224
225 const Result result = this->onSkipScanlines(countLines);
226 fCurrScanline += countLines;
227 return result;
228 }
OLDNEW
« no previous file with comments | « src/codec/SkBmpStandardCodec.cpp ('k') | src/codec/SkCodec_libgif.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698