epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2006 The Android Open Source Project |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 9 | |
| 10 | #include "SkBlurMask.h" |
| 11 | #include "SkTemplates.h" |
| 12 | |
reed@android.com | 4560767 | 2009-09-21 00:27:08 +0000 | [diff] [blame] | 13 | /** The sum buffer is an array of u32 to hold the accumulated sum of all of the |
| 14 | src values at their position, plus all values above and to the left. |
| 15 | When we sample into this buffer, we need an initial row and column of 0s, |
| 16 | so we have an index correspondence as follows: |
| 17 | |
| 18 | src[i, j] == sum[i+1, j+1] |
| 19 | sum[0, j] == sum[i, 0] == 0 |
| 20 | |
| 21 | We assume that the sum buffer's stride == its width |
| 22 | */ |
reed@google.com | 03016a3 | 2011-08-12 14:59:59 +0000 | [diff] [blame] | 23 | static void build_sum_buffer(uint32_t sum[], int srcW, int srcH, |
| 24 | const uint8_t src[], int srcRB) { |
reed@android.com | 4560767 | 2009-09-21 00:27:08 +0000 | [diff] [blame] | 25 | int sumW = srcW + 1; |
| 26 | |
| 27 | SkASSERT(srcRB >= srcW); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 28 | // mod srcRB so we can apply it after each row |
reed@android.com | 4560767 | 2009-09-21 00:27:08 +0000 | [diff] [blame] | 29 | srcRB -= srcW; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 30 | |
| 31 | int x, y; |
| 32 | |
reed@android.com | 4560767 | 2009-09-21 00:27:08 +0000 | [diff] [blame] | 33 | // zero out the top row and column |
| 34 | memset(sum, 0, sumW * sizeof(sum[0])); |
| 35 | sum += sumW; |
| 36 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 37 | // special case first row |
| 38 | uint32_t X = 0; |
reed@android.com | 4560767 | 2009-09-21 00:27:08 +0000 | [diff] [blame] | 39 | *sum++ = 0; // initialze the first column to 0 |
reed@google.com | 03016a3 | 2011-08-12 14:59:59 +0000 | [diff] [blame] | 40 | for (x = srcW - 1; x >= 0; --x) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 41 | X = *src++ + X; |
reed@android.com | 4560767 | 2009-09-21 00:27:08 +0000 | [diff] [blame] | 42 | *sum++ = X; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 43 | } |
| 44 | src += srcRB; |
| 45 | |
| 46 | // now do the rest of the rows |
reed@google.com | 03016a3 | 2011-08-12 14:59:59 +0000 | [diff] [blame] | 47 | for (y = srcH - 1; y > 0; --y) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 48 | uint32_t L = 0; |
| 49 | uint32_t C = 0; |
reed@android.com | 4560767 | 2009-09-21 00:27:08 +0000 | [diff] [blame] | 50 | *sum++ = 0; // initialze the first column to 0 |
reed@google.com | 03016a3 | 2011-08-12 14:59:59 +0000 | [diff] [blame] | 51 | for (x = srcW - 1; x >= 0; --x) { |
reed@android.com | 4560767 | 2009-09-21 00:27:08 +0000 | [diff] [blame] | 52 | uint32_t T = sum[-sumW]; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 53 | X = *src++ + L + T - C; |
reed@android.com | 4560767 | 2009-09-21 00:27:08 +0000 | [diff] [blame] | 54 | *sum++ = X; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 55 | L = X; |
| 56 | C = T; |
| 57 | } |
| 58 | src += srcRB; |
| 59 | } |
| 60 | } |
| 61 | |
reed@google.com | 03016a3 | 2011-08-12 14:59:59 +0000 | [diff] [blame] | 62 | /** |
| 63 | * sw and sh are the width and height of the src. Since the sum buffer |
| 64 | * matches that, but has an extra row and col at the beginning (with zeros), |
| 65 | * we can just use sw and sh as our "max" values for pinning coordinates |
| 66 | * when sampling into sum[][] |
reed@android.com | 4560767 | 2009-09-21 00:27:08 +0000 | [diff] [blame] | 67 | */ |
| 68 | static void apply_kernel(uint8_t dst[], int rx, int ry, const uint32_t sum[], |
| 69 | int sw, int sh) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 70 | uint32_t scale = (1 << 24) / ((2*rx + 1)*(2*ry + 1)); |
| 71 | |
reed@android.com | 4560767 | 2009-09-21 00:27:08 +0000 | [diff] [blame] | 72 | int sumStride = sw + 1; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 73 | |
| 74 | int dw = sw + 2*rx; |
| 75 | int dh = sh + 2*ry; |
| 76 | |
reed@android.com | 4560767 | 2009-09-21 00:27:08 +0000 | [diff] [blame] | 77 | int prev_y = -2*ry; |
| 78 | int next_y = 1; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 79 | |
reed@android.com | 4560767 | 2009-09-21 00:27:08 +0000 | [diff] [blame] | 80 | for (int y = 0; y < dh; y++) { |
| 81 | int py = SkClampPos(prev_y) * sumStride; |
| 82 | int ny = SkFastMin32(next_y, sh) * sumStride; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 83 | |
reed@android.com | 4560767 | 2009-09-21 00:27:08 +0000 | [diff] [blame] | 84 | int prev_x = -2*rx; |
| 85 | int next_x = 1; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 86 | |
reed@android.com | 4560767 | 2009-09-21 00:27:08 +0000 | [diff] [blame] | 87 | for (int x = 0; x < dw; x++) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 88 | int px = SkClampPos(prev_x); |
| 89 | int nx = SkFastMin32(next_x, sw); |
| 90 | |
reed@android.com | 4560767 | 2009-09-21 00:27:08 +0000 | [diff] [blame] | 91 | uint32_t tmp = sum[px+py] + sum[nx+ny] - sum[nx+py] - sum[px+ny]; |
| 92 | *dst++ = SkToU8(tmp * scale >> 24); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 93 | |
| 94 | prev_x += 1; |
| 95 | next_x += 1; |
| 96 | } |
| 97 | prev_y += 1; |
| 98 | next_y += 1; |
| 99 | } |
| 100 | } |
| 101 | |
reed@google.com | 03016a3 | 2011-08-12 14:59:59 +0000 | [diff] [blame] | 102 | /** |
| 103 | * sw and sh are the width and height of the src. Since the sum buffer |
| 104 | * matches that, but has an extra row and col at the beginning (with zeros), |
| 105 | * we can just use sw and sh as our "max" values for pinning coordinates |
| 106 | * when sampling into sum[][] |
reed@android.com | 4560767 | 2009-09-21 00:27:08 +0000 | [diff] [blame] | 107 | */ |
| 108 | static void apply_kernel_interp(uint8_t dst[], int rx, int ry, |
| 109 | const uint32_t sum[], int sw, int sh, U8CPU outer_weight) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 110 | SkASSERT(rx > 0 && ry > 0); |
| 111 | SkASSERT(outer_weight <= 255); |
| 112 | |
| 113 | int inner_weight = 255 - outer_weight; |
| 114 | |
| 115 | // round these guys up if they're bigger than 127 |
| 116 | outer_weight += outer_weight >> 7; |
| 117 | inner_weight += inner_weight >> 7; |
| 118 | |
| 119 | uint32_t outer_scale = (outer_weight << 16) / ((2*rx + 1)*(2*ry + 1)); |
| 120 | uint32_t inner_scale = (inner_weight << 16) / ((2*rx - 1)*(2*ry - 1)); |
| 121 | |
reed@android.com | 4560767 | 2009-09-21 00:27:08 +0000 | [diff] [blame] | 122 | int sumStride = sw + 1; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 123 | |
| 124 | int dw = sw + 2*rx; |
| 125 | int dh = sh + 2*ry; |
| 126 | |
reed@android.com | 4560767 | 2009-09-21 00:27:08 +0000 | [diff] [blame] | 127 | int prev_y = -2*ry; |
| 128 | int next_y = 1; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 129 | |
reed@android.com | 4560767 | 2009-09-21 00:27:08 +0000 | [diff] [blame] | 130 | for (int y = 0; y < dh; y++) { |
| 131 | int py = SkClampPos(prev_y) * sumStride; |
| 132 | int ny = SkFastMin32(next_y, sh) * sumStride; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 133 | |
reed@android.com | 4560767 | 2009-09-21 00:27:08 +0000 | [diff] [blame] | 134 | int ipy = SkClampPos(prev_y + 1) * sumStride; |
| 135 | int iny = SkClampMax(next_y - 1, sh) * sumStride; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 136 | |
reed@android.com | 4560767 | 2009-09-21 00:27:08 +0000 | [diff] [blame] | 137 | int prev_x = -2*rx; |
| 138 | int next_x = 1; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 139 | |
reed@android.com | 4560767 | 2009-09-21 00:27:08 +0000 | [diff] [blame] | 140 | for (int x = 0; x < dw; x++) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 141 | int px = SkClampPos(prev_x); |
| 142 | int nx = SkFastMin32(next_x, sw); |
| 143 | |
| 144 | int ipx = SkClampPos(prev_x + 1); |
| 145 | int inx = SkClampMax(next_x - 1, sw); |
| 146 | |
reed@android.com | 4560767 | 2009-09-21 00:27:08 +0000 | [diff] [blame] | 147 | uint32_t outer_sum = sum[px+py] + sum[nx+ny] - sum[nx+py] - sum[px+ny]; |
| 148 | uint32_t inner_sum = sum[ipx+ipy] + sum[inx+iny] - sum[inx+ipy] - sum[ipx+iny]; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 149 | *dst++ = SkToU8((outer_sum * outer_scale + inner_sum * inner_scale) >> 24); |
| 150 | |
| 151 | prev_x += 1; |
| 152 | next_x += 1; |
| 153 | } |
| 154 | prev_y += 1; |
| 155 | next_y += 1; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | #include "SkColorPriv.h" |
| 160 | |
reed@android.com | 0e3c664 | 2009-09-18 13:41:56 +0000 | [diff] [blame] | 161 | static void merge_src_with_blur(uint8_t dst[], int dstRB, |
| 162 | const uint8_t src[], int srcRB, |
| 163 | const uint8_t blur[], int blurRB, |
| 164 | int sw, int sh) { |
| 165 | dstRB -= sw; |
| 166 | srcRB -= sw; |
| 167 | blurRB -= sw; |
| 168 | while (--sh >= 0) { |
| 169 | for (int x = sw - 1; x >= 0; --x) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 170 | *dst = SkToU8(SkAlphaMul(*blur, SkAlpha255To256(*src))); |
| 171 | dst += 1; |
| 172 | src += 1; |
| 173 | blur += 1; |
| 174 | } |
reed@android.com | 0e3c664 | 2009-09-18 13:41:56 +0000 | [diff] [blame] | 175 | dst += dstRB; |
| 176 | src += srcRB; |
| 177 | blur += blurRB; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 178 | } |
| 179 | } |
| 180 | |
| 181 | static void clamp_with_orig(uint8_t dst[], int dstRowBytes, |
reed@android.com | 0e3c664 | 2009-09-18 13:41:56 +0000 | [diff] [blame] | 182 | const uint8_t src[], int srcRowBytes, |
| 183 | int sw, int sh, |
reed@android.com | 4560767 | 2009-09-21 00:27:08 +0000 | [diff] [blame] | 184 | SkBlurMask::Style style) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 185 | int x; |
reed@android.com | 0e3c664 | 2009-09-18 13:41:56 +0000 | [diff] [blame] | 186 | while (--sh >= 0) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 187 | switch (style) { |
| 188 | case SkBlurMask::kSolid_Style: |
reed@android.com | 0e3c664 | 2009-09-18 13:41:56 +0000 | [diff] [blame] | 189 | for (x = sw - 1; x >= 0; --x) { |
| 190 | int s = *src; |
| 191 | int d = *dst; |
| 192 | *dst = SkToU8(s + d - SkMulDiv255Round(s, d)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 193 | dst += 1; |
| 194 | src += 1; |
| 195 | } |
| 196 | break; |
| 197 | case SkBlurMask::kOuter_Style: |
reed@android.com | 0e3c664 | 2009-09-18 13:41:56 +0000 | [diff] [blame] | 198 | for (x = sw - 1; x >= 0; --x) { |
| 199 | if (*src) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 200 | *dst = SkToU8(SkAlphaMul(*dst, SkAlpha255To256(255 - *src))); |
reed@android.com | 0e3c664 | 2009-09-18 13:41:56 +0000 | [diff] [blame] | 201 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 202 | dst += 1; |
| 203 | src += 1; |
| 204 | } |
| 205 | break; |
| 206 | default: |
| 207 | SkASSERT(!"Unexpected blur style here"); |
| 208 | break; |
| 209 | } |
| 210 | dst += dstRowBytes - sw; |
reed@android.com | 0e3c664 | 2009-09-18 13:41:56 +0000 | [diff] [blame] | 211 | src += srcRowBytes - sw; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 212 | } |
| 213 | } |
| 214 | |
reed@google.com | 03016a3 | 2011-08-12 14:59:59 +0000 | [diff] [blame] | 215 | /////////////////////////////////////////////////////////////////////////////// |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 216 | |
| 217 | // we use a local funciton to wrap the class static method to work around |
| 218 | // a bug in gcc98 |
| 219 | void SkMask_FreeImage(uint8_t* image); |
reed@google.com | 03016a3 | 2011-08-12 14:59:59 +0000 | [diff] [blame] | 220 | void SkMask_FreeImage(uint8_t* image) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 221 | SkMask::FreeImage(image); |
| 222 | } |
| 223 | |
| 224 | bool SkBlurMask::Blur(SkMask* dst, const SkMask& src, |
reed@google.com | 03016a3 | 2011-08-12 14:59:59 +0000 | [diff] [blame] | 225 | SkScalar radius, Style style, Quality quality) { |
| 226 | if (src.fFormat != SkMask::kA8_Format) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 227 | return false; |
reed@google.com | 03016a3 | 2011-08-12 14:59:59 +0000 | [diff] [blame] | 228 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 229 | |
senorblanco@chromium.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 230 | // Force high quality off for small radii (performance) |
| 231 | if (radius < SkIntToScalar(3)) quality = kLow_Quality; |
| 232 | |
| 233 | // highQuality: use three box blur passes as a cheap way to approximate a Gaussian blur |
| 234 | int passCount = (quality == kHigh_Quality) ? 3 : 1; |
| 235 | SkScalar passRadius = SkScalarDiv(radius, SkScalarSqrt(SkIntToScalar(passCount))); |
| 236 | |
| 237 | int rx = SkScalarCeil(passRadius); |
| 238 | int outer_weight = 255 - SkScalarRound((SkIntToScalar(rx) - passRadius) * 255); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 239 | |
| 240 | SkASSERT(rx >= 0); |
| 241 | SkASSERT((unsigned)outer_weight <= 255); |
reed@android.com | 0e3c664 | 2009-09-18 13:41:56 +0000 | [diff] [blame] | 242 | if (rx <= 0) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 243 | return false; |
reed@android.com | 0e3c664 | 2009-09-18 13:41:56 +0000 | [diff] [blame] | 244 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 245 | |
| 246 | int ry = rx; // only do square blur for now |
| 247 | |
senorblanco@chromium.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 248 | int padx = passCount * rx; |
| 249 | int pady = passCount * ry; |
| 250 | dst->fBounds.set(src.fBounds.fLeft - padx, src.fBounds.fTop - pady, |
| 251 | src.fBounds.fRight + padx, src.fBounds.fBottom + pady); |
reed@android.com | 49f0ff2 | 2009-03-19 21:52:42 +0000 | [diff] [blame] | 252 | dst->fRowBytes = dst->fBounds.width(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 253 | dst->fFormat = SkMask::kA8_Format; |
| 254 | dst->fImage = NULL; |
| 255 | |
reed@android.com | 0e3c664 | 2009-09-18 13:41:56 +0000 | [diff] [blame] | 256 | if (src.fImage) { |
reed@android.com | 543ed93 | 2009-04-24 12:43:40 +0000 | [diff] [blame] | 257 | size_t dstSize = dst->computeImageSize(); |
| 258 | if (0 == dstSize) { |
| 259 | return false; // too big to allocate, abort |
| 260 | } |
| 261 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 262 | int sw = src.fBounds.width(); |
| 263 | int sh = src.fBounds.height(); |
| 264 | const uint8_t* sp = src.fImage; |
reed@android.com | 543ed93 | 2009-04-24 12:43:40 +0000 | [diff] [blame] | 265 | uint8_t* dp = SkMask::AllocImage(dstSize); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 266 | |
| 267 | SkAutoTCallVProc<uint8_t, SkMask_FreeImage> autoCall(dp); |
| 268 | |
| 269 | // build the blurry destination |
| 270 | { |
reed@google.com | 03016a3 | 2011-08-12 14:59:59 +0000 | [diff] [blame] | 271 | const size_t storageW = sw + 2 * (passCount - 1) * rx + 1; |
| 272 | const size_t storageH = sh + 2 * (passCount - 1) * ry + 1; |
| 273 | SkAutoTMalloc<uint32_t> storage(storageW * storageH); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 274 | uint32_t* sumBuffer = storage.get(); |
| 275 | |
senorblanco@chromium.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 276 | //pass1: sp is source, dp is destination |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 277 | build_sum_buffer(sumBuffer, sw, sh, sp, src.fRowBytes); |
reed@google.com | 03016a3 | 2011-08-12 14:59:59 +0000 | [diff] [blame] | 278 | if (outer_weight == 255) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 279 | apply_kernel(dp, rx, ry, sumBuffer, sw, sh); |
reed@google.com | 03016a3 | 2011-08-12 14:59:59 +0000 | [diff] [blame] | 280 | } else { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 281 | apply_kernel_interp(dp, rx, ry, sumBuffer, sw, sh, outer_weight); |
reed@google.com | 03016a3 | 2011-08-12 14:59:59 +0000 | [diff] [blame] | 282 | } |
senorblanco@chromium.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 283 | |
reed@google.com | 03016a3 | 2011-08-12 14:59:59 +0000 | [diff] [blame] | 284 | if (quality == kHigh_Quality) { |
senorblanco@chromium.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 285 | //pass2: dp is source, tmpBuffer is destination |
| 286 | int tmp_sw = sw + 2 * rx; |
| 287 | int tmp_sh = sh + 2 * ry; |
| 288 | SkAutoTMalloc<uint8_t> tmpBuffer(dstSize); |
| 289 | build_sum_buffer(sumBuffer, tmp_sw, tmp_sh, dp, tmp_sw); |
| 290 | if (outer_weight == 255) |
| 291 | apply_kernel(tmpBuffer.get(), rx, ry, sumBuffer, tmp_sw, tmp_sh); |
| 292 | else |
reed@google.com | 03016a3 | 2011-08-12 14:59:59 +0000 | [diff] [blame] | 293 | apply_kernel_interp(tmpBuffer.get(), rx, ry, sumBuffer, |
| 294 | tmp_sw, tmp_sh, outer_weight); |
senorblanco@chromium.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 295 | |
| 296 | //pass3: tmpBuffer is source, dp is destination |
| 297 | tmp_sw += 2 * rx; |
| 298 | tmp_sh += 2 * ry; |
| 299 | build_sum_buffer(sumBuffer, tmp_sw, tmp_sh, tmpBuffer.get(), tmp_sw); |
| 300 | if (outer_weight == 255) |
| 301 | apply_kernel(dp, rx, ry, sumBuffer, tmp_sw, tmp_sh); |
| 302 | else |
reed@google.com | 03016a3 | 2011-08-12 14:59:59 +0000 | [diff] [blame] | 303 | apply_kernel_interp(dp, rx, ry, sumBuffer, tmp_sw, tmp_sh, |
| 304 | outer_weight); |
senorblanco@chromium.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 305 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | dst->fImage = dp; |
| 309 | // if need be, alloc the "real" dst (same size as src) and copy/merge |
| 310 | // the blur into it (applying the src) |
reed@android.com | 0e3c664 | 2009-09-18 13:41:56 +0000 | [diff] [blame] | 311 | if (style == kInner_Style) { |
| 312 | // now we allocate the "real" dst, mirror the size of src |
reed@android.com | 543ed93 | 2009-04-24 12:43:40 +0000 | [diff] [blame] | 313 | size_t srcSize = src.computeImageSize(); |
| 314 | if (0 == srcSize) { |
| 315 | return false; // too big to allocate, abort |
| 316 | } |
| 317 | dst->fImage = SkMask::AllocImage(srcSize); |
reed@android.com | 0e3c664 | 2009-09-18 13:41:56 +0000 | [diff] [blame] | 318 | merge_src_with_blur(dst->fImage, src.fRowBytes, |
| 319 | sp, src.fRowBytes, |
reed@google.com | 03016a3 | 2011-08-12 14:59:59 +0000 | [diff] [blame] | 320 | dp + passCount * (rx + ry * dst->fRowBytes), |
| 321 | dst->fRowBytes, sw, sh); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 322 | SkMask::FreeImage(dp); |
reed@android.com | 0e3c664 | 2009-09-18 13:41:56 +0000 | [diff] [blame] | 323 | } else if (style != kNormal_Style) { |
reed@google.com | 03016a3 | 2011-08-12 14:59:59 +0000 | [diff] [blame] | 324 | clamp_with_orig(dp + passCount * (rx + ry * dst->fRowBytes), |
| 325 | dst->fRowBytes, sp, src.fRowBytes, sw, sh, style); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 326 | } |
| 327 | (void)autoCall.detach(); |
| 328 | } |
| 329 | |
reed@android.com | 0e3c664 | 2009-09-18 13:41:56 +0000 | [diff] [blame] | 330 | if (style == kInner_Style) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 331 | dst->fBounds = src.fBounds; // restore trimmed bounds |
reed@android.com | 0e3c664 | 2009-09-18 13:41:56 +0000 | [diff] [blame] | 332 | dst->fRowBytes = src.fRowBytes; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 333 | } |
| 334 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 335 | return true; |
| 336 | } |
| 337 | |