commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/effects/SkAlphaThresholdFilter.h" |
robertphillips | f624204 | 2016-04-01 10:34:43 -0700 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/core/SkBitmap.h" |
| 11 | #include "include/core/SkRegion.h" |
Michael Ludwig | 8ee6cf3 | 2019-08-02 09:57:04 -0400 | [diff] [blame] | 12 | #include "src/core/SkImageFilter_Base.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "src/core/SkReadBuffer.h" |
| 14 | #include "src/core/SkSpecialImage.h" |
| 15 | #include "src/core/SkWriteBuffer.h" |
robertphillips | f7142e7 | 2016-04-18 07:20:05 -0700 | [diff] [blame] | 16 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 17 | #if SK_SUPPORT_GPU |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 18 | #include "include/gpu/GrContext.h" |
| 19 | #include "include/private/GrRecordingContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 20 | #include "src/gpu/GrCaps.h" |
| 21 | #include "src/gpu/GrColorSpaceXform.h" |
| 22 | #include "src/gpu/GrFixedClip.h" |
| 23 | #include "src/gpu/GrRecordingContextPriv.h" |
| 24 | #include "src/gpu/GrRenderTargetContext.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 25 | #include "src/gpu/GrTextureProxy.h" |
Brian Salomon | b8f098d | 2020-01-07 11:15:44 -0500 | [diff] [blame] | 26 | #include "src/gpu/effects/GrTextureEffect.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 27 | #include "src/gpu/effects/generated/GrAlphaThresholdFragmentProcessor.h" |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 28 | #endif |
commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 29 | |
Michael Ludwig | d668f7f | 2019-07-30 10:03:16 -0400 | [diff] [blame] | 30 | namespace { |
| 31 | |
Michael Ludwig | 8ee6cf3 | 2019-08-02 09:57:04 -0400 | [diff] [blame] | 32 | class SkAlphaThresholdFilterImpl final : public SkImageFilter_Base { |
commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 33 | public: |
senorblanco | 9ea3d57 | 2014-07-08 09:16:22 -0700 | [diff] [blame] | 34 | SkAlphaThresholdFilterImpl(const SkRegion& region, SkScalar innerThreshold, |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 35 | SkScalar outerThreshold, sk_sp<SkImageFilter> input, |
Michael Ludwig | a00318f | 2019-08-01 09:30:33 -0400 | [diff] [blame] | 36 | const CropRect* cropRect = nullptr) |
| 37 | : INHERITED(&input, 1, cropRect) |
| 38 | , fRegion(region) |
| 39 | , fInnerThreshold(innerThreshold) |
| 40 | , fOuterThreshold(outerThreshold) {} |
commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 41 | |
| 42 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 43 | void flatten(SkWriteBuffer&) const override; |
commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 44 | |
Michael Ludwig | e30a485 | 2019-08-14 14:35:42 -0400 | [diff] [blame] | 45 | sk_sp<SkSpecialImage> onFilterImage(const Context&, SkIPoint* offset) const override; |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 46 | |
commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 47 | #if SK_SUPPORT_GPU |
Greg Daniel | 4395612 | 2020-02-11 15:49:27 -0500 | [diff] [blame] | 48 | GrSurfaceProxyView createMaskTexture(GrRecordingContext*, |
| 49 | const SkMatrix&, |
| 50 | const SkIRect& bounds) const; |
commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 51 | #endif |
| 52 | |
| 53 | private: |
Michael Ludwig | a00318f | 2019-08-01 09:30:33 -0400 | [diff] [blame] | 54 | friend void SkAlphaThresholdFilter::RegisterFlattenables(); |
Mike Klein | 4fee323 | 2018-10-18 17:27:16 -0400 | [diff] [blame] | 55 | SK_FLATTENABLE_HOOKS(SkAlphaThresholdFilterImpl) |
| 56 | |
commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 57 | SkRegion fRegion; |
| 58 | SkScalar fInnerThreshold; |
| 59 | SkScalar fOuterThreshold; |
Michael Ludwig | a00318f | 2019-08-01 09:30:33 -0400 | [diff] [blame] | 60 | |
Michael Ludwig | 8ee6cf3 | 2019-08-02 09:57:04 -0400 | [diff] [blame] | 61 | typedef SkImageFilter_Base INHERITED; |
commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 62 | }; |
| 63 | |
Michael Ludwig | d668f7f | 2019-07-30 10:03:16 -0400 | [diff] [blame] | 64 | }; // end namespace |
| 65 | |
Michael Ludwig | a00318f | 2019-08-01 09:30:33 -0400 | [diff] [blame] | 66 | sk_sp<SkImageFilter> SkAlphaThresholdFilter::Make(const SkRegion& region, SkScalar innerThreshold, |
| 67 | SkScalar outerThreshold, |
| 68 | sk_sp<SkImageFilter> input, |
| 69 | const SkImageFilter::CropRect* cropRect) { |
Brian Osman | aba642c | 2020-02-06 12:52:25 -0500 | [diff] [blame] | 70 | innerThreshold = SkTPin(innerThreshold, 0.f, 1.f); |
| 71 | outerThreshold = SkTPin(outerThreshold, 0.f, 1.f); |
Michael Ludwig | a00318f | 2019-08-01 09:30:33 -0400 | [diff] [blame] | 72 | if (!SkScalarIsFinite(innerThreshold) || !SkScalarIsFinite(outerThreshold)) { |
| 73 | return nullptr; |
| 74 | } |
| 75 | return sk_sp<SkImageFilter>(new SkAlphaThresholdFilterImpl( |
| 76 | region, innerThreshold, outerThreshold, std::move(input), cropRect)); |
| 77 | } |
| 78 | |
Mike Klein | fa5f6ce | 2018-10-20 08:21:31 -0400 | [diff] [blame] | 79 | void SkAlphaThresholdFilter::RegisterFlattenables() { |
Brian Salomon | 2335644 | 2018-11-30 15:33:19 -0500 | [diff] [blame] | 80 | SK_REGISTER_FLATTENABLE(SkAlphaThresholdFilterImpl); |
Mike Klein | 1295672 | 2018-10-19 10:00:21 -0400 | [diff] [blame] | 81 | } |
halcanary | 0745653 | 2015-12-07 10:29:54 -0800 | [diff] [blame] | 82 | |
Michael Ludwig | a00318f | 2019-08-01 09:30:33 -0400 | [diff] [blame] | 83 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 84 | |
reed | 60c9b58 | 2016-04-03 09:11:13 -0700 | [diff] [blame] | 85 | sk_sp<SkFlattenable> SkAlphaThresholdFilterImpl::CreateProc(SkReadBuffer& buffer) { |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 86 | SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); |
| 87 | SkScalar inner = buffer.readScalar(); |
| 88 | SkScalar outer = buffer.readScalar(); |
| 89 | SkRegion rgn; |
| 90 | buffer.readRegion(&rgn); |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 91 | return SkAlphaThresholdFilter::Make(rgn, inner, outer, common.getInput(0), |
| 92 | &common.cropRect()); |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 93 | } |
commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 94 | |
Michael Ludwig | a00318f | 2019-08-01 09:30:33 -0400 | [diff] [blame] | 95 | void SkAlphaThresholdFilterImpl::flatten(SkWriteBuffer& buffer) const { |
| 96 | this->INHERITED::flatten(buffer); |
| 97 | buffer.writeScalar(fInnerThreshold); |
| 98 | buffer.writeScalar(fOuterThreshold); |
| 99 | buffer.writeRegion(fRegion); |
commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | #if SK_SUPPORT_GPU |
Greg Daniel | 4395612 | 2020-02-11 15:49:27 -0500 | [diff] [blame] | 103 | GrSurfaceProxyView SkAlphaThresholdFilterImpl::createMaskTexture(GrRecordingContext* context, |
| 104 | const SkMatrix& inMatrix, |
| 105 | const SkIRect& bounds) const { |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 106 | auto rtContext = GrRenderTargetContext::MakeWithFallback( |
| 107 | context, GrColorType::kAlpha_8, nullptr, SkBackingFit::kApprox, bounds.size()); |
robertphillips | d728f0c | 2016-11-21 11:05:03 -0800 | [diff] [blame] | 108 | if (!rtContext) { |
Greg Daniel | 4395612 | 2020-02-11 15:49:27 -0500 | [diff] [blame] | 109 | return {}; |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 110 | } |
| 111 | |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 112 | SkRegion::Iterator iter(fRegion); |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 113 | rtContext->clear(nullptr, SK_PMColor4fTRANSPARENT, |
| 114 | GrRenderTargetContext::CanClearFullscreen::kYes); |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 115 | |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 116 | GrFixedClip clip(SkIRect::MakeWH(bounds.width(), bounds.height())); |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 117 | while (!iter.done()) { |
Mike Klein | 1688507 | 2018-12-11 09:54:31 -0500 | [diff] [blame] | 118 | GrPaint paint; |
| 119 | paint.setPorterDuffXPFactory(SkBlendMode::kSrc); |
| 120 | |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 121 | SkRect rect = SkRect::Make(iter.rect()); |
Mike Klein | 1688507 | 2018-12-11 09:54:31 -0500 | [diff] [blame] | 122 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 123 | rtContext->drawRect(clip, std::move(paint), GrAA::kNo, inMatrix, rect); |
Mike Klein | 1688507 | 2018-12-11 09:54:31 -0500 | [diff] [blame] | 124 | |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 125 | iter.next(); |
| 126 | } |
| 127 | |
Greg Daniel | 4395612 | 2020-02-11 15:49:27 -0500 | [diff] [blame] | 128 | return rtContext->readSurfaceView(); |
commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 129 | } |
| 130 | #endif |
| 131 | |
Michael Ludwig | e30a485 | 2019-08-14 14:35:42 -0400 | [diff] [blame] | 132 | sk_sp<SkSpecialImage> SkAlphaThresholdFilterImpl::onFilterImage(const Context& ctx, |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 133 | SkIPoint* offset) const { |
| 134 | SkIPoint inputOffset = SkIPoint::Make(0, 0); |
Michael Ludwig | e30a485 | 2019-08-14 14:35:42 -0400 | [diff] [blame] | 135 | sk_sp<SkSpecialImage> input(this->filterInput(0, ctx, &inputOffset)); |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 136 | if (!input) { |
| 137 | return nullptr; |
commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 138 | } |
| 139 | |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 140 | const SkIRect inputBounds = SkIRect::MakeXYWH(inputOffset.x(), inputOffset.y(), |
| 141 | input->width(), input->height()); |
| 142 | |
| 143 | SkIRect bounds; |
| 144 | if (!this->applyCropRect(ctx, inputBounds, &bounds)) { |
| 145 | return nullptr; |
| 146 | } |
| 147 | |
| 148 | #if SK_SUPPORT_GPU |
Michael Ludwig | e30a485 | 2019-08-14 14:35:42 -0400 | [diff] [blame] | 149 | if (ctx.gpuBacked()) { |
| 150 | auto context = ctx.getContext(); |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 151 | |
Greg Daniel | 37c127f | 2020-02-05 10:37:27 -0500 | [diff] [blame] | 152 | GrSurfaceProxyView inputView = (input->view(context)); |
Greg Daniel | 8354717 | 2020-01-29 11:11:03 -0500 | [diff] [blame] | 153 | SkASSERT(inputView.asTextureProxy()); |
| 154 | const GrProtected isProtected = inputView.proxy()->isProtected(); |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 155 | |
| 156 | offset->fX = bounds.left(); |
| 157 | offset->fY = bounds.top(); |
| 158 | |
| 159 | bounds.offset(-inputOffset); |
| 160 | |
| 161 | SkMatrix matrix(ctx.ctm()); |
Robert Phillips | dcf1fb4 | 2018-04-10 17:50:44 -0400 | [diff] [blame] | 162 | matrix.postTranslate(SkIntToScalar(-offset->fX), SkIntToScalar(-offset->fY)); |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 163 | |
Greg Daniel | 4395612 | 2020-02-11 15:49:27 -0500 | [diff] [blame] | 164 | GrSurfaceProxyView maskView = this->createMaskTexture(context, matrix, bounds); |
| 165 | if (!maskView) { |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 166 | return nullptr; |
| 167 | } |
| 168 | |
Brian Salomon | b8f098d | 2020-01-07 11:15:44 -0500 | [diff] [blame] | 169 | auto textureFP = GrTextureEffect::Make( |
Greg Daniel | d2ccbb5 | 2020-02-05 10:45:39 -0500 | [diff] [blame] | 170 | std::move(inputView), input->alphaType(), |
Mike Reed | c80ee45 | 2020-05-21 16:05:02 +0000 | [diff] [blame] | 171 | SkMatrix::MakeTrans(input->subset().x(), input->subset().y())); |
Brian Osman | a4aa133 | 2017-10-19 12:54:28 -0400 | [diff] [blame] | 172 | textureFP = GrColorSpaceXformEffect::Make(std::move(textureFP), input->getColorSpace(), |
Michael Ludwig | 03f9ca3 | 2019-08-14 14:35:15 -0400 | [diff] [blame] | 173 | input->alphaType(), ctx.colorSpace()); |
Brian Osman | a4aa133 | 2017-10-19 12:54:28 -0400 | [diff] [blame] | 174 | if (!textureFP) { |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 175 | return nullptr; |
| 176 | } |
| 177 | |
Greg Daniel | 4395612 | 2020-02-11 15:49:27 -0500 | [diff] [blame] | 178 | auto thresholdFP = GrAlphaThresholdFragmentProcessor::Make( |
| 179 | std::move(maskView), fInnerThreshold, fOuterThreshold, bounds); |
Brian Osman | a4aa133 | 2017-10-19 12:54:28 -0400 | [diff] [blame] | 180 | if (!thresholdFP) { |
| 181 | return nullptr; |
| 182 | } |
| 183 | |
| 184 | std::unique_ptr<GrFragmentProcessor> fpSeries[] = { std::move(textureFP), |
| 185 | std::move(thresholdFP) }; |
| 186 | auto fp = GrFragmentProcessor::RunInSeries(fpSeries, 2); |
| 187 | |
Michael Ludwig | 03f9ca3 | 2019-08-14 14:35:15 -0400 | [diff] [blame] | 188 | return DrawWithFP(context, std::move(fp), bounds, ctx.colorType(), ctx.colorSpace(), |
Greg Daniel | ca9dbe2 | 2020-01-02 13:44:30 -0500 | [diff] [blame] | 189 | isProtected); |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 190 | } |
| 191 | #endif |
| 192 | |
| 193 | SkBitmap inputBM; |
| 194 | |
| 195 | if (!input->getROPixels(&inputBM)) { |
| 196 | return nullptr; |
| 197 | } |
| 198 | |
| 199 | if (inputBM.colorType() != kN32_SkColorType) { |
| 200 | return nullptr; |
| 201 | } |
| 202 | |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 203 | if (!inputBM.getPixels() || inputBM.width() <= 0 || inputBM.height() <= 0) { |
| 204 | return nullptr; |
| 205 | } |
| 206 | |
| 207 | |
commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 208 | SkMatrix localInverse; |
senorblanco@chromium.org | 4cb543d | 2014-03-14 15:44:01 +0000 | [diff] [blame] | 209 | if (!ctx.ctm().invert(&localInverse)) { |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 210 | return nullptr; |
commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 211 | } |
| 212 | |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 213 | SkImageInfo info = SkImageInfo::MakeN32(bounds.width(), bounds.height(), |
robertphillips | 247e534 | 2016-04-12 12:39:26 -0700 | [diff] [blame] | 214 | kPremul_SkAlphaType); |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 215 | |
| 216 | SkBitmap dst; |
| 217 | if (!dst.tryAllocPixels(info)) { |
| 218 | return nullptr; |
commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 219 | } |
| 220 | |
commit-bot@chromium.org | 9109e18 | 2014-01-07 16:04:01 +0000 | [diff] [blame] | 221 | U8CPU innerThreshold = (U8CPU)(fInnerThreshold * 0xFF); |
| 222 | U8CPU outerThreshold = (U8CPU)(fOuterThreshold * 0xFF); |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 223 | SkColor* dptr = dst.getAddr32(0, 0); |
| 224 | int dstWidth = dst.width(), dstHeight = dst.height(); |
Robert Phillips | 22c57ab | 2016-12-19 16:51:53 -0500 | [diff] [blame] | 225 | SkIPoint srcOffset = { bounds.fLeft - inputOffset.fX, bounds.fTop - inputOffset.fY }; |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 226 | for (int y = 0; y < dstHeight; ++y) { |
Robert Phillips | 22c57ab | 2016-12-19 16:51:53 -0500 | [diff] [blame] | 227 | const SkColor* sptr = inputBM.getAddr32(srcOffset.fX, srcOffset.fY+y); |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 228 | |
| 229 | for (int x = 0; x < dstWidth; ++x) { |
| 230 | const SkColor& source = sptr[x]; |
| 231 | SkColor outputColor(source); |
commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 232 | SkPoint position; |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 233 | localInverse.mapXY((SkScalar)x + bounds.fLeft, (SkScalar)y + bounds.fTop, &position); |
commit-bot@chromium.org | 9109e18 | 2014-01-07 16:04:01 +0000 | [diff] [blame] | 234 | if (fRegion.contains((int32_t)position.x(), (int32_t)position.y())) { |
commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 235 | if (SkColorGetA(source) < innerThreshold) { |
| 236 | U8CPU alpha = SkColorGetA(source); |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 237 | if (alpha == 0) { |
commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 238 | alpha = 1; |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 239 | } |
commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 240 | float scale = (float)innerThreshold / alpha; |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 241 | outputColor = SkColorSetARGB(innerThreshold, |
commit-bot@chromium.org | 9109e18 | 2014-01-07 16:04:01 +0000 | [diff] [blame] | 242 | (U8CPU)(SkColorGetR(source) * scale), |
| 243 | (U8CPU)(SkColorGetG(source) * scale), |
| 244 | (U8CPU)(SkColorGetB(source) * scale)); |
commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 245 | } |
| 246 | } else { |
| 247 | if (SkColorGetA(source) > outerThreshold) { |
| 248 | float scale = (float)outerThreshold / SkColorGetA(source); |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 249 | outputColor = SkColorSetARGB(outerThreshold, |
commit-bot@chromium.org | 9109e18 | 2014-01-07 16:04:01 +0000 | [diff] [blame] | 250 | (U8CPU)(SkColorGetR(source) * scale), |
| 251 | (U8CPU)(SkColorGetG(source) * scale), |
| 252 | (U8CPU)(SkColorGetB(source) * scale)); |
commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 253 | } |
| 254 | } |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 255 | dptr[y * dstWidth + x] = outputColor; |
commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 256 | } |
| 257 | } |
| 258 | |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 259 | offset->fX = bounds.left(); |
| 260 | offset->fY = bounds.top(); |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame] | 261 | return SkSpecialImage::MakeFromRaster(SkIRect::MakeWH(bounds.width(), bounds.height()), |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 262 | dst); |
commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 263 | } |