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

Side by Side Diff: include/codec/SkScanlineDecoder.h

Issue 1332053002: Fill incomplete images in SkCodec parent class (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Response to comments Created 5 years, 3 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
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 #ifndef SkScanlineDecoder_DEFINED 8 #ifndef SkScanlineDecoder_DEFINED
9 #define SkScanlineDecoder_DEFINED 9 #define SkScanlineDecoder_DEFINED
10 10
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 /** 93 /**
94 * Write the next countLines scanlines into dst. 94 * Write the next countLines scanlines into dst.
95 * 95 *
96 * Not valid to call before calling start(). 96 * Not valid to call before calling start().
97 * 97 *
98 * @param dst Must be non-null, and large enough to hold countLines 98 * @param dst Must be non-null, and large enough to hold countLines
99 * scanlines of size rowBytes. 99 * scanlines of size rowBytes.
100 * @param countLines Number of lines to write. 100 * @param countLines Number of lines to write.
101 * @param rowBytes Number of bytes per row. Must be large enough to hold 101 * @param rowBytes Number of bytes per row. Must be large enough to hold
102 * a scanline based on the SkImageInfo used to create this object. 102 * a scanline based on the SkImageInfo used to create this object.
103 * @return the number of lines successfully decoded
103 */ 104 */
104 SkCodec::Result getScanlines(void* dst, int countLines, size_t rowBytes) { 105 uint32_t getScanlines(void* dst, int countLines, size_t rowBytes) {
105 SkASSERT(!fDstInfo.isEmpty()); 106 SkASSERT(!fDstInfo.isEmpty());
106 if ((rowBytes < fDstInfo.minRowBytes() && countLines > 1 ) || countLines <= 0 107 if ((rowBytes < fDstInfo.minRowBytes() && countLines > 1 ) || countLines <= 0
107 || fCurrScanline + countLines > fDstInfo.height()) { 108 || fCurrScanline + countLines > fDstInfo.height()) {
108 return SkCodec::kInvalidParameters; 109 return SkCodec::kInvalidParameters;
109 } 110 }
110 const SkCodec::Result result = this->onGetScanlines(dst, countLines, row Bytes); 111 uint32_t decodedLines = this->onGetScanlines(dst, countLines, rowBytes);
111 fCurrScanline += countLines; 112 fCurrScanline += decodedLines;
112 return result; 113 return decodedLines;
113 } 114 }
114 115
115 /** 116 /**
116 * Skip count scanlines. 117 * Skip count scanlines.
117 * 118 *
118 * Not valid to call before calling start(). 119 * Not valid to call before calling start().
119 * 120 *
120 * The default version just calls onGetScanlines and discards the dst. 121 * The default version just calls onGetScanlines and discards the dst.
121 * NOTE: If skipped lines are the only lines with alpha, this default 122 * NOTE: If skipped lines are the only lines with alpha, this default
122 * will make reallyHasAlpha return true, when it could have returned 123 * will make reallyHasAlpha return true, when it could have returned
123 * false. 124 * false.
125 *
126 * @return true if the scanlines were successfully skipped, false otherwise
scroggo 2015/09/25 15:55:05 I think we should further specify what this might
msarett 2015/10/01 12:44:52 I will add to the comment.
124 */ 127 */
125 SkCodec::Result skipScanlines(int countLines) { 128 bool skipScanlines(int countLines) {
126 SkASSERT(!fDstInfo.isEmpty()); 129 SkASSERT(!fDstInfo.isEmpty());
127 if (fCurrScanline + countLines > fDstInfo.height()) { 130 if (countLines <= 0 || fCurrScanline + countLines > fDstInfo.height()) {
128 // Arguably, we could just skip the scanlines which are remaining, 131 // Arguably, we could just skip the scanlines which are remaining,
129 // and return kSuccess. We choose to return invalid so the client 132 // and return kSuccess. We choose to return invalid so the client
130 // can catch their bug. 133 // can catch their bug.
131 return SkCodec::kInvalidParameters; 134 return SkCodec::kInvalidParameters;
scroggo 2015/09/25 15:55:05 This return a bool. Not sure what though.
msarett 2015/10/01 12:44:52 Making it return false.
132 } 135 }
133 const SkCodec::Result result = this->onSkipScanlines(countLines); 136 uint32_t skippedLines = this->onSkipScanlines(countLines);
scroggo 2015/09/25 15:55:05 As suggested in the first patch set, this should b
msarett 2015/10/01 12:44:52 Done.
134 fCurrScanline += countLines; 137 fCurrScanline += skippedLines;
135 return result; 138 return skippedLines == (uint32_t) countLines;
136 } 139 }
137 140
138 /** 141 /**
139 * Some images may initially report that they have alpha due to the format 142 * Some images may initially report that they have alpha due to the format
140 * of the encoded data, but then never use any colors which have alpha 143 * of the encoded data, but then never use any colors which have alpha
141 * less than 100%. This function can be called *after* decoding to 144 * less than 100%. This function can be called *after* decoding to
142 * determine if such an image truly had alpha. Calling it before decoding 145 * determine if such an image truly had alpha. Calling it before decoding
143 * is undefined. 146 * is undefined.
144 * FIXME: see skbug.com/3582. 147 * FIXME: see skbug.com/3582.
145 */ 148 */
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 kNone_SkScanlineOrder, 216 kNone_SkScanlineOrder,
214 }; 217 };
215 218
216 /** 219 /**
217 * An enum representing the order in which scanlines will be returned by 220 * An enum representing the order in which scanlines will be returned by
218 * the scanline decoder. 221 * the scanline decoder.
219 */ 222 */
220 SkScanlineOrder getScanlineOrder() const { return this->onGetScanlineOrder() ; } 223 SkScanlineOrder getScanlineOrder() const { return this->onGetScanlineOrder() ; }
221 224
222 /** 225 /**
223 * Returns the y-coordinate of the next row to be returned by the scanline 226 * Returns the y-coordinate of the next dst row to be returned by the scanl ine
224 * decoder. This will be overridden in the case of 227 * decoder.
225 * kOutOfOrder_SkScanlineOrder and should be unnecessary in the case of
226 * kNone_SkScanlineOrder.
227 */ 228 */
228 int getY() const { 229 int getY() const {
229 SkASSERT(kNone_SkScanlineOrder != this->getScanlineOrder()); 230 return this->getY(fCurrScanline);
230 return this->onGetY(); 231 }
232
233 /**
234 * Returns the y-coordinate of the dst row that corresponds to the
235 * src y-coordinate.
236 */
237 int getY(int srcY) const;
238
239 uint32_t getFillValue(const SkImageInfo& dstInfo) const {
240 return fCodec->getFillValue(dstInfo);
241 }
242
243 void* getFillDst(void* dstStart, size_t rowBytes, uint32_t decodedScanlines) const {
244 return fCodec->getFillDst(dstStart, rowBytes, decodedScanlines);
231 } 245 }
232 246
233 protected: 247 protected:
234 SkScanlineDecoder(const SkImageInfo& srcInfo) 248 SkScanlineDecoder(SkCodec* codec, const SkImageInfo& srcInfo)
235 : fSrcInfo(srcInfo) 249 : fCodec(codec)
250 , fSrcInfo(srcInfo)
236 , fDstInfo() 251 , fDstInfo()
237 , fOptions() 252 , fOptions()
238 , fCurrScanline(0) {} 253 , fCurrScanline(0) {}
239 254
240 virtual SkISize onGetScaledDimensions(float /* desiredScale */) { 255 virtual SkISize onGetScaledDimensions(float /* desiredScale */) {
241 // By default, scaling is not supported. 256 // By default, scaling is not supported.
242 return this->getInfo().dimensions(); 257 return this->getInfo().dimensions();
243 } 258 }
244 259
245 virtual SkEncodedFormat onGetEncodedFormat() const = 0; 260 virtual SkEncodedFormat onGetEncodedFormat() const = 0;
246 261
247 virtual bool onReallyHasAlpha() const { return false; } 262 virtual bool onReallyHasAlpha() const { return false; }
248 263
249 /** 264 /**
250 * Most images types will be kTopDown and will not need to override this fu nction. 265 * Most images types will be kTopDown and will not need to override this fu nction.
251 */ 266 */
252 virtual SkScanlineOrder onGetScanlineOrder() const { return kTopDown_SkScanl ineOrder; } 267 virtual SkScanlineOrder onGetScanlineOrder() const { return kTopDown_SkScanl ineOrder; }
253 268
254 /**
255 * Most images will be kTopDown and will not need to override this function .
256 */
257 virtual int onGetY() const { return fCurrScanline; }
258
259 const SkImageInfo& dstInfo() const { return fDstInfo; } 269 const SkImageInfo& dstInfo() const { return fDstInfo; }
260 270
261 const SkCodec::Options& options() const { return fOptions; } 271 const SkCodec::Options& options() const { return fOptions; }
262 272
263 private: 273 private:
264 const SkImageInfo fSrcInfo; 274 SkAutoTDelete<SkCodec> fCodec;
265 SkImageInfo fDstInfo; 275 const SkImageInfo fSrcInfo;
266 SkCodec::Options fOptions; 276 SkImageInfo fDstInfo;
267 int fCurrScanline; 277 SkCodec::Options fOptions;
278 int fCurrScanline;
268 279
269 virtual SkCodec::Result onStart(const SkImageInfo& dstInfo, 280 virtual SkCodec::Result onStart(const SkImageInfo& dstInfo,
270 const SkCodec::Options& options, 281 const SkCodec::Options& options,
271 SkPMColor ctable[], int* ctableCount) = 0; 282 SkPMColor ctable[], int* ctableCount) = 0;
272 283
273 // Naive default version just calls onGetScanlines on temp memory. 284 // Naive default version just calls onGetScanlines on temp memory.
274 virtual SkCodec::Result onSkipScanlines(int countLines) { 285 virtual uint32_t onSkipScanlines(int countLines) {
275 SkAutoMalloc storage(fDstInfo.minRowBytes()); 286 SkAutoMalloc storage(fDstInfo.minRowBytes());
276 // Note that we pass 0 to rowBytes so we continue to use the same memory . 287 // Note that we pass 0 to rowBytes so we continue to use the same memory .
277 // Also note that while getScanlines checks that rowBytes is big enough, 288 // Also note that while getScanlines checks that rowBytes is big enough,
278 // onGetScanlines bypasses that check. 289 // onGetScanlines bypasses that check.
279 // Calling the virtual method also means we do not double count 290 // Calling the virtual method also means we do not double count
280 // countLines. 291 // countLines.
281 return this->onGetScanlines(storage.get(), countLines, 0); 292 return this->onGetScanlines(storage.get(), countLines, 0);
282 } 293 }
283 294
284 virtual SkCodec::Result onGetScanlines(void* dst, int countLines, 295 virtual uint32_t onGetScanlines(void* dst, int countLines, size_t rowBytes) = 0;
285 size_t rowBytes) = 0;
286 296
287 }; 297 };
288 #endif // SkScanlineDecoder_DEFINED 298 #endif // SkScanlineDecoder_DEFINED
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698