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

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

Issue 1260673002: SkScaledCodec class (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Move Jpeg Swizzler to ScanlineDecoder 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 28 matching lines...) Expand all
39 /** 39 /**
40 * Clean up after reading/skipping scanlines. 40 * Clean up after reading/skipping scanlines.
41 * 41 *
42 * It is possible that not all scanlines will have been read/skipped. In 42 * It is possible that not all scanlines will have been read/skipped. In
43 * fact, in the case of subset decodes, it is likely that there will be 43 * fact, in the case of subset decodes, it is likely that there will be
44 * scanlines at the bottom of the image that have been ignored. 44 * scanlines at the bottom of the image that have been ignored.
45 */ 45 */
46 virtual ~SkScanlineDecoder() {} 46 virtual ~SkScanlineDecoder() {}
47 47
48 /** 48 /**
49 * Return a size that approximately supports the desired scale factor.
50 * The codec may not be able to scale efficiently to the exact scale
51 * factor requested, so return a size that approximates that scale.
52 * The returned value is the codec's suggestion for the closest valid
53 * scale that it can natively support
scroggo 2015/08/06 15:09:10 Maybe this should have a FIXME: share this with Sk
emmaleer 2015/08/06 18:59:52 Acknowledged.
54 */
55 SkISize getScaledDimensions(float desiredScale) {
56 return this->onGetScaledDimensions(desiredScale);
57 }
58
59 /**
49 * Returns the default info, corresponding to the encoded data. 60 * Returns the default info, corresponding to the encoded data.
50 */ 61 */
51 const SkImageInfo& getInfo() { return fSrcInfo; } 62 const SkImageInfo& getInfo() { return fSrcInfo; }
52 63
53 /** 64 /**
54 * Initialize on the first scanline, with the specified options. 65 * Initialize on the first scanline, with the specified options.
55 * 66 *
56 * This must be called in order to call getScanlnies or skipScanlines. If 67 * This must be called in order to call getScanlnies or skipScanlines. If
57 * it has been called before, this will require rewinding the stream. 68 * it has been called before, this will require rewinding the stream.
58 * 69 *
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 * of the encoded data, but then never use any colors which have alpha 139 * of the encoded data, but then never use any colors which have alpha
129 * less than 100%. This function can be called *after* decoding to 140 * less than 100%. This function can be called *after* decoding to
130 * determine if such an image truly had alpha. Calling it before decoding 141 * determine if such an image truly had alpha. Calling it before decoding
131 * is undefined. 142 * is undefined.
132 * FIXME: see skbug.com/3582. 143 * FIXME: see skbug.com/3582.
133 */ 144 */
134 bool reallyHasAlpha() const { 145 bool reallyHasAlpha() const {
135 return this->onReallyHasAlpha(); 146 return this->onReallyHasAlpha();
136 } 147 }
137 148
149 /**
150 * Format of the encoded data.
151 */
152 SkEncodedFormat getEncodedFormat() const { return this->onGetEncodedFormat() ; }
153
154 /**
155 * returns true if the image must be scaled, in the y direction, after readi ng, not during.
156 * To scale afterwards, we first decode every line and then sample the lines we want afterwards.
157 * An example is interlaced pngs, where calling getScanlines once (regardles s of the count
158 * used) needs to read the entire image, therefore it is inefficient to call
159 * getScanlines more than once. Instead, it should only ever be called with all the
160 * rows needed.
161 */
162 bool requiresPostYSampling() {
163 return this->onRequiresPostYSampling();
164 }
165
138 protected: 166 protected:
139 SkScanlineDecoder(const SkImageInfo& srcInfo) 167 SkScanlineDecoder(const SkImageInfo& srcInfo)
140 : fSrcInfo(srcInfo) 168 : fSrcInfo(srcInfo)
141 , fDstInfo() 169 , fDstInfo()
142 , fCurrScanline(0) {} 170 , fCurrScanline(0) {}
143 171
172 virtual SkISize onGetScaledDimensions(float /* desiredScale */) {
173 // By default, scaling is not supported.
174 return this->getInfo().dimensions();
175 }
176
177 virtual SkEncodedFormat onGetEncodedFormat() const = 0;
178
144 virtual bool onReallyHasAlpha() const { return false; } 179 virtual bool onReallyHasAlpha() const { return false; }
145 180
181 /**
182 * returns true if the image type is hard to sample and must be scaled after reading, not during
183 * An example is interlaced pngs, where the entire image must be read for ea ch decode
184 */
185 virtual bool onRequiresPostYSampling() { return false; }
186
146 const SkImageInfo& dstInfo() const { return fDstInfo; } 187 const SkImageInfo& dstInfo() const { return fDstInfo; }
147 188
148 private: 189 private:
149 const SkImageInfo fSrcInfo; 190 const SkImageInfo fSrcInfo;
150 SkImageInfo fDstInfo; 191 SkImageInfo fDstInfo;
151 int fCurrScanline; 192 int fCurrScanline;
152 193
153 virtual SkCodec::Result onStart(const SkImageInfo& dstInfo, 194 virtual SkCodec::Result onStart(const SkImageInfo& dstInfo,
154 const SkCodec::Options& options, 195 const SkCodec::Options& options,
155 SkPMColor ctable[], int* ctableCount) = 0; 196 SkPMColor ctable[], int* ctableCount) = 0;
156 197
157 // Naive default version just calls onGetScanlines on temp memory. 198 // Naive default version just calls onGetScanlines on temp memory.
158 virtual SkCodec::Result onSkipScanlines(int countLines) { 199 virtual SkCodec::Result onSkipScanlines(int countLines) {
159 SkAutoMalloc storage(fDstInfo.minRowBytes()); 200 SkAutoMalloc storage(fDstInfo.minRowBytes());
160 // Note that we pass 0 to rowBytes so we continue to use the same memory . 201 // Note that we pass 0 to rowBytes so we continue to use the same memory .
161 // Also note that while getScanlines checks that rowBytes is big enough, 202 // Also note that while getScanlines checks that rowBytes is big enough,
162 // onGetScanlines bypasses that check. 203 // onGetScanlines bypasses that check.
163 // Calling the virtual method also means we do not double count 204 // Calling the virtual method also means we do not double count
164 // countLines. 205 // countLines.
165 return this->onGetScanlines(storage.get(), countLines, 0); 206 return this->onGetScanlines(storage.get(), countLines, 0);
166 } 207 }
167 208
168 virtual SkCodec::Result onGetScanlines(void* dst, int countLines, 209 virtual SkCodec::Result onGetScanlines(void* dst, int countLines,
169 size_t rowBytes) = 0; 210 size_t rowBytes) = 0;
170 211
171 }; 212 };
172 #endif // SkScanlineDecoder_DEFINED 213 #endif // SkScanlineDecoder_DEFINED
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698