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 "SkDevice.h" |
11 #include "SkReadBuffer.h" | 12 #include "SkReadBuffer.h" |
12 #include "SkWriteBuffer.h" | 13 #include "SkWriteBuffer.h" |
13 #include "SkRect.h" | 14 #include "SkRect.h" |
14 #include "SkUnPreMultiply.h" | 15 #include "SkUnPreMultiply.h" |
15 | 16 |
16 #if SK_SUPPORT_GPU | 17 #if SK_SUPPORT_GPU |
17 #include "effects/GrMatrixConvolutionEffect.h" | 18 #include "effects/GrMatrixConvolutionEffect.h" |
18 #endif | 19 #endif |
19 | 20 |
20 // We need to be able to read at most SK_MaxS32 bytes, so divide that | 21 // We need to be able to read at most SK_MaxS32 bytes, so divide that |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 break; | 235 break; |
235 case kClampToBlack_TileMode: | 236 case kClampToBlack_TileMode: |
236 filterPixels<ClampToBlackPixelFetcher>(src, result, rect, bounds); | 237 filterPixels<ClampToBlackPixelFetcher>(src, result, rect, bounds); |
237 break; | 238 break; |
238 } | 239 } |
239 } | 240 } |
240 | 241 |
241 // FIXME: This should be refactored to SkImageFilterUtils for | 242 // FIXME: This should be refactored to SkImageFilterUtils for |
242 // use by other filters. For now, we assume the input is always | 243 // use by other filters. For now, we assume the input is always |
243 // premultiplied and unpremultiply it | 244 // premultiplied and unpremultiply it |
244 static SkBitmap unpremultiplyBitmap(const SkBitmap& src) | 245 static SkBitmap unpremultiplyBitmap(SkImageFilter::Proxy* proxy, const SkBitmap&
src) |
245 { | 246 { |
246 SkAutoLockPixels alp(src); | 247 SkAutoLockPixels alp(src); |
247 if (!src.getPixels()) { | 248 if (!src.getPixels()) { |
248 return SkBitmap(); | 249 return SkBitmap(); |
249 } | 250 } |
250 SkBitmap result; | 251 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(src.width(), src.heigh
t())); |
251 if (!result.tryAllocPixels(src.info())) { | 252 if (!device) { |
252 return SkBitmap(); | 253 return SkBitmap(); |
253 } | 254 } |
| 255 SkBitmap result = device->accessBitmap(false); |
| 256 SkAutoLockPixels alp_result(result); |
254 for (int y = 0; y < src.height(); ++y) { | 257 for (int y = 0; y < src.height(); ++y) { |
255 const uint32_t* srcRow = src.getAddr32(0, y); | 258 const uint32_t* srcRow = src.getAddr32(0, y); |
256 uint32_t* dstRow = result.getAddr32(0, y); | 259 uint32_t* dstRow = result.getAddr32(0, y); |
257 for (int x = 0; x < src.width(); ++x) { | 260 for (int x = 0; x < src.width(); ++x) { |
258 dstRow[x] = SkUnPreMultiply::PMColorToColor(srcRow[x]); | 261 dstRow[x] = SkUnPreMultiply::PMColorToColor(srcRow[x]); |
259 } | 262 } |
260 } | 263 } |
261 return result; | 264 return result; |
262 } | 265 } |
263 | 266 |
(...skipping 11 matching lines...) Expand all Loading... |
275 if (src.colorType() != kN32_SkColorType) { | 278 if (src.colorType() != kN32_SkColorType) { |
276 return false; | 279 return false; |
277 } | 280 } |
278 | 281 |
279 SkIRect bounds; | 282 SkIRect bounds; |
280 if (!this->applyCropRect(ctx, proxy, src, &srcOffset, &bounds, &src)) { | 283 if (!this->applyCropRect(ctx, proxy, src, &srcOffset, &bounds, &src)) { |
281 return false; | 284 return false; |
282 } | 285 } |
283 | 286 |
284 if (!fConvolveAlpha && !src.isOpaque()) { | 287 if (!fConvolveAlpha && !src.isOpaque()) { |
285 src = unpremultiplyBitmap(src); | 288 src = unpremultiplyBitmap(proxy, src); |
286 } | 289 } |
287 | 290 |
288 SkAutoLockPixels alp(src); | 291 SkAutoLockPixels alp(src); |
289 if (!src.getPixels()) { | 292 if (!src.getPixels()) { |
290 return false; | 293 return false; |
291 } | 294 } |
292 | 295 |
293 if (!result->tryAllocPixels(src.info().makeWH(bounds.width(), bounds.height(
)))) { | 296 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds
.height())); |
| 297 if (!device) { |
294 return false; | 298 return false; |
295 } | 299 } |
| 300 *result = device->accessBitmap(false); |
| 301 SkAutoLockPixels alp_result(*result); |
296 | 302 |
297 offset->fX = bounds.fLeft; | 303 offset->fX = bounds.fLeft; |
298 offset->fY = bounds.fTop; | 304 offset->fY = bounds.fTop; |
299 bounds.offset(-srcOffset); | 305 bounds.offset(-srcOffset); |
300 SkIRect interior = SkIRect::MakeXYWH(bounds.left() + fKernelOffset.fX, | 306 SkIRect interior = SkIRect::MakeXYWH(bounds.left() + fKernelOffset.fX, |
301 bounds.top() + fKernelOffset.fY, | 307 bounds.top() + fKernelOffset.fY, |
302 bounds.width() - fKernelSize.fWidth + 1
, | 308 bounds.width() - fKernelSize.fWidth + 1
, |
303 bounds.height() - fKernelSize.fHeight +
1); | 309 bounds.height() - fKernelSize.fHeight +
1); |
304 SkIRect top = SkIRect::MakeLTRB(bounds.left(), bounds.top(), bounds.right(),
interior.top()); | 310 SkIRect top = SkIRect::MakeLTRB(bounds.left(), bounds.top(), bounds.right(),
interior.top()); |
305 SkIRect bottom = SkIRect::MakeLTRB(bounds.left(), interior.bottom(), | 311 SkIRect bottom = SkIRect::MakeLTRB(bounds.left(), interior.bottom(), |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 str->appendf("%f ", fKernel[y * fKernelSize.width() + x]); | 382 str->appendf("%f ", fKernel[y * fKernelSize.width() + x]); |
377 } | 383 } |
378 } | 384 } |
379 str->appendf(")"); | 385 str->appendf(")"); |
380 str->appendf("gain: %f bias: %f ", fGain, fBias); | 386 str->appendf("gain: %f bias: %f ", fGain, fBias); |
381 str->appendf("offset: (%d, %d) ", fKernelOffset.fX, fKernelOffset.fY); | 387 str->appendf("offset: (%d, %d) ", fKernelOffset.fX, fKernelOffset.fY); |
382 str->appendf("convolveAlpha: %s", fConvolveAlpha ? "true" : "false"); | 388 str->appendf("convolveAlpha: %s", fConvolveAlpha ? "true" : "false"); |
383 str->append(")"); | 389 str->append(")"); |
384 } | 390 } |
385 #endif | 391 #endif |
OLD | NEW |