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

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

Powered by Google App Engine
This is Rietveld 408576698