252l_int32 wpix, hpix, wt, ht, nx, ny;
253l_int32 xoverlap, yoverlap, wtlast, htlast;
254l_int32 left, top, xtraleft, xtraright, xtratop, xtrabot, width, height;
256PIX *pixs, *pixt, *pixd;
259 return (
PIX *)ERROR_PTR(
"pt not defined", __func__, NULL);
260 if ((pixs = pt->
pix) == NULL)
261 return (
PIX *)ERROR_PTR(
"pix not found", __func__, NULL);
263 if (i < 0 || i >= ny)
264 return (
PIX *)ERROR_PTR(
"invalid row index i", __func__, NULL);
265 if (j < 0 || j >= nx)
266 return (
PIX *)ERROR_PTR(
"invalid column index j", __func__, NULL);
270 pixGetDimensions(pixs, &wpix, &hpix, NULL);
274 wtlast = wpix - wt * (nx - 1);
275 htlast = hpix - ht * (ny - 1);
276 left = L_MAX(0, j * wt - xoverlap);
277 top = L_MAX(0, i * ht - yoverlap);
284 width = wt + xoverlap;
285 else if (j == nx - 1)
286 width = wtlast + xoverlap;
288 width = wt + 2 * xoverlap;
293 height = ht + yoverlap;
294 else if (i == ny - 1)
295 height = htlast + yoverlap;
297 height = ht + 2 * yoverlap;
298 box = boxCreate(left, top, width, height);
299 pixt = pixClipRectangle(pixs, box, NULL);
303 if (xoverlap == 0 && yoverlap == 0)
310 xtratop = xtrabot = xtraleft = xtraright = 0;
312 xtraleft = xtraright = xoverlap;
314 xtratop = xtrabot = yoverlap;
315 if (i == 0 && j == 0)
316 pixd = pixAddMirroredBorder(pixt, xoverlap, xtraright,
318 else if (i == 0 && j == nx - 1)
319 pixd = pixAddMirroredBorder(pixt, xtraleft, xoverlap,
321 else if (i == ny - 1 && j == 0)
322 pixd = pixAddMirroredBorder(pixt, xoverlap, xtraright,
324 else if (i == ny - 1 && j == nx - 1)
325 pixd = pixAddMirroredBorder(pixt, xtraleft, xoverlap,
328 pixd = pixAddMirroredBorder(pixt, 0, 0, yoverlap, xtrabot);
329 else if (i == ny - 1)
330 pixd = pixAddMirroredBorder(pixt, 0, 0, xtratop, yoverlap);
332 pixd = pixAddMirroredBorder(pixt, xoverlap, xtraright, 0, 0);
333 else if (j == nx - 1)
334 pixd = pixAddMirroredBorder(pixt, xtraleft, xoverlap, 0, 0);
336 pixd = pixClone(pixt);