diff options
Diffstat (limited to 'src/effects/SkKernel33MaskFilter.cpp')
-rw-r--r-- | src/effects/SkKernel33MaskFilter.cpp | 60 |
1 files changed, 27 insertions, 33 deletions
diff --git a/src/effects/SkKernel33MaskFilter.cpp b/src/effects/SkKernel33MaskFilter.cpp index 429e120..5051f71 100644 --- a/src/effects/SkKernel33MaskFilter.cpp +++ b/src/effects/SkKernel33MaskFilter.cpp @@ -1,21 +1,21 @@ #include "SkKernel33MaskFilter.h" #include "SkColorPriv.h" -SkMask::Format SkKernel33ProcMaskFilter::getFormat() -{ +SkMask::Format SkKernel33ProcMaskFilter::getFormat() { return SkMask::kA8_Format; } -bool SkKernel33ProcMaskFilter::filterMask(SkMask* dst, const SkMask& src, const SkMatrix&, SkIPoint* margin) -{ +bool SkKernel33ProcMaskFilter::filterMask(SkMask* dst, const SkMask& src, + const SkMatrix&, SkIPoint* margin) { // margin??? dst->fImage = NULL; dst->fBounds = src.fBounds; dst->fBounds.inset(-1, -1); dst->fFormat = SkMask::kA8_Format; - if (NULL == src.fImage) + if (NULL == src.fImage) { return true; + } dst->fRowBytes = dst->fBounds.width(); size_t size = dst->computeImageSize(); @@ -39,28 +39,26 @@ bool SkKernel33ProcMaskFilter::filterMask(SkMask* dst, const SkMask& src, const unsigned scale = fPercent256; - for (int y = -1; y <= h; y++) - { + for (int y = -1; y <= h; y++) { uint8_t* dstRow = dstImage; - for (int x = -1; x <= w; x++) - { + for (int x = -1; x <= w; x++) { memset(storage, 0, sizeof(storage)); uint8_t* storagePtr = &storage[0][0]; - for (int ky = y - 1; ky <= y + 1; ky++) - { + for (int ky = y - 1; ky <= y + 1; ky++) { const uint8_t* srcRow = srcImage + ky * srcRB; // may be out-of-range - for (int kx = x - 1; kx <= x + 1; kx++) - { - if ((unsigned)ky < (unsigned)h && (unsigned)kx < (unsigned)w) + for (int kx = x - 1; kx <= x + 1; kx++) { + if ((unsigned)ky < (unsigned)h && (unsigned)kx < (unsigned)w) { *storagePtr = srcRow[kx]; + } storagePtr++; } } int value = this->computeValue(srcRows); - if (scale < 256) + if (scale < 256) { value = SkAlphaBlend(value, srcRows[1][1], scale); + } *dstRow++ = SkToU8(value); } dstImage += dst->fRowBytes; @@ -68,57 +66,53 @@ bool SkKernel33ProcMaskFilter::filterMask(SkMask* dst, const SkMask& src, const return true; } -void SkKernel33ProcMaskFilter::flatten(SkFlattenableWriteBuffer& wb) -{ +void SkKernel33ProcMaskFilter::flatten(SkFlattenableWriteBuffer& wb) { this->INHERITED::flatten(wb); wb.write32(fPercent256); } SkKernel33ProcMaskFilter::SkKernel33ProcMaskFilter(SkFlattenableReadBuffer& rb) - : SkMaskFilter(rb) -{ + : SkMaskFilter(rb) { fPercent256 = rb.readS32(); } /////////////////////////////////////////////////////////////////////////////// -uint8_t SkKernel33MaskFilter::computeValue(uint8_t* const* srcRows) -{ +uint8_t SkKernel33MaskFilter::computeValue(uint8_t* const* srcRows) { int value = 0; - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { value += fKernel[i][j] * srcRows[i][j]; + } + } value >>= fShift; - if (value < 0) + if (value < 0) { value = 0; - else if (value > 255) + } else if (value > 255) { value = 255; + } return (uint8_t)value; } -void SkKernel33MaskFilter::flatten(SkFlattenableWriteBuffer& wb) -{ +void SkKernel33MaskFilter::flatten(SkFlattenableWriteBuffer& wb) { this->INHERITED::flatten(wb); wb.writeMul4(fKernel, 9 * sizeof(int)); wb.write32(fShift); } -SkFlattenable::Factory SkKernel33MaskFilter::getFactory() -{ +SkFlattenable::Factory SkKernel33MaskFilter::getFactory() { return Create; } -SkFlattenable* SkKernel33MaskFilter::Create(SkFlattenableReadBuffer& rb) -{ +SkFlattenable* SkKernel33MaskFilter::Create(SkFlattenableReadBuffer& rb) { return new SkKernel33MaskFilter(rb); } SkKernel33MaskFilter::SkKernel33MaskFilter(SkFlattenableReadBuffer& rb) - : SkKernel33ProcMaskFilter(rb) -{ + : SkKernel33ProcMaskFilter(rb) { rb.read(fKernel, 9 * sizeof(int)); fShift = rb.readS32(); } |