| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 The Android Open Source Project | 2 * Copyright 2012 The Android Open Source Project |
| 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 "SkMatrixConvolutionImageFilter.h" | 8 #include "SkMatrixConvolutionImageFilter.h" |
| 9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| 11 #include "SkNx.h" |
| 11 #include "SkReadBuffer.h" | 12 #include "SkReadBuffer.h" |
| 12 #include "SkSpecialImage.h" | 13 #include "SkSpecialImage.h" |
| 13 #include "SkSpecialSurface.h" | 14 #include "SkSpecialSurface.h" |
| 14 #include "SkWriteBuffer.h" | 15 #include "SkWriteBuffer.h" |
| 15 #include "SkRect.h" | 16 #include "SkRect.h" |
| 16 #include "SkUnPreMultiply.h" | 17 #include "SkUnPreMultiply.h" |
| 17 | 18 |
| 18 #if SK_SUPPORT_GPU | 19 #if SK_SUPPORT_GPU |
| 19 #include "GrContext.h" | 20 #include "GrContext.h" |
| 20 #include "GrDrawContext.h" | 21 #include "GrDrawContext.h" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 SkBitmap* result, | 168 SkBitmap* result, |
| 168 const SkIRect& r, | 169 const SkIRect& r, |
| 169 const SkIRect& bounds) const { | 170 const SkIRect& bounds) const { |
| 170 SkIRect rect(r); | 171 SkIRect rect(r); |
| 171 if (!rect.intersect(bounds)) { | 172 if (!rect.intersect(bounds)) { |
| 172 return; | 173 return; |
| 173 } | 174 } |
| 174 for (int y = rect.fTop; y < rect.fBottom; ++y) { | 175 for (int y = rect.fTop; y < rect.fBottom; ++y) { |
| 175 SkPMColor* dptr = result->getAddr32(rect.fLeft - bounds.fLeft, y - bound
s.fTop); | 176 SkPMColor* dptr = result->getAddr32(rect.fLeft - bounds.fLeft, y - bound
s.fTop); |
| 176 for (int x = rect.fLeft; x < rect.fRight; ++x) { | 177 for (int x = rect.fLeft; x < rect.fRight; ++x) { |
| 177 SkScalar sumA = 0, sumR = 0, sumG = 0, sumB = 0; | 178 Sk4s sum = 0; |
| 178 for (int cy = 0; cy < fKernelSize.fHeight; cy++) { | 179 for (int cy = 0; cy < fKernelSize.fHeight; cy++) { |
| 179 for (int cx = 0; cx < fKernelSize.fWidth; cx++) { | 180 for (int cx = 0; cx < fKernelSize.fWidth; cx++) { |
| 180 SkPMColor s = PixelFetcher::fetch(src, | 181 SkPMColor s = PixelFetcher::fetch(src, |
| 181 x + cx - fKernelOffset.fX, | 182 x + cx - fKernelOffset.fX, |
| 182 y + cy - fKernelOffset.fY, | 183 y + cy - fKernelOffset.fY, |
| 183 bounds); | 184 bounds); |
| 184 SkScalar k = fKernel[cy * fKernelSize.fWidth + cx]; | 185 SkScalar k = fKernel[cy * fKernelSize.fWidth + cx]; |
| 185 if (convolveAlpha) { | 186 |
| 186 sumA += SkScalarMul(SkIntToScalar(SkGetPackedA32(s)), k)
; | 187 sum += k * SkNx_cast<SkScalar>(Sk4b::Load(&s)); |
| 187 } | |
| 188 sumR += SkScalarMul(SkIntToScalar(SkGetPackedR32(s)), k); | |
| 189 sumG += SkScalarMul(SkIntToScalar(SkGetPackedG32(s)), k); | |
| 190 sumB += SkScalarMul(SkIntToScalar(SkGetPackedB32(s)), k); | |
| 191 } | 188 } |
| 192 } | 189 } |
| 193 int a = convolveAlpha | 190 Sk4s d = Sk4s::Max(0, Sk4s::Min(sum * fGain + fBias, 255.0f)); |
| 194 ? SkClampMax(SkScalarFloorToInt(SkScalarMul(sumA, fGain) + fBi
as), 255) | 191 |
| 195 : 255; | 192 if (convolveAlpha) { |
| 196 int r = SkClampMax(SkScalarFloorToInt(SkScalarMul(sumR, fGain) + fBi
as), a); | 193 d = Sk4s::Min(d, d[3]); |
| 197 int g = SkClampMax(SkScalarFloorToInt(SkScalarMul(sumG, fGain) + fBi
as), a); | |
| 198 int b = SkClampMax(SkScalarFloorToInt(SkScalarMul(sumB, fGain) + fBi
as), a); | |
| 199 if (!convolveAlpha) { | |
| 200 a = SkGetPackedA32(PixelFetcher::fetch(src, x, y, bounds)); | |
| 201 *dptr++ = SkPreMultiplyARGB(a, r, g, b); | |
| 202 } else { | 194 } else { |
| 203 *dptr++ = SkPackARGB32(a, r, g, b); | 195 SkScalar a01 = (1/255.0f) * SkGetPackedA32(PixelFetcher::fetch(s
rc, x, y, bounds)); |
| 196 d = Sk4s{d[0],d[1],d[2], 255} * a01; |
| 204 } | 197 } |
| 198 SkNx_cast<uint8_t>(d).store(dptr++); |
| 205 } | 199 } |
| 206 } | 200 } |
| 207 } | 201 } |
| 208 | 202 |
| 209 template<class PixelFetcher> | 203 template<class PixelFetcher> |
| 210 void SkMatrixConvolutionImageFilter::filterPixels(const SkBitmap& src, | 204 void SkMatrixConvolutionImageFilter::filterPixels(const SkBitmap& src, |
| 211 SkBitmap* result, | 205 SkBitmap* result, |
| 212 const SkIRect& rect, | 206 const SkIRect& rect, |
| 213 const SkIRect& bounds) const { | 207 const SkIRect& bounds) const { |
| 214 if (fConvolveAlpha) { | 208 if (fConvolveAlpha) { |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 str->appendf("%f ", fKernel[y * fKernelSize.width() + x]); | 408 str->appendf("%f ", fKernel[y * fKernelSize.width() + x]); |
| 415 } | 409 } |
| 416 } | 410 } |
| 417 str->appendf(")"); | 411 str->appendf(")"); |
| 418 str->appendf("gain: %f bias: %f ", fGain, fBias); | 412 str->appendf("gain: %f bias: %f ", fGain, fBias); |
| 419 str->appendf("offset: (%d, %d) ", fKernelOffset.fX, fKernelOffset.fY); | 413 str->appendf("offset: (%d, %d) ", fKernelOffset.fX, fKernelOffset.fY); |
| 420 str->appendf("convolveAlpha: %s", fConvolveAlpha ? "true" : "false"); | 414 str->appendf("convolveAlpha: %s", fConvolveAlpha ? "true" : "false"); |
| 421 str->append(")"); | 415 str->append(")"); |
| 422 } | 416 } |
| 423 #endif | 417 #endif |
| OLD | NEW |