OLD | NEW |
1 /* libs/graphics/effects/SkBlurMask.cpp | 1 /* libs/graphics/effects/SkBlurMask.cpp |
2 ** | 2 ** |
3 ** Copyright 2006, The Android Open Source Project | 3 ** Copyright 2006, The Android Open Source Project |
4 ** | 4 ** |
5 ** Licensed under the Apache License, Version 2.0 (the "License"); | 5 ** Licensed under the Apache License, Version 2.0 (the "License"); |
6 ** you may not use this file except in compliance with the License. | 6 ** you may not use this file except in compliance with the License. |
7 ** You may obtain a copy of the License at | 7 ** You may obtain a copy of the License at |
8 ** | 8 ** |
9 ** http://www.apache.org/licenses/LICENSE-2.0 | 9 ** http://www.apache.org/licenses/LICENSE-2.0 |
10 ** | 10 ** |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 int ry = rx; // only do square blur for now | 227 int ry = rx; // only do square blur for now |
228 | 228 |
229 dst->fBounds.set(src.fBounds.fLeft - rx, src.fBounds.fTop - ry, | 229 dst->fBounds.set(src.fBounds.fLeft - rx, src.fBounds.fTop - ry, |
230 src.fBounds.fRight + rx, src.fBounds.fBottom + ry); | 230 src.fBounds.fRight + rx, src.fBounds.fBottom + ry); |
231 dst->fRowBytes = SkToU16(dst->fBounds.width()); | 231 dst->fRowBytes = SkToU16(dst->fBounds.width()); |
232 dst->fFormat = SkMask::kA8_Format; | 232 dst->fFormat = SkMask::kA8_Format; |
233 dst->fImage = NULL; | 233 dst->fImage = NULL; |
234 | 234 |
235 if (src.fImage) | 235 if (src.fImage) |
236 { | 236 { |
| 237 size_t dstSize = dst->computeImageSize(); |
| 238 if (0 == dstSize) { |
| 239 return false; // too big to allocate, abort |
| 240 } |
| 241 |
237 int sw = src.fBounds.width(); | 242 int sw = src.fBounds.width(); |
238 int sh = src.fBounds.height(); | 243 int sh = src.fBounds.height(); |
239 const uint8_t* sp = src.fImage; | 244 const uint8_t* sp = src.fImage; |
240 uint8_t* dp = SkMask::AllocImage(dst->computeImageSize()); | 245 uint8_t* dp = SkMask::AllocImage(dstSize); |
241 | 246 |
242 SkAutoTCallVProc<uint8_t, SkMask_FreeImage> autoCall(dp); | 247 SkAutoTCallVProc<uint8_t, SkMask_FreeImage> autoCall(dp); |
243 | 248 |
244 // build the blurry destination | 249 // build the blurry destination |
245 { | 250 { |
246 SkAutoTMalloc<uint32_t> storage(sw * sh); | 251 SkAutoTMalloc<uint32_t> storage(sw * sh); |
247 uint32_t* sumBuffer = storage.get(); | 252 uint32_t* sumBuffer = storage.get(); |
248 | 253 |
249 build_sum_buffer(sumBuffer, sw, sh, sp, src.fRowBytes); | 254 build_sum_buffer(sumBuffer, sw, sh, sp, src.fRowBytes); |
250 if (outer_weight == 255) | 255 if (outer_weight == 255) |
251 apply_kernel(dp, rx, ry, sumBuffer, sw, sh); | 256 apply_kernel(dp, rx, ry, sumBuffer, sw, sh); |
252 else | 257 else |
253 apply_kernel_interp(dp, rx, ry, sumBuffer, sw, sh, outer_weight)
; | 258 apply_kernel_interp(dp, rx, ry, sumBuffer, sw, sh, outer_weight)
; |
254 } | 259 } |
255 | 260 |
256 dst->fImage = dp; | 261 dst->fImage = dp; |
257 // if need be, alloc the "real" dst (same size as src) and copy/merge | 262 // if need be, alloc the "real" dst (same size as src) and copy/merge |
258 // the blur into it (applying the src) | 263 // the blur into it (applying the src) |
259 if (style == kInner_Style) | 264 if (style == kInner_Style) |
260 { | 265 { |
261 dst->fImage = SkMask::AllocImage(src.computeImageSize()); | 266 size_t srcSize = src.computeImageSize(); |
| 267 if (0 == srcSize) { |
| 268 return false; // too big to allocate, abort |
| 269 } |
| 270 dst->fImage = SkMask::AllocImage(srcSize); |
262 merge_src_with_blur(dst->fImage, sp, sw, sh, | 271 merge_src_with_blur(dst->fImage, sp, sw, sh, |
263 dp + rx + ry*dst->fBounds.width(), | 272 dp + rx + ry*dst->fBounds.width(), |
264 dst->fBounds.width()); | 273 dst->fBounds.width()); |
265 SkMask::FreeImage(dp); | 274 SkMask::FreeImage(dp); |
266 } | 275 } |
267 else if (style != kNormal_Style) | 276 else if (style != kNormal_Style) |
268 { | 277 { |
269 clamp_with_orig(dp + rx + ry*dst->fBounds.width(), | 278 clamp_with_orig(dp + rx + ry*dst->fBounds.width(), |
270 dst->fBounds.width(), | 279 dst->fBounds.width(), |
271 sp, sw, sh, | 280 sp, sw, sh, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 | 332 |
324 for (int i = 0; i < 256; i++) | 333 for (int i = 0; i < 256; i++) |
325 { | 334 { |
326 int square = i * i; | 335 int square = i * i; |
327 int linear = i * 255; | 336 int linear = i * 255; |
328 int n = SkAlphaBlend(square, linear, scale); | 337 int n = SkAlphaBlend(square, linear, scale); |
329 gamma[i] = SkToU8(n * div255 >> 16); | 338 gamma[i] = SkToU8(n * div255 >> 16); |
330 } | 339 } |
331 } | 340 } |
332 #endif | 341 #endif |
OLD | NEW |