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

Side by Side Diff: src/codec/SkSwizzler.h

Issue 1445313002: Make SkAndroidCodec support gif (Closed) Base URL: https://skia.googlesource.com/skia.git@bmp
Patch Set: Response to comments Created 5 years, 1 month 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 | « src/codec/SkSampledCodec.cpp ('k') | src/codec/SkSwizzler.cpp » ('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 SkSwizzler_DEFINED 8 #ifndef SkSwizzler_DEFINED
9 #define SkSwizzler_DEFINED 9 #define SkSwizzler_DEFINED
10 10
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 119
120 /** 120 /**
121 * Create a new SkSwizzler. 121 * Create a new SkSwizzler.
122 * @param SrcConfig Description of the format of the source. 122 * @param SrcConfig Description of the format of the source.
123 * @param ctable Unowned pointer to an array of up to 256 colors for an 123 * @param ctable Unowned pointer to an array of up to 256 colors for an
124 * index source. 124 * index source.
125 * @param dstInfo Describes the destination. 125 * @param dstInfo Describes the destination.
126 * @param options Indicates if dst is zero-initialized. The 126 * @param options Indicates if dst is zero-initialized. The
127 * implementation may choose to skip writing zeroes 127 * implementation may choose to skip writing zeroes
128 * if set to kYes_ZeroInitialized. 128 * if set to kYes_ZeroInitialized.
129 * Contains subset information. 129 * Contains partial scanline information.
130 * @param frame Is non-NULL if the source pixels are part of an image
131 * frame that is a subset of the full image.
132 *
133 * Note that a deeper discussion of partial scanline subsets and image fram e
134 * subsets is below. Currently, we do not support both simultaneously. If
135 * options->fSubset is non-NULL, frame must be NULL.
136 *
130 * @return A new SkSwizzler or nullptr on failure. 137 * @return A new SkSwizzler or nullptr on failure.
131 */ 138 */
132 static SkSwizzler* CreateSwizzler(SrcConfig, const SkPMColor* ctable, 139 static SkSwizzler* CreateSwizzler(SrcConfig, const SkPMColor* ctable,
133 const SkImageInfo& dstInfo, const SkCodec: :Options&); 140 const SkImageInfo& dstInfo, const SkCodec: :Options&,
141 const SkIRect* frame = nullptr);
134 142
135 /** 143 /**
136 * Swizzle a line. Generally this will be called height times, once 144 * Swizzle a line. Generally this will be called height times, once
137 * for each row of source. 145 * for each row of source.
138 * By allowing the caller to pass in the dst pointer, we give the caller 146 * By allowing the caller to pass in the dst pointer, we give the caller
139 * flexibility to use the swizzler even when the encoded data does not 147 * flexibility to use the swizzler even when the encoded data does not
140 * store the rows in order. This also improves usability for scaled and 148 * store the rows in order. This also improves usability for scaled and
141 * subset decodes. 149 * subset decodes.
142 * @param dst Where we write the output. 150 * @param dst Where we write the output.
143 * @param src The next row of the source data. 151 * @param src The next row of the source data.
144 * @return A result code describing if the row was fully opaque, fully 152 * @return A result code describing if the row was fully opaque, fully
145 * transparent, or neither 153 * transparent, or neither
146 */ 154 */
147 ResultAlpha swizzle(void* dst, const uint8_t* SK_RESTRICT src); 155 ResultAlpha swizzle(void* dst, const uint8_t* SK_RESTRICT src);
148 156
149 /** 157 /**
150 * Implement fill using a custom width. 158 * Implement fill using a custom width.
151 */ 159 */
152 void fill(const SkImageInfo& info, void* dst, size_t rowBytes, uint32_t colo rOrIndex, 160 void fill(const SkImageInfo& info, void* dst, size_t rowBytes, uint32_t colo rOrIndex,
153 SkCodec::ZeroInitialized zeroInit) override { 161 SkCodec::ZeroInitialized zeroInit) override {
154 const SkImageInfo fillInfo = info.makeWH(fDstWidth, info.height()); 162 const SkImageInfo fillInfo = info.makeWH(fAllocatedWidth, info.height()) ;
155 SkSampler::Fill(fillInfo, dst, rowBytes, colorOrIndex, zeroInit); 163 SkSampler::Fill(fillInfo, dst, rowBytes, colorOrIndex, zeroInit);
156 } 164 }
157 165
158 private: 166 private:
159 167
160 /** 168 /**
161 * Method for converting raw data to Skia pixels. 169 * Method for converting raw data to Skia pixels.
162 * @param dstRow Row in which to write the resulting pixels. 170 * @param dstRow Row in which to write the resulting pixels.
163 * @param src Row of src data, in format specified by SrcConfig 171 * @param src Row of src data, in format specified by SrcConfig
164 * @param dstWidth Width in pixels of the destination 172 * @param dstWidth Width in pixels of the destination
165 * @param bpp if bitsPerPixel % 8 == 0, deltaSrc is bytesPerPixel 173 * @param bpp if bitsPerPixel % 8 == 0, deltaSrc is bytesPerPixel
166 * else, deltaSrc is bitsPerPixel 174 * else, deltaSrc is bitsPerPixel
167 * @param deltaSrc bpp * sampleX 175 * @param deltaSrc bpp * sampleX
168 * @param ctable Colors (used for kIndex source). 176 * @param ctable Colors (used for kIndex source).
169 * @param offset The offset before the first pixel to sample. 177 * @param offset The offset before the first pixel to sample.
170 Is in bytes or bits based on what deltaSrc is in. 178 Is in bytes or bits based on what deltaSrc is in.
171 */ 179 */
172 typedef ResultAlpha (*RowProc)(void* SK_RESTRICT dstRow, 180 typedef ResultAlpha (*RowProc)(void* SK_RESTRICT dstRow,
173 const uint8_t* SK_RESTRICT src, 181 const uint8_t* SK_RESTRICT src,
174 int dstWidth, int bpp, int deltaSrc, int offs et, 182 int dstWidth, int bpp, int deltaSrc, int offs et,
175 const SkPMColor ctable[]); 183 const SkPMColor ctable[]);
176 184
177 const RowProc fRowProc; 185 const RowProc fRowProc;
178 const SkPMColor* fColorTable; // Unowned pointer 186 const SkPMColor* fColorTable; // Unowned pointer
179 const int fSrcOffset; // Offset of the src in pixels, allows for partial 187
180 // scanline decodes. 188 // Subset Swizzles
181 int fX0; // Start coordinate for the src, may b e different than 189 // There are two types of subset swizzles that we support. We do not
182 // fSrcOffset if we are sampling. 190 // support both at the same time.
183 const int fSubsetWidth; // Width of the subset of the source b efore any sampling. 191 // TODO: If we want to support partial scanlines for gifs (which may
184 int fDstWidth; // Width of dst, which may differ with sampling. 192 // use frame subsets), we will need to support both subsetting
185 int fSampleX; // step between X samples 193 // modes at the same time.
186 const int fBPP; // if bitsPerPixel % 8 == 0 194 // (1) Partial Scanlines
195 // The client only wants to write a subset of the source pixels
196 // to the destination. This subset is specified to CreateSwizzler
197 // using options->fSubset. We will store subset information in
198 // the following fields.
199 //
200 // fSrcOffset: The starting pixel of the source.
201 // fSrcOffsetUnits: Derived from fSrcOffset with two key
202 // differences:
203 // (1) This takes the size of source pixels into
204 // account by multiplying by fSrcBPP. This may
205 // be measured in bits or bytes depending on
206 // which is natural for the SrcConfig.
207 // (2) If we are sampling, this will be larger
208 // than fSrcOffset * fSrcBPP, since sampling
209 // implies that we will skip some pixels.
210 // fDstOffset: Will be zero. There is no destination offset
211 // for this type of subset.
212 // fDstOffsetBytes: Will be zero.
213 // fSrcWidth: The width of the desired subset of source
214 // pixels, before any sampling is performed.
215 // fDstWidth: Will be equal to fSrcWidth, since this is also
216 // calculated before any sampling is performed.
217 // For this type of subset, the destination width
218 // matches the desired subset of the source.
219 // fSwizzleWidth: The actual number of pixels that will be
220 // written by the RowProc. This is a scaled
221 // version of fSrcWidth/fDstWidth.
222 // fAllocatedWidth: Will be equal to fSwizzleWidth. For this type
223 // of subset, the number of pixels written is the
224 // same as the actual width of the destination.
225 // (2) Frame Subset
226 // The client will decode the entire width of the source into a
227 // subset of destination memory. This subset is specified to
228 // CreateSwizzler in the "frame" parameter. We store subset
229 // information in the following fields.
230 //
231 // fSrcOffset: Will be zero. The starting pixel of the source.
232 // fSrcOffsetUnits: Will only be non-zero if we are sampling,
233 // since sampling implies that we will skip some
234 // pixels. Note that this is measured in bits
235 // or bytes depending on which is natural for
236 // SrcConfig.
237 // fDstOffset: First pixel to write in destination.
238 // fDstOffsetBytes: fDstOffset * fDstBPP.
239 // fSrcWidth: The entire width of the source pixels, before
240 // any sampling is performed.
241 // fDstWidth: The entire width of the destination memory,
242 // before any sampling is performed.
243 // fSwizzleWidth: The actual number of pixels that will be
244 // written by the RowProc. This is a scaled
245 // version of fSrcWidth.
246 // fAllocatedWidth: The actual number of pixels in destination
247 // memory. This is a scaled version of
248 // fDstWidth.
249 //
250 // If we are not subsetting, these fields are more straightforward.
251 // fSrcOffset = fDstOffet = fDstOffsetBytes = 0
252 // fSrcOffsetUnits may be non-zero (we will skip the first few pixel s when sampling)
253 // fSrcWidth = fDstWidth = Full original width
254 // fSwizzleWidth = fAllcoatedWidth = Scaled width (if we are samplin g)
255 const int fSrcOffset;
256 const int fDstOffset;
257 int fSrcOffsetUnits;
258 int fDstOffsetBytes;
259 const int fSrcWidth;
260 const int fDstWidth;
261 int fSwizzleWidth;
262 int fAllocatedWidth;
263
264 int fSampleX; // Step between X samples
265 const int fSrcBPP; // Bits/bytes per pixel for the SrcCon fig
266 // if bitsPerPixel % 8 == 0
187 // fBPP is bytesPerPixel 267 // fBPP is bytesPerPixel
188 // else 268 // else
189 // fBPP is bitsPerPixel 269 // fBPP is bitsPerPixel
270 const int fDstBPP; // Bytes per pixel for the destination color type
190 271
191 SkSwizzler(RowProc proc, const SkPMColor* ctable, int srcOffset, int subsetW idth, int bpp); 272 SkSwizzler(RowProc proc, const SkPMColor* ctable, int srcOffset, int srcWidt h, int dstOffset,
273 int dstWidth, int srcBPP, int dstBPP);
192 274
193 int onSetSampleX(int) override; 275 int onSetSampleX(int) override;
194 276
195 }; 277 };
196 #endif // SkSwizzler_DEFINED 278 #endif // SkSwizzler_DEFINED
OLDNEW
« no previous file with comments | « src/codec/SkSampledCodec.cpp ('k') | src/codec/SkSwizzler.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698