@@ -58,6 +58,146 @@ static int dilateMask(const uint8_t *src, int src_y_stride, uint8_t *dst, int ra
5858// radii is 254 pixels.
5959void dilateDistanceXY (const uint8_t *src, uint8_t *dst, int xradius, int yradius, int width, int height, int & r_new_width, int & r_new_height)
6060{
61+ /*
62+ int new_width = width + 2 * xradius;
63+ int new_height = height + 2 * yradius;
64+
65+ // Compute the x distance of each pixel from the nearest set pixel.
66+ uint8_t *xd;
67+ xd = new uint8_t[new_width * height];
68+ for(int y = 0; y < height; y++)
69+ {
70+ uint8_t *xdptr;
71+ xdptr = xd + new_width * y;
72+
73+ const uint8_t *sptr;
74+ sptr = src + width * y;
75+ for(int x = 0; x < width; x++)
76+ {
77+ // If there is a value at x, take it
78+ if (sptr[x] != 0)
79+ {
80+ xdptr[x + xradius] = 0;
81+ continue;
82+ }
83+
84+ // Otherwise search back...
85+ int db;
86+ db = 255;
87+ for(int z = x; z >= 0 && (x - z) < 255; z--)
88+ {
89+ if (sptr[z] != 0)
90+ {
91+ db = x - z;
92+ break;
93+ }
94+ }
95+
96+ // Now search forwards...
97+ int df;
98+ df = 255;
99+ for(int z = x; (z < width) && (z - x) < 255; z++)
100+ {
101+ if (sptr[z] != 0)
102+ {
103+ df = z - x;
104+ break;
105+ }
106+ }
107+
108+ // Distance is the minimum.
109+ int d;
110+ d = SkMin32(db, df);
111+ xdptr[x + xradius] = d;
112+ }
113+
114+ // Now expand the fringes.
115+ for(int x = 0; x < xradius; x++)
116+ {
117+ if (xdptr[xradius] + (xradius - x) < 255)
118+ xdptr[x] = ((xradius - x) + xdptr[xradius]);
119+ else
120+ xdptr[x] = 255;
121+
122+ if (xdptr[width + xradius - 1] + x + 1 < 255)
123+ xdptr[width + xradius + x] = xdptr[width + xradius - 1] + x + 1;
124+ else
125+ xdptr[width + xradius + x] = 255;
126+ }
127+ }
128+
129+ unsigned int rf;
130+ rf = xradius * xradius * yradius * yradius;
131+
132+ memset(dst, 0, new_width * new_height);
133+
134+ // Now use xd to compute the spread mask.
135+ for(int x = 0; x < new_width; x++)
136+ {
137+ for(int y = 0; y < new_height; y++)
138+ {
139+ uint8_t *dptr = dst + y * new_width + x;
140+
141+ // If the distance at x, y is 0 then we are done.
142+ if (y >= yradius && y < (new_height - yradius) && xd[(y - yradius) * new_width + x] == 0)
143+ {
144+ *dptr = 255;
145+ continue;
146+ }
147+
148+ // Otherwise, search up.
149+ *dptr = 0;
150+ for(int z = y; z >= 0; z--)
151+ {
152+ unsigned int yf;
153+ yf = (y - z) * xradius;
154+ yf *= yf;
155+ if (yf >= rf)
156+ break;
157+
158+ unsigned int xf;
159+ if (z >= yradius && z < (new_height - yradius))
160+ xf = yradius * xd[(z - yradius) * new_width + x];
161+ else
162+ xf = yradius * 255;
163+ xf *= xf;
164+ if (xf < rf - yf)
165+ {
166+ *dptr = 255;
167+ break;
168+ }
169+ }
170+
171+ if (*dptr == 255)
172+ continue;
173+
174+ // Search downwards
175+ for(int z = y; z < new_height; z++)
176+ {
177+ unsigned int yf;
178+ yf = (z - y) * xradius;
179+ yf *= yf;
180+ if (yf >= rf)
181+ break;
182+
183+ unsigned int xf;
184+ if (z >= yradius && z < (new_height - yradius))
185+ xf = yradius * xd[(z - yradius) * new_width + x];
186+ else
187+ xf = yradius * 255;
188+ xf *= xf;
189+ if (xf < rf - yf)
190+ {
191+ *dptr = 255;
192+ break;
193+ }
194+ }
195+ }
196+ }
197+
198+ r_new_width = new_width;
199+ r_new_height = new_height;
200+ */
61201 int new_width = width + 2 * xradius;
62202 int new_height = height + 2 * yradius;
63203
0 commit comments