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

Side by Side Diff: src/codec/SkScaledCodec.cpp

Issue 1332053002: Fill incomplete images in SkCodec parent class (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Response to comments Created 5 years, 3 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
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 #include "SkCodecPriv.h" 8 #include "SkCodecPriv.h"
9 #include "SkScaledCodec.h" 9 #include "SkScaledCodec.h"
10 #include "SkStream.h" 10 #include "SkStream.h"
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 } 171 }
172 if (sampleYPtr) { 172 if (sampleYPtr) {
173 *sampleYPtr = sampleY; 173 *sampleYPtr = sampleY;
174 } 174 }
175 } 175 }
176 176
177 // TODO: Implement subsetting in onGetPixels which works when and when not sampl ing 177 // TODO: Implement subsetting in onGetPixels which works when and when not sampl ing
178 178
179 SkCodec::Result SkScaledCodec::onGetPixels(const SkImageInfo& requestedInfo, voi d* dst, 179 SkCodec::Result SkScaledCodec::onGetPixels(const SkImageInfo& requestedInfo, voi d* dst,
180 size_t rowBytes, const Options& optio ns, 180 size_t rowBytes, const Options& optio ns,
181 SkPMColor ctable[], int* ctableCount) { 181 SkPMColor ctable[], int* ctableCount,
182 int* incompleteScanlines) {
182 183
183 if (options.fSubset) { 184 if (options.fSubset) {
184 // Subsets are not supported. 185 // Subsets are not supported.
185 return kUnimplemented; 186 return kUnimplemented;
186 } 187 }
187 188
188 Result result = fScanlineDecoder->start(requestedInfo, &options, ctable, cta bleCount); 189 Result result = fScanlineDecoder->start(requestedInfo, &options, ctable, cta bleCount);
189 if (kSuccess == result) { 190 if (kSuccess == result) {
190 // native decode supported 191 // native decode supported
192 uint32_t lines;
191 switch (fScanlineDecoder->getScanlineOrder()) { 193 switch (fScanlineDecoder->getScanlineOrder()) {
192 case SkScanlineDecoder::kTopDown_SkScanlineOrder: 194 case SkScanlineDecoder::kTopDown_SkScanlineOrder:
193 case SkScanlineDecoder::kBottomUp_SkScanlineOrder: 195 case SkScanlineDecoder::kBottomUp_SkScanlineOrder:
194 case SkScanlineDecoder::kNone_SkScanlineOrder: 196 case SkScanlineDecoder::kNone_SkScanlineOrder:
195 return fScanlineDecoder->getScanlines(dst, requestedInfo.height( ), rowBytes); 197 lines = fScanlineDecoder->getScanlines(dst, requestedInfo.height (), rowBytes);
198 if (lines != requestedInfo.height()) {
199 *incompleteScanlines = requestedInfo.height() - lines;
200 return kIncompleteInput;
201 }
202 return kSuccess;
196 case SkScanlineDecoder::kOutOfOrder_SkScanlineOrder: { 203 case SkScanlineDecoder::kOutOfOrder_SkScanlineOrder: {
197 for (int y = 0; y < requestedInfo.height(); y++) { 204 for (int y = 0; y < requestedInfo.height(); y++) {
198 int dstY = fScanlineDecoder->getY(); 205 int dstY = fScanlineDecoder->getY();
199 void* dstPtr = SkTAddOffset<void>(dst, rowBytes * dstY); 206 void* dstPtr = SkTAddOffset<void>(dst, rowBytes * dstY);
200 result = fScanlineDecoder->getScanlines(dstPtr, 1, rowBytes) ; 207 lines = fScanlineDecoder->getScanlines(dstPtr, 1, rowBytes);
201 // FIXME (msarett): Make the SkCodec base class take care of filling 208 if (1 != lines) {
202 // uninitialized pixels so we can return immediately on kInc ompleteInput. 209 // TODO (msarett): Can we share this code with SkGifCode c?
203 if (kSuccess != result && kIncompleteInput != result) { 210 const SkImageInfo fillInfo = requestedInfo.makeWH(reques tedInfo.width(), 1);
204 return result; 211 const uint32_t fillValue = this->getFillValue(fillInfo);
212 for (; y < requestedInfo.height(); y++) {
213 int dstY = fScanlineDecoder->getY(y);
214 void* dstRow = SkTAddOffset<void>(dst, rowBytes * ds tY);
215 SkSwizzler::Fill(dstRow, fillInfo, rowBytes, fillVal ue,
216 options.fZeroInitialized);
217 }
218 break;
205 } 219 }
206 } 220 }
207 return result; 221 return result;
208 } 222 }
209 } 223 }
210 } 224 }
211 225
212 if (kInvalidScale != result) { 226 if (kInvalidScale != result) {
213 // no scaling requested 227 // no scaling requested
214 return result; 228 return result;
(...skipping 14 matching lines...) Expand all
229 SkImageInfo info = requestedInfo; 243 SkImageInfo info = requestedInfo;
230 // use original height as scanlineDecoder does not support y sampling native ly 244 // use original height as scanlineDecoder does not support y sampling native ly
231 info = info.makeWH(requestedInfo.width(), srcHeight); 245 info = info.makeWH(requestedInfo.width(), srcHeight);
232 246
233 // update scanlineDecoder with new info 247 // update scanlineDecoder with new info
234 result = fScanlineDecoder->start(info, &options, ctable, ctableCount); 248 result = fScanlineDecoder->start(info, &options, ctable, ctableCount);
235 if (kSuccess != result) { 249 if (kSuccess != result) {
236 return result; 250 return result;
237 } 251 }
238 252
253 uint32_t lines;
239 switch(fScanlineDecoder->getScanlineOrder()) { 254 switch(fScanlineDecoder->getScanlineOrder()) {
240 case SkScanlineDecoder::kTopDown_SkScanlineOrder: { 255 case SkScanlineDecoder::kTopDown_SkScanlineOrder: {
241 result = fScanlineDecoder->skipScanlines(Y0); 256 if (!fScanlineDecoder->skipScanlines(Y0)) {
242 if (kSuccess != result && kIncompleteInput != result) { 257 *incompleteScanlines = dstHeight;
243 return result; 258 return kIncompleteInput;
244 } 259 }
245 for (int y = 0; y < dstHeight; y++) { 260 for (int y = 0; y < dstHeight; y++) {
246 result = fScanlineDecoder->getScanlines(dst, 1, rowBytes); 261 lines = fScanlineDecoder->getScanlines(dst, 1, rowBytes);
247 if (kSuccess != result && kIncompleteInput != result) { 262 if (1 != lines) {
248 return result; 263 *incompleteScanlines = dstHeight - y;
264 return kIncompleteInput;
249 } 265 }
250 if (y < dstHeight - 1) { 266 if (y < dstHeight - 1) {
251 result = fScanlineDecoder->skipScanlines(sampleY - 1); 267 if (!fScanlineDecoder->skipScanlines(sampleY - 1)) {
252 if (kSuccess != result && kIncompleteInput != result) { 268 *incompleteScanlines = dstHeight - y;
253 return result; 269 return kIncompleteInput;
254 } 270 }
255 } 271 }
256 dst = SkTAddOffset<void>(dst, rowBytes); 272 dst = SkTAddOffset<void>(dst, rowBytes);
257 } 273 }
258 return result; 274 return kSuccess;
259 } 275 }
260 case SkScanlineDecoder::kBottomUp_SkScanlineOrder: 276 case SkScanlineDecoder::kBottomUp_SkScanlineOrder:
261 case SkScanlineDecoder::kOutOfOrder_SkScanlineOrder: { 277 case SkScanlineDecoder::kOutOfOrder_SkScanlineOrder: {
262 for (int y = 0; y < srcHeight; y++) { 278 Result result = kSuccess;
279 int y;
280 for (y = 0; y < srcHeight; y++) {
263 int srcY = fScanlineDecoder->getY(); 281 int srcY = fScanlineDecoder->getY();
264 if (is_coord_necessary(srcY, sampleY, dstHeight)) { 282 if (is_coord_necessary(srcY, sampleY, dstHeight)) {
265 void* dstPtr = SkTAddOffset<void>(dst, rowBytes * get_dst_co ord(srcY, sampleY)); 283 void* dstPtr = SkTAddOffset<void>(dst, rowBytes * get_dst_co ord(srcY, sampleY));
266 result = fScanlineDecoder->getScanlines(dstPtr, 1, rowBytes) ; 284 lines = fScanlineDecoder->getScanlines(dstPtr, 1, rowBytes);
267 if (kSuccess != result && kIncompleteInput != result) { 285 if (1 != lines) {
268 return result; 286 result = kIncompleteInput;
287 break;
269 } 288 }
270 } else { 289 } else {
271 result = fScanlineDecoder->skipScanlines(1); 290 if (!fScanlineDecoder->skipScanlines(1)) {
272 if (kSuccess != result && kIncompleteInput != result) { 291 result = kIncompleteInput;
273 return result; 292 break;
274 } 293 }
275 } 294 }
276 } 295 }
296
297 // Fill the remaining rows on an incomplete input
298 if (kIncompleteInput == result) {
299 const SkImageInfo fillInfo = requestedInfo.makeWH(requestedInfo. width(), 1);
300 const uint32_t fillValue = this->getFillValue(fillInfo);
301 for (; y < srcHeight; y++) {
302 int srcY = fScanlineDecoder->getY(y);
303 if (is_coord_necessary(srcY, sampleY, dstHeight)) {
304 void* dstRow = SkTAddOffset<void>(dst,
305 rowBytes * get_dst_coord(srcY, sampleY));
306 SkSwizzler::Fill(dstRow, fillInfo, rowBytes, fillValue,
307 options.fZeroInitialized);
308 }
309 }
310 }
277 return result; 311 return result;
278 } 312 }
279 case SkScanlineDecoder::kNone_SkScanlineOrder: { 313 case SkScanlineDecoder::kNone_SkScanlineOrder: {
280 SkAutoMalloc storage(srcHeight * rowBytes); 314 SkAutoMalloc storage(srcHeight * rowBytes);
281 uint8_t* storagePtr = static_cast<uint8_t*>(storage.get()); 315 uint8_t* storagePtr = static_cast<uint8_t*>(storage.get());
282 result = fScanlineDecoder->getScanlines(storagePtr, srcHeight, rowBy tes); 316 int scanlines = (int) fScanlineDecoder->getScanlines(storagePtr, src Height, rowBytes);
283 if (kSuccess != result && kIncompleteInput != result) {
284 return result;
285 }
286 storagePtr += Y0 * rowBytes; 317 storagePtr += Y0 * rowBytes;
287 for (int y = 0; y < dstHeight; y++) { 318 scanlines -= Y0;
319 int y = 0;
320 while(y < dstHeight && scanlines > 0) {
288 memcpy(dst, storagePtr, rowBytes); 321 memcpy(dst, storagePtr, rowBytes);
289 storagePtr += sampleY * rowBytes; 322 storagePtr += sampleY * rowBytes;
290 dst = SkTAddOffset<void>(dst, rowBytes); 323 dst = SkTAddOffset<void>(dst, rowBytes);
324 scanlines -= sampleY;
325 y++;
291 } 326 }
292 return result; 327 if (y < dstHeight) {
328 *incompleteScanlines = dstHeight - y;
329 return kIncompleteInput;
330 }
331 return kSuccess;
293 } 332 }
294 default: 333 default:
295 SkASSERT(false); 334 SkASSERT(false);
296 return kUnimplemented; 335 return kUnimplemented;
297 } 336 }
298 } 337 }
338
339 uint32_t SkScaledCodec::onGetFillValue(const SkImageInfo& dstInfo) const {
340 return fScanlineDecoder->getFillValue(dstInfo);
341 }
342
343 void* SkScaledCodec::onGetFillDst(void* dst, size_t rowBytes,
344 uint32_t decodedScanlines) const {
345 return fScanlineDecoder->getFillDst(dst, rowBytes, decodedScanlines);
346 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698