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

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

Issue 1287423002: Scanline decoding for bmp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Response to comments from previous patch sets 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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 bool reallyHasAlpha() const { 146 bool reallyHasAlpha() const {
147 return this->onReallyHasAlpha(); 147 return this->onReallyHasAlpha();
148 } 148 }
149 149
150 /** 150 /**
151 * Format of the encoded data. 151 * Format of the encoded data.
152 */ 152 */
153 SkEncodedFormat getEncodedFormat() const { return this->onGetEncodedFormat() ; } 153 SkEncodedFormat getEncodedFormat() const { return this->onGetEncodedFormat() ; }
154 154
155 /** 155 /**
156 * returns true if the image must be scaled, in the y direction, after readi ng, not during. 156 * The order in which rows are output from the scanline decoder is not the
157 * To scale afterwards, we first decode every line and then sample the lines we want afterwards. 157 * same for all variations of all image types. This explains the possible
158 * An example is interlaced pngs, where calling getScanlines once (regardles s of the count 158 * output row orderings.
159 * used) needs to read the entire image, therefore it is inefficient to call
160 * getScanlines more than once. Instead, it should only ever be called with all the
161 * rows needed.
162 */ 159 */
163 bool requiresPostYSampling() { 160 enum SkScanlineOrder {
164 return this->onRequiresPostYSampling(); 161 /*
162 * By far the most common, this indicates that the image can be decoded
163 * reliably using the scanline decoder, and that rows will be output in
164 * the logical order.
165 */
166 kTopDown_SkScanlineOrder,
167
168 /*
169 * This indicates that scanline decoder can reliably output rows, but
170 * they will not be in logical order. If the scanline format is
171 * kOutOfOrder, the getY() API should be used to determine the actual
172 * y-coordinates of the output rows.
173 *
174 * For this scanline ordering, it is advisable to get and skip
175 * scanlines one at a time.
176 *
177 * Upside down bmps and interlaced gifs are examples.
178 */
179 kOutOfOrder_SkScanlineOrder,
180
181 /*
182 * Indicates that the entire image must be decoded in order to output
183 * any amount of scanlines. In this case, it is a REALLY BAD IDEA to
184 * request scanlines 1-by-1 or in small chunks. The client should
185 * determine which scanlines are needed and ask for all of them in
186 * a single call to getScanlines().
187 *
188 * Interlaced pngs are an example.
189 */
190 kNone_SkScanlineOrder,
191 };
192
193 /**
194 * An enum representing the order in which scanlines will be returned by
195 * the scanline decoder.
196 */
197 SkScanlineOrder getScanlineOrder() const { return this->onGetScanlineOrder() ; }
198
199 /**
200 * Returns the y-coordinate of the next row to be returned by the scanline
201 * decoder. This will be overridden in the case of
202 * kOutOfOrder_SkScanlineOrder and should be unnecessary in the case of
203 * kNone_SkScanlineOrder.
204 */
205 int getY() const {
206 SkASSERT(kNone_SkScanlineOrder != this->getScanlineOrder());
207 return this->onGetY();
165 } 208 }
166 209
167 protected: 210 protected:
168 SkScanlineDecoder(const SkImageInfo& srcInfo) 211 SkScanlineDecoder(const SkImageInfo& srcInfo)
169 : fSrcInfo(srcInfo) 212 : fSrcInfo(srcInfo)
170 , fDstInfo() 213 , fDstInfo()
214 , fOptions()
171 , fCurrScanline(0) {} 215 , fCurrScanline(0) {}
172 216
173 virtual SkISize onGetScaledDimensions(float /* desiredScale */) { 217 virtual SkISize onGetScaledDimensions(float /* desiredScale */) {
174 // By default, scaling is not supported. 218 // By default, scaling is not supported.
175 return this->getInfo().dimensions(); 219 return this->getInfo().dimensions();
176 } 220 }
177 221
178 virtual SkEncodedFormat onGetEncodedFormat() const = 0; 222 virtual SkEncodedFormat onGetEncodedFormat() const = 0;
179 223
180 virtual bool onReallyHasAlpha() const { return false; } 224 virtual bool onReallyHasAlpha() const { return false; }
181 225
182 /** 226 /**
183 * returns true if the image type is hard to sample and must be scaled after reading, not during 227 * Most images types will be kTopDown and will not need to override this fu nction.
184 * An example is interlaced pngs, where the entire image must be read for ea ch decode
185 */ 228 */
186 virtual bool onRequiresPostYSampling() { return false; } 229 virtual SkScanlineOrder onGetScanlineOrder() const { return kTopDown_SkScanl ineOrder; }
230
231 /**
232 * Most images will be kTopDown and will not need to override this function .
233 */
234 virtual int onGetY() const { return fCurrScanline; }
187 235
188 const SkImageInfo& dstInfo() const { return fDstInfo; } 236 const SkImageInfo& dstInfo() const { return fDstInfo; }
189 237
238 const SkCodec::Options& options() const { return fOptions; }
239
190 private: 240 private:
191 const SkImageInfo fSrcInfo; 241 const SkImageInfo fSrcInfo;
192 SkImageInfo fDstInfo; 242 SkImageInfo fDstInfo;
243 SkCodec::Options fOptions;
193 int fCurrScanline; 244 int fCurrScanline;
194 245
195 virtual SkCodec::Result onStart(const SkImageInfo& dstInfo, 246 virtual SkCodec::Result onStart(const SkImageInfo& dstInfo,
196 const SkCodec::Options& options, 247 const SkCodec::Options& options,
197 SkPMColor ctable[], int* ctableCount) = 0; 248 SkPMColor ctable[], int* ctableCount) = 0;
198 249
199 // Naive default version just calls onGetScanlines on temp memory. 250 // Naive default version just calls onGetScanlines on temp memory.
200 virtual SkCodec::Result onSkipScanlines(int countLines) { 251 virtual SkCodec::Result onSkipScanlines(int countLines) {
201 SkAutoMalloc storage(fDstInfo.minRowBytes()); 252 SkAutoMalloc storage(fDstInfo.minRowBytes());
202 // Note that we pass 0 to rowBytes so we continue to use the same memory . 253 // Note that we pass 0 to rowBytes so we continue to use the same memory .
203 // Also note that while getScanlines checks that rowBytes is big enough, 254 // Also note that while getScanlines checks that rowBytes is big enough,
204 // onGetScanlines bypasses that check. 255 // onGetScanlines bypasses that check.
205 // Calling the virtual method also means we do not double count 256 // Calling the virtual method also means we do not double count
206 // countLines. 257 // countLines.
207 return this->onGetScanlines(storage.get(), countLines, 0); 258 return this->onGetScanlines(storage.get(), countLines, 0);
208 } 259 }
209 260
210 virtual SkCodec::Result onGetScanlines(void* dst, int countLines, 261 virtual SkCodec::Result onGetScanlines(void* dst, int countLines,
211 size_t rowBytes) = 0; 262 size_t rowBytes) = 0;
212 263
213 }; 264 };
214 #endif // SkScanlineDecoder_DEFINED 265 #endif // SkScanlineDecoder_DEFINED
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698