src/pixtiling.c
PIXTILING *
pixTilingCreate(PIX     *pixs,
		l_int32  nx,
		l_int32  ny,
		l_int32  w,
		l_int32  h,
		l_int32  xoverlap,
                l_int32  yoverlap)
{
l_int32     width, height;
PIXTILING  *pt;

    PROCNAME("pixTilingCreate");

    if (!pixs)
        return (PIXTILING *)ERROR_PTR("pixs not defined", procName, NULL);
    if (nx < 1 && w < 1)
        return (PIXTILING *)ERROR_PTR("invalid width spec", procName, NULL);
    if (ny < 1 && h < 1)
        return (PIXTILING *)ERROR_PTR("invalid height spec", procName, NULL);

        /* Find the tile width and number of tiles.  All tiles except the
         * rightmost ones have the same width.  The width of the
         * rightmost ones are at least the width of the others and
         * less than twice that width.  Ditto for tile height. */
    pixGetDimensions(pixs, &width, &height, NULL);
    if (nx == 0)
        nx = L_MAX(1, width / w);
    w = width / nx;  /* possibly reset */
    if (ny == 0)
        ny = L_MAX(1, height / h);
    h = height / ny;  /* possibly reset */
    if (xoverlap > w || yoverlap > h) {
        L_INFO_INT2("tile width = %d, tile height = %d", procName, w, h);
        return (PIXTILING *)ERROR_PTR("overlap too large", procName, NULL);
    }

    if ((pt = (PIXTILING *)CALLOC(1, sizeof(PIXTILING))) == NULL)
        return (PIXTILING *)ERROR_PTR("pt not made", procName, NULL);
    pt->pix = pixClone(pixs);
    pt->xoverlap = xoverlap;
    pt->yoverlap = yoverlap;
    pt->nx = nx;
    pt->ny = ny;
    pt->w = w;
    pt->h = h;
    pt->strip = TRUE;
    return pt;
}
/*!
 *  pixTilingCreate()
 *
 *      Input:  pixs  (pix to be tiled; any depth; colormap OK)
 *              nx    (number of tiles across image)
 *              ny    (number of tiles down image)
 *              w     (desired width of each tile)
 *              h     (desired height of each tile)
 *              overlap (amount of overlap into neighboring tile on each side)
 *      Return: pixtiling, or null on error
 *
 *  Notes:
 *      (1) We put a clone of pixs in the PixTiling.
 *      (2) The input to pixTilingCreate() for horizontal tiling can be
 *          either the number of tiles across the image or the approximate
 *          width of the tiles.  If the latter, the actual width will be
 *          determined by making all tiles but the last of equal width, and
 *          making the last as close to the others as possible.  The same
 *          consideration is applied independently to the vertical tiling.
 *          To specify tile width, set nx = 0; to specify the number of
 *          tiles horizontally across the image, set w = 0.
 *      (3) If pixs is to be tiled in one-dimensional strips, use ny = 1 for
 *          vertical strips and nx = 1 for horizontal strips.
 *      (4) The overlap must not be larger than the width or height of
 *          the leftmost or topmost tile(s).
 */


(1) We put a clone of pixs in the PixTiling.
(2) The input to pixTilingCreate() for horizontal tiling can be
either the number of tiles across the image or the approximate
width of the tiles.  If the latter, the actual width will be
determined by making all tiles but the last of equal width, and
making the last as close to the others as possible.  The same
consideration is applied independently to the vertical tiling.
To specify tile width, set nx = 0; to specify the number of
tiles horizontally across the image, set w = 0.
(3) If pixs is to be tiled in one-dimensional strips, use ny = 1 for
vertical strips and nx = 1 for horizontal strips.
(4) The overlap must not be larger than the width or height of
the leftmost or topmost tile(s).
( 1 ) We put a clone of pixs in the PixTiling . ( 2 ) The input to pixTilingCreate () for horizontal tiling can be either the number of tiles across the image or the approximate width of the tiles . If the latter the actual width will be determined by making all tiles but the last of equal width and making the last as close to the others as possible . The same consideration is applied independently to the vertical tiling . To specify tile width set nx = 0 ; to specify the number of tiles horizontally across the image set w = 0 . ( 3 ) If pixs is to be tiled in one - dimensional strips use ny = 1 for vertical strips and nx = 1 for horizontal strips . ( 4 ) The overlap must not be larger than the width or height of the leftmost or topmost tile ( s ) .
PIXTILING *
pixTilingCreate(PIX     *pixs,
		l_int32  nx,
		l_int32  ny,
		l_int32  w,
		l_int32  h,
		l_int32  xoverlap,
                l_int32  yoverlap)
{
l_int32     width, height;
PIXTILING  *pt;
    PROCNAME("pixTilingCreate");
    if (!pixs)
        return (PIXTILING *)ERROR_PTR("pixs not defined", procName, NULL);
    if (nx < 1 && w < 1)
        return (PIXTILING *)ERROR_PTR("invalid width spec", procName, NULL);
    if (ny < 1 && h < 1)
        return (PIXTILING *)ERROR_PTR("invalid height spec", procName, NULL);
    pixGetDimensions(pixs, &width, &height, NULL);
    if (nx == 0)
        nx = L_MAX(1, width / w);
    w = width / nx;  
    if (ny == 0)
        ny = L_MAX(1, height / h);
    h = height / ny;  
    if (xoverlap > w || yoverlap > h) {
        L_INFO_INT2("tile width = %d, tile height = %d", procName, w, h);
        return (PIXTILING *)ERROR_PTR("overlap too large", procName, NULL);
    }
    if ((pt = (PIXTILING *)CALLOC(1, sizeof(PIXTILING))) == NULL)
        return (PIXTILING *)ERROR_PTR("pt not made", procName, NULL);
    pt->pix = pixClone(pixs);
    pt->xoverlap = xoverlap;
    pt->yoverlap = yoverlap;
    pt->nx = nx;
    pt->ny = ny;
    pt->w = w;
    pt->h = h;
    pt->strip = TRUE;
    return pt;
}
PIXTILING * pixTilingCreate ( PIX * pixs , l_int32 nx , l_int32 ny , l_int32 w , l_int32 h , l_int32 xoverlap , l_int32 yoverlap ) { l_int32 width , height ; PIXTILING * pt ; PROCNAME ( " " ) ; if ( ! pixs ) return ( PIXTILING * ) ERROR_PTR ( " " , procName , NULL ) ; if ( nx < 1 && w < 1 ) return ( PIXTILING * ) ERROR_PTR ( " " , procName , NULL ) ; if ( ny < 1 && h < 1 ) return ( PIXTILING * ) ERROR_PTR ( " " , procName , NULL ) ; pixGetDimensions ( pixs , & width , & height , NULL ) ; if ( nx == 0 ) nx = L_MAX ( 1 , width / w ) ; w = width / nx ; if ( ny == 0 ) ny = L_MAX ( 1 , height / h ) ; h = height / ny ; if ( xoverlap > w || yoverlap > h ) { L_INFO_INT2 ( " " , procName , w , h ) ; return ( PIXTILING * ) ERROR_PTR ( " " , procName , NULL ) ; } if ( ( pt = ( PIXTILING * ) CALLOC ( 1 , sizeof ( PIXTILING ) ) ) == NULL ) return ( PIXTILING * ) ERROR_PTR ( " " , procName , NULL ) ; pt -> pix = pixClone ( pixs ) ; pt -> xoverlap = xoverlap ; pt -> yoverlap = yoverlap ; pt -> nx = nx ; pt -> ny = ny ; pt -> w = w ; pt -> h = h ; pt -> strip = TRUE ; return pt ; }
pixTilingCreate()
      Input:  pixs  (pix to be tiled; any depth; colormap OK)
              nx    (number of tiles across image)
              ny    (number of tiles down image)
              w     (desired width of each tile)
              h     (desired height of each tile)
              overlap (amount of overlap into neighboring tile on each side)
      Return: pixtiling, or null on error
pixTilingCreate () Input : pixs ( pix to be tiled ; any depth ; colormap OK ) nx ( number of tiles across image ) ny ( number of tiles down image ) w ( desired width of each tile ) h ( desired height of each tile ) overlap ( amount of overlap into neighboring tile on each side ) Return : pixtiling or null on error
/* Find the tile width and number of tiles.  All tiles except the
         * rightmost ones have the same width.  The width of the
         * rightmost ones are at least the width of the others and
         * less than twice that width.  Ditto for tile height. */ /* possibly reset */ /* possibly reset */