ImageGear for C and C++ on Linux v18.8 - Updated
Padding
User Guide > How to Work with... > Formats with Additional Functionality > TIFF, MODCA, and IOCA > Tiled Images > Padding

Those areas of tiles that are on the border of an image, but are not completely filled with image data, are filled with padding. The image below illustrates a tiled image and shows padding to the right side and bottom of the image. Padding to the right and bottom of the image is the most frequent tiled storage situation that you will encounter:

When ImageGear loads a tiled image (or any image) it reads the header or tag data to find out the width and height of the actual image. This data will not include the padding. As ImageGear loads the file, it discards the padding. The following ImageGear-supported file formats allow the use of tiled storage: TIFF, IBM IOCA, and IBM MO:DCA. Currently, the highest level of control given to you for working with tiled images is for the TIFF format, which will be mentioned frequently throughout this section.

If you were to call IG_load_file() to load a tiled image, it would load the first tile of the first page. If you want to load more than one tile and stitch them together, you should call one of the IG_load_tiles_stitch ...() functions. In addition to loading and stitching any number of tiles, ImageGear also allows you to query the tiles of an image before loading it, tell ImageGear which tiles to "stitch together" when loading, and how to tile the image when you save it to disk.

If you wish to specify which tiles of a TIFF image to load and stitch, your first task will be to find out whether the image actually has tiles or not. The function IG_tile_count_get() can be called to get this information. This function returns the number of tiles per row, and the number of tiles per column. If this function returns zeros for the number of tiles across the image (lpTileCols) and the number of tiles down the length of the image (lpTileRows), you will know that the image is not tiled. There are two other versions of this function: if you have already opened a TIFF file and have a File Descriptor handle for it, use the function IG_tile_count_get_FD(); if the file has already been loaded into memory (using IG_load_mem()), use the function IG_tile_count_get_mem().

The following ImageGear functions can be used to load and stitch TIFF tiles:

 
Copy Code
AT_ERRCOUNT ACCUAPI IG_load_tiles_stitch(const LPSTR lpszFileName, UINT nPage,
LPAT_STITCH lpStitch, LPHIGEAR lphIGear);
AT_ERRCOUNT ACCUAPI IG_load_tiles_stitch_FD(INT fd, LONG lOffset, UINT nPage,
LPAT_STITCH lpStitch, LPHIGEAR lphIGear);
AT_ERRCOUNT ACCUAPI IG_load_tiles_stitch_mem(LPVOID lpImage, DWORD dwImageSize, UINT
nPage, LPAT_STITCH lpStitch, LPHIGEAR lphIGear);

Each function takes a page number that specifies which page of a multi-page file to load. Set this to 1 if it is not a multi-page file. Each also takes a structure of type AT_STITCH that will tell ImageGear which tiles to stitch together and load. Here is the definition of AT_STITCH:

 
Copy Code
typedef struct tagAT_STITCH
{
LONG uRefTile; /* Upper left-hand corner tile # */
LONG uTileRows; /* Number of tiles to stitch across*/
LONG uTileCols; /* Number of tiles to stitch down */
}AT_STITCH, FAR *LPAT_STITCH;

Set the structure member uRefTile to the number of the tile that you would like to be used as the upper left-most tile in the image that will be loaded and stitched. Set uTileRows to the number of tiles across that you would like your stitched image to use. Set uTileCols to the number of columns of tiles that you would like your stitched image to use. If you wish to stitch all tiles together, simply pass in a NULL for this structure.

Below are some examples of how a tiled image can be stitched together. Figure 1 shows a tiled TIFF image that contains a total of 9 tiles. Note that for simplicity, the tiles are shown to evenly cover the exact height and width of the image. This rarely happens.

The numbering scheme in Figure 1 reflects the way that ImageGear keeps track of the tiles. When you refer to specific tiles, the upper-left-most tile will be 1. The tiles are then numbered sequentially from left to right, top to bottom.

Figure 1: TIFF image with 9 tiles. The numbering scheme shown is the same one you should use when interfacing with tiles using ImageGear.

Figure 2 shows all of the tiles stitched together, which would be the result if you set the AT_STITCH structure to NULL.

Figure 2: All of the tiles are loaded and stitched together.

The following call achieves the results shown in Figure 2:

 
Copy Code
IG_load_tiles_stitch("KidsKatz.tif", 1, NULL, &hIGear)

Figure 3: Tiles 5, 6, 8, and 9 are loaded and stitched together.

To achieve the results shown in Figure 3, make the following calls:

 
Copy Code
AT_STITCH stitchStruct;
HIGEAR hIGear;
stitchStruct.uRefTile = 5;
stitchStruct.uTileRows = 2;
stitchStruct.uTileCols = 2;IG_load_tiles_stitch("KidsKatz.tif", 1, &stitchStruct, &hIGear)

You may want to find out the width and height of the tiles in the image so that you can make an informed decision about which tiles to load. First use the function IG_info_get_ex() which will return the width and height of the image. Then divide the width of the image by the number of tiles per row, and the height of the image by the number of tiles per column. To get the height and width of an image that is already opened and for which you have a File Descriptor handle, call IG_info_get_FD_ex(); to get the height and width of an image that has been loaded into memory and for which you have a HIGEAR handle, call IG_info_get_mem_ex().