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" |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 // FIXME: This should be refactored to SkImageFilterUtils for | 258 // FIXME: This should be refactored to SkImageFilterUtils for |
259 // use by other filters. For now, we assume the input is always | 259 // use by other filters. For now, we assume the input is always |
260 // premultiplied and unpremultiply it | 260 // premultiplied and unpremultiply it |
261 static SkBitmap unpremultiplyBitmap(const SkBitmap& src) | 261 static SkBitmap unpremultiplyBitmap(const SkBitmap& src) |
262 { | 262 { |
263 SkAutoLockPixels alp(src); | 263 SkAutoLockPixels alp(src); |
264 if (!src.getPixels()) { | 264 if (!src.getPixels()) { |
265 return SkBitmap(); | 265 return SkBitmap(); |
266 } | 266 } |
267 SkBitmap result; | 267 SkBitmap result; |
268 if (!result.allocPixels(src.info())) { | 268 if (!result.tryAllocPixels(src.info())) { |
269 return SkBitmap(); | 269 return SkBitmap(); |
270 } | 270 } |
271 for (int y = 0; y < src.height(); ++y) { | 271 for (int y = 0; y < src.height(); ++y) { |
272 const uint32_t* srcRow = src.getAddr32(0, y); | 272 const uint32_t* srcRow = src.getAddr32(0, y); |
273 uint32_t* dstRow = result.getAddr32(0, y); | 273 uint32_t* dstRow = result.getAddr32(0, y); |
274 for (int x = 0; x < src.width(); ++x) { | 274 for (int x = 0; x < src.width(); ++x) { |
275 dstRow[x] = SkUnPreMultiply::PMColorToColor(srcRow[x]); | 275 dstRow[x] = SkUnPreMultiply::PMColorToColor(srcRow[x]); |
276 } | 276 } |
277 } | 277 } |
278 return result; | 278 return result; |
(...skipping 21 matching lines...) Expand all Loading... |
300 | 300 |
301 if (!fConvolveAlpha && !src.isOpaque()) { | 301 if (!fConvolveAlpha && !src.isOpaque()) { |
302 src = unpremultiplyBitmap(src); | 302 src = unpremultiplyBitmap(src); |
303 } | 303 } |
304 | 304 |
305 SkAutoLockPixels alp(src); | 305 SkAutoLockPixels alp(src); |
306 if (!src.getPixels()) { | 306 if (!src.getPixels()) { |
307 return false; | 307 return false; |
308 } | 308 } |
309 | 309 |
310 if (!result->allocPixels(src.info().makeWH(bounds.width(), bounds.height()))
) { | 310 if (!result->tryAllocPixels(src.info().makeWH(bounds.width(), bounds.height(
)))) { |
311 return false; | 311 return false; |
312 } | 312 } |
313 | 313 |
314 offset->fX = bounds.fLeft; | 314 offset->fX = bounds.fLeft; |
315 offset->fY = bounds.fTop; | 315 offset->fY = bounds.fTop; |
316 bounds.offset(-srcOffset); | 316 bounds.offset(-srcOffset); |
317 SkIRect interior = SkIRect::MakeXYWH(bounds.left() + fKernelOffset.fX, | 317 SkIRect interior = SkIRect::MakeXYWH(bounds.left() + fKernelOffset.fX, |
318 bounds.top() + fKernelOffset.fY, | 318 bounds.top() + fKernelOffset.fY, |
319 bounds.width() - fKernelSize.fWidth + 1
, | 319 bounds.width() - fKernelSize.fWidth + 1
, |
320 bounds.height() - fKernelSize.fHeight +
1); | 320 bounds.height() - fKernelSize.fHeight +
1); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 fKernelSize, | 376 fKernelSize, |
377 fKernel, | 377 fKernel, |
378 fGain, | 378 fGain, |
379 fBias, | 379 fBias, |
380 fKernelOffset, | 380 fKernelOffset, |
381 convert_tilemodes(fTileMode), | 381 convert_tilemodes(fTileMode), |
382 fConvolveAlpha); | 382 fConvolveAlpha); |
383 return true; | 383 return true; |
384 } | 384 } |
385 #endif | 385 #endif |
OLD | NEW |