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

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: Remove testing only changes. 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 | « no previous file | include/codec/SkScanlineDecoder.h » ('j') | include/codec/SkScanlineDecoder.h » ('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 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
djsollen 2015/03/25 13:08:42 What if the stream cannot be rewound?
scroggo 2015/03/25 13:49:15 I've added a comment that we will return NULL. Fo
68 * new one.
69 *
70 * @param dstInfo Info of the destination. If the dimensions do not match
71 * those of getInfo, this implies a scale.
72 * @return New SkScanlineDecoder, or NULL on failure.
73 *
74 * NOTE: If any rows were previously decoded, this requires rewinding the
75 * SkStream.
76 *
77 * NOTE: The scanline decoder is owned by the SkCodec and will delete it
78 * when the SkCodec is deleted.
79 */
80 SkScanlineDecoder* getScanlineDecoder(const SkImageInfo& dstInfo);
81
82 /**
83 * Some images may initially report that they have alpha due to the format
84 * of the encoded data, but then never use any colors which have alpha
85 * less than 100%. This function can be called *after* decoding to
86 * determine if such an image truly had alpha. Calling it before decoding
87 * is undefined.
88 * FIXME: see skbug.com/3582.
89 */
90 bool reallyHasAlpha() const {
91 return this->onReallyHasAlpha();
92 }
93
59 protected: 94 protected:
60 SkCodec(const SkImageInfo&, SkStream*); 95 SkCodec(const SkImageInfo&, SkStream*);
61 96
62 /** 97 /**
63 * The SkAlphaType is a conservative answer. i.e. it is possible that it 98 * The SkAlphaType is a conservative answer. i.e. it is possible that it
64 * initially returns a non-opaque answer, but completing the decode 99 * initially returns a non-opaque answer, but completing the decode
65 * reveals that the image is actually opaque. 100 * reveals that the image is actually opaque.
66 */ 101 */
67 #ifdef SK_SUPPORT_LEGACY_BOOL_ONGETINFO 102 #ifdef SK_SUPPORT_LEGACY_BOOL_ONGETINFO
68 bool onGetInfo(SkImageInfo* info) SK_OVERRIDE { 103 bool onGetInfo(SkImageInfo* info) SK_OVERRIDE {
69 *info = fInfo; 104 *info = fInfo;
70 return true; 105 return true;
71 } 106 }
72 #endif 107 #endif
73 108
74 // Helper for subclasses.
75 const SkImageInfo& getOriginalInfo() { return fInfo; }
76
77 virtual SkISize onGetScaledDimensions(float /* desiredScale */) const { 109 virtual SkISize onGetScaledDimensions(float /* desiredScale */) const {
78 // By default, scaling is not supported. 110 // By default, scaling is not supported.
79 return fInfo.dimensions(); 111 return fInfo.dimensions();
80 } 112 }
81 113
82 virtual SkEncodedFormat onGetEncodedFormat() const = 0; 114 virtual SkEncodedFormat onGetEncodedFormat() const = 0;
83 115
84 /** 116 /**
117 * Override if your codec supports scanline decoding.
118 *
119 * No need to call rewindIfNeeded(), which will have already been called
120 * by the base class.
121 *
122 * @param dstInfo Info of the destination. If the dimensions do not match
123 * those of getInfo, this implies a scale.
124 * @return New SkScanlineDecoder on success, NULL otherwise. The SkCodec
125 * will take ownership of the returned scanline decoder.
126 */
127 virtual SkScanlineDecoder* onGetScanlineDecoder(const SkImageInfo& dstInfo) {
128 return NULL;
129 }
130
131 virtual bool onReallyHasAlpha() const { return false; }
132
133 /**
85 * If the stream was previously read, attempt to rewind. 134 * If the stream was previously read, attempt to rewind.
86 * @returns: 135 * @returns:
87 * true 136 * true
88 * - if the stream needed to be rewound, and the rewind 137 * - if the stream needed to be rewound, and the rewind
89 * succeeded. 138 * succeeded.
90 * - if the stream did not need to be rewound. 139 * - if the stream did not need to be rewound.
91 * false 140 * false
92 * - if the stream needed to be rewound, and rewind failed. 141 * - if the stream needed to be rewound, and rewind failed.
93 * Subclasses MUST call this function before reading the stream (e.g. in 142 * Subclasses MUST call this function before reading the stream (e.g. in
94 * onGetPixels). If it returns false, onGetPixels should return 143 * onGetPixels). If it returns false, onGetPixels should return
95 * kCouldNotRewind. 144 * kCouldNotRewind.
96 */ 145 */
97 bool SK_WARN_UNUSED_RESULT rewindIfNeeded(); 146 bool SK_WARN_UNUSED_RESULT rewindIfNeeded();
98 147
99 /* 148 /*
100 * 149 *
101 * Get method for the input stream 150 * Get method for the input stream
102 * 151 *
103 */ 152 */
104 SkStream* stream() { 153 SkStream* stream() {
105 return fStream.get(); 154 return fStream.get();
106 } 155 }
107 156
108 private: 157 private:
109 const SkImageInfo fInfo; 158 const SkImageInfo fInfo;
110 SkAutoTDelete<SkStream> fStream; 159 SkAutoTDelete<SkStream> fStream;
111 bool fNeedsRewind; 160 bool fNeedsRewind;
161 SkAutoTDelete<SkScanlineDecoder> fScanlineDecoder;
112 162
113 typedef SkImageGenerator INHERITED; 163 typedef SkImageGenerator INHERITED;
114 }; 164 };
115 #endif // SkCodec_DEFINED 165 #endif // SkCodec_DEFINED
OLDNEW
« no previous file with comments | « no previous file | include/codec/SkScanlineDecoder.h » ('j') | include/codec/SkScanlineDecoder.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698