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

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

Issue 1260673002: SkScaledCodec class (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 4 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 17 matching lines...) Expand all
28 * Write the next countLines scanlines into dst. 28 * Write the next countLines scanlines into dst.
29 * 29 *
30 * @param dst Must be non-null, and large enough to hold countLines 30 * @param dst Must be non-null, and large enough to hold countLines
31 * scanlines of size rowBytes. 31 * scanlines of size rowBytes.
32 * @param countLines Number of lines to write. 32 * @param countLines Number of lines to write.
33 * @param rowBytes Number of bytes per row. Must be large enough to hold 33 * @param rowBytes Number of bytes per row. Must be large enough to hold
34 * a scanline based on the SkImageInfo used to create this object. 34 * a scanline based on the SkImageInfo used to create this object.
35 */ 35 */
36 SkCodec::Result getScanlines(void* dst, int countLines, size_t rowBytes) { 36 SkCodec::Result getScanlines(void* dst, int countLines, size_t rowBytes) {
37 if ((rowBytes < fDstInfo.minRowBytes() && countLines > 1 ) || countLines <= 0 37 if ((rowBytes < fDstInfo.minRowBytes() && countLines > 1 ) || countLines <= 0
38 || fCurrScanline + countLines > fDstInfo.height()) { 38 || fCurrScanline + countLines > fSrcInfo.height()) {
39 return SkCodec::kInvalidParameters; 39 return SkCodec::kInvalidParameters;
40 } 40 }
41 const SkCodec::Result result = this->onGetScanlines(dst, countLines, row Bytes); 41 const SkCodec::Result result = this->onGetScanlines(dst, countLines, row Bytes);
42 fCurrScanline += countLines; 42 fCurrScanline += countLines;
43 return result; 43 return result;
44 } 44 }
45 45
46 /** 46 /**
47 * Skip count scanlines. 47 * Skip count scanlines.
48 * 48 *
49 * The default version just calls onGetScanlines and discards the dst. 49 * The default version just calls onGetScanlines and discards the dst.
50 * NOTE: If skipped lines are the only lines with alpha, this default 50 * NOTE: If skipped lines are the only lines with alpha, this default
51 * will make reallyHasAlpha return true, when it could have returned 51 * will make reallyHasAlpha return true, when it could have returned
52 * false. 52 * false.
53 */ 53 */
54 SkCodec::Result skipScanlines(int countLines) { 54 SkCodec::Result skipScanlines(int countLines) {
55 if (fCurrScanline + countLines > fDstInfo.height()) { 55 if (fCurrScanline + countLines > fSrcInfo.height()) {
56 // Arguably, we could just skip the scanlines which are remaining, 56 // Arguably, we could just skip the scanlines which are remaining,
57 // and return kSuccess. We choose to return invalid so the client 57 // and return kSuccess. We choose to return invalid so the client
58 // can catch their bug. 58 // can catch their bug.
59 return SkCodec::kInvalidParameters; 59 return SkCodec::kInvalidParameters;
60 } 60 }
61 const SkCodec::Result result = this->onSkipScanlines(countLines); 61 const SkCodec::Result result = this->onSkipScanlines(countLines);
62 fCurrScanline += countLines; 62 fCurrScanline += countLines;
63 return result; 63 return result;
64 } 64 }
65 65
66 /** 66 /**
67 * Some images may initially report that they have alpha due to the format 67 * Some images may initially report that they have alpha due to the format
68 * of the encoded data, but then never use any colors which have alpha 68 * of the encoded data, but then never use any colors which have alpha
69 * less than 100%. This function can be called *after* decoding to 69 * less than 100%. This function can be called *after* decoding to
70 * determine if such an image truly had alpha. Calling it before decoding 70 * determine if such an image truly had alpha. Calling it before decoding
71 * is undefined. 71 * is undefined.
72 * FIXME: see skbug.com/3582. 72 * FIXME: see skbug.com/3582.
73 */ 73 */
74 bool reallyHasAlpha() const { 74 bool reallyHasAlpha() const {
75 return this->onReallyHasAlpha(); 75 return this->onReallyHasAlpha();
76 } 76 }
77 77
78 bool setSampleX(int sampleX) {
scroggo 2015/07/27 15:09:19 Please add comments explaining what this does.
emmaleer 2015/07/27 18:31:38 Acknowledged.
79 return this->onSetSampleX(sampleX);
80 }
81
78 protected: 82 protected:
79 SkScanlineDecoder(const SkImageInfo& requested) 83 SkScanlineDecoder(const SkImageInfo& requested, const SkImageInfo src)
scroggo 2015/07/27 15:09:19 This should be a const reference. That way we do n
emmaleer 2015/07/27 18:31:38 Acknowledged.
80 : fDstInfo(requested) 84 : fDstInfo(requested)
81 , fCurrScanline(0) {} 85 , fCurrScanline(0)
86 , fSrcInfo(src) {}
82 87
83 virtual bool onReallyHasAlpha() const { return false; } 88 virtual bool onReallyHasAlpha() const { return false; }
84 89
90 virtual bool onSetSampleX(int SampleX){ return false; }
91
85 const SkImageInfo& dstInfo() const { return fDstInfo; } 92 const SkImageInfo& dstInfo() const { return fDstInfo; }
86 93
87 private: 94 private:
88 const SkImageInfo fDstInfo; 95 const SkImageInfo fDstInfo;
89 int fCurrScanline; 96 int fCurrScanline;
97 const SkImageInfo fSrcInfo;
90 98
91 // Naive default version just calls onGetScanlines on temp memory. 99 // Naive default version just calls onGetScanlines on temp memory.
92 virtual SkCodec::Result onSkipScanlines(int countLines) { 100 virtual SkCodec::Result onSkipScanlines(int countLines) {
93 SkAutoMalloc storage(fDstInfo.minRowBytes()); 101 SkAutoMalloc storage(fDstInfo.minRowBytes());
94 // Note that we pass 0 to rowBytes so we continue to use the same memory . 102 // Note that we pass 0 to rowBytes so we continue to use the same memory .
95 // Also note that while getScanlines checks that rowBytes is big enough, 103 // Also note that while getScanlines checks that rowBytes is big enough,
96 // onGetScanlines bypasses that check. 104 // onGetScanlines bypasses that check.
97 // Calling the virtual method also means we do not double count 105 // Calling the virtual method also means we do not double count
98 // countLines. 106 // countLines.
99 return this->onGetScanlines(storage.get(), countLines, 0); 107 return this->onGetScanlines(storage.get(), countLines, 0);
100 } 108 }
101 109
102 virtual SkCodec::Result onGetScanlines(void* dst, int countLines, 110 virtual SkCodec::Result onGetScanlines(void* dst, int countLines,
103 size_t rowBytes) = 0; 111 size_t rowBytes) = 0;
104 112
105 }; 113 };
106 #endif // SkScanlineDecoder_DEFINED 114 #endif // SkScanlineDecoder_DEFINED
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698