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" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 26 | #include "src/gpu/effects/generated/GrAlphaThresholdFragmentProcessor.h" |
| 27 | #include "src/gpu/effects/generated/GrSimpleTextureEffect.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 |
Robert Phillips | be9aff2 | 2019-02-15 11:33:22 -0500 | [diff] [blame] | 48 | sk_sp<GrTextureProxy> createMaskTexture(GrRecordingContext*, |
robertphillips | d728f0c | 2016-11-21 11:05:03 -0800 | [diff] [blame] | 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) { |
| 70 | innerThreshold = SkScalarPin(innerThreshold, 0.f, 1.f); |
| 71 | outerThreshold = SkScalarPin(outerThreshold, 0.f, 1.f); |
| 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 |
Robert Phillips | be9aff2 | 2019-02-15 11:33:22 -0500 | [diff] [blame] | 103 | sk_sp<GrTextureProxy> SkAlphaThresholdFilterImpl::createMaskTexture(GrRecordingContext* context, |
robertphillips | d728f0c | 2016-11-21 11:05:03 -0800 | [diff] [blame] | 104 | const SkMatrix& inMatrix, |
| 105 | const SkIRect& bounds) const { |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 106 | auto rtContext = context->priv().makeDeferredRenderTargetContextWithFallback( |
| 107 | SkBackingFit::kApprox, bounds.width(), bounds.height(), GrColorType::kAlpha_8, nullptr); |
robertphillips | d728f0c | 2016-11-21 11:05:03 -0800 | [diff] [blame] | 108 | if (!rtContext) { |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 109 | return nullptr; |
| 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 | |
Robert Phillips | f200a90 | 2017-01-30 13:27:37 -0500 | [diff] [blame] | 128 | return rtContext->asTextureProxyRef(); |
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 | |
Robert Phillips | 8e1c4e6 | 2017-02-19 12:27:01 -0500 | [diff] [blame] | 152 | sk_sp<GrTextureProxy> inputProxy(input->asTextureProxyRef(context)); |
| 153 | SkASSERT(inputProxy); |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 154 | const bool isProtected = inputProxy->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 | |
robertphillips | d728f0c | 2016-11-21 11:05:03 -0800 | [diff] [blame] | 164 | sk_sp<GrTextureProxy> maskProxy(this->createMaskTexture(context, matrix, bounds)); |
| 165 | if (!maskProxy) { |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 166 | return nullptr; |
| 167 | } |
| 168 | |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 169 | GrColorType srcColorType = SkColorTypeToGrColorType(input->colorType()); |
| 170 | auto textureFP = GrSimpleTextureEffect::Make(std::move(inputProxy), srcColorType, |
| 171 | SkMatrix::MakeTrans(input->subset().x(), |
| 172 | input->subset().y())); |
Brian Osman | a4aa133 | 2017-10-19 12:54:28 -0400 | [diff] [blame] | 173 | textureFP = GrColorSpaceXformEffect::Make(std::move(textureFP), input->getColorSpace(), |
Michael Ludwig | 03f9ca3 | 2019-08-14 14:35:15 -0400 | [diff] [blame] | 174 | input->alphaType(), ctx.colorSpace()); |
Brian Osman | a4aa133 | 2017-10-19 12:54:28 -0400 | [diff] [blame] | 175 | if (!textureFP) { |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 176 | return nullptr; |
| 177 | } |
| 178 | |
Brian Osman | a4aa133 | 2017-10-19 12:54:28 -0400 | [diff] [blame] | 179 | auto thresholdFP = GrAlphaThresholdFragmentProcessor::Make(std::move(maskProxy), |
| 180 | fInnerThreshold, |
| 181 | fOuterThreshold, |
| 182 | bounds); |
| 183 | if (!thresholdFP) { |
| 184 | return nullptr; |
| 185 | } |
| 186 | |
| 187 | std::unique_ptr<GrFragmentProcessor> fpSeries[] = { std::move(textureFP), |
| 188 | std::move(thresholdFP) }; |
| 189 | auto fp = GrFragmentProcessor::RunInSeries(fpSeries, 2); |
| 190 | |
Michael Ludwig | 03f9ca3 | 2019-08-14 14:35:15 -0400 | [diff] [blame] | 191 | return DrawWithFP(context, std::move(fp), bounds, ctx.colorType(), ctx.colorSpace(), |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 192 | isProtected ? GrProtected::kYes : GrProtected::kNo); |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 193 | } |
| 194 | #endif |
| 195 | |
| 196 | SkBitmap inputBM; |
| 197 | |
| 198 | if (!input->getROPixels(&inputBM)) { |
| 199 | return nullptr; |
| 200 | } |
| 201 | |
| 202 | if (inputBM.colorType() != kN32_SkColorType) { |
| 203 | return nullptr; |
| 204 | } |
| 205 | |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 206 | if (!inputBM.getPixels() || inputBM.width() <= 0 || inputBM.height() <= 0) { |
| 207 | return nullptr; |
| 208 | } |
| 209 | |
| 210 | |
commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 211 | SkMatrix localInverse; |
senorblanco@chromium.org | 4cb543d | 2014-03-14 15:44:01 +0000 | [diff] [blame] | 212 | if (!ctx.ctm().invert(&localInverse)) { |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 213 | return nullptr; |
commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 214 | } |
| 215 | |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 216 | SkImageInfo info = SkImageInfo::MakeN32(bounds.width(), bounds.height(), |
robertphillips | 247e534 | 2016-04-12 12:39:26 -0700 | [diff] [blame] | 217 | kPremul_SkAlphaType); |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 218 | |
| 219 | SkBitmap dst; |
| 220 | if (!dst.tryAllocPixels(info)) { |
| 221 | return nullptr; |
commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 222 | } |
| 223 | |
commit-bot@chromium.org | 9109e18 | 2014-01-07 16:04:01 +0000 | [diff] [blame] | 224 | U8CPU innerThreshold = (U8CPU)(fInnerThreshold * 0xFF); |
| 225 | U8CPU outerThreshold = (U8CPU)(fOuterThreshold * 0xFF); |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 226 | SkColor* dptr = dst.getAddr32(0, 0); |
| 227 | int dstWidth = dst.width(), dstHeight = dst.height(); |
Robert Phillips | 22c57ab | 2016-12-19 16:51:53 -0500 | [diff] [blame] | 228 | SkIPoint srcOffset = { bounds.fLeft - inputOffset.fX, bounds.fTop - inputOffset.fY }; |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 229 | for (int y = 0; y < dstHeight; ++y) { |
Robert Phillips | 22c57ab | 2016-12-19 16:51:53 -0500 | [diff] [blame] | 230 | const SkColor* sptr = inputBM.getAddr32(srcOffset.fX, srcOffset.fY+y); |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 231 | |
| 232 | for (int x = 0; x < dstWidth; ++x) { |
| 233 | const SkColor& source = sptr[x]; |
| 234 | SkColor outputColor(source); |
commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 235 | SkPoint position; |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 236 | 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] | 237 | 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] | 238 | if (SkColorGetA(source) < innerThreshold) { |
| 239 | U8CPU alpha = SkColorGetA(source); |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 240 | if (alpha == 0) { |
commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 241 | alpha = 1; |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 242 | } |
commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 243 | float scale = (float)innerThreshold / alpha; |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 244 | outputColor = SkColorSetARGB(innerThreshold, |
commit-bot@chromium.org | 9109e18 | 2014-01-07 16:04:01 +0000 | [diff] [blame] | 245 | (U8CPU)(SkColorGetR(source) * scale), |
| 246 | (U8CPU)(SkColorGetG(source) * scale), |
| 247 | (U8CPU)(SkColorGetB(source) * scale)); |
commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 248 | } |
| 249 | } else { |
| 250 | if (SkColorGetA(source) > outerThreshold) { |
| 251 | float scale = (float)outerThreshold / SkColorGetA(source); |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 252 | outputColor = SkColorSetARGB(outerThreshold, |
commit-bot@chromium.org | 9109e18 | 2014-01-07 16:04:01 +0000 | [diff] [blame] | 253 | (U8CPU)(SkColorGetR(source) * scale), |
| 254 | (U8CPU)(SkColorGetG(source) * scale), |
| 255 | (U8CPU)(SkColorGetB(source) * scale)); |
commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 256 | } |
| 257 | } |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 258 | dptr[y * dstWidth + x] = outputColor; |
commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 259 | } |
| 260 | } |
| 261 | |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 262 | offset->fX = bounds.left(); |
| 263 | offset->fY = bounds.top(); |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame] | 264 | return SkSpecialImage::MakeFromRaster(SkIRect::MakeWH(bounds.width(), bounds.height()), |
robertphillips | af9b8c8 | 2016-04-12 11:02:25 -0700 | [diff] [blame] | 265 | dst); |
commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 266 | } |