4Copyright 2013 Google Inc.
6Use of this source code is governed by a BSD-style license that can be
7found in the LICENSE file.
11from __future__
import print_function
17 """Returns the percent of samples within n std deviations of the normal."""
18 return math.erf(n / math.sqrt(2))
22 """Returns the percent of samples within the std deviation range a, b"""
51 (
float(subpxl_index)/subpxls_per_pixel + 1.0/(2.0*subpxls_per_pixel))
53 )
for subpxl_index
in range(subpxls_per_pixel)
66for sample_offset, sample_align
in sample_offsets:
71 current_sample_left = sample_offset - sample_units_width
72 current_std_dev_left = -std_dev_max
76 current_sample_right = math.floor(current_sample_left + 1)
77 if current_sample_right > sample_offset + sample_units_width:
79 current_sample_right = sample_offset + sample_units_width
80 current_std_dev_right = current_std_dev_left + (
81 (current_sample_right - current_sample_left) / sample_units_width
85 coeffs.append(coverage * target_sum)
86 coeffs_rounded.append(
int(
round(coverage * target_sum)))
88 current_sample_left = current_sample_right
89 current_std_dev_left = current_std_dev_right
93 coeffs_rounded_sum = sum(coeffs_rounded)
94 if coeffs_rounded_sum > target_sum:
99 if coeffs_rounded_sum < target_sum:
105 print(
"Initial sum is 0x%0.2X, adjusting." % (coeffs_rounded_sum,))
106 coeff_diff = [(coeff_rounded - coeff) * delta
107 for coeff, coeff_rounded
in zip(coeffs, coeffs_rounded)]
114 return self.
item < other.item
116 return "arr[%d] == %s" % (self.
index, repr(self.
item))
118 coeff_pkg = [
IndexTracker(i, diff)
for i, diff
in enumerate(coeff_diff)]
125 num_elements_to_force_round =
abs(coeffs_rounded_sum - target_sum)
126 for i
in xrange(num_elements_to_force_round):
127 print(
"Adding %d to index %d to force round %f." % (
128 delta, coeff_pkg[i].index, coeffs[coeff_pkg[i].index]))
129 coeffs_rounded[coeff_pkg[i].index] += delta
131 print(
"Prepending %d 0x00 for allignment." % (sample_align,))
132 coeffs_rounded_aligned = ([0] *
int(sample_align)) + coeffs_rounded
134 print(
', '.
join([
"0x%0.2X" % coeff_rounded
135 for coeff_rounded
in coeffs_rounded_aligned]))
136 print(sum(coeffs), hex(sum(coeffs_rounded)))
static void round(SkPoint *p)
def withinStdDevRange(a, b)
def print(*args, **kwargs)
SIN Vec< N, float > abs(const Vec< N, float > &x)
static SkString join(const CommandLineFlags::StringArray &)