static uint8_t* create_half_plane_profile(int profileWidth) { SkASSERT(!(profileWidth & 0x1)); // The full kernel is 6 sigmas wide. float sigma = profileWidth / 6.f; int halfKernelSize = profileWidth / 2; SkAutoTArray<float> halfKernel(halfKernelSize); uint8_t* profile = new uint8_t[profileWidth]; // The half kernel should sum to 0.5. const float tot = 2.f * make_unnormalized_half_kernel(halfKernel.get(), halfKernelSize, sigma); float sum = 0.f; // Populate the profile from the right edge to the middle. for (int i = 0; i < halfKernelSize; ++i) { halfKernel[halfKernelSize - i - 1] /= tot; sum += halfKernel[halfKernelSize - i - 1]; profile[profileWidth - i - 1] = SkUnitScalarClampToByte(sum); } // Populate the profile from the middle to the left edge (by flipping the half kernel and // continuing the summation). for (int i = 0; i < halfKernelSize; ++i) { sum += halfKernel[i]; profile[halfKernelSize - i - 1] = SkUnitScalarClampToByte(sum); } // Ensure tail goes to 0. profile[profileWidth - 1] = 0; return profile; }
static uint8_t* create_profile(float halfWH, float sigma) { int kernelWH = SkScalarCeilToInt(6.0f*sigma); kernelWH = (kernelWH + 1) & ~1; // make it the next even number up SkAutoTArray<float> halfKernel(kernelWH*kernelWH/2); make_half_kernel(halfKernel.get(), kernelWH, sigma); float offset; int numSteps; compute_profile_offset_and_size(halfWH, sigma, &offset, &numSteps); uint8_t* weights = new uint8_t[numSteps]; for (int i = 0; i < numSteps; ++i) { weights[i] = eval_at(offset+i, halfWH, halfKernel.get(), kernelWH); } return weights; }