OLD | NEW |
---|---|
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 Loading... | |
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 |
msarett
2015/11/17 18:00:50
This is complicated :(.
I'm continuing to think a
| |
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. | |
202 // If we are sampling, this will be a few pixels | |
203 // larger than fSrcOffset (depending on the | |
scroggo
2015/11/17 18:18:25
Hmm, fSrcOffset is in pixels, but this one is not,
msarett
2015/11/17 18:58:07
Tried to restate this a little clearer.
| |
204 // sample size) since sampling implies that we | |
205 // will skip some pixels. | |
206 // This also takes the size of source pixels into | |
207 // account by multiplying by fSrcBPP. This may | |
208 // be measured in bits or bytes depending on | |
209 // which is natural for the SrcConfig. | |
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 | |
scroggo
2015/11/17 18:18:25
I don't think we have a Skia standard for this, bu
msarett
2015/11/17 18:58:07
Done.
| |
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 // If we are sampling, this will be a few pixels | |
234 // larger than fSrcOffset (depending on the | |
235 // sample size) since sampling implies that we | |
236 // will skip some pixels. | |
237 // This also takes the size of source pixels into | |
238 // account by multiplying by fSrcBPP. This may | |
239 // be measured in bits or bytes depending on | |
240 // which is natural for the SrcConfig. | |
241 // fDstOffset: First pixel to write in destination. | |
242 // fDstOffsetBytes: fDstOffset * fDstBPP. | |
243 // fSrcWidth: The entire width of the source pixels, before | |
244 // any sampling is performed. | |
245 // fDstWidth: The entire width of the destination memory, | |
246 // before any sampling is performed. | |
247 // fSwizzleWidth: The actual number of pixels that will be | |
248 // written by the RowProc. This is a scaled | |
249 // version of fSrcWidth. | |
250 // fAllocatedWidth: The actual number of pixels in destination | |
251 // memory. This is a scaled version of | |
252 // fDstWidth. | |
253 // | |
254 // If we are not subsetting, these fields are more straightforward. | |
255 // fSrcOffset = fDstOffet = fDstOffsetBytes = 0 | |
256 // fSrcOffsetUnits may be non-zero (we will skip the first few pixel s when sampling) | |
257 // fSrcWidth = fDstWidth = Full original width | |
258 // fSwizzleWidth = fAllcoatedWidth = Scaled width (if we are samplin g) | |
259 const int fSrcOffset; | |
260 const int fDstOffset; | |
261 int fSrcOffsetUnits; | |
262 int fDstOffsetBytes; | |
263 const int fSrcWidth; | |
264 const int fDstWidth; | |
265 int fSwizzleWidth; | |
266 int fAllocatedWidth; | |
267 | |
268 int fSampleX; // Step between X samples | |
269 const int fSrcBPP; // Bits/bytes per pixel for the SrcCon fig | |
270 // if bitsPerPixel % 8 == 0 | |
187 // fBPP is bytesPerPixel | 271 // fBPP is bytesPerPixel |
188 // else | 272 // else |
189 // fBPP is bitsPerPixel | 273 // fBPP is bitsPerPixel |
274 const int fDstBPP; // Bytes per pixel for the destination color type | |
190 | 275 |
191 SkSwizzler(RowProc proc, const SkPMColor* ctable, int srcOffset, int subsetW idth, int bpp); | 276 SkSwizzler(RowProc proc, const SkPMColor* ctable, int srcOffset, int srcWidt h, int dstOffset, |
277 int dstWidth, int srcBPP, int dstBPP); | |
192 | 278 |
193 int onSetSampleX(int) override; | 279 int onSetSampleX(int) override; |
194 | 280 |
195 }; | 281 }; |
196 #endif // SkSwizzler_DEFINED | 282 #endif // SkSwizzler_DEFINED |
OLD | NEW |