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

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

Issue 1010903003: Add scanline decoding to SkCodec. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Build with no-clobbered Created 5 years, 9 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 | « gyp/codec.gyp ('k') | include/codec/SkScanlineDecoder.h » ('j') | no next file with comments »
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 SkCodec_DEFINED 8 #ifndef SkCodec_DEFINED
9 #define SkCodec_DEFINED 9 #define SkCodec_DEFINED
10 10
11 #include "SkEncodedFormat.h" 11 #include "SkEncodedFormat.h"
12 #include "SkImageGenerator.h" 12 #include "SkImageGenerator.h"
13 #include "SkImageInfo.h" 13 #include "SkImageInfo.h"
14 #include "SkScanlineDecoder.h"
14 #include "SkSize.h" 15 #include "SkSize.h"
15 #include "SkStream.h" 16 #include "SkStream.h"
16 #include "SkTemplates.h" 17 #include "SkTemplates.h"
17 #include "SkTypes.h" 18 #include "SkTypes.h"
18 19
19 class SkData; 20 class SkData;
20 21
21 /** 22 /**
22 * Abstraction layer directly on top of an image codec. 23 * Abstraction layer directly on top of an image codec.
23 */ 24 */
(...skipping 25 matching lines...) Expand all
49 */ 50 */
50 SkISize getScaledDimensions(float desiredScale) const { 51 SkISize getScaledDimensions(float desiredScale) const {
51 return this->onGetScaledDimensions(desiredScale); 52 return this->onGetScaledDimensions(desiredScale);
52 } 53 }
53 54
54 /** 55 /**
55 * Format of the encoded data. 56 * Format of the encoded data.
56 */ 57 */
57 SkEncodedFormat getEncodedFormat() const { return this->onGetEncodedFormat() ; } 58 SkEncodedFormat getEncodedFormat() const { return this->onGetEncodedFormat() ; }
58 59
60 /**
61 * Return an object which can be used to decode individual scanlines.
62 *
63 * This object is owned by the SkCodec, which will handle its lifetime. The
64 * returned object is only valid until the SkCodec is deleted or the next
65 * call to getScanlineDecoder, whichever comes first.
66 *
67 * Calling a second time will rewind and replace the existing one with a
68 * new one. If the stream cannot be rewound, this will delete the existing
69 * one and return NULL.
70 *
71 * @param dstInfo Info of the destination. If the dimensions do not match
72 * those of getInfo, this implies a scale.
73 * @return New SkScanlineDecoder, or NULL on failure.
74 *
75 * NOTE: If any rows were previously decoded, this requires rewinding the
76 * SkStream.
77 *
78 * NOTE: The scanline decoder is owned by the SkCodec and will delete it
79 * when the SkCodec is deleted.
80 */
81 SkScanlineDecoder* getScanlineDecoder(const SkImageInfo& dstInfo);
82
83 /**
84 * Some images may initially report that they have alpha due to the format
85 * of the encoded data, but then never use any colors which have alpha
86 * less than 100%. This function can be called *after* decoding to
87 * determine if such an image truly had alpha. Calling it before decoding
88 * is undefined.
89 * FIXME: see skbug.com/3582.
90 */
91 bool reallyHasAlpha() const {
92 return this->onReallyHasAlpha();
93 }
94
59 protected: 95 protected:
60 SkCodec(const SkImageInfo&, SkStream*); 96 SkCodec(const SkImageInfo&, SkStream*);
61 97
62 /** 98 /**
63 * The SkAlphaType is a conservative answer. i.e. it is possible that it 99 * The SkAlphaType is a conservative answer. i.e. it is possible that it
64 * initially returns a non-opaque answer, but completing the decode 100 * initially returns a non-opaque answer, but completing the decode
65 * reveals that the image is actually opaque. 101 * reveals that the image is actually opaque.
66 */ 102 */
67 #ifdef SK_SUPPORT_LEGACY_BOOL_ONGETINFO 103 #ifdef SK_SUPPORT_LEGACY_BOOL_ONGETINFO
68 bool onGetInfo(SkImageInfo* info) SK_OVERRIDE { 104 bool onGetInfo(SkImageInfo* info) SK_OVERRIDE {
69 *info = fInfo; 105 *info = fInfo;
70 return true; 106 return true;
71 } 107 }
72 #endif 108 #endif
73 109
74 virtual SkISize onGetScaledDimensions(float /* desiredScale */) const { 110 virtual SkISize onGetScaledDimensions(float /* desiredScale */) const {
75 // By default, scaling is not supported. 111 // By default, scaling is not supported.
76 return fInfo.dimensions(); 112 return fInfo.dimensions();
77 } 113 }
78 114
79 virtual SkEncodedFormat onGetEncodedFormat() const = 0; 115 virtual SkEncodedFormat onGetEncodedFormat() const = 0;
80 116
81 /** 117 /**
118 * Override if your codec supports scanline decoding.
119 *
120 * No need to call rewindIfNeeded(), which will have already been called
121 * by the base class.
122 *
123 * @param dstInfo Info of the destination. If the dimensions do not match
124 * those of getInfo, this implies a scale.
125 * @return New SkScanlineDecoder on success, NULL otherwise. The SkCodec
126 * will take ownership of the returned scanline decoder.
127 */
128 virtual SkScanlineDecoder* onGetScanlineDecoder(const SkImageInfo& dstInfo) {
129 return NULL;
130 }
131
132 virtual bool onReallyHasAlpha() const { return false; }
133
134 /**
82 * If the stream was previously read, attempt to rewind. 135 * If the stream was previously read, attempt to rewind.
83 * @returns: 136 * @returns:
84 * true 137 * true
85 * - if the stream needed to be rewound, and the rewind 138 * - if the stream needed to be rewound, and the rewind
86 * succeeded. 139 * succeeded.
87 * - if the stream did not need to be rewound. 140 * - if the stream did not need to be rewound.
88 * false 141 * false
89 * - if the stream needed to be rewound, and rewind failed. 142 * - if the stream needed to be rewound, and rewind failed.
90 * Subclasses MUST call this function before reading the stream (e.g. in 143 * Subclasses MUST call this function before reading the stream (e.g. in
91 * onGetPixels). If it returns false, onGetPixels should return 144 * onGetPixels). If it returns false, onGetPixels should return
92 * kCouldNotRewind. 145 * kCouldNotRewind.
93 */ 146 */
94 bool SK_WARN_UNUSED_RESULT rewindIfNeeded(); 147 bool SK_WARN_UNUSED_RESULT rewindIfNeeded();
95 148
96 /* 149 /*
97 * 150 *
98 * Get method for the input stream 151 * Get method for the input stream
99 * 152 *
100 */ 153 */
101 SkStream* stream() { 154 SkStream* stream() {
102 return fStream.get(); 155 return fStream.get();
103 } 156 }
104 157
105 private: 158 private:
106 const SkImageInfo fInfo; 159 const SkImageInfo fInfo;
107 SkAutoTDelete<SkStream> fStream; 160 SkAutoTDelete<SkStream> fStream;
108 bool fNeedsRewind; 161 bool fNeedsRewind;
162 SkAutoTDelete<SkScanlineDecoder> fScanlineDecoder;
109 163
110 typedef SkImageGenerator INHERITED; 164 typedef SkImageGenerator INHERITED;
111 }; 165 };
112 #endif // SkCodec_DEFINED 166 #endif // SkCodec_DEFINED
OLDNEW
« no previous file with comments | « gyp/codec.gyp ('k') | include/codec/SkScanlineDecoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698