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

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: Add SkScanlineOrder enum to SkScanlineDecoder.h 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
« no previous file with comments | « no previous file | src/codec/SkBmpCodec.h » ('j') | src/codec/SkBmpCodec.cpp » ('J')
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 #ifndef SkScanlineDecoder_DEFINED 8 #ifndef SkScanlineDecoder_DEFINED
9 #define SkScanlineDecoder_DEFINED 9 #define SkScanlineDecoder_DEFINED
10 10
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 */ 145 */
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 /**
156 * returns true if the image must be scaled, in the y direction, after readi ng, not during. 157 * 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. 158 * 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 159 * 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 */ 160 */
163 bool requiresPostYSampling() { 161 enum SkScanlineOrder {
164 return this->onRequiresPostYSampling(); 162 /*
163 * By far the most common, this indicates that the image can be decoded
164 * reliably using the scanline decoder, and that rows will be output in
165 * the logical order.
166 */
167 kTopDown_SkScanlineOrder,
168
169 /*
170 * This indicates that scanline decoder can reliably output rows, but
171 * they will not be in logical order. If the scanline format is
172 * kOutOfOrder, the getY() API should be used to determine the actual
173 * y-coordinates of the output rows.
174 *
175 * For this scanline ordering, it is advisable to get and skip
176 * scanlines one at a time.
177 *
178 * Upside down bmps and interlaced gifs are examples.
scroggo 2015/08/26 22:40:09 Should upside down be its own ordering? It seems l
179 */
180 kOutOfOrder_SkScanlineOrder,
181
182 /*
183 * Indicates that the entire image must be decoded in order to output
184 * any amount of scanlines. In this case, it is a REALLY BAD IDEA to
185 * request scanlines 1-by-1 or in small chunks. The client should
186 * determine which scanlines are needed and ask for all of them in
187 * a single call to getScanlines().
188 *
189 * Interlaced pngs are an example.
190 */
191 kNone_SkScanlineOrder,
scroggo 2015/08/26 22:40:09 I'm not a huge fan of this name, but do not have a
192 };
193
194 /**
195 * An enum representing the order in which scanlines will be returned by
196 * the scanline decoder.
197 */
198 SkScanlineOrder getScanlineOrder() const { return this->onGetScanlineOrder() ; }
199
200 /**
201 * Returns the y-coordinate of the next row to be returned by the scanline
202 * decoder. This will be overridden in the case of
203 * kOutOfOrder_SkScanlineOrder and should be unnecessary in the case of
204 * kNone_SkScanlineOrder.
205 */
206 int getY() const {
207 SkASSERT(kNone_SkScanlineOrder != this->getScanlineOrder());
208 return this->onGetY();
165 } 209 }
166 210
211
167 protected: 212 protected:
168 SkScanlineDecoder(const SkImageInfo& srcInfo) 213 SkScanlineDecoder(const SkImageInfo& srcInfo)
169 : fSrcInfo(srcInfo) 214 : fSrcInfo(srcInfo)
170 , fDstInfo() 215 , fDstInfo()
216 , fOptions()
171 , fCurrScanline(0) {} 217 , fCurrScanline(0) {}
172 218
173 virtual SkISize onGetScaledDimensions(float /* desiredScale */) { 219 virtual SkISize onGetScaledDimensions(float /* desiredScale */) {
174 // By default, scaling is not supported. 220 // By default, scaling is not supported.
175 return this->getInfo().dimensions(); 221 return this->getInfo().dimensions();
176 } 222 }
177 223
178 virtual SkEncodedFormat onGetEncodedFormat() const = 0; 224 virtual SkEncodedFormat onGetEncodedFormat() const = 0;
179 225
180 virtual bool onReallyHasAlpha() const { return false; } 226 virtual bool onReallyHasAlpha() const { return false; }
181 227
182 /** 228 /**
183 * returns true if the image type is hard to sample and must be scaled after reading, not during 229 * 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 */ 230 */
186 virtual bool onRequiresPostYSampling() { return false; } 231 virtual SkScanlineOrder onGetScanlineOrder() const { return kTopDown_SkScanl ineOrder; }
232
233 /**
234 * Most images will be kTopDown and will not need to override this function .
235 */
236 virtual int onGetY() const { return fCurrScanline; }
187 237
188 const SkImageInfo& dstInfo() const { return fDstInfo; } 238 const SkImageInfo& dstInfo() const { return fDstInfo; }
189 239
240 const SkCodec::Options& options() const { return fOptions; }
241
190 private: 242 private:
191 const SkImageInfo fSrcInfo; 243 const SkImageInfo fSrcInfo;
192 SkImageInfo fDstInfo; 244 SkImageInfo fDstInfo;
245 SkCodec::Options fOptions;
193 int fCurrScanline; 246 int fCurrScanline;
194 247
195 virtual SkCodec::Result onStart(const SkImageInfo& dstInfo, 248 virtual SkCodec::Result onStart(const SkImageInfo& dstInfo,
196 const SkCodec::Options& options, 249 const SkCodec::Options& options,
197 SkPMColor ctable[], int* ctableCount) = 0; 250 SkPMColor ctable[], int* ctableCount) = 0;
198 251
199 // Naive default version just calls onGetScanlines on temp memory. 252 // Naive default version just calls onGetScanlines on temp memory.
200 virtual SkCodec::Result onSkipScanlines(int countLines) { 253 virtual SkCodec::Result onSkipScanlines(int countLines) {
201 SkAutoMalloc storage(fDstInfo.minRowBytes()); 254 SkAutoMalloc storage(fDstInfo.minRowBytes());
202 // Note that we pass 0 to rowBytes so we continue to use the same memory . 255 // 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, 256 // Also note that while getScanlines checks that rowBytes is big enough,
204 // onGetScanlines bypasses that check. 257 // onGetScanlines bypasses that check.
205 // Calling the virtual method also means we do not double count 258 // Calling the virtual method also means we do not double count
206 // countLines. 259 // countLines.
207 return this->onGetScanlines(storage.get(), countLines, 0); 260 return this->onGetScanlines(storage.get(), countLines, 0);
208 } 261 }
209 262
210 virtual SkCodec::Result onGetScanlines(void* dst, int countLines, 263 virtual SkCodec::Result onGetScanlines(void* dst, int countLines,
211 size_t rowBytes) = 0; 264 size_t rowBytes) = 0;
212 265
213 }; 266 };
214 #endif // SkScanlineDecoder_DEFINED 267 #endif // SkScanlineDecoder_DEFINED
OLDNEW
« no previous file with comments | « no previous file | src/codec/SkBmpCodec.h » ('j') | src/codec/SkBmpCodec.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698