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

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

Issue 1075243003: Implementing filling for SkBmpCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Sharing code in static helper Created 5 years, 8 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 | « src/codec/SkSwizzler.h ('k') | tests/SwizzlerTest.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 #include "SkCodecPriv.h" 8 #include "SkCodecPriv.h"
9 #include "SkColorPriv.h" 9 #include "SkColorPriv.h"
10 #include "SkSwizzler.h" 10 #include "SkSwizzler.h"
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 SkDEBUGCODE(fNextMode = kDesignateRow_NextMode); 415 SkDEBUGCODE(fNextMode = kDesignateRow_NextMode);
416 416
417 // Choose the row 417 // Choose the row
418 void* row = SkTAddOffset<void>(fDstRow, y*fDstRowBytes); 418 void* row = SkTAddOffset<void>(fDstRow, y*fDstRowBytes);
419 419
420 // Decode the row 420 // Decode the row
421 return fRowProc(row, src, fDstInfo.width(), fDeltaSrc, fCurrY, 421 return fRowProc(row, src, fDstInfo.width(), fDeltaSrc, fCurrY,
422 fColorTable); 422 fColorTable);
423 } 423 }
424 424
425 void SkSwizzler::Fill(void* dst, const SkImageInfo& dstInfo, size_t dstRowBytes, uint32_t y, 425 void SkSwizzler::Fill(void* dstStartRow, const SkImageInfo& dstInfo, size_t dstR owBytes,
426 uint32_t colorOrIndex, SkPMColor* colorTable) { 426 uint32_t numRows, uint32_t colorOrIndex, const SkPMColor* colorTable) {
427 SkASSERT(dst != NULL); 427 SkASSERT(dstStartRow != NULL);
428 SkASSERT(y < (uint32_t) dstInfo.height()); 428 SkASSERT(numRows <= (uint32_t) dstInfo.height());
429 429
430 // Get dst start row 430 // Calculate bytes to fill. We use getSafeSize since the last row may not b e padded.
431 void* dstRow = SkTAddOffset<void*>(dst, y * dstRowBytes); 431 const size_t bytesToFill = dstInfo.makeWH(dstInfo.width(), numRows).getSafeS ize(dstRowBytes);
432
433 // Calculate remaining bytes. This is tricky since the final row may not be padded.
434 const size_t totalBytes = dstInfo.getSafeSize(dstRowBytes);
435 const size_t remainingBytes = totalBytes - y * dstRowBytes;
436 432
437 // Use the proper memset routine to fill the remaining bytes 433 // Use the proper memset routine to fill the remaining bytes
438 switch(dstInfo.colorType()) { 434 switch(dstInfo.colorType()) {
439 case kN32_SkColorType: 435 case kN32_SkColorType:
440 // Assume input is an index if we have a color table 436 // Assume input is an index if we have a color table
441 uint32_t color; 437 uint32_t color;
442 if (NULL != colorTable) { 438 if (NULL != colorTable) {
443 SkASSERT(colorOrIndex == (uint8_t) colorOrIndex); 439 SkASSERT(colorOrIndex == (uint8_t) colorOrIndex);
444 color = colorTable[colorOrIndex]; 440 color = colorTable[colorOrIndex];
445 // Otherwise, assume the input is a color 441 // Otherwise, assume the input is a color
446 } else { 442 } else {
447 color = colorOrIndex; 443 color = colorOrIndex;
448 } 444 }
449 445
450 // We must fill row by row in the case of unaligned row bytes 446 // We must fill row by row in the case of unaligned row bytes
451 if (SkIsAlign4((size_t) dstRow) && SkIsAlign4(dstRowBytes)) { 447 if (SkIsAlign4((size_t) dstStartRow) && SkIsAlign4(dstRowBytes)) {
452 sk_memset32((uint32_t*) dstRow, color, 448 sk_memset32((uint32_t*) dstStartRow, color,
453 (uint32_t) remainingBytes / sizeof(SkPMColor)); 449 (uint32_t) bytesToFill / sizeof(SkPMColor));
454 } else { 450 } else {
455 // This is an unlikely, slow case 451 // This is an unlikely, slow case
456 SkCodecPrintf("Warning: Strange number of row bytes, fill will b e slow.\n"); 452 SkCodecPrintf("Warning: Strange number of row bytes, fill will b e slow.\n");
457 for (int32_t row = y; row < dstInfo.height(); row++) { 453 uint32_t* dstRow = (uint32_t*) dstStartRow;
458 uint32_t* dstPtr = (uint32_t*) dstRow; 454 for (uint32_t row = 0; row < numRows; row++) {
459 for (int32_t col = 0; col < dstInfo.width(); col++) { 455 for (int32_t col = 0; col < dstInfo.width(); col++) {
460 dstPtr[col] = color; 456 dstRow[col] = color;
461 } 457 }
462 dstRow = SkTAddOffset<void*>(dstRow, dstRowBytes); 458 dstRow = SkTAddOffset<uint32_t>(dstRow, dstRowBytes);
463 } 459 }
464 } 460 }
465 break; 461 break;
466 // On an index destination color type, always assume the input is an ind ex 462 // On an index destination color type, always assume the input is an ind ex
467 case kIndex_8_SkColorType: 463 case kIndex_8_SkColorType:
468 SkASSERT(colorOrIndex == (uint8_t) colorOrIndex); 464 SkASSERT(colorOrIndex == (uint8_t) colorOrIndex);
469 memset(dstRow, colorOrIndex, remainingBytes); 465 memset(dstStartRow, colorOrIndex, bytesToFill);
470 break; 466 break;
471 default: 467 default:
472 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n"); 468 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n");
473 SkASSERT(false); 469 SkASSERT(false);
474 break; 470 break;
475 } 471 }
476 } 472 }
OLDNEW
« no previous file with comments | « src/codec/SkSwizzler.h ('k') | tests/SwizzlerTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698