src/pixabasic.c
PIXA *
pixaSplitPix(PIX      *pixs,
             l_int32   nx,
             l_int32   ny,
             l_int32   borderwidth,
             l_uint32  bordercolor)
{
l_int32  w, h, d, cellw, cellh, i, j;
PIX     *pixt;
PIXA    *pixa;

    PROCNAME("pixaSplitPix");

    if (!pixs)
        return (PIXA *)ERROR_PTR("pixs not defined", procName, NULL);
    if (nx <= 0 || ny <= 0)
        return (PIXA *)ERROR_PTR("nx and ny must be > 0", procName, NULL);
    borderwidth = L_MAX(0, borderwidth);

    if ((pixa = pixaCreate(nx * ny)) == NULL)
        return (PIXA *)ERROR_PTR("pixa not made", procName, NULL);
    pixGetDimensions(pixs, &w, &h, &d);
    cellw = (w + nx - 1) / nx;  /* round up */
    cellh = (h + ny - 1) / ny;

    for (i = 0; i < ny; i++) {
        for (j = 0; j < nx; j++) {
            if ((pixt = pixCreate(cellw + 2 * borderwidth,
                                  cellh + 2 * borderwidth, d)) == NULL)
                return (PIXA *)ERROR_PTR("pixt not made", procName, NULL);
            pixCopyColormap(pixt, pixs);
            if (borderwidth == 0) {  /* initialize full image to white */
                if (d == 1)
                    pixClearAll(pixt);
                else
                    pixSetAll(pixt);
            }
            else
                pixSetAllArbitrary(pixt, bordercolor);
            pixRasterop(pixt, borderwidth, borderwidth, cellw, cellh,
                        PIX_SRC, pixs, j * cellw, i * cellh);
            pixaAddPix(pixa, pixt, L_INSERT);
        }
    }

    return pixa;
}
/*!
 *  pixaSplitPix()
 *
 *      Input:  pixs  (with individual components on a lattice)
 *              nx   (number of mosaic cells horizontally)
 *              ny   (number of mosaic cells vertically)
 *              borderwidth  (of added border on all sides)
 *              bordercolor  (in our RGBA format: 0xrrggbbaa)
 *      Return: pixa, or null on error
 *
 *  Notes:
 *      (1) This is a variant on pixaCreateFromPix(), where we
 *          simply divide the image up into (approximately) equal
 *          subunits.  If you want the subimages to have essentially
 *          the same aspect ratio as the input pix, use nx = ny.
 *      (2) If borderwidth is 0, we ignore the input bordercolor and
 *          redefine it to white.
 *      (3) The bordercolor is always used to initialize each tiled pix,
 *          so that if the src is clipped, the unblitted part will
 *          be this color.  This avoids 1 pixel wide black stripes at the
 *          left and lower edges.
 */
pixaSplitPix()
Input:  pixs  (with individual components on a lattice)
nx   (number of mosaic cells horizontally)
ny   (number of mosaic cells vertically)
borderwidth  (of added border on all sides)
bordercolor  (in our RGBA format: 0xrrggbbaa)
Return: pixa, or null on error

(1) This is a variant on pixaCreateFromPix(), where we
simply divide the image up into (approximately) equal
subunits.  If you want the subimages to have essentially
the same aspect ratio as the input pix, use nx = ny.
(2) If borderwidth is 0, we ignore the input bordercolor and
redefine it to white.
(3) The bordercolor is always used to initialize each tiled pix,
so that if the src is clipped, the unblitted part will
be this color.  This avoids 1 pixel wide black stripes at the
left and lower edges.
pixaSplitPix () Input : pixs ( with individual components on a lattice ) nx ( number of mosaic cells horizontally ) ny ( number of mosaic cells vertically ) borderwidth ( of added border on all sides ) bordercolor ( in our RGBA format : 0xrrggbbaa ) Return : pixa or null on error ( 1 ) This is a variant on pixaCreateFromPix () where we simply divide the image up into ( approximately ) equal subunits . If you want the subimages to have essentially the same aspect ratio as the input pix use nx = ny . ( 2 ) If borderwidth is 0 we ignore the input bordercolor and redefine it to white . ( 3 ) The bordercolor is always used to initialize each tiled pix so that if the src is clipped the unblitted part will be this color . This avoids 1 pixel wide black stripes at the left and lower edges .
PIXA *
pixaSplitPix(PIX      *pixs,
             l_int32   nx,
             l_int32   ny,
             l_int32   borderwidth,
             l_uint32  bordercolor)
{
l_int32  w, h, d, cellw, cellh, i, j;
PIX     *pixt;
PIXA    *pixa;
    PROCNAME("pixaSplitPix");
    if (!pixs)
        return (PIXA *)ERROR_PTR("pixs not defined", procName, NULL);
    if (nx <= 0 || ny <= 0)
        return (PIXA *)ERROR_PTR("nx and ny must be > 0", procName, NULL);
    borderwidth = L_MAX(0, borderwidth);
    if ((pixa = pixaCreate(nx * ny)) == NULL)
        return (PIXA *)ERROR_PTR("pixa not made", procName, NULL);
    pixGetDimensions(pixs, &w, &h, &d);
    cellw = (w + nx - 1) / nx;  
    cellh = (h + ny - 1) / ny;
    for (i = 0; i < ny; i++) {
        for (j = 0; j < nx; j++) {
            if ((pixt = pixCreate(cellw + 2 * borderwidth,
                                  cellh + 2 * borderwidth, d)) == NULL)
                return (PIXA *)ERROR_PTR("pixt not made", procName, NULL);
            pixCopyColormap(pixt, pixs);
            if (borderwidth == 0) {  
                if (d == 1)
                    pixClearAll(pixt);
                else
                    pixSetAll(pixt);
            }
            else
                pixSetAllArbitrary(pixt, bordercolor);
            pixRasterop(pixt, borderwidth, borderwidth, cellw, cellh,
                        PIX_SRC, pixs, j * cellw, i * cellh);
            pixaAddPix(pixa, pixt, L_INSERT);
        }
    }
    return pixa;
}
PIXA * pixaSplitPix ( PIX * pixs , l_int32 nx , l_int32 ny , l_int32 borderwidth , l_uint32 bordercolor ) { l_int32 w , h , d , cellw , cellh , i , j ; PIX * pixt ; PIXA * pixa ; PROCNAME ( " " ) ; if ( ! pixs ) return ( PIXA * ) ERROR_PTR ( " " , procName , NULL ) ; if ( nx <= 0 || ny <= 0 ) return ( PIXA * ) ERROR_PTR ( " " , procName , NULL ) ; borderwidth = L_MAX ( 0 , borderwidth ) ; if ( ( pixa = pixaCreate ( nx * ny ) ) == NULL ) return ( PIXA * ) ERROR_PTR ( " " , procName , NULL ) ; pixGetDimensions ( pixs , & w , & h , & d ) ; cellw = ( w + nx - 1 ) / nx ; cellh = ( h + ny - 1 ) / ny ; for ( i = 0 ; i < ny ; i ++ ) { for ( j = 0 ; j < nx ; j ++ ) { if ( ( pixt = pixCreate ( cellw + 2 * borderwidth , cellh + 2 * borderwidth , d ) ) == NULL ) return ( PIXA * ) ERROR_PTR ( " " , procName , NULL ) ; pixCopyColormap ( pixt , pixs ) ; if ( borderwidth == 0 ) { if ( d == 1 ) pixClearAll ( pixt ) ; else pixSetAll ( pixt ) ; } else pixSetAllArbitrary ( pixt , bordercolor ) ; pixRasterop ( pixt , borderwidth , borderwidth , cellw , cellh , PIX_SRC , pixs , j * cellw , i * cellh ) ; pixaAddPix ( pixa , pixt , L_INSERT ) ; } } return pixa ; }
pixaSplitPix()
      Input:  pixs  (with individual components on a lattice)
              nx   (number of mosaic cells horizontally)
              ny   (number of mosaic cells vertically)
              borderwidth  (of added border on all sides)
              bordercolor  (in our RGBA format: 0xrrggbbaa)
      Return: pixa, or null on error
pixaSplitPix () Input : pixs ( with individual components on a lattice ) nx ( number of mosaic cells horizontally ) ny ( number of mosaic cells vertically ) borderwidth ( of added border on all sides ) bordercolor ( in our RGBA format : 0xrrggbbaa ) Return : pixa or null on error
/* round up */ /* initialize full image to white */